diff --git a/contracts.go b/contracts.go index e30fb86..9c51b89 100644 --- a/contracts.go +++ b/contracts.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" ) @@ -22,29 +21,21 @@ type Contract interface { fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (tx *types.Transaction, err error) + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (tx *types.Transaction, err error) // Pack packs the method and arguments into a byte array representing // the smart contract call data Pack( - wallet *Wallet, method string, arguments json.RawMessage) ([]byte, error) // Parse parses the arguments as JSON format into an array of smart // contract function call arguments Parse( - wallet *Wallet, method string, arguments json.RawMessage) ([]interface{}, error) - - // EstimateGasLimit estimates the gas limit for a smart contract method call - EstimateGasLimit( - wallet *Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) } // ContractFactory is a function that takes an address and return a Contract instance diff --git a/contracts/feralfile-airdrop-v1/airdrop.go b/contracts/feralfile-airdrop-v1/airdrop.go index ffa85b6..c932a1b 100644 --- a/contracts/feralfile-airdrop-v1/airdrop.go +++ b/contracts/feralfile-airdrop-v1/airdrop.go @@ -1,14 +1,12 @@ package airdropv1 import ( - "context" "encoding/json" "fmt" "math/big" ethereum "github.com/bitmark-inc/account-vault-ethereum" airdropv1 "github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding/feralfile-airdrop-v1" - goEthereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" @@ -66,8 +64,9 @@ func (c *FeralFileAirdropV1Contract) Call( fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (*types.Transaction, error) { + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contractAddr := common.HexToAddress(c.contractAddress) contract, err := airdropv1.NewFeralFileAirdropV1( contractAddr, @@ -82,15 +81,16 @@ func (c *FeralFileAirdropV1Contract) Call( } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -111,12 +111,6 @@ func (c *FeralFileAirdropV1Contract) Call( return nil, fmt.Errorf("invalid amount") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit return contract.Mint(t, tokenID, amount) case "airdrop": if len(params) != 2 { @@ -133,13 +127,6 @@ func (c *FeralFileAirdropV1Contract) Call( return nil, fmt.Errorf("invalid to address") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.Airdrop(t, tokenID, to) } @@ -147,7 +134,6 @@ func (c *FeralFileAirdropV1Contract) Call( } func (c *FeralFileAirdropV1Contract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := airdropv1.FeralFileAirdropV1MetaData.GetAbi() @@ -155,7 +141,7 @@ func (c *FeralFileAirdropV1Contract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -164,7 +150,6 @@ func (c *FeralFileAirdropV1Contract) Pack( } func (c *FeralFileAirdropV1Contract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { @@ -198,29 +183,6 @@ func (c *FeralFileAirdropV1Contract) Parse( } } -func (c *FeralFileAirdropV1Contract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - data, err := c.Pack(wallet, method, arguments) - if nil != err { - return 0, err - } - - gas, err := wallet.RPCClient().EstimateGas(context.Background(), goEthereum.CallMsg{ - From: common.HexToAddress(wallet.Account()), - To: &contractAddr, - Data: data, - }) - - if nil != err { - return 0, err - } - - return gas * 115 / 100, nil // add 15% buffer -} - func init() { ethereum.RegisterContract("FeralFileAirdropV1", FeralFileAirdropV1ContractFactory) } diff --git a/contracts/feralfile-english-auction/english_auction.go b/contracts/feralfile-english-auction/english_auction.go index 790df3d..6296bac 100644 --- a/contracts/feralfile-english-auction/english_auction.go +++ b/contracts/feralfile-english-auction/english_auction.go @@ -1,7 +1,6 @@ package english_auction import ( - "context" "encoding/hex" "encoding/json" "errors" @@ -10,7 +9,6 @@ import ( "strconv" "strings" - goEthereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" @@ -60,8 +58,9 @@ func (c *FeralfileEnglishAuctionContract) Call( fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (*types.Transaction, error) { + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contractAddr := common.HexToAddress(c.contractAddress) contract, err := english_auction.NewFeralfileEnglishAuction(contractAddr, wallet.RPCClient()) if err != nil { @@ -73,15 +72,16 @@ func (c *FeralfileEnglishAuctionContract) Call( } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -97,13 +97,6 @@ func (c *FeralfileEnglishAuctionContract) Call( return nil, fmt.Errorf("invalid auctions params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.RegisterAuctions(t, auctions) case "placeSignedBid": if len(params) != 7 { @@ -213,7 +206,6 @@ func (c *FeralfileEnglishAuctionContract) Call( } func (c *FeralfileEnglishAuctionContract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := english_auction.FeralfileEnglishAuctionMetaData.GetAbi() @@ -221,7 +213,7 @@ func (c *FeralfileEnglishAuctionContract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -230,7 +222,6 @@ func (c *FeralfileEnglishAuctionContract) Pack( } func (c *FeralfileEnglishAuctionContract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { @@ -402,29 +393,6 @@ func (c *FeralfileEnglishAuctionContract) Parse( } } -func (c *FeralfileEnglishAuctionContract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - data, err := c.Pack(wallet, method, arguments) - if nil != err { - return 0, err - } - - gas, err := wallet.RPCClient().EstimateGas(context.Background(), goEthereum.CallMsg{ - From: common.HexToAddress(wallet.Account()), - To: &contractAddr, - Data: data, - }) - - if nil != err { - return 0, err - } - - return gas * 115 / 100, nil // add 15% buffer -} - func init() { ethereum.RegisterContract("FeralfileEnglishAuction", FeralfileEnglishAuctionFactory) } diff --git a/contracts/feralfile-exhibition-v2/feralfile.go b/contracts/feralfile-exhibition-v2/feralfile.go index 84afeae..20819f8 100644 --- a/contracts/feralfile-exhibition-v2/feralfile.go +++ b/contracts/feralfile-exhibition-v2/feralfile.go @@ -1,12 +1,10 @@ package feralfilev2 import ( - "context" "encoding/json" "fmt" "math/big" - goEthereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" @@ -66,8 +64,9 @@ func (c *FeralfileExhibitionV2Contract) Call( fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (*types.Transaction, error) { + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contractAddr := common.HexToAddress(c.contractAddress) contract, err := feralfilev2.NewFeralfileExhibitionV2(contractAddr, wallet.RPCClient()) if err != nil { @@ -80,21 +79,22 @@ func (c *FeralfileExhibitionV2Contract) Call( } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } switch method { - case "create_artwork": + case "createArtwork": if len(params) != 4 { return nil, fmt.Errorf("invalid params") } @@ -125,7 +125,7 @@ func (c *FeralfileExhibitionV2Contract) Call( title, artistName, editionSize) - case "swap_artwork_from_bitmark": + case "swapArtworkFromBitmark": if len(params) != 5 { return nil, fmt.Errorf("invalid params") } @@ -155,13 +155,6 @@ func (c *FeralfileExhibitionV2Contract) Call( return nil, fmt.Errorf("invalid ipfs cid params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SwapArtworkFromBitmark( t, artworkID, @@ -184,19 +177,12 @@ func (c *FeralfileExhibitionV2Contract) Call( return nil, fmt.Errorf("invalid token id params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SafeTransferFrom( t, common.HexToAddress(wallet.Account()), to, tokenID) - case "approve_for_all": + case "setApprovalForAll": if len(params) != 1 { return nil, fmt.Errorf("invalid params") } @@ -206,13 +192,6 @@ func (c *FeralfileExhibitionV2Contract) Call( return nil, fmt.Errorf("invalid operator params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SetApprovalForAll(t, operator, true) default: return nil, fmt.Errorf("unsupported method") @@ -220,7 +199,6 @@ func (c *FeralfileExhibitionV2Contract) Call( } func (c *FeralfileExhibitionV2Contract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := feralfilev2.FeralfileExhibitionV2MetaData.GetAbi() @@ -228,33 +206,19 @@ func (c *FeralfileExhibitionV2Contract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } - switch method { - case "create_artwork": - method = "createArtwork" - case "swap_artwork_from_bitmark": - method = "swapArtworkFromBitmark" - case "transfer": - method = "safeTransferFrom" - case "approve_for_all": - method = "setApprovalForAll" - default: - return nil, fmt.Errorf("unsupported method") - } - return abi.Pack(method, parsedArgs...) } func (c *FeralfileExhibitionV2Contract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { - case "create_artwork": + case "createArtwork": var params struct { Fingerprint string `json:"fingerprint"` Title string `json:"title"` @@ -272,7 +236,7 @@ func (c *FeralfileExhibitionV2Contract) Parse( params.ArtistName, big.NewInt(params.EditionSize)}, nil - case "swap_artwork_from_bitmark": + case "swapArtworkFromBitmark": var params struct { ArtworkID ethereum.BigInt `json:"artwork_id"` BitmarkID ethereum.BigInt `json:"bitmark_id"` @@ -291,7 +255,7 @@ func (c *FeralfileExhibitionV2Contract) Parse( ¶ms.EditionNumber.Int, params.To, params.IPFSCID}, nil - case "transfer": + case "safeTransferFrom": var params struct { To common.Address `json:"to"` TokenID ethereum.BigInt `json:"token_id"` @@ -300,9 +264,9 @@ func (c *FeralfileExhibitionV2Contract) Parse( return nil, err } - return []interface{}{common.HexToAddress(wallet.Account()), params.To, ¶ms.TokenID.Int}, nil + return []interface{}{params.To, ¶ms.TokenID.Int}, nil - case "approve_for_all": + case "setApprovalForAll": var params struct { Operator common.Address `json:"operator"` } @@ -316,29 +280,6 @@ func (c *FeralfileExhibitionV2Contract) Parse( } } -func (c *FeralfileExhibitionV2Contract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - data, err := c.Pack(wallet, method, arguments) - if nil != err { - return 0, err - } - - gas, err := wallet.RPCClient().EstimateGas(context.Background(), goEthereum.CallMsg{ - From: common.HexToAddress(wallet.Account()), - To: &contractAddr, - Data: data, - }) - - if nil != err { - return 0, err - } - - return gas * 115 / 100, nil // add 15% buffer -} - func init() { ethereum.RegisterContract("FeralfileExhibitionV2", FeralfileExhibitionV2ContractFactory) } diff --git a/contracts/feralfile-exhibition-v3/feralfile.go b/contracts/feralfile-exhibition-v3/feralfile.go index c23656a..1dd7649 100644 --- a/contracts/feralfile-exhibition-v3/feralfile.go +++ b/contracts/feralfile-exhibition-v3/feralfile.go @@ -1,7 +1,6 @@ package feralfilev3 import ( - "context" "encoding/hex" "encoding/json" "errors" @@ -10,7 +9,6 @@ import ( "strconv" "strings" - goEthereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" @@ -70,8 +68,9 @@ func (c *FeralfileExhibitionV3Contract) Call( fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (*types.Transaction, error) { + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contractAddr := common.HexToAddress(c.contractAddress) contract, err := feralfilev3.NewFeralfileExhibitionV3(contractAddr, wallet.RPCClient()) if err != nil { @@ -84,21 +83,22 @@ func (c *FeralfileExhibitionV3Contract) Call( } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } switch method { - case "register_artworks": + case "createArtworks": if len(params) != 1 { return nil, fmt.Errorf("invalid params") } @@ -109,7 +109,7 @@ func (c *FeralfileExhibitionV3Contract) Call( } return contract.CreateArtworks(t, artworkParams) - case "mint_editions": + case "batchMint": if len(params) != 1 { return nil, fmt.Errorf("invalid params") } @@ -119,15 +119,8 @@ func (c *FeralfileExhibitionV3Contract) Call( return nil, fmt.Errorf("invalid mint params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.BatchMint(t, mintParams) - case "authorized_transfer": + case "authorizedTransfer": if len(params) != 1 { return nil, fmt.Errorf("invalid params") } @@ -137,15 +130,8 @@ func (c *FeralfileExhibitionV3Contract) Call( return nil, fmt.Errorf("invalid transfer params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.AuthorizedTransfer(t, transferParams) - case "burn_editions": + case "burnEditions": if len(params) != 1 { return nil, errors.New("Invalid parameters") } @@ -156,7 +142,7 @@ func (c *FeralfileExhibitionV3Contract) Call( } return contract.BurnEditions(t, burnParams) - case "transfer": + case "safeTransferFrom": if len(params) != 2 { return nil, fmt.Errorf("invalid params") } @@ -171,18 +157,11 @@ func (c *FeralfileExhibitionV3Contract) Call( return nil, fmt.Errorf("invalid token id params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SafeTransferFrom(t, common.HexToAddress(wallet.Account()), to, tokenID) - case "approve_for_all": + case "setApprovalForAll": if len(params) != 1 { return nil, fmt.Errorf("invalid params") } @@ -192,13 +171,6 @@ func (c *FeralfileExhibitionV3Contract) Call( return nil, fmt.Errorf("invalid operator params") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SetApprovalForAll(t, operator, true) default: return nil, fmt.Errorf("unsupported method") @@ -206,7 +178,6 @@ func (c *FeralfileExhibitionV3Contract) Call( } func (c *FeralfileExhibitionV3Contract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := feralfilev3.FeralfileExhibitionV3MetaData.GetAbi() @@ -214,37 +185,19 @@ func (c *FeralfileExhibitionV3Contract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } - switch method { - case "register_artworks": - method = "createArtworks" - case "mint_editions": - method = "batchMint" - case "authorized_transfer": - method = "authorizedTransfer" - case "burn_editions": - method = "burnEditions" - case "transfer": - method = "safeTransferFrom" - case "approve_for_all": - method = "setApprovalForAll" - default: - return nil, fmt.Errorf("unsupported method") - } - return abi.Pack(method, parsedArgs...) } func (c *FeralfileExhibitionV3Contract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { - case "register_artworks": + case "createArtworks": var params []struct { Fingerprint string `json:"fingerprint"` Title string `json:"title"` @@ -271,7 +224,7 @@ func (c *FeralfileExhibitionV3Contract) Parse( } return []interface{}{artworkParams}, nil - case "mint_editions": + case "batchMint": var params []struct { ArtworkID ethereum.BigInt `json:"artwork_id"` EditionNumber ethereum.BigInt `json:"edition_number"` @@ -300,7 +253,7 @@ func (c *FeralfileExhibitionV3Contract) Parse( } return []interface{}{mintParams}, nil - case "authorized_transfer": + case "authorizedTransfer": var params []struct { From common.Address `json:"from"` To common.Address `json:"to"` @@ -352,7 +305,7 @@ func (c *FeralfileExhibitionV3Contract) Parse( } return []interface{}{transferParams}, nil - case "burn_editions": + case "burnEditions": var params []ethereum.BigInt if err := json.Unmarshal(arguments, ¶ms); err != nil { return nil, err @@ -365,7 +318,7 @@ func (c *FeralfileExhibitionV3Contract) Parse( } return []interface{}{burnParams}, nil - case "transfer": + case "safeTransferFrom": var params struct { To common.Address `json:"to"` TokenID ethereum.BigInt `json:"token_id"` @@ -374,8 +327,8 @@ func (c *FeralfileExhibitionV3Contract) Parse( return nil, err } - return []interface{}{common.HexToAddress(wallet.Account()), params.To, ¶ms.TokenID.Int}, nil - case "approve_for_all": + return []interface{}{params.To, ¶ms.TokenID.Int}, nil + case "setApprovalForAll": var params struct { Operator common.Address `json:"operator"` } @@ -389,29 +342,6 @@ func (c *FeralfileExhibitionV3Contract) Parse( } } -func (c *FeralfileExhibitionV3Contract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - data, err := c.Pack(wallet, method, arguments) - if nil != err { - return 0, err - } - - gas, err := wallet.RPCClient().EstimateGas(context.Background(), goEthereum.CallMsg{ - From: common.HexToAddress(wallet.Account()), - To: &contractAddr, - Data: data, - }) - - if nil != err { - return 0, err - } - - return gas * 115 / 100, nil // add 15% buffer -} - func init() { ethereum.RegisterContract("FeralfileExhibitionV3", FeralfileExhibitionV3ContractFactory) } diff --git a/contracts/feralfile-exhibition-v4/feralfile.go b/contracts/feralfile-exhibition-v4/feralfile.go index be5354b..d60b689 100644 --- a/contracts/feralfile-exhibition-v4/feralfile.go +++ b/contracts/feralfile-exhibition-v4/feralfile.go @@ -1,7 +1,6 @@ package feralfilev4 import ( - "context" "encoding/hex" "encoding/json" "errors" @@ -10,7 +9,6 @@ import ( "strconv" "strings" - goEthereum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" @@ -81,8 +79,9 @@ func (c *FeralfileExhibitionV4Contract) Call( fund string, arguments json.RawMessage, noSend bool, - customizeGasPriceInWei *int64, - customizedNonce *uint64) (*types.Transaction, error) { + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contractAddr := common.HexToAddress(c.contractAddress) contract, err := feralfilev4.NewFeralfileExhibitionV4(contractAddr, wallet.RPCClient()) if err != nil { @@ -95,15 +94,16 @@ func (c *FeralfileExhibitionV4Contract) Call( } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -119,13 +119,6 @@ func (c *FeralfileExhibitionV4Contract) Call( return nil, errors.New("Invalid token burn parameters") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit * 115 / 100 - return contract.BurnArtworks(t, tokenIDs) case "mintArtworks": if len(params) != 1 { @@ -137,13 +130,6 @@ func (c *FeralfileExhibitionV4Contract) Call( return nil, errors.New("Invalid token mint parameters") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.MintArtworks(t, mintData) case "setTokenBaseURI": if len(params) != 1 { @@ -195,7 +181,7 @@ func (c *FeralfileExhibitionV4Contract) Call( } return contract.BuyArtworks(t, r, s, v, saleData) - case "approve_for_all": + case "setApprovalForAll": if len(params) != 1 { return nil, errors.New("Invalid parameters") } @@ -205,13 +191,6 @@ func (c *FeralfileExhibitionV4Contract) Call( return nil, errors.New("Invalid operator") } - gasLimit, err := c.EstimateGasLimit(wallet, contractAddr, method, arguments) - if nil != err { - return nil, err - } - - t.GasLimit = gasLimit - return contract.SetApprovalForAll(t, operator, true) default: return nil, fmt.Errorf("unsupported method") @@ -219,7 +198,6 @@ func (c *FeralfileExhibitionV4Contract) Call( } func (c *FeralfileExhibitionV4Contract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := feralfilev4.FeralfileExhibitionV4MetaData.GetAbi() @@ -227,35 +205,15 @@ func (c *FeralfileExhibitionV4Contract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } - switch method { - case "burnArtworks": - method = "burnArtworks" - case "mintArtworks": - method = "mintArtworks" - case "setTokenBaseURI": - method = "setTokenBaseURI" - case "startSale": - method = "startSale" - case "transferOwnership": - method = "transferOwnership" - case "approve_for_all": - method = "setApprovalForAll" - case "buyArtworks": - method = "buyArtworks" - default: - return nil, fmt.Errorf("unsupported method") - } - return abi.Pack(method, parsedArgs...) } func (c *FeralfileExhibitionV4Contract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { @@ -310,7 +268,7 @@ func (c *FeralfileExhibitionV4Contract) Parse( return nil, err } return []interface{}{newOwner}, nil - case "approve_for_all": + case "setApprovalForAll": var params struct { Operator common.Address `json:"operator"` } @@ -397,29 +355,6 @@ func (c *FeralfileExhibitionV4Contract) Parse( } } -func (c *FeralfileExhibitionV4Contract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - data, err := c.Pack(wallet, method, arguments) - if nil != err { - return 0, err - } - - gas, err := wallet.RPCClient().EstimateGas(context.Background(), goEthereum.CallMsg{ - From: common.HexToAddress(wallet.Account()), - To: &contractAddr, - Data: data, - }) - - if nil != err { - return 0, err - } - - return gas * 115 / 100, nil // add 15% buffer -} - func init() { ethereum.RegisterContract("FeralfileExhibitionV4", FeralfileExhibitionV4ContractFactory) } diff --git a/contracts/owner-data/ownerdata.go b/contracts/owner-data/ownerdata.go index f8dc1d9..1bf7fa8 100644 --- a/contracts/owner-data/ownerdata.go +++ b/contracts/owner-data/ownerdata.go @@ -32,7 +32,15 @@ func (c *OwnerDataContract) Deploy(wallet *ethereum.Wallet, arguments json.RawMe } // Call is the entry function for account vault to interact with a smart contract. -func (c *OwnerDataContract) Call(wallet *ethereum.Wallet, method, fund string, arguments json.RawMessage, noSend bool, customizeGasPriceInWei *int64, customizedNonce *uint64) (*types.Transaction, error) { +func (c *OwnerDataContract) Call( + wallet *ethereum.Wallet, + method, + fund string, + arguments json.RawMessage, + noSend bool, + gasLimit uint64, + gasPrice *int64, + nonce *uint64) (*types.Transaction, error) { contract, err := ownerdata.NewOwnerData(common.HexToAddress(c.contractAddress), wallet.RPCClient()) if err != nil { return nil, err @@ -44,15 +52,16 @@ func (c *OwnerDataContract) Call(wallet *ethereum.Wallet, method, fund string, a } t.NoSend = noSend - if customizeGasPriceInWei != nil && *customizeGasPriceInWei != 0 { - t.GasPrice = big.NewInt(*customizeGasPriceInWei * params.Wei) + t.GasLimit = gasLimit + if gasPrice != nil && *gasPrice != 0 { + t.GasPrice = big.NewInt(*gasPrice * params.Wei) } - if customizedNonce != nil { - t.Nonce = big.NewInt(int64(*customizedNonce)) + if nonce != nil { + t.Nonce = big.NewInt(int64(*nonce)) } - params, err := c.Parse(wallet, method, arguments) + params, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -95,7 +104,6 @@ func (c *OwnerDataContract) Call(wallet *ethereum.Wallet, method, fund string, a } func (c *OwnerDataContract) Pack( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]byte, error) { abi, err := ownerdata.OwnerDataMetaData.GetAbi() @@ -103,7 +111,7 @@ func (c *OwnerDataContract) Pack( return nil, err } - parsedArgs, err := c.Parse(wallet, method, arguments) + parsedArgs, err := c.Parse(method, arguments) if nil != err { return nil, err } @@ -112,7 +120,6 @@ func (c *OwnerDataContract) Pack( } func (c *OwnerDataContract) Parse( - wallet *ethereum.Wallet, method string, arguments json.RawMessage) ([]interface{}, error) { switch method { @@ -181,14 +188,6 @@ func (c *OwnerDataContract) Parse( } } -func (c *OwnerDataContract) EstimateGasLimit( - wallet *ethereum.Wallet, - contractAddr common.Address, - method string, - arguments json.RawMessage) (uint64, error) { - return 0, errors.New("not implemented") -} - func init() { ethereum.RegisterContract("OwnerData", OwnerDataContractFactory) }