diff options
46 files changed, 99 insertions, 194 deletions
diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 84cf22e3c..73e95e02a 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -147,21 +147,21 @@ func bindTypeGo(kind abi.Type) string { switch { case strings.HasPrefix(stringKind, "address"): - parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 2 { return stringKind } return fmt.Sprintf("%scommon.Address", parts[1]) case strings.HasPrefix(stringKind, "bytes"): - parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 3 { return stringKind } return fmt.Sprintf("%s[%s]byte", parts[2], parts[1]) case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"): - parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 4 { return stringKind } @@ -172,7 +172,7 @@ func bindTypeGo(kind abi.Type) string { return fmt.Sprintf("%s*big.Int", parts[3]) case strings.HasPrefix(stringKind, "bool") || strings.HasPrefix(stringKind, "string"): - parts := regexp.MustCompile("([a-z]+)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`([a-z]+)(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 3 { return stringKind } @@ -191,7 +191,7 @@ func bindTypeJava(kind abi.Type) string { switch { case strings.HasPrefix(stringKind, "address"): - parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 2 { return stringKind } @@ -201,7 +201,7 @@ func bindTypeJava(kind abi.Type) string { return fmt.Sprintf("Addresses") case strings.HasPrefix(stringKind, "bytes"): - parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 3 { return stringKind } @@ -211,7 +211,7 @@ func bindTypeJava(kind abi.Type) string { return "byte[]" case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"): - parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 4 { return stringKind } @@ -230,7 +230,7 @@ func bindTypeJava(kind abi.Type) string { return fmt.Sprintf("BigInts") case strings.HasPrefix(stringKind, "bool"): - parts := regexp.MustCompile("bool(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`bool(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 2 { return stringKind } @@ -240,7 +240,7 @@ func bindTypeJava(kind abi.Type) string { return fmt.Sprintf("bool[]") case strings.HasPrefix(stringKind, "string"): - parts := regexp.MustCompile("string(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) + parts := regexp.MustCompile(`string(\[[0-9]*\])?`).FindStringSubmatch(stringKind) if len(parts) != 2 { return stringKind } @@ -278,7 +278,7 @@ func namedTypeJava(javaKind string, solKind abi.Type) string { case "bool[]": return "Bools" case "BigInt": - parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(solKind.String()) + parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(solKind.String()) if len(parts) != 4 { return javaKind } diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 7af7ff386..2bd341bd2 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -65,7 +65,7 @@ var ( // string int uint fixed // string32 int8 uint8 uint[] // address int256 uint256 fixed128x128[2] - fullTypeRegex = regexp.MustCompile("([a-zA-Z0-9]+)(\\[([0-9]*)\\])?") + fullTypeRegex = regexp.MustCompile(`([a-zA-Z0-9]+)(\[([0-9]*)\])?`) // typeRegex parses the abi sub types typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?") ) diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go index 7ce663dc0..14b839579 100644 --- a/cmd/ethtest/main.go +++ b/cmd/ethtest/main.go @@ -88,12 +88,7 @@ func runTestWithReader(test string, r io.Reader) error { default: err = fmt.Errorf("Invalid test type specified: %v", test) } - - if err != nil { - return err - } - - return nil + return err } func getFiles(path string) ([]string, error) { diff --git a/cmd/geth/accountcmd_test.go b/cmd/geth/accountcmd_test.go index b6abde6d8..113df983e 100644 --- a/cmd/geth/accountcmd_test.go +++ b/cmd/geth/accountcmd_test.go @@ -148,7 +148,7 @@ Passphrase: {{.InputLine "foobar"}} "Unlocked account f466859ead1932d743d622cb74fc058882e8648a", } for _, m := range wantMessages { - if strings.Index(geth.stderrText(), m) == -1 { + if !strings.Contains(geth.stderrText(), m) { t.Errorf("stderr text does not contain %q", m) } } @@ -193,7 +193,7 @@ Passphrase: {{.InputLine "foobar"}} "Unlocked account 289d485d9771714cce91d3393d764e1311907acc", } for _, m := range wantMessages { - if strings.Index(geth.stderrText(), m) == -1 { + if !strings.Contains(geth.stderrText(), m) { t.Errorf("stderr text does not contain %q", m) } } @@ -212,7 +212,7 @@ func TestUnlockFlagPasswordFile(t *testing.T) { "Unlocked account 289d485d9771714cce91d3393d764e1311907acc", } for _, m := range wantMessages { - if strings.Index(geth.stderrText(), m) == -1 { + if !strings.Contains(geth.stderrText(), m) { t.Errorf("stderr text does not contain %q", m) } } @@ -260,7 +260,7 @@ In order to avoid this warning, you need to remove the following duplicate key f "Unlocked account f466859ead1932d743d622cb74fc058882e8648a", } for _, m := range wantMessages { - if strings.Index(geth.stderrText(), m) == -1 { + if !strings.Contains(geth.stderrText(), m) { t.Errorf("stderr text does not contain %q", m) } } diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index a56507e4d..287efc9c8 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -95,7 +95,7 @@ func StartNode(stack *node.Node) { func FormatTransactionData(data string) []byte { d := common.StringToByteFunc(data, func(s string) (ret []byte) { - slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000) + slice := regexp.MustCompile(`\n|\s`).Split(s, 1000000000) for _, dataItem := range slice { d := common.FormatData(dataItem) ret = append(ret, d...) diff --git a/common/big_test.go b/common/big_test.go index 1eb0c0c1f..4d04a8db3 100644 --- a/common/big_test.go +++ b/common/big_test.go @@ -27,7 +27,7 @@ func TestMisc(t *testing.T) { c := []byte{1, 2, 3, 4} z := BitTest(a, 1) - if z != true { + if !z { t.Error("Expected true got", z) } @@ -79,11 +79,11 @@ func TestBigCopy(t *testing.T) { z := BigToBytes(c, 16) zbytes := []byte{232, 212, 165, 16, 0} - if bytes.Compare(y, ybytes) != 0 { + if !bytes.Equal(y, ybytes) { t.Error("Got", ybytes) } - if bytes.Compare(z, zbytes) != 0 { + if !bytes.Equal(z, zbytes) { t.Error("Got", zbytes) } } diff --git a/common/bytes_test.go b/common/bytes_test.go index 2e5208477..98d402c48 100644 --- a/common/bytes_test.go +++ b/common/bytes_test.go @@ -181,7 +181,7 @@ func TestFromHex(t *testing.T) { input := "0x01" expected := []byte{1} result := FromHex(input) - if bytes.Compare(expected, result) != 0 { + if !bytes.Equal(expected, result) { t.Errorf("Expected % x got % x", expected, result) } } @@ -190,7 +190,7 @@ func TestFromHexOddLength(t *testing.T) { input := "0x1" expected := []byte{1} result := FromHex(input) - if bytes.Compare(expected, result) != 0 { + if !bytes.Equal(expected, result) { t.Errorf("Expected % x got % x", expected, result) } } diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index b0ca9bd75..d27bddd9f 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -32,7 +32,7 @@ import ( ) var ( - versionRegexp = regexp.MustCompile("[0-9]+\\.[0-9]+\\.[0-9]+") + versionRegexp = regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`) solcParams = []string{ "--combined-json", "bin,abi,userdoc,devdoc", "--add-std", // include standard lib contracts diff --git a/common/format.go b/common/format.go index 119637d2e..fccc29962 100644 --- a/common/format.go +++ b/common/format.go @@ -27,7 +27,7 @@ import ( // the unnecessary precision off from the formatted textual representation. type PrettyDuration time.Duration -var prettyDurationRe = regexp.MustCompile("\\.[0-9]+") +var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`) // String implements the Stringer interface, allowing pretty printing of duration // values rounded to three decimals. diff --git a/compression/rle/read_write.go b/compression/rle/read_write.go index 03dffd607..0e7ad90ae 100644 --- a/compression/rle/read_write.go +++ b/compression/rle/read_write.go @@ -76,9 +76,9 @@ func compressChunk(dat []byte) (ret []byte, n int) { } return []byte{token, byte(j + 2)}, j case len(dat) >= 32: - if dat[0] == empty[0] && bytes.Compare(dat[:32], empty) == 0 { + if dat[0] == empty[0] && bytes.Equal(dat[:32], empty) { return []byte{token, emptyShaToken}, 32 - } else if dat[0] == emptyList[0] && bytes.Compare(dat[:32], emptyList) == 0 { + } else if dat[0] == emptyList[0] && bytes.Equal(dat[:32], emptyList) { return []byte{token, emptyListShaToken}, 32 } fallthrough diff --git a/console/console.go b/console/console.go index 6e3d7e43c..8865f5e89 100644 --- a/console/console.go +++ b/console/console.go @@ -36,9 +36,9 @@ import ( ) var ( - passwordRegexp = regexp.MustCompile("personal.[nus]") - onlyWhitespace = regexp.MustCompile("^\\s*$") - exit = regexp.MustCompile("^\\s*exit\\s*;*\\s*$") + passwordRegexp = regexp.MustCompile(`personal.[nus]`) + onlyWhitespace = regexp.MustCompile(`^\s*$`) + exit = regexp.MustCompile(`^\s*exit\s*;*\s*$`) ) // HistoryFile is the file within the data directory to store input scrollback. @@ -275,10 +275,7 @@ func (c *Console) Evaluate(statement string) error { fmt.Fprintf(c.printer, "[native] error: %v\n", r) } }() - if err := c.jsre.Evaluate(statement, c.printer); err != nil { - return err - } - return nil + return c.jsre.Evaluate(statement, c.printer) } // Interactive starts an interactive user session, where input is propted from diff --git a/core/blockchain.go b/core/blockchain.go index 3c9e1f7cb..8c2be7231 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -402,10 +402,7 @@ func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) { // Export writes the active chain to the given writer. func (self *BlockChain) Export(w io.Writer) error { - if err := self.ExportN(w, uint64(0), self.currentBlock.NumberU64()); err != nil { - return err - } - return nil + return self.ExportN(w, uint64(0), self.currentBlock.NumberU64()) } // ExportN writes a subset of the active chain to the given writer. diff --git a/core/dao.go b/core/dao.go index 1260c310a..a7f544c3d 100644 --- a/core/dao.go +++ b/core/dao.go @@ -45,11 +45,11 @@ func ValidateDAOHeaderExtraData(config *params.ChainConfig, header *types.Header } // Depending whether we support or oppose the fork, validate the extra-data contents if config.DAOForkSupport { - if bytes.Compare(header.Extra, params.DAOForkBlockExtra) != 0 { + if !bytes.Equal(header.Extra, params.DAOForkBlockExtra) { return ValidationError("DAO pro-fork bad block extra-data: 0x%x", header.Extra) } } else { - if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 { + if bytes.Equal(header.Extra, params.DAOForkBlockExtra) { return ValidationError("DAO no-fork bad block extra-data: 0x%x", header.Extra) } } diff --git a/core/database_util_test.go b/core/database_util_test.go index c8fd857ea..d96aa71ba 100644 --- a/core/database_util_test.go +++ b/core/database_util_test.go @@ -430,7 +430,7 @@ func TestReceiptStorage(t *testing.T) { rlpHave, _ := rlp.EncodeToBytes(r) rlpWant, _ := rlp.EncodeToBytes(receipt) - if bytes.Compare(rlpHave, rlpWant) != 0 { + if !bytes.Equal(rlpHave, rlpWant) { t.Fatalf("receipt #%d [%x]: receipt mismatch: have %v, want %v", i, receipt.TxHash, r, receipt) } } @@ -488,7 +488,7 @@ func TestBlockReceiptStorage(t *testing.T) { rlpHave, _ := rlp.EncodeToBytes(rs[i]) rlpWant, _ := rlp.EncodeToBytes(receipts[i]) - if bytes.Compare(rlpHave, rlpWant) != 0 { + if !bytes.Equal(rlpHave, rlpWant) { t.Fatalf("receipt #%d: receipt mismatch: have %v, want %v", i, rs[i], receipts[i]) } } diff --git a/core/state/iterator.go b/core/state/iterator.go index 14265b277..a58a15ad3 100644 --- a/core/state/iterator.go +++ b/core/state/iterator.go @@ -123,7 +123,7 @@ func (it *NodeIterator) step() error { if !it.dataIt.Next() { it.dataIt = nil } - if bytes.Compare(account.CodeHash, emptyCodeHash) != 0 { + if !bytes.Equal(account.CodeHash, emptyCodeHash) { it.codeHash = common.BytesToHash(account.CodeHash) it.code, err = it.state.db.Get(account.CodeHash) if err != nil { diff --git a/core/state/sync_test.go b/core/state/sync_test.go index cb585f78c..43d146e3a 100644 --- a/core/state/sync_test.go +++ b/core/state/sync_test.go @@ -84,7 +84,7 @@ func checkStateAccounts(t *testing.T, db ethdb.Database, root common.Hash, accou if nonce := state.GetNonce(acc.address); nonce != acc.nonce { t.Errorf("account %d: nonce mismatch: have %v, want %v", i, nonce, acc.nonce) } - if code := state.GetCode(acc.address); bytes.Compare(code, acc.code) != 0 { + if code := state.GetCode(acc.address); !bytes.Equal(code, acc.code) { t.Errorf("account %d: code mismatch: have %x, want %x", i, code, acc.code) } } @@ -294,7 +294,7 @@ func TestIncompleteStateSync(t *testing.T) { // Skim through the accounts and make sure the root hash is not a code node codeHash := false for _, acc := range srcAccounts { - if bytes.Compare(root.Bytes(), crypto.Sha3(acc.code)) == 0 { + if root == crypto.Keccak256Hash(acc.code) { codeHash = true break } diff --git a/core/types/bloom9.go b/core/types/bloom9.go index bcca59907..32aa47a41 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -97,14 +97,8 @@ func CreateBloom(receipts Receipts) Bloom { func LogsBloom(logs []*Log) *big.Int { bin := new(big.Int) for _, log := range logs { - data := make([]common.Hash, len(log.Topics)) bin.Or(bin, bloom9(log.Address.Bytes())) - - for i, topic := range log.Topics { - data[i] = topic - } - - for _, b := range data { + for _, b := range log.Topics { bin.Or(bin, bloom9(b[:])) } } diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 86a582306..f42605d32 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -217,7 +217,7 @@ func TestValidateSignatureValues(t *testing.T) { func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) { sum := f(msg) - if bytes.Compare(exp, sum) != 0 { + if !bytes.Equal(exp, sum) { t.Fatalf("hash %s mismatch: want: %x have: %x", name, exp, sum) } } diff --git a/crypto/ecies/ecies.go b/crypto/ecies/ecies.go index 86a70261d..b1a716c00 100644 --- a/crypto/ecies/ecies.go +++ b/crypto/ecies/ecies.go @@ -291,9 +291,8 @@ func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err e // Decrypt decrypts an ECIES ciphertext. func (prv *PrivateKey) Decrypt(rand io.Reader, c, s1, s2 []byte) (m []byte, err error) { - if c == nil || len(c) == 0 { - err = ErrInvalidMessage - return + if len(c) == 0 { + return nil, ErrInvalidMessage } params := prv.PublicKey.Params if params == nil { diff --git a/eth/handler.go b/eth/handler.go index 771e69b8d..1de3f67e6 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -607,38 +607,16 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { } case msg.Code == NewBlockHashesMsg: - // Retrieve and deserialize the remote new block hashes notification - type announce struct { - Hash common.Hash - Number uint64 - } - var announces = []announce{} - - if p.version < eth62 { - // We're running the old protocol, make block number unknown (0) - var hashes []common.Hash - if err := msg.Decode(&hashes); err != nil { - return errResp(ErrDecode, "%v: %v", msg, err) - } - for _, hash := range hashes { - announces = append(announces, announce{hash, 0}) - } - } else { - // Otherwise extract both block hash and number - var request newBlockHashesData - if err := msg.Decode(&request); err != nil { - return errResp(ErrDecode, "%v: %v", msg, err) - } - for _, block := range request { - announces = append(announces, announce{block.Hash, block.Number}) - } + var announces newBlockHashesData + if err := msg.Decode(&announces); err != nil { + return errResp(ErrDecode, "%v: %v", msg, err) } // Mark the hashes as present at the remote node for _, block := range announces { p.MarkBlock(block.Hash) } // Schedule all the unknown hashes for retrieval - unknown := make([]announce, 0, len(announces)) + unknown := make(newBlockHashesData, 0, len(announces)) for _, block := range announces { if !pm.blockchain.HasBlock(block.Hash) { unknown = append(unknown, block) diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index b802d347f..8692a43bd 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -388,10 +388,7 @@ func (s *Service) reportLatency(out *json.Encoder) error { "latency": strconv.Itoa(int((time.Since(start) / time.Duration(2)).Nanoseconds() / 1000000)), }}, } - if err := out.Encode(latency); err != nil { - return err - } - return nil + return out.Encode(latency) } // blockStats is the information to report about individual blocks. @@ -440,10 +437,7 @@ func (s *Service) reportBlock(out *json.Encoder, block *types.Block) error { report := map[string][]interface{}{ "emit": {"block", stats}, } - if err := out.Encode(report); err != nil { - return err - } - return nil + return out.Encode(report) } // assembleBlockStats retrieves any required metadata to report a single block @@ -497,9 +491,7 @@ func (s *Service) reportHistory(out *json.Encoder, list []uint64) error { indexes := make([]uint64, 0, historyUpdateRange) if len(list) > 0 { // Specific indexes requested, send them back in particular - for _, idx := range list { - indexes = append(indexes, idx) - } + indexes = append(indexes, list...) } else { // No indexes requested, send back the top ones var head *types.Header @@ -533,10 +525,7 @@ func (s *Service) reportHistory(out *json.Encoder, list []uint64) error { report := map[string][]interface{}{ "emit": {"history", stats}, } - if err := out.Encode(report); err != nil { - return err - } - return nil + return out.Encode(report) } // pendStats is the information to report about pending transactions. @@ -564,10 +553,7 @@ func (s *Service) reportPending(out *json.Encoder) error { report := map[string][]interface{}{ "emit": {"pending", stats}, } - if err := out.Encode(report); err != nil { - return err - } - return nil + return out.Encode(report) } // blockStats is the information to report about the local node. @@ -618,8 +604,5 @@ func (s *Service) reportStats(out *json.Encoder) error { report := map[string][]interface{}{ "emit": {"stats", stats}, } - if err := out.Encode(report); err != nil { - return err - } - return nil + return out.Encode(report) } diff --git a/miner/worker.go b/miner/worker.go index 9e70c8f04..68ce44db0 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -449,7 +449,7 @@ func (self *worker) commitNewWork() { // Depending whether we support or oppose the fork, override differently if self.config.DAOForkSupport { header.Extra = common.CopyBytes(params.DAOForkBlockExtra) - } else if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 { + } else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) { header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data } } diff --git a/mobile/bind.go b/mobile/bind.go index a25c37aca..bc4eb25ba 100644 --- a/mobile/bind.go +++ b/mobile/bind.go @@ -114,17 +114,12 @@ type BoundContract struct { // DeployContract deploys a contract onto the Ethereum blockchain and binds the // deployment address with a wrapper. func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client *EthereumClient, args *Interfaces) (contract *BoundContract, _ error) { - // Convert all the deployment parameters to Go types - params := make([]interface{}, len(args.objects)) - for i, obj := range args.objects { - params[i] = obj - } // Deploy the contract to the network parsed, err := abi.JSON(strings.NewReader(abiJSON)) if err != nil { return nil, err } - addr, tx, bound, err := bind.DeployContract(&opts.opts, parsed, bytecode, client.client, params...) + addr, tx, bound, err := bind.DeployContract(&opts.opts, parsed, bytecode, client.client, args.objects...) if err != nil { return nil, err } @@ -159,32 +154,18 @@ func (c *BoundContract) GetDeployer() *Transaction { // Call invokes the (constant) contract method with params as input values and // sets the output to result. func (c *BoundContract) Call(opts *CallOpts, out *Interfaces, method string, args *Interfaces) error { - // Convert all the input and output parameters to Go types - params := make([]interface{}, len(args.objects)) - for i, obj := range args.objects { - params[i] = obj - } results := make([]interface{}, len(out.objects)) - for i, obj := range out.objects { - results[i] = obj - } - // Execute the call to the contract and wrap any results - if err := c.contract.Call(&opts.opts, &results, method, params...); err != nil { + copy(results, out.objects) + if err := c.contract.Call(&opts.opts, &results, method, args.objects...); err != nil { return err } - for i, res := range results { - out.objects[i] = res - } + copy(out.objects, results) return nil } // Transact invokes the (paid) contract method with params as input values. func (c *BoundContract) Transact(opts *TransactOpts, method string, args *Interfaces) (tx *Transaction, _ error) { - params := make([]interface{}, len(args.objects)) - for i, obj := range args.objects { - params[i] = obj - } - rawTx, err := c.contract.Transact(&opts.opts, method, params) + rawTx, err := c.contract.Transact(&opts.opts, method, args.objects) if err != nil { return nil, err } diff --git a/node/config_test.go b/node/config_test.go index b258d2a8b..d18732fdb 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -137,7 +137,7 @@ func TestNodeKeyPersistency(t *testing.T) { if err != nil { t.Fatalf("failed to read previously persisted node key: %v", err) } - if bytes.Compare(blob1, blob2) != 0 { + if !bytes.Equal(blob1, blob2) { t.Fatalf("persisted node key mismatch: have %x, want %x", blob2, blob1) } diff --git a/node/node_test.go b/node/node_test.go index 6b2b62d73..95fa53b06 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -218,7 +218,7 @@ func TestServiceRestarts(t *testing.T) { } defer stack.Stop() - if running != true || started != 1 { + if running || started != 1 { t.Fatalf("running/started mismatch: have %v/%d, want true/1", running, started) } // Restart the stack a few times and check successful service restarts @@ -227,7 +227,7 @@ func TestServiceRestarts(t *testing.T) { t.Fatalf("iter %d: failed to restart stack: %v", i, err) } } - if running != true || started != 4 { + if !running || started != 4 { t.Fatalf("running/started mismatch: have %v/%d, want true/4", running, started) } } diff --git a/p2p/discover/database.go b/p2p/discover/database.go index d6ea507bb..8d20d1ec7 100644 --- a/p2p/discover/database.go +++ b/p2p/discover/database.go @@ -258,7 +258,7 @@ func (db *nodeDB) expireNodes() error { continue } // Skip the node if not expired yet (and not self) - if bytes.Compare(id[:], db.self[:]) != 0 { + if !bytes.Equal(id[:], db.self[:]) { if seen := db.lastPong(id); seen.After(threshold) { continue } diff --git a/p2p/discover/node.go b/p2p/discover/node.go index eec0bae0c..8b1062d87 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -224,11 +224,8 @@ func (n NodeID) GoString() string { // HexID converts a hex string to a NodeID. // The string may be prefixed with 0x. func HexID(in string) (NodeID, error) { - if strings.HasPrefix(in, "0x") { - in = in[2:] - } var id NodeID - b, err := hex.DecodeString(in) + b, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) if err != nil { return id, err } else if len(b) != len(id) { diff --git a/p2p/discv5/database.go b/p2p/discv5/database.go index 7c47c27fd..44be8a74e 100644 --- a/p2p/discv5/database.go +++ b/p2p/discv5/database.go @@ -269,7 +269,7 @@ func (db *nodeDB) expireNodes() error { continue } // Skip the node if not expired yet (and not self) - if bytes.Compare(id[:], db.self[:]) != 0 { + if !bytes.Equal(id[:], db.self[:]) { if seen := db.lastPong(id); seen.After(threshold) { continue } diff --git a/p2p/discv5/node.go b/p2p/discv5/node.go index b2025ebcb..cfc833ff5 100644 --- a/p2p/discv5/node.go +++ b/p2p/discv5/node.go @@ -262,11 +262,8 @@ func (n NodeID) GoString() string { // HexID converts a hex string to a NodeID. // The string may be prefixed with 0x. func HexID(in string) (NodeID, error) { - if strings.HasPrefix(in, "0x") { - in = in[2:] - } var id NodeID - b, err := hex.DecodeString(in) + b, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) if err != nil { return id, err } else if len(b) != len(id) { diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 5ecc5c500..4ddebb021 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -354,7 +354,7 @@ func (s *DbStore) Get(key Key) (chunk *Chunk, err error) { hasher := s.hashfunc() hasher.Write(data) hash := hasher.Sum(nil) - if bytes.Compare(hash, key) != 0 { + if !bytes.Equal(hash, key) { s.db.Delete(getDataKey(index.Idx)) err = fmt.Errorf("invalid chunk. hash=%x, key=%v", hash, key[:]) return diff --git a/swarm/storage/types.go b/swarm/storage/types.go index 0dcbc0100..c36522012 100644 --- a/swarm/storage/types.go +++ b/swarm/storage/types.go @@ -41,7 +41,7 @@ func (x Key) Size() uint { } func (x Key) isEqual(y Key) bool { - return bytes.Compare(x, y) == 0 + return bytes.Equal(x, y) } func (h Key) bits(i, j uint) uint { diff --git a/tests/block_test_util.go b/tests/block_test_util.go index f04329546..ea63c9996 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -552,9 +552,7 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) { // Nothing to see here, please move along... func prepInt(base int, s string) string { if base == 16 { - if strings.HasPrefix(s, "0x") { - s = s[2:] - } + s = strings.TrimPrefix(s, "0x") if len(s) == 0 { s = "00" } diff --git a/tests/init.go b/tests/init.go index 361be5f62..7b0924bc3 100644 --- a/tests/init.go +++ b/tests/init.go @@ -87,11 +87,7 @@ func readJsonHttp(uri string, value interface{}) error { } defer resp.Body.Close() - err = readJson(resp.Body, value) - if err != nil { - return err - } - return nil + return readJson(resp.Body, value) } func readJsonFile(fn string, value interface{}) error { diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 8221815a8..7841aecfe 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -159,7 +159,7 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error { } else { rexp = common.FromHex(test.Out) } - if bytes.Compare(rexp, ret) != 0 { + if !bytes.Equal(rexp, ret) { return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret) } diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index d6411147f..f3b9fd1c9 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -172,7 +172,7 @@ func runVmTest(test VmTest) error { // Compare expected and actual return rexp := common.FromHex(test.Out) - if bytes.Compare(rexp, ret) != 0 { + if !bytes.Equal(rexp, ret) { return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret) } diff --git a/trie/sync_test.go b/trie/sync_test.go index 6405a51c3..4168c4d65 100644 --- a/trie/sync_test.go +++ b/trie/sync_test.go @@ -67,7 +67,7 @@ func checkTrieContents(t *testing.T, db Database, root []byte, content map[strin t.Fatalf("inconsistent trie at %x: %v", root, err) } for key, val := range content { - if have := trie.Get([]byte(key)); bytes.Compare(have, val) != 0 { + if have := trie.Get([]byte(key)); !bytes.Equal(have, val) { t.Errorf("entry %x: content mismatch: have %x, want %x", key, have, val) } } diff --git a/whisper/shhapi/api.go b/whisper/shhapi/api.go index 24d54b653..379bb90d3 100644 --- a/whisper/shhapi/api.go +++ b/whisper/shhapi/api.go @@ -178,14 +178,10 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) { Messages: make(map[common.Hash]*whisperv5.ReceivedMessage), AcceptP2P: args.AcceptP2P, } - if len(filter.KeySym) > 0 { filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym) } - - for _, t := range args.Topics { - filter.Topics = append(filter.Topics, t) - } + filter.Topics = append(filter.Topics, args.Topics...) if len(args.Topics) == 0 { info := "NewFilter: at least one topic must be specified" diff --git a/whisper/shhapi/api_test.go b/whisper/shhapi/api_test.go index d2890a9a3..60b6fbd04 100644 --- a/whisper/shhapi/api_test.go +++ b/whisper/shhapi/api_test.go @@ -253,7 +253,7 @@ func TestUnmarshalPostArgs(t *testing.T) { if a.FilterID != 64 { t.Fatalf("wrong FilterID: %d.", a.FilterID) } - if bytes.Compare(a.PeerID[:], a.Topic[:]) != 0 { + if !bytes.Equal(a.PeerID[:], a.Topic[:]) { t.Fatalf("wrong PeerID: %x.", a.PeerID) } } diff --git a/whisper/whisperv2/envelope_test.go b/whisper/whisperv2/envelope_test.go index 75e2fbe8a..c1b128c61 100644 --- a/whisper/whisperv2/envelope_test.go +++ b/whisper/whisperv2/envelope_test.go @@ -40,10 +40,10 @@ func TestEnvelopeOpen(t *testing.T) { if opened.Flags != message.Flags { t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags) } - if bytes.Compare(opened.Signature, message.Signature) != 0 { + if !bytes.Equal(opened.Signature, message.Signature) { t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature) } - if bytes.Compare(opened.Payload, message.Payload) != 0 { + if !bytes.Equal(opened.Payload, message.Payload) { t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload) } if opened.Sent.Unix() != message.Sent.Unix() { @@ -71,7 +71,7 @@ func TestEnvelopeAnonymousOpenUntargeted(t *testing.T) { if opened.To != nil { t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) } - if bytes.Compare(opened.Payload, payload) != 0 { + if !bytes.Equal(opened.Payload, payload) { t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) } } @@ -96,7 +96,7 @@ func TestEnvelopeAnonymousOpenTargeted(t *testing.T) { if opened.To != nil { t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) } - if bytes.Compare(opened.Payload, payload) == 0 { + if bytes.Equal(opened.Payload, payload) { t.Fatalf("payload match, should have been encrypted: 0x%x", opened.Payload) } } @@ -127,7 +127,7 @@ func TestEnvelopeIdentifiedOpenUntargeted(t *testing.T) { if opened.To != nil { t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) } - if bytes.Compare(opened.Payload, payload) != 0 { + if !bytes.Equal(opened.Payload, payload) { t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) } } @@ -152,7 +152,7 @@ func TestEnvelopeIdentifiedOpenTargeted(t *testing.T) { if opened.To != nil { t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) } - if bytes.Compare(opened.Payload, payload) != 0 { + if !bytes.Equal(opened.Payload, payload) { t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) } } diff --git a/whisper/whisperv2/filter.go b/whisper/whisperv2/filter.go index ed7dcd6ae..7404859b7 100644 --- a/whisper/whisperv2/filter.go +++ b/whisper/whisperv2/filter.go @@ -120,10 +120,7 @@ func (self filterer) Compare(f filter.Filter) bool { break } } - if !self.matcher.Matches(topics) { - return false - } - return true + return self.matcher.Matches(topics) } // Trigger is called when a filter successfully matches an inbound message. diff --git a/whisper/whisperv2/filter_test.go b/whisper/whisperv2/filter_test.go index 5a14a84bb..ffdfd7b34 100644 --- a/whisper/whisperv2/filter_test.go +++ b/whisper/whisperv2/filter_test.go @@ -91,7 +91,7 @@ func TestFilterTopicsCreation(t *testing.T) { continue } for k := 0; k < len(condition); k++ { - if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { + if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) { t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) } } @@ -115,7 +115,7 @@ func TestFilterTopicsCreation(t *testing.T) { continue } for k := 0; k < len(condition); k++ { - if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { + if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) { t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) } } @@ -135,7 +135,7 @@ func TestFilterTopicsCreation(t *testing.T) { continue } for k := 0; k < len(condition); k++ { - if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { + if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) { t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) } } @@ -156,7 +156,7 @@ func TestFilterTopicsCreation(t *testing.T) { continue } for k := 0; k < len(condition); k++ { - if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { + if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) { t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) } } diff --git a/whisper/whisperv2/message_test.go b/whisper/whisperv2/message_test.go index efa64e431..d3b307d2a 100644 --- a/whisper/whisperv2/message_test.go +++ b/whisper/whisperv2/message_test.go @@ -40,7 +40,7 @@ func TestMessageSimpleWrap(t *testing.T) { if len(msg.Signature) != 0 { t.Fatalf("signature found for simple wrapping: 0x%x", msg.Signature) } - if bytes.Compare(msg.Payload, payload) != 0 { + if !bytes.Equal(msg.Payload, payload) { t.Fatalf("payload mismatch after wrapping: have 0x%x, want 0x%x", msg.Payload, payload) } if msg.TTL/time.Second != DefaultTTL/time.Second { @@ -65,7 +65,7 @@ func TestMessageCleartextSignRecover(t *testing.T) { if msg.Flags&signatureFlag != signatureFlag { t.Fatalf("signature flag mismatch: have %d, want %d", msg.Flags&signatureFlag, signatureFlag) } - if bytes.Compare(msg.Payload, payload) != 0 { + if !bytes.Equal(msg.Payload, payload) { t.Fatalf("payload mismatch after signing: have 0x%x, want 0x%x", msg.Payload, payload) } diff --git a/whisper/whisperv2/topic_test.go b/whisper/whisperv2/topic_test.go index 66c84ba35..bb6568996 100644 --- a/whisper/whisperv2/topic_test.go +++ b/whisper/whisperv2/topic_test.go @@ -33,13 +33,13 @@ func TestTopicCreation(t *testing.T) { // Create the topics individually for i, tt := range topicCreationTests { topic := NewTopic(tt.data) - if bytes.Compare(topic[:], tt.hash[:]) != 0 { + if !bytes.Equal(topic[:], tt.hash[:]) { t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) } } for i, tt := range topicCreationTests { topic := NewTopicFromString(string(tt.data)) - if bytes.Compare(topic[:], tt.hash[:]) != 0 { + if !bytes.Equal(topic[:], tt.hash[:]) { t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) } } @@ -55,13 +55,13 @@ func TestTopicCreation(t *testing.T) { topics := NewTopics(binaryData...) for i, tt := range topicCreationTests { - if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + if !bytes.Equal(topics[i][:], tt.hash[:]) { t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) } } topics = NewTopicsFromStrings(textualData...) for i, tt := range topicCreationTests { - if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + if !bytes.Equal(topics[i][:], tt.hash[:]) { t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) } } diff --git a/whisper/whisperv5/message_test.go b/whisper/whisperv5/message_test.go index 5cbc9182f..3eb71653d 100644 --- a/whisper/whisperv5/message_test.go +++ b/whisper/whisperv5/message_test.go @@ -104,10 +104,10 @@ func singleMessageTest(t *testing.T, symmetric bool) { } padsz := len(decrypted.Padding) - if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 { + if !bytes.Equal(steg[:padsz], decrypted.Padding) { t.Fatalf("failed with seed %d: compare padding.", seed) } - if bytes.Compare(text, decrypted.Payload) != 0 { + if !bytes.Equal(text, decrypted.Payload) { t.Fatalf("failed with seed %d: compare payload.", seed) } if !isMessageSigned(decrypted.Raw[0]) { @@ -256,10 +256,10 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) { } padsz := len(decrypted.Padding) - if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 { + if !bytes.Equal(steg[:padsz], decrypted.Padding) { t.Fatalf("failed with seed %d: compare padding.", seed) } - if bytes.Compare(text, decrypted.Payload) != 0 { + if !bytes.Equal(text, decrypted.Payload) { t.Fatalf("failed with seed %d: compare payload.", seed) } if !isMessageSigned(decrypted.Raw[0]) { diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go index 88da59bff..34e2ec255 100644 --- a/whisper/whisperv5/peer_test.go +++ b/whisper/whisperv5/peer_test.go @@ -207,7 +207,7 @@ func checkPropagation(t *testing.T) { func validateMail(t *testing.T, index int, mail []*ReceivedMessage) bool { var cnt int for _, m := range mail { - if bytes.Compare(m.Payload, expectedMessage) == 0 { + if bytes.Equal(m.Payload, expectedMessage) { cnt++ } } diff --git a/whisper/whisperv5/whisper_test.go b/whisper/whisperv5/whisper_test.go index 9af95f445..dbe0627fa 100644 --- a/whisper/whisperv5/whisper_test.go +++ b/whisper/whisperv5/whisper_test.go @@ -239,7 +239,7 @@ func TestWhisperSymKeyManagement(t *testing.T) { if k1 == nil { t.Fatalf("first key does not exist.") } - if bytes.Compare(k1, randomKey) == 0 { + if bytes.Equal(k1, randomKey) { t.Fatalf("k1 == randomKey.") } if k2 != nil { @@ -264,10 +264,10 @@ func TestWhisperSymKeyManagement(t *testing.T) { if k2 == nil { t.Fatalf("k2 does not exist.") } - if bytes.Compare(k1, k2) == 0 { + if bytes.Equal(k1, k2) { t.Fatalf("k1 == k2.") } - if bytes.Compare(k1, randomKey) == 0 { + if bytes.Equal(k1, randomKey) { t.Fatalf("k1 == randomKey.") } if len(k1) != aesKeyLength { |