From 3c4f3e87cb950cc924d5350658d6457e28e03336 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Fri, 22 Nov 2024 12:52:21 -0300 Subject: [PATCH] Feat: calldata flag to seer evm generator --- evm/generators.go | 88 +++-- examples/ownable-erc-721/OwnableERC721.go | 404 +++++++++++++--------- version/version.go | 2 +- 3 files changed, 291 insertions(+), 203 deletions(-) diff --git a/evm/generators.go b/evm/generators.go index 82df8a2..e211c55 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}} @@ -1417,17 +1419,23 @@ 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) - } + // 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.Printf(deployCalldataHex) + return nil + } + if safeAddress != "" { // Create Safe proposal for deployment value := transactionOpts.Value if value == nil { @@ -1440,7 +1448,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 +1456,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 +1476,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 +1524,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 +1662,7 @@ func {{.HandlerName}}() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool {{range .MethodArgs}} var {{.CLIVar}} {{.CLIType}} @@ -1754,36 +1763,42 @@ func {{.HandlerName}}() *cobra.Command { TransactOpts: *transactionOpts, } - 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 - } + 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}} - ) + txCalldata, err := abi.Pack( + methodName, + {{- range .MethodArgs}} + {{.CLIVar}}, + {{- end}} + ) - if err != nil { - return err - } - + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + + if safeAddress != "" { // 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 +1815,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 +1863,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..66c058b 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.13 // 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 @@ -1429,17 +1430,23 @@ 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) - } + // 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.Printf(deployCalldataHex) + return nil + } + if safeAddress != "" { // Create Safe proposal for deployment value := transactionOpts.Value if value == nil { @@ -1452,7 +1459,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 +1467,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 +1535,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 +2239,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 @@ -2340,35 +2349,41 @@ func CreateApproveCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // Generate transaction data (override method name if safe function is specified) + methodName := "approve" + if safeFunction != "" { + methodName = safeFunction + } + + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) - transaction, err := abi.Pack( - methodName, - to0, - tokenId, - ) + if err != nil { + return err + } - if err != nil { - return err - } + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + if safeAddress != "" { // 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 +2448,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 +2464,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 @@ -2557,35 +2574,41 @@ func CreateMintCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // Generate transaction data (override method name if safe function is specified) + methodName := "mint" + if safeFunction != "" { + methodName = safeFunction + } - transaction, err := abi.Pack( - methodName, - to0, - tokenId, - ) + txCalldata, err := abi.Pack( + methodName, + to0, + tokenId, + ) - if err != nil { - return err - } + if err != nil { + return err + } + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + + if safeAddress != "" { // 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 +2673,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,6 +2689,7 @@ func CreateRenounceOwnershipCommand() *cobra.Command { var safeAddress, safeApi string var safeOperationType uint8 var safeNonce *big.Int + var calldata bool cmd := &cobra.Command{ Use: "renounce-ownership", @@ -2756,33 +2781,39 @@ func CreateRenounceOwnershipCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // Generate transaction data (override method name if safe function is specified) + methodName := "renounceOwnership" + if safeFunction != "" { + methodName = safeFunction + } - transaction, err := abi.Pack( - methodName, - ) + txCalldata, err := abi.Pack( + methodName, + ) - if err != nil { - return err - } + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + if safeAddress != "" { // 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 +2874,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 +2887,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 @@ -2973,36 +3006,42 @@ func CreateSafeTransferFromCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // 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, - ) + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + ) - if err != nil { - return err - } + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + if safeAddress != "" { // 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 +3107,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 +3124,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 @@ -3214,37 +3255,43 @@ func CreateSafeTransferFrom0Command() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // 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, - ) + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + data, + ) - if err != nil { - return err - } + if err != nil { + return err + } + + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + if safeAddress != "" { // 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 +3358,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 +3376,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 @@ -3441,35 +3490,41 @@ func CreateSetApprovalForAllCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // Generate transaction data (override method name if safe function is specified) + methodName := "setApprovalForAll" + if safeFunction != "" { + methodName = safeFunction + } - transaction, err := abi.Pack( - methodName, - operator, - approved, - ) + txCalldata, err := abi.Pack( + methodName, + operator, + approved, + ) - if err != nil { - return err - } + if err != nil { + return err + } + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + + if safeAddress != "" { // 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 +3589,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 +3605,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 @@ -3667,36 +3724,42 @@ func CreateTransferFromCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // 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, - ) + txCalldata, err := abi.Pack( + methodName, + from0, + to0, + tokenId, + ) - if err != nil { - return err - } + if err != nil { + return err + } + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + + if safeAddress != "" { // 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 +3825,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 +3842,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 @@ -3879,34 +3944,40 @@ func CreateTransferOwnershipCommand() *cobra.Command { TransactOpts: *transactionOpts, } - if safeAddress != "" { - abi, err := OwnableERC721MetaData.GetAbi() - if err != nil { - return fmt.Errorf("failed to get ABI: %v", err) - } + 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 - } + // Generate transaction data (override method name if safe function is specified) + methodName := "transferOwnership" + if safeFunction != "" { + methodName = safeFunction + } - transaction, err := abi.Pack( - methodName, - newOwner, - ) + txCalldata, err := abi.Pack( + methodName, + newOwner, + ) - if err != nil { - return err - } + if err != nil { + return err + } + if calldata { + txCalldataHex := hex.EncodeToString(txCalldata) + cmd.Printf(txCalldataHex) + return nil + } + + if safeAddress != "" { // 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 +4041,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"