From 4ae9ee995d2a2e2cd9539fb13c8143220b41d04c Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cavalcante Date: Mon, 4 Nov 2024 23:38:58 -0300 Subject: [PATCH] Apply go suggestions --- cmd/web3/contracts.go | 11 ++--- cmd/web3/did.go | 14 +++--- cmd/web3/generate.go | 20 ++++----- cmd/web3/main.go | 96 ++++++++++++++++++++-------------------- cmd/web3/start.go | 2 +- cmd/web3/transactions.go | 18 ++++---- 6 files changed, 81 insertions(+), 80 deletions(-) diff --git a/cmd/web3/contracts.go b/cmd/web3/contracts.go index eaf7f6a..fab87b7 100644 --- a/cmd/web3/contracts.go +++ b/cmd/web3/contracts.go @@ -9,6 +9,7 @@ import ( "github.com/gochain/gochain/v4/accounts/abi" "github.com/gochain/web3" ) + func ListContract(contractFile string) { myabi, err := web3.GetABI(contractFile) if err != nil { @@ -28,7 +29,7 @@ func ListContract(contractFile string) { func GetContractConst(ctx context.Context, rpcURL, contractAddress, contractFile, functionName string, parameters ...interface{}) ([]interface{}, error) { client, err := web3.Dial(rpcURL) if err != nil { - return nil, fmt.Errorf("Failed to connect to %q: %v", rpcURL, err) + return nil, fmt.Errorf("failed to connect to %q: %v", rpcURL, err) } defer client.Close() myabi, err := web3.GetABI(contractFile) @@ -37,14 +38,14 @@ func GetContractConst(ctx context.Context, rpcURL, contractAddress, contractFile } fn, ok := myabi.Methods[functionName] if !ok { - return nil, fmt.Errorf("There is no such function: %v", functionName) + return nil, fmt.Errorf("there is no such function: %v", functionName) } if !fn.IsConstant() { return nil, err } res, err := web3.CallConstantFunction(ctx, client, *myabi, contractAddress, functionName, parameters...) if err != nil { - return nil, fmt.Errorf("Error calling constant function: %v", err) + return nil, fmt.Errorf("error calling constant function: %v", err) } return res, nil } @@ -73,7 +74,7 @@ func callContract(ctx context.Context, client web3.Client, privateKey, contractA if m.IsConstant() { res, err := web3.CallConstantFunction(ctx, client, *myabi, contractAddress, functionName, parameters...) if err != nil { - fatalExit(fmt.Errorf("Error calling constant function: %v", err)) + fatalExit(fmt.Errorf("error calling constant function: %v", err)) } switch format { case "json": @@ -104,7 +105,7 @@ func callContract(ctx context.Context, client web3.Client, privateKey, contractA tx, err = web3.CallTransactFunction(ctx, client, *myabi, contractAddress, privateKey, functionName, amount, gasPrice, gasLimit, parameters...) } if err != nil { - fatalExit(fmt.Errorf("Error calling contract: %v", err)) + fatalExit(fmt.Errorf("error calling contract: %v", err)) } fmt.Println("Transaction hash:", tx.Hash.Hex()) if !waitForReceipt { diff --git a/cmd/web3/did.go b/cmd/web3/did.go index 3895c6b..f1da0ab 100644 --- a/cmd/web3/did.go +++ b/cmd/web3/did.go @@ -360,23 +360,23 @@ func VerifyClaim(ctx context.Context, rpcURL, privateKey, registryAddress, filen func readDIDDocument(ctx context.Context, rpcURL, registryAddress, id string) (*did.Document, error) { if registryAddress == "" { - return nil, fmt.Errorf("Registry contract address required") + return nil, fmt.Errorf("registry contract address required") } d, err := did.Parse(id) if err != nil { - return nil, fmt.Errorf("Invalid DID: %s", id) + return nil, fmt.Errorf("invalid DID: %s", id) } client, err := web3.Dial(rpcURL) if err != nil { - return nil, fmt.Errorf("Failed to connect to %q: %v", rpcURL, err) + return nil, fmt.Errorf("failed to connect to %q: %v", rpcURL, err) } defer client.Close() myabi, err := abi.JSON(strings.NewReader(assets.DIDRegistryABI)) if err != nil { - return nil, fmt.Errorf("Cannot initialize DIDRegistry ABI: %v", err) + return nil, fmt.Errorf("cannot initialize DIDRegistry ABI: %v", err) } var idBytes32 [32]byte @@ -384,7 +384,7 @@ func readDIDDocument(ctx context.Context, rpcURL, registryAddress, id string) (* result, err := web3.CallConstantFunction(ctx, client, myabi, registryAddress, "hash", idBytes32) if err != nil { - return nil, fmt.Errorf("Cannot call the contract: %v", err) + return nil, fmt.Errorf("cannot call the contract: %v", err) } if len(result) != 1 { log.Fatalf("Expected single result but got: %v", result) @@ -393,13 +393,13 @@ func readDIDDocument(ctx context.Context, rpcURL, registryAddress, id string) (* hash := result[0].(string) resp, err := http.Get(fmt.Sprintf("https://ipfs.infura.io:5001/api/v0/cat?arg=%s", hash)) if err != nil { - return nil, fmt.Errorf("Unable to fetch DID document from IPFS: %s", err) + return nil, fmt.Errorf("unable to fetch DID document from IPFS: %s", err) } defer resp.Body.Close() var doc did.Document if err := json.NewDecoder(resp.Body).Decode(&doc); err != nil { - return nil, fmt.Errorf("Unable to decode DID document: %s", err) + return nil, fmt.Errorf("unable to decode DID document: %s", err) } return &doc, nil } diff --git a/cmd/web3/generate.go b/cmd/web3/generate.go index e0bc61b..ee52a91 100644 --- a/cmd/web3/generate.go +++ b/cmd/web3/generate.go @@ -31,18 +31,18 @@ func GenerateCode(ctx context.Context, c *cli.Context) { case "objc": lang = bind.LangObjC default: - fatalExit(fmt.Errorf("Unsupported destination language: %v", lang)) + fatalExit(fmt.Errorf("unsupported destination language: %v", lang)) } abiFile := c.String("abi") if abiFile == "" { - fatalExit(errors.New("Please set the ABI file name")) + fatalExit(errors.New("please set the ABI file name")) } abi, err := ioutil.ReadFile(abiFile) if err != nil { - fatalExit(fmt.Errorf("Failed to read file %q: %v", abiFile, err)) + fatalExit(fmt.Errorf("failed to read file %q: %v", abiFile, err)) } abis := []string{string(abi)} @@ -51,12 +51,12 @@ func GenerateCode(ctx context.Context, c *cli.Context) { code, err := bind.Bind(types, abis, bins, nil, c.String("pkg"), lang, nil, nil) if err != nil { - fatalExit(fmt.Errorf("Failed to generate ABI binding %q: %v", abiFile, err)) + fatalExit(fmt.Errorf("failed to generate ABI binding %q: %v", abiFile, err)) } outFile := c.String("out") if err := ioutil.WriteFile(outFile, []byte(code), 0600); err != nil { - fatalExit(fmt.Errorf("Failed to write ABI binding %q: %v", abiFile, err)) + fatalExit(fmt.Errorf("failed to write ABI binding %q: %v", abiFile, err)) } fmt.Println("The generated code has been successfully written to", outFile, "file") } @@ -72,11 +72,11 @@ func getOpenZeppelinLib(ctx context.Context, version string) error { cmd.Stderr = os.Stderr err := cmd.Run() if err != nil { - fatalExit(fmt.Errorf("Cloning finished with error: %v", err)) + fatalExit(fmt.Errorf("cloning finished with error: %v", err)) } err = os.RemoveAll("lib/oz/.git") if err != nil { - fatalExit(fmt.Errorf("Cannot cleanup .git dir in lib/oz: %v", err)) + fatalExit(fmt.Errorf("cannot cleanup .git dir in lib/oz: %v", err)) } } return nil @@ -164,12 +164,12 @@ func GenerateContract(ctx context.Context, contractType string, c *cli.Context) func processTemplate(openZeppelinVersion string, params interface{}, fileName, contractTemplate string) { tmpl, err := template.New("contract").Parse(contractTemplate) if err != nil { - fatalExit(fmt.Errorf("Cannot parse the template: %v", err)) + fatalExit(fmt.Errorf("cannot parse the template: %v", err)) } var buff bytes.Buffer err = tmpl.Execute(&buff, params) if err != nil { - fatalExit(fmt.Errorf("Cannot execute the template: %v", err)) + fatalExit(fmt.Errorf("cannot execute the template: %v", err)) } s := fmt.Sprintf("// @openzeppelin v%v\n", openZeppelinVersion) s += buff.String() @@ -178,7 +178,7 @@ func processTemplate(openZeppelinVersion string, params interface{}, fileName, c func writeStringToFile(s, fileName string) { err := ioutil.WriteFile(fileName+".sol", []byte(s), 0666) if err != nil { - fatalExit(fmt.Errorf("Cannot create the file: %v", err)) + fatalExit(fmt.Errorf("cannot create the file: %v", err)) } fmt.Println("The sample contract has been successfully written to", fileName+".sol", "file") } diff --git a/cmd/web3/main.go b/cmd/web3/main.go index e9970b3..d151f83 100644 --- a/cmd/web3/main.go +++ b/cmd/web3/main.go @@ -217,7 +217,7 @@ func main() { if c.Bool("erc20") { contractAddress = c.String("address") if contractAddress == "" { - fatalExit(errors.New("You must set ERC20 contract address")) + fatalExit(errors.New("you must set ERC20 contract address")) } } GetAddressDetails(ctx, network, c.Args().First(), privateKey, true, contractAddress, c.String("block")) @@ -507,7 +507,7 @@ func main() { price, limit := parseGasPriceAndLimit(c) client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } client.SetChainID(network.ChainID) defer client.Close() @@ -797,9 +797,9 @@ func main() { }, Action: func(c *cli.Context) { f := c.String("keyfile") - kbytes, err := ioutil.ReadFile(f) + kbytes, err := os.ReadFile(f) if err != nil { - fatalExit(fmt.Errorf("Failed to read file %q: %v", f, err)) + fatalExit(fmt.Errorf("failed to read file %q: %v", f, err)) } key, err := keystore.DecryptKey(kbytes, c.String("password")) if err != nil { @@ -813,7 +813,7 @@ func main() { }, { Name: "transfer", - Usage: fmt.Sprintf("Transfer GO/ETH or ERC20 tokens to another account. eg: `web3 transfer 10.1 to 0xADDRESS`"), + Usage: "transfer GO/ETH or ERC20 tokens to another account. eg: `web3 transfer 10.1 to 0xADDRESS`", Aliases: []string{"send"}, Flags: []cli.Flag{ cli.StringFlag{ @@ -860,7 +860,7 @@ func main() { if c.Bool("erc20") { contractAddress = c.String("address") if contractAddress == "" { - fatalExit(errors.New("You must set ERC20 contract address")) + fatalExit(errors.New("you must set ERC20 contract address")) } } price, limit := parseGasPriceAndLimit(c) @@ -1200,17 +1200,17 @@ func getNetwork(name, rpcURL string, testnet bool) web3.Network { var network web3.Network if rpcURL != "" { if name != "" { - fatalExit(fmt.Errorf("Cannot set both rpcURL %q and network %q", rpcURL, network)) + fatalExit(fmt.Errorf("cannot set both rpcURL %q and network %q", rpcURL, network)) } if testnet { - fatalExit(fmt.Errorf("Cannot set both rpcURL %q and testnet", rpcURL)) + fatalExit(fmt.Errorf("cannot set both rpcURL %q and testnet", rpcURL)) } network.URL = rpcURL network.Unit = "GO" } else { if testnet { if name != "" { - fatalExit(fmt.Errorf("Cannot set both network %q and testnet", name)) + fatalExit(fmt.Errorf("cannot set both network %q and testnet", name)) } name = "testnet" } else if name == "" { @@ -1219,7 +1219,7 @@ func getNetwork(name, rpcURL string, testnet bool) web3.Network { var ok bool network, ok = web3.Networks[name] if !ok { - fatalExit(fmt.Errorf("Unrecognized network %q", name)) + fatalExit(fmt.Errorf("unrecognized network %q", name)) } if verbose { log.Printf("Network: %v", name) @@ -1256,7 +1256,7 @@ func parseGasPriceAndLimit(c *cli.Context) (*big.Int, uint64) { func GetBlockDetails(ctx context.Context, network web3.Network, numberOrHash string, txFormat, txInputFormat string) { client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } defer client.Close() var block *web3.Block @@ -1266,13 +1266,13 @@ func GetBlockDetails(ctx context.Context, network web3.Network, numberOrHash str includeTxs = true case "count", "hash": default: - fatalExit(fmt.Errorf(`Unrecognized transaction format %q: must be "count", "hash", or "detail"`, txFormat)) + fatalExit(fmt.Errorf(`unrecognized transaction format %q: must be "count", "hash", or "detail"`, txFormat)) } if strings.HasPrefix(numberOrHash, "0x") { var err error block, err = client.GetBlockByHash(ctx, numberOrHash, includeTxs) if err != nil { - fatalExit(fmt.Errorf("Cannot get block details from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get block details from the network: %v", err)) } } else { var blockN *big.Int @@ -1280,12 +1280,12 @@ func GetBlockDetails(ctx context.Context, network web3.Network, numberOrHash str if numberOrHash != "" { blockN, err = web3.ParseBigInt(numberOrHash) if err != nil { - fatalExit(fmt.Errorf("Block argument must be a number (decimal integer) %q: %v", numberOrHash, err)) + fatalExit(fmt.Errorf("block argument must be a number (decimal integer) %q: %v", numberOrHash, err)) } } block, err = client.GetBlockByNumber(ctx, blockN, includeTxs) if err != nil { - fatalExit(fmt.Errorf("Cannot get block details from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get block details from the network: %v", err)) } } if verbose { @@ -1369,13 +1369,13 @@ func (fa fmtAddresses) String() string { func GetTransactionDetails(ctx context.Context, network web3.Network, txhash, inputFormat string) { client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } defer client.Close() // fmt.Println(network.URL) tx, err := client.GetTransactionByHash(ctx, common.HexToHash(txhash)) if err != nil { - fatalExit(fmt.Errorf("Cannot get transaction details from %v network: %v", network.Name, err)) + fatalExit(fmt.Errorf("cannot get transaction details from %v network: %v", network.Name, err)) } if verbose { fmt.Println("Transaction details:") @@ -1424,7 +1424,7 @@ func GetAddressDetails(ctx context.Context, network web3.Network, addrHash, priv contractAddress string, blockNumber string) { if addrHash == "" { if privateKey == "" { - fatalExit(errors.New("Missing address. Must be specified as only argument, or implied from a private key.")) + fatalExit(errors.New("missing address. Must be specified as only argument, or implied from a private key")) } acct, err := web3.ParsePrivateKey(privateKey) if err != nil { @@ -1455,22 +1455,22 @@ func GetAddressDetails(ctx context.Context, network web3.Network, addrHash, priv if blockNumber != "" { blockN, err = web3.ParseBigInt(blockNumber) if err != nil { - fatalExit(fmt.Errorf("Block argument must be a number (decimal integer) %q: %v", blockNumber, err)) + fatalExit(fmt.Errorf("block argument must be a number (decimal integer) %q: %v", blockNumber, err)) } } client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } defer client.Close() bal, err := client.GetBalance(ctx, addrHash, blockN) if err != nil { - fatalExit(fmt.Errorf("Cannot get address balance from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get address balance from the network: %v", err)) } code, err := client.GetCode(ctx, addrHash, nil) if err != nil { - fatalExit(fmt.Errorf("Cannot get address code from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get address code from the network: %v", err)) } if verbose { log.Println("Address details:") @@ -1503,12 +1503,12 @@ func GetAddressDetails(ctx context.Context, network web3.Network, addrHash, priv func GetSnapshot(ctx context.Context, rpcURL string) { client, err := web3.Dial(rpcURL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", rpcURL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", rpcURL, err)) } defer client.Close() s, err := client.GetSnapshot(ctx) if err != nil { - fatalExit(fmt.Errorf("Cannot get snapshot from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get snapshot from the network: %v", err)) } if verbose { log.Println("Snapshot details:") @@ -1567,12 +1567,12 @@ func GetSnapshot(ctx context.Context, rpcURL string) { func GetID(ctx context.Context, rpcURL string) { client, err := web3.Dial(rpcURL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", rpcURL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", rpcURL, err)) } defer client.Close() id, err := client.GetID(ctx) if err != nil { - fatalExit(fmt.Errorf("Cannot get id info from the network: %v", err)) + fatalExit(fmt.Errorf("cannot get id info from the network: %v", err)) } if verbose { log.Println("Snapshot details:") @@ -1590,12 +1590,12 @@ func GetID(ctx context.Context, rpcURL string) { // BuildSol builds a contract. Generated files will be under output, or the current directory. func BuildSol(ctx context.Context, filename, solcVersion, evmVersion string, optimize bool, output string) { if filename == "" { - fatalExit(errors.New("Missing file name arg")) + fatalExit(errors.New("missing file name arg")) } flatOut := "" if output != "" { if err := os.MkdirAll(output, 0777); err != nil { - fatalExit(fmt.Errorf("Failed to create output directory: %v", err)) + fatalExit(fmt.Errorf("failed to create output directory: %v", err)) } basename := filepath.Base(filename) oName := strings.TrimSuffix(basename, filepath.Ext(basename)) + "_flatten.sol" @@ -1603,11 +1603,11 @@ func BuildSol(ctx context.Context, filename, solcVersion, evmVersion string, opt } name, sourceFile, err := FlattenSourceFile(ctx, filename, flatOut) if err != nil { - fatalExit(fmt.Errorf("Cannot generate flattened file: %v", err)) + fatalExit(fmt.Errorf("cannot generate flattened file: %v", err)) } b, err := ioutil.ReadFile(sourceFile) if err != nil { - fatalExit(fmt.Errorf("Failed to read file %q: %v", sourceFile, err)) + fatalExit(fmt.Errorf("failed to read file %q: %v", sourceFile, err)) } str := string(b) // convert content to a 'string' if verbose { @@ -1615,7 +1615,7 @@ func BuildSol(ctx context.Context, filename, solcVersion, evmVersion string, opt } compileData, err := web3.CompileSolidityString(ctx, str, solcVersion, evmVersion, optimize) if err != nil { - fatalExit(fmt.Errorf("Failed to compile %q: %v", sourceFile, err)) + fatalExit(fmt.Errorf("failed to compile %q: %v", sourceFile, err)) } if verbose { log.Println("Compiled Sol Details:", marshalJSON(compileData)) @@ -1635,11 +1635,11 @@ func BuildSol(ctx context.Context, filename, solcVersion, evmVersion string, opt path := filepath.Join(output, fileparts[1]) err := ioutil.WriteFile(path+".bin", []byte(v.Code), 0600) if err != nil { - fatalExit(fmt.Errorf("Cannot write the bin file: %v", err)) + fatalExit(fmt.Errorf("cannot write the bin file: %v", err)) } err = ioutil.WriteFile(path+".abi", []byte(marshalJSON(v.Info.AbiDefinition)), 0600) if err != nil { - fatalExit(fmt.Errorf("Cannot write the abi file: %v", err)) + fatalExit(fmt.Errorf("cannot write the abi file: %v", err)) } filenames = append(filenames, fileparts[1]) } @@ -1669,11 +1669,11 @@ func BuildSol(ctx context.Context, filename, solcVersion, evmVersion string, opt func FlattenSol(ctx context.Context, iFile, oFile string) { if iFile == "" { - fatalExit(errors.New("Missing file name arg")) + fatalExit(errors.New("missing file name arg")) } _, oFile, err := FlattenSourceFile(ctx, iFile, oFile) if err != nil { - fatalExit(fmt.Errorf("Cannot generate flattened file: %v", err)) + fatalExit(fmt.Errorf("cannot generate flattened file: %v", err)) } switch format { case "json": @@ -1688,11 +1688,11 @@ func DeploySol(ctx context.Context, network web3.Network, gasPrice *big.Int, gasLimit uint64, upgradeable bool, timeoutInSeconds uint64, params ...interface{}) { if binFile == "" { - fatalExit(errors.New("Missing contract name arg.")) + fatalExit(errors.New("missing contract name arg")) } client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } client.SetChainID(network.ChainID) defer client.Close() @@ -1701,10 +1701,10 @@ func DeploySol(ctx context.Context, network web3.Network, if strings.HasPrefix(binFile, "http") { bin, err = gotils.GetBytes(binFile) } else { - bin, err = ioutil.ReadFile(binFile) + bin, err = os.ReadFile(binFile) } if err != nil { - fatalExit(fmt.Errorf("Cannot read bin file %q: %v", binFile, err)) + fatalExit(fmt.Errorf("cannot read bin file %q: %v", binFile, err)) } var abi string if len(params) > 0 { @@ -1716,18 +1716,18 @@ func DeploySol(ctx context.Context, network web3.Network, b, err = ioutil.ReadFile(abiFile) } if err != nil { - fatalExit(fmt.Errorf("Cannot read abi file %q: %v", abiFile, err)) + fatalExit(fmt.Errorf("cannot read abi file %q: %v", abiFile, err)) } abi = string(b) } tx, err := web3.DeployContract(ctx, client, privateKey, string(bin), abi, gasPrice, gasLimit, params...) if err != nil { - fatalExit(fmt.Errorf("Error deploying contract: %v", err)) + fatalExit(fmt.Errorf("error deploying contract: %v", err)) } waitCtx, _ := context.WithTimeout(ctx, time.Duration(timeoutInSeconds)*time.Second) receipt, err := web3.WaitForReceipt(waitCtx, client, tx.Hash) if err != nil { - fatalExit(fmt.Errorf("Cannot get the receipt for transaction with hash '%v': %v", tx.Hash.Hex(), err)) + fatalExit(fmt.Errorf("cannot get the receipt for transaction with hash '%v': %v", tx.Hash.Hex(), err)) } switch format { @@ -1737,7 +1737,7 @@ func DeploySol(ctx context.Context, network web3.Network, } if receipt.Status != types.ReceiptStatusSuccessful { - fatalExit(fmt.Errorf("Contract deploy tx failed: %s. Did you pass in the correct constructor arguments?", tx.Hash.Hex())) + fatalExit(fmt.Errorf("contract deploy tx failed: %s. Did you pass in the correct constructor arguments?", tx.Hash.Hex())) } // Exit early if contract is static. @@ -1763,7 +1763,7 @@ func DeploySol(ctx context.Context, network web3.Network, } if proxyReceipt.Status != types.ReceiptStatusSuccessful { - fatalExit(fmt.Errorf("Upgradeable proxy contract deploy tx failed: %s", proxyTx.Hash.Hex())) + fatalExit(fmt.Errorf("upgradeable proxy contract deploy tx failed: %s", proxyTx.Hash.Hex())) } fmt.Println("Upgradeable contract has been successfully deployed.") @@ -1794,12 +1794,12 @@ func VerifyContract(ctx context.Context, network web3.Network, explorerURL, cont } source, err := ioutil.ReadFile(sourceCodeFile) if err != nil { - fatalExit(fmt.Errorf("Cannot read the source code file %q: %v", sourceCodeFile, err)) + fatalExit(fmt.Errorf("cannot read the source code file %q: %v", sourceCodeFile, err)) } if compilerVersion == "" { sol, err := web3.SolidityVersion(string(source)) if err != nil { - fatalExit(fmt.Errorf("Cannot parse the version from the source code file %q: %v", sourceCodeFile, err)) + fatalExit(fmt.Errorf("cannot parse the version from the source code file %q: %v", sourceCodeFile, err)) } compilerVersion = sol.Version } @@ -1849,7 +1849,7 @@ func VerifyContract(ctx context.Context, network web3.Network, explorerURL, cont if err != nil { fatalExit(fmt.Errorf("cannot parse the error message: %v", err)) } - fatalExit(fmt.Errorf("Cannot verify the contract: %s, error code: %v", errResp.Error.Message, resp.StatusCode)) + fatalExit(fmt.Errorf("cannot verify the contract: %s, error code: %v", errResp.Error.Message, resp.StatusCode)) } func UpgradeContract(ctx context.Context, rpcURL string, chainID *big.Int, privateKey, contractAddress, newTargetAddress string, amount *big.Int, timeoutInSeconds uint64) { @@ -1949,7 +1949,7 @@ func ResumeContract(ctx context.Context, rpcURL string, chainID *big.Int, privat func marshalJSON(data interface{}) string { b, err := json.MarshalIndent(data, "", " ") if err != nil { - fatalExit(fmt.Errorf("Cannot marshal json: %v", err)) + fatalExit(fmt.Errorf("cannot marshal json: %v", err)) } return string(b) } diff --git a/cmd/web3/start.go b/cmd/web3/start.go index 62068ec..ffa2bc2 100644 --- a/cmd/web3/start.go +++ b/cmd/web3/start.go @@ -86,7 +86,7 @@ func start(ctx context.Context, c *cli.Context) error { cmd.Stderr = os.Stderr err = cmd.Run() if err != nil { - fatalExit(fmt.Errorf("Failed to run command %v", err)) + fatalExit(fmt.Errorf("failed to run command %v", err)) } return nil } diff --git a/cmd/web3/transactions.go b/cmd/web3/transactions.go index 43b8922..88a7dfc 100644 --- a/cmd/web3/transactions.go +++ b/cmd/web3/transactions.go @@ -16,7 +16,7 @@ import ( func IncreaseGas(ctx context.Context, privateKey string, network web3.Network, txHash string, amountGwei string) { client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } defer client.Close() // then we'll clone the original and increase gas @@ -42,7 +42,7 @@ func ReplaceTx(ctx context.Context, privateKey string, network web3.Network, non gasPrice *big.Int, gasLimit uint64, data []byte) *types.Transaction { client, err := web3.Dial(network.URL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", network.URL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", network.URL, err)) } defer client.Close() if gasPrice == nil { @@ -81,7 +81,7 @@ func ReplaceTx(ctx context.Context, privateKey string, network web3.Network, non func Transfer(ctx context.Context, rpcURL string, chainID *big.Int, privateKey, contractAddress string, gasPrice *big.Int, gasLimit uint64, wait, toString bool, timeoutInSeconds uint64, tail []string) { if len(tail) < 3 { - fatalExit(errors.New("Invalid arguments. Format is: `transfer X to ADDRESS`")) + fatalExit(errors.New("invalid arguments. Format is: `transfer X to ADDRESS`")) } amountS := tail[0] @@ -93,7 +93,7 @@ func Transfer(ctx context.Context, rpcURL string, chainID *big.Int, privateKey, client, err := web3.Dial(rpcURL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", rpcURL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", rpcURL, err)) } client.SetChainID(chainID) defer client.Close() @@ -110,15 +110,15 @@ func Transfer(ctx context.Context, rpcURL string, chainID *big.Int, privateKey, amount := web3.DecToInt(amountD, 18) if toAddress == "" { - fatalExit(errors.New("The recepient address cannot be empty")) + fatalExit(errors.New("the recepient address cannot be empty")) } if !common.IsHexAddress(toAddress) { - fatalExit(fmt.Errorf("Invalid to 'address': %s", toAddress)) + fatalExit(fmt.Errorf("invalid to 'address': %s", toAddress)) } address := common.HexToAddress(toAddress) tx, err := web3.Send(ctx, client, privateKey, address, amount, gasPrice, gasLimit) if err != nil { - fatalExit(fmt.Errorf("Cannot create transaction: %v", err)) + fatalExit(fmt.Errorf("cannot create transaction: %v", err)) } fmt.Println("Transaction address:", tx.Hash.Hex()) } @@ -174,7 +174,7 @@ func GetTransactionReceipt(ctx context.Context, rpcURL, txhash, contractFile str var myabi *abi.ABI client, err := web3.Dial(rpcURL) if err != nil { - fatalExit(fmt.Errorf("Failed to connect to %q: %v", rpcURL, err)) + fatalExit(fmt.Errorf("failed to connect to %q: %v", rpcURL, err)) } defer client.Close() if contractFile != "" { @@ -185,7 +185,7 @@ func GetTransactionReceipt(ctx context.Context, rpcURL, txhash, contractFile str } r, err := client.GetTransactionReceipt(ctx, common.HexToHash(txhash)) if err != nil { - fatalExit(fmt.Errorf("Failed to get transaction receipt: %v", err)) + fatalExit(fmt.Errorf("failed to get transaction receipt: %v", err)) } if verbose { fmt.Println("Transaction Receipt Details:")