diff --git a/evm/generators.go b/evm/generators.go index 82df8a2..145e6db 100644 --- a/evm/generators.go +++ b/evm/generators.go @@ -1309,6 +1309,8 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { var salt [32]byte var predictAddress bool var safeNonce *big.Int + var calldata bool + {{range .DeployHandler.MethodArgs}} var {{.CLIVar}} {{.CLIType}} {{if (ne .CLIRawVar .CLIVar)}}var {{.CLIRawVar}} {{.CLIRawType}}{{end}} @@ -1318,12 +1320,15 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { Use: "deploy", Short: "Deploy a new {{.StructName}} contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if !calldata { + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } + + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1393,6 +1398,22 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Generate deploy bytecode with constructor arguments + deployCalldata, err := generate{{.StructName}}DeployBytecode( + {{- range .DeployHandler.MethodArgs}} + {{.CLIVar}}, + {{- end}} + ) + if err != nil { + return fmt.Errorf("failed to generate deploy bytecode: %v", err) + } + + if calldata { + deployCalldataHex := hex.EncodeToString(deployCalldata) + cmd.Println(deployCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1418,16 +1439,6 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) if safeAddress != "" { - // Generate deploy bytecode with constructor arguments - deployBytecode, err := generate{{.StructName}}DeployBytecode( - {{- range .DeployHandler.MethodArgs}} - {{.CLIVar}}, - {{- end}} - ) - if err != nil { - return fmt.Errorf("failed to generate deploy bytecode: %v", err) - } - // Create Safe proposal for deployment value := transactionOpts.Value if value == nil { @@ -1440,7 +1451,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { if safeOperationType == 0 { from = common.HexToAddress(safeCreateCall) } - deploymentAddress, err := PredictDeploymentAddressSafe(from, salt, deployBytecode) + deploymentAddress, err := PredictDeploymentAddressSafe(from, salt, deployCalldata) if err != nil { return fmt.Errorf("failed to predict deployment address: %v", err) } @@ -1448,7 +1459,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { return nil } else { fmt.Println("Creating Safe proposal...") - err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployBytecode, SafeOperationType(safeOperationType), salt, safeNonce) + err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployCalldata, SafeOperationType(safeOperationType), salt, safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -1468,7 +1479,6 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { return deploymentErr } - cmd.Printf("Transaction hash: %s\nContract address: %s\n", deploymentTransaction.Hash().Hex(), address.Hex()) if transactionOpts.NoSend { estimationMessage := ethereum.CallMsg{ @@ -1517,6 +1527,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command { cmd.Flags().StringVar(&safeSaltRaw, "safe-salt", "", "Salt to use for the Safe transaction") cmd.Flags().BoolVar(&predictAddress, "safe-predict-address", false, "Predict the deployment address (only works for Safe transactions)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") {{range .DeployHandler.MethodArgs}} cmd.Flags().{{.Flag}} @@ -1654,6 +1665,7 @@ func {{.HandlerName}}() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool {{range .MethodArgs}} var {{.CLIVar}} {{.CLIType}} @@ -1664,19 +1676,21 @@ func {{.HandlerName}}() *cobra.Command { Use: "{{(KebabCase .MethodName)}}", Short: "Execute the {{.MethodName}} method on a {{$structName}} contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1720,6 +1734,34 @@ func {{.HandlerName}}() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := {{$structName}}MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "{{ToLowerCamel .MethodName}}" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + {{- range .MethodArgs}} + {{.CLIVar}}, + {{- end}} + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1755,35 +1797,13 @@ func {{.HandlerName}}() *cobra.Command { } if safeAddress != "" { - abi, err := {{$structName}}MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "{{ToLowerCamel .MethodName}}" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - {{- range .MethodArgs}} - {{.CLIVar}}, - {{- end}} - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -1800,7 +1820,7 @@ func {{.HandlerName}}() *cobra.Command { return err } - cmd.Printf("Transaction hash: %s\n", transaction.Hash().Hex()) + cmd.Printf("Transaction hash: %s\n", transaction.Hash().Hex()) if transactionOpts.NoSend { estimationMessage := ethereum.CallMsg{ From: transactionOpts.From, @@ -1848,6 +1868,7 @@ func {{.HandlerName}}() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") {{range .MethodArgs}} cmd.Flags().{{.Flag}} diff --git a/examples/ownable-erc-721/OwnableERC721.go b/examples/ownable-erc-721/OwnableERC721.go index 6a739b4..52d4855 100644 --- a/examples/ownable-erc-721/OwnableERC721.go +++ b/examples/ownable-erc-721/OwnableERC721.go @@ -1,5 +1,5 @@ // This file was generated by seer: https://github.com/G7DAO/seer. -// seer version: 0.3.4 +// seer version: 0.3.14 // seer command: seer evm generate --package main --cli --includemain --abi fixtures/OwnableERC721.json --bytecode fixtures/OwnableERC721.bin --struct OwnableERC721 --output examples/ownable-erc-721/OwnableERC721.go // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. @@ -1315,6 +1315,7 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { var salt [32]byte var predictAddress bool var safeNonce *big.Int + var calldata bool var name_0 string @@ -1327,12 +1328,15 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { Use: "deploy", Short: "Deploy a new OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if !calldata { + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } + + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -1405,6 +1409,22 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Generate deploy bytecode with constructor arguments + deployCalldata, err := generateOwnableERC721DeployBytecode( + name_0, + symbol, + owner, + ) + if err != nil { + return fmt.Errorf("failed to generate deploy bytecode: %v", err) + } + + if calldata { + deployCalldataHex := hex.EncodeToString(deployCalldata) + cmd.Println(deployCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -1430,16 +1450,6 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate) if safeAddress != "" { - // Generate deploy bytecode with constructor arguments - deployBytecode, err := generateOwnableERC721DeployBytecode( - name_0, - symbol, - owner, - ) - if err != nil { - return fmt.Errorf("failed to generate deploy bytecode: %v", err) - } - // Create Safe proposal for deployment value := transactionOpts.Value if value == nil { @@ -1452,7 +1462,7 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { if safeOperationType == 0 { from = common.HexToAddress(safeCreateCall) } - deploymentAddress, err := PredictDeploymentAddressSafe(from, salt, deployBytecode) + deploymentAddress, err := PredictDeploymentAddressSafe(from, salt, deployCalldata) if err != nil { return fmt.Errorf("failed to predict deployment address: %v", err) } @@ -1460,7 +1470,7 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { return nil } else { fmt.Println("Creating Safe proposal...") - err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployBytecode, SafeOperationType(safeOperationType), salt, safeNonce) + err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployCalldata, SafeOperationType(safeOperationType), salt, safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -1528,6 +1538,7 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { cmd.Flags().StringVar(&safeSaltRaw, "safe-salt", "", "Salt to use for the Safe transaction") cmd.Flags().BoolVar(&predictAddress, "safe-predict-address", false, "Predict the deployment address (only works for Safe transactions)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&name_0, "name-0", "", "name-0 argument") cmd.Flags().StringVar(&symbol, "symbol", "", "symbol argument") @@ -2231,6 +2242,7 @@ func CreateApproveCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var to0 common.Address var to0Raw string @@ -2241,19 +2253,21 @@ func CreateApproveCommand() *cobra.Command { Use: "approve", Short: "Execute the Approve method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2306,6 +2320,33 @@ func CreateApproveCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "approve" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2341,34 +2382,13 @@ func CreateApproveCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "approve" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - to0, - tokenId, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2433,6 +2453,7 @@ func CreateApproveCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") cmd.Flags().StringVar(&tokenIdRaw, "token-id", "", "token-id argument") @@ -2448,6 +2469,7 @@ func CreateMintCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var to0 common.Address var to0Raw string @@ -2458,19 +2480,21 @@ func CreateMintCommand() *cobra.Command { Use: "mint", Short: "Execute the Mint method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2523,6 +2547,33 @@ func CreateMintCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "mint" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2558,34 +2609,13 @@ func CreateMintCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "mint" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - to0, - tokenId, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2650,6 +2680,7 @@ func CreateMintCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") cmd.Flags().StringVar(&tokenIdRaw, "token-id", "", "token-id argument") @@ -2665,24 +2696,27 @@ func CreateRenounceOwnershipCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool cmd := &cobra.Command{ Use: "renounce-ownership", Short: "Execute the RenounceOwnership method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2722,6 +2756,31 @@ func CreateRenounceOwnershipCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "renounceOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2757,32 +2816,13 @@ func CreateRenounceOwnershipCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "renounceOwnership" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2843,6 +2883,7 @@ func CreateRenounceOwnershipCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") return cmd } @@ -2855,6 +2896,7 @@ func CreateSafeTransferFromCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var from0 common.Address var from0Raw string @@ -2867,19 +2909,21 @@ func CreateSafeTransferFromCommand() *cobra.Command { Use: "safe-transfer-from", Short: "Execute the SafeTransferFrom method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -2939,6 +2983,34 @@ func CreateSafeTransferFromCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -2974,35 +3046,13 @@ func CreateSafeTransferFromCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "safeTransferFrom" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - from0, - to0, - tokenId, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3068,6 +3118,7 @@ func CreateSafeTransferFromCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -3084,6 +3135,7 @@ func CreateSafeTransferFrom0Command() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var from0 common.Address var from0Raw string @@ -3098,19 +3150,21 @@ func CreateSafeTransferFrom0Command() *cobra.Command { Use: "safe-transfer-from-0", Short: "Execute the SafeTransferFrom0 method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3180,6 +3234,35 @@ func CreateSafeTransferFrom0Command() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom0" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + data, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3215,36 +3298,13 @@ func CreateSafeTransferFrom0Command() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "safeTransferFrom0" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - from0, - to0, - tokenId, - data, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3311,6 +3371,7 @@ func CreateSafeTransferFrom0Command() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -3328,6 +3389,7 @@ func CreateSetApprovalForAllCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var operator common.Address var operatorRaw string @@ -3338,19 +3400,21 @@ func CreateSetApprovalForAllCommand() *cobra.Command { Use: "set-approval-for-all", Short: "Execute the SetApprovalForAll method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3407,6 +3471,33 @@ func CreateSetApprovalForAllCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "setApprovalForAll" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + operator, + approved, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3442,34 +3533,13 @@ func CreateSetApprovalForAllCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "setApprovalForAll" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - operator, - approved, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3534,6 +3604,7 @@ func CreateSetApprovalForAllCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&operatorRaw, "operator", "", "operator argument (common.Address)") cmd.Flags().StringVar(&approvedRaw, "approved", "", "approved argument (true, t, y, yes, 1 OR false, f, n, no, 0)") @@ -3549,6 +3620,7 @@ func CreateTransferFromCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var from0 common.Address var from0Raw string @@ -3561,19 +3633,21 @@ func CreateTransferFromCommand() *cobra.Command { Use: "transfer-from", Short: "Execute the TransferFrom method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3633,6 +3707,34 @@ func CreateTransferFromCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "transferFrom" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3668,35 +3770,13 @@ func CreateTransferFromCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "transferFrom" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - from0, - to0, - tokenId, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3762,6 +3842,7 @@ func CreateTransferFromCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -3778,6 +3859,7 @@ func CreateTransferOwnershipCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool var newOwner common.Address var newOwnerRaw string @@ -3786,19 +3868,21 @@ func CreateTransferOwnershipCommand() *cobra.Command { Use: "transfer-ownership", Short: "Execute the TransferOwnership method on a OwnableERC721 contract", PreRunE: func(cmd *cobra.Command, args []string) error { - if contractAddressRaw == "" { - return fmt.Errorf("--contract not specified") - } else if !common.IsHexAddress(contractAddressRaw) { - return fmt.Errorf("--contract is not a valid Ethereum address") - } - contractAddress = common.HexToAddress(contractAddressRaw) + if !calldata { + if contractAddressRaw == "" { + return fmt.Errorf("--contract not specified") + } else if !common.IsHexAddress(contractAddressRaw) { + return fmt.Errorf("--contract is not a valid Ethereum address") + } + contractAddress = common.HexToAddress(contractAddressRaw) - if keyfile == "" { - return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") - } + if keyfile == "" { + return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)") + } - if rpc == "" { - return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + if rpc == "" { + return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)") + } } if safeAddress != "" { @@ -3845,6 +3929,32 @@ func CreateTransferOwnershipCommand() *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "transferOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + newOwner, + ) + + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Println(txCalldataHex) + return nil + } + client, clientErr := NewClient(rpc) if clientErr != nil { return clientErr @@ -3880,33 +3990,13 @@ func CreateTransferOwnershipCommand() *cobra.Command { } if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } - - // Generate transaction data (override method name if safe function is specified) - methodName := "transferOwnership" - if safeFunction != "" { - methodName = safeFunction - } - - transaction, err := abi.Pack( - methodName, - newOwner, - ) - - if err != nil { - return err - } - // Create Safe proposal for transaction value := transactionOpts.Value if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType), safeNonce) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, txCalldata, value, safeApi, SafeOperationType(safeOperationType), safeNonce) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3970,6 +4060,7 @@ func CreateTransferOwnershipCommand() *cobra.Command { cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)") + cmd.Flags().BoolVar(&calldata, "calldata", false, "Set this flag if want to return the calldata instead of sending the transaction") cmd.Flags().StringVar(&newOwnerRaw, "new-owner", "", "new-owner argument (common.Address)") diff --git a/version/version.go b/version/version.go index ac013a2..565b96d 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -var SeerVersion string = "0.3.13" +var SeerVersion string = "0.3.14"