github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/calls/contracts/forwarder/forwarder.go (about) 1 package forwarder 2 3 import ( 4 "math/big" 5 "strings" 6 7 "github.com/ChainSafe/chainbridge-core/chains/evm/calls" 8 "github.com/ChainSafe/chainbridge-core/chains/evm/calls/consts" 9 "github.com/ChainSafe/chainbridge-core/chains/evm/calls/contracts" 10 "github.com/ethereum/go-ethereum/accounts/abi" 11 "github.com/ethereum/go-ethereum/common" 12 ) 13 14 // ForwarderContract matches an instance of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/MinimalForwarder.sol 15 type ForwarderContract struct { 16 contracts.Contract 17 } 18 19 type ForwardRequest struct { 20 From common.Address 21 To common.Address 22 Value *big.Int 23 Gas *big.Int 24 Nonce *big.Int 25 Data []byte 26 } 27 28 func NewForwarderContract( 29 client calls.ContractCallerDispatcher, 30 contractAddress common.Address, 31 ) *ForwarderContract { 32 a, _ := abi.JSON(strings.NewReader(consts.MinimalForwarderABI)) 33 b := common.FromHex(consts.MinimalForwarderBin) 34 return &ForwarderContract{ 35 contracts.NewContract(contractAddress, a, b, client, nil), 36 } 37 } 38 39 func (c *ForwarderContract) GetNonce(from common.Address) (*big.Int, error) { 40 res, err := c.CallContract("getNonce", from) 41 if err != nil { 42 return nil, err 43 } 44 45 nonce := abi.ConvertType(res[0], new(big.Int)).(*big.Int) 46 return nonce, nil 47 } 48 49 func (c *ForwarderContract) PrepareExecute( 50 forwardReq ForwardRequest, 51 sig []byte, 52 ) ([]byte, error) { 53 return c.ABI.Pack("execute", forwardReq, sig) 54 }