github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/encoding/ethereum.go (about) 1 package encoding 2 3 import ( 4 "math/big" 5 "strings" 6 7 "github.com/hyperledger/burrow/encoding/web3hex" 8 ) 9 10 // Convert Burrow's ChainID to a *big.Int so it can be used as a nonce for Ethereum signing. 11 // For compatibility with Ethereum tooling this function first tries to interpret the ChainID as an integer encoded 12 // either as an eth-style 0x-prefixed hex string or a base 10 integer, falling back to interpreting the string's 13 // raw bytes as a big-endian integer 14 func GetEthChainID(chainID string) *big.Int { 15 if strings.HasPrefix(chainID, "0x") { 16 d := new(web3hex.Decoder) 17 b := d.BigInt(chainID) 18 if d.Err() == nil { 19 return b 20 } 21 } 22 b := new(big.Int) 23 id, ok := b.SetString(chainID, 10) 24 if ok { 25 return id 26 } 27 return b.SetBytes([]byte(chainID)) 28 }