-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add calldata flag to seer evm generator #115
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.Printf(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,15 +1451,15 @@ 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) | ||
} | ||
fmt.Println("Predicted deployment address:", deploymentAddress.Hex()) | ||
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.Printf(txCalldataHex) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
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}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
cmd.Println
instead ofcmd.Printf
- you want to have the newline at the end of the print output as it makes the output more usable in a terminal window.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!