From 265576c22e9880001fb3c55e61c5cc6cb5006e33 Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Thu, 31 May 2018 16:53:53 -0700 Subject: [PATCH 1/4] params: golint warnings, comments --- cmd/faucet/faucet.go | 2 +- cmd/puppeth/genesis.go | 6 +++--- cmd/puppeth/module_dashboard.go | 2 +- cmd/puppeth/wizard_faucet.go | 2 +- cmd/puppeth/wizard_genesis.go | 2 +- cmd/puppeth/wizard_node.go | 2 +- cmd/puppeth/wizard_wallet.go | 2 +- core/blockchain_test.go | 20 +++++++++--------- core/tx_pool.go | 2 +- core/types/transaction_signing.go | 2 +- core/vm/runtime/runtime.go | 2 +- internal/ethapi/api.go | 6 +++--- light/txpool.go | 2 +- miner/worker.go | 2 +- params/config.go | 35 ++++++++++++++++++------------- params/denomination.go | 10 ++++----- params/gas_table.go | 9 +++++--- params/protocol_params.go | 2 +- params/version.go | 1 + tests/block_test_util.go | 1 + tests/init.go | 18 ++++++++-------- tests/transaction_test.go | 2 +- 22 files changed, 72 insertions(+), 60 deletions(-) diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 5bad09bbd5..5f00dde741 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -474,7 +474,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) { amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil)) tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil) - signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainId) + signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID) if err != nil { f.lock.Unlock() if err = sendError(conn, err); err != nil { diff --git a/cmd/puppeth/genesis.go b/cmd/puppeth/genesis.go index 1974a94aa2..5f39a889d1 100644 --- a/cmd/puppeth/genesis.go +++ b/cmd/puppeth/genesis.go @@ -103,8 +103,8 @@ func newCppEthereumGenesisSpec(network string, genesis *core.Genesis) (*cppEther spec.Params.ByzantiumForkBlock = (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()) spec.Params.ConstantinopleForkBlock = (hexutil.Uint64)(math.MaxUint64) - spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) - spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) + spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) + spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) @@ -284,7 +284,7 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) spec.Params.GasLimitBoundDivisor = (hexutil.Uint64)(params.GasLimitBoundDivisor) - spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) + spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) spec.Params.MaxCodeSize = params.MaxCodeSize spec.Params.EIP155Transition = genesis.Config.EIP155Block.Uint64() spec.Params.EIP98Transition = math.MaxUint64 diff --git a/cmd/puppeth/module_dashboard.go b/cmd/puppeth/module_dashboard.go index 4f9e88899a..a517623381 100644 --- a/cmd/puppeth/module_dashboard.go +++ b/cmd/puppeth/module_dashboard.go @@ -609,7 +609,7 @@ func deployDashboard(client *sshClient, network string, conf *config, config *da } template.Must(template.New("").Parse(dashboardContent)).Execute(indexfile, map[string]interface{}{ "Network": network, - "NetworkID": conf.Genesis.Config.ChainId, + "NetworkID": conf.Genesis.Config.ChainID, "NetworkTitle": strings.Title(network), "EthstatsPage": config.ethstats, "ExplorerPage": config.explorer, diff --git a/cmd/puppeth/wizard_faucet.go b/cmd/puppeth/wizard_faucet.go index 9a429bc96d..6f08408947 100644 --- a/cmd/puppeth/wizard_faucet.go +++ b/cmd/puppeth/wizard_faucet.go @@ -49,7 +49,7 @@ func (w *wizard) deployFaucet() { existed := err == nil infos.node.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") - infos.node.network = w.conf.Genesis.Config.ChainId.Int64() + infos.node.network = w.conf.Genesis.Config.ChainID.Int64() // Figure out which port to listen on fmt.Println() diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index f255ef6e65..6c4cd571fb 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -121,7 +121,7 @@ func (w *wizard) makeGenesis() { // Query the user for some custom extras fmt.Println() fmt.Println("Specify your chain/network ID if you want an explicit one (default = random)") - genesis.Config.ChainId = new(big.Int).SetUint64(uint64(w.readDefaultInt(rand.Intn(65536)))) + genesis.Config.ChainID = new(big.Int).SetUint64(uint64(w.readDefaultInt(rand.Intn(65536)))) // All done, store the genesis and flush to disk log.Info("Configured new genesis block") diff --git a/cmd/puppeth/wizard_node.go b/cmd/puppeth/wizard_node.go index a60948bc67..f3fef4034f 100644 --- a/cmd/puppeth/wizard_node.go +++ b/cmd/puppeth/wizard_node.go @@ -56,7 +56,7 @@ func (w *wizard) deployNode(boot bool) { existed := err == nil infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") - infos.network = w.conf.Genesis.Config.ChainId.Int64() + infos.network = w.conf.Genesis.Config.ChainID.Int64() // Figure out where the user wants to store the persistent data fmt.Println() diff --git a/cmd/puppeth/wizard_wallet.go b/cmd/puppeth/wizard_wallet.go index 933cd9ae59..7624d11e20 100644 --- a/cmd/puppeth/wizard_wallet.go +++ b/cmd/puppeth/wizard_wallet.go @@ -52,7 +52,7 @@ func (w *wizard) deployWallet() { existed := err == nil infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") - infos.network = w.conf.Genesis.Config.ChainId.Int64() + infos.network = w.conf.Genesis.Config.ChainID.Int64() // Figure out which port to listen on fmt.Println() diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 89c071174f..5dbf63d1d6 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -578,7 +578,7 @@ func TestFastVsFullChains(t *testing.T) { Alloc: GenesisAlloc{address: {Balance: funds}}, } genesis = gspec.MustCommit(gendb) - signer = types.NewEIP155Signer(gspec.Config.ChainId) + signer = types.NewEIP155Signer(gspec.Config.ChainID) ) blocks, receipts := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), gendb, 1024, func(i int, block *BlockGen) { block.SetCoinbase(common.Address{0x00}) @@ -753,7 +753,7 @@ func TestChainTxReorgs(t *testing.T) { }, } genesis = gspec.MustCommit(db) - signer = types.NewEIP155Signer(gspec.Config.ChainId) + signer = types.NewEIP155Signer(gspec.Config.ChainID) ) // Create two transactions shared between the chains: @@ -859,7 +859,7 @@ func TestLogReorgs(t *testing.T) { code = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000)}}} genesis = gspec.MustCommit(db) - signer = types.NewEIP155Signer(gspec.Config.ChainId) + signer = types.NewEIP155Signer(gspec.Config.ChainID) ) blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}) @@ -906,7 +906,7 @@ func TestReorgSideEvent(t *testing.T) { Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000)}}, } genesis = gspec.MustCommit(db) - signer = types.NewEIP155Signer(gspec.Config.ChainId) + signer = types.NewEIP155Signer(gspec.Config.ChainID) ) blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}) @@ -1032,7 +1032,7 @@ func TestEIP155Transition(t *testing.T) { funds = big.NewInt(1000000000) deleteAddr = common.Address{1} gspec = &Genesis{ - Config: ¶ms.ChainConfig{ChainId: big.NewInt(1), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)}, + Config: ¶ms.ChainConfig{ChainID: big.NewInt(1), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)}, Alloc: GenesisAlloc{address: {Balance: funds}, deleteAddr: {Balance: new(big.Int)}}, } genesis = gspec.MustCommit(db) @@ -1063,7 +1063,7 @@ func TestEIP155Transition(t *testing.T) { } block.AddTx(tx) - tx, err = basicTx(types.NewEIP155Signer(gspec.Config.ChainId)) + tx, err = basicTx(types.NewEIP155Signer(gspec.Config.ChainID)) if err != nil { t.Fatal(err) } @@ -1075,7 +1075,7 @@ func TestEIP155Transition(t *testing.T) { } block.AddTx(tx) - tx, err = basicTx(types.NewEIP155Signer(gspec.Config.ChainId)) + tx, err = basicTx(types.NewEIP155Signer(gspec.Config.ChainID)) if err != nil { t.Fatal(err) } @@ -1103,7 +1103,7 @@ func TestEIP155Transition(t *testing.T) { } // generate an invalid chain id transaction - config := ¶ms.ChainConfig{ChainId: big.NewInt(2), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)} + config := ¶ms.ChainConfig{ChainID: big.NewInt(2), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)} blocks, _ = GenerateChain(config, blocks[len(blocks)-1], ethash.NewFaker(), db, 4, func(i int, block *BlockGen) { var ( tx *types.Transaction @@ -1137,7 +1137,7 @@ func TestEIP161AccountRemoval(t *testing.T) { theAddr = common.Address{1} gspec = &Genesis{ Config: ¶ms.ChainConfig{ - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: new(big.Int), EIP155Block: new(big.Int), EIP158Block: big.NewInt(2), @@ -1153,7 +1153,7 @@ func TestEIP161AccountRemoval(t *testing.T) { var ( tx *types.Transaction err error - signer = types.NewEIP155Signer(gspec.Config.ChainId) + signer = types.NewEIP155Signer(gspec.Config.ChainID) ) switch i { case 0: diff --git a/core/tx_pool.go b/core/tx_pool.go index 7393c8286f..c1dd7ac73e 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -222,7 +222,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block config: config, chainconfig: chainconfig, chain: chain, - signer: types.NewEIP155Signer(chainconfig.ChainId), + signer: types.NewEIP155Signer(chainconfig.ChainID), pending: make(map[common.Address]*txList), queue: make(map[common.Address]*txList), beats: make(map[common.Address]time.Time), diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index dfc84fdac7..c195d23a32 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -43,7 +43,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer { var signer Signer switch { case config.IsEIP155(blockNumber): - signer = NewEIP155Signer(config.ChainId) + signer = NewEIP155Signer(config.ChainID) case config.IsHomestead(blockNumber): signer = HomesteadSigner{} default: diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index c8c5d34d9d..cda49a34b4 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -52,7 +52,7 @@ type Config struct { func setDefaults(cfg *Config) { if cfg.ChainConfig == nil { cfg.ChainConfig = ¶ms.ChainConfig{ - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: new(big.Int), DAOForkBlock: new(big.Int), DAOForkSupport: false, diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a524dbadd8..87eba7e1a3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -354,7 +354,7 @@ func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args SendTxArgs var chainID *big.Int if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { - chainID = config.ChainId + chainID = config.ChainID } return wallet.SignTxWithPassphrase(account, passwd, tx, chainID) } @@ -1096,7 +1096,7 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti // Request the wallet to sign the transaction var chainID *big.Int if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { - chainID = config.ChainId + chainID = config.ChainID } return wallet.SignTx(account, tx, chainID) } @@ -1216,7 +1216,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen var chainID *big.Int if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { - chainID = config.ChainId + chainID = config.ChainID } signed, err := wallet.SignTx(account, tx, chainID) if err != nil { diff --git a/light/txpool.go b/light/txpool.go index 1fabc3dc5a..5b4d06d90d 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -89,7 +89,7 @@ type TxRelayBackend interface { func NewTxPool(config *params.ChainConfig, chain *LightChain, relay TxRelayBackend) *TxPool { pool := &TxPool{ config: config, - signer: types.NewEIP155Signer(config.ChainId), + signer: types.NewEIP155Signer(config.ChainID), nonce: make(map[common.Address]uint64), pending: make(map[common.Hash]*types.Transaction), mined: make(map[common.Hash][]*types.Transaction), diff --git a/miner/worker.go b/miner/worker.go index 640e9032e7..45bf8c2051 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -370,7 +370,7 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error } work := &Work{ config: self.config, - signer: types.NewEIP155Signer(self.config.ChainId), + signer: types.NewEIP155Signer(self.config.ChainID), state: state, ancestors: set.New(), family: set.New(), diff --git a/params/config.go b/params/config.go index dc02c7ca37..9f66c159e9 100644 --- a/params/config.go +++ b/params/config.go @@ -23,15 +23,16 @@ import ( "github.com/ethereum/go-ethereum/common" ) +// Genesis hashes to enforce below configs on. var ( - MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") // Mainnet genesis hash to enforce below configs on - TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") // Testnet genesis hash to enforce below configs on + MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") + TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") ) var ( // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = &ChainConfig{ - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(1150000), DAOForkBlock: big.NewInt(1920000), DAOForkSupport: true, @@ -46,7 +47,7 @@ var ( // TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network. TestnetChainConfig = &ChainConfig{ - ChainId: big.NewInt(3), + ChainID: big.NewInt(3), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: true, @@ -61,7 +62,7 @@ var ( // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. RinkebyChainConfig = &ChainConfig{ - ChainId: big.NewInt(4), + ChainID: big.NewInt(4), HomesteadBlock: big.NewInt(1), DAOForkBlock: nil, DAOForkSupport: true, @@ -101,7 +102,7 @@ var ( // that any network, identified by its genesis block, can have its own // set of configuration options. type ChainConfig struct { - ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection + ChainID *big.Int `json:"chainID"` // Chain id identifies the current chain and is used for replay protection HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead) @@ -154,7 +155,7 @@ func (c *ChainConfig) String() string { engine = "unknown" } return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Engine: %v}", - c.ChainId, + c.ChainID, c.HomesteadBlock, c.DAOForkBlock, c.DAOForkSupport, @@ -172,27 +173,32 @@ func (c *ChainConfig) IsHomestead(num *big.Int) bool { return isForked(c.HomesteadBlock, num) } -// IsDAO returns whether num is either equal to the DAO fork block or greater. +// IsDAOFork returns whether num is either equal to the DAO fork block or greater. func (c *ChainConfig) IsDAOFork(num *big.Int) bool { return isForked(c.DAOForkBlock, num) } +// IsEIP150 returns whether num is either equal to the IsEIP150 fork block or greater. func (c *ChainConfig) IsEIP150(num *big.Int) bool { return isForked(c.EIP150Block, num) } +// IsEIP155 returns whether num is either equal to the IsEIP155 fork block or greater. func (c *ChainConfig) IsEIP155(num *big.Int) bool { return isForked(c.EIP155Block, num) } +// IsEIP158 returns whether num is either equal to the IsEIP158 fork block or greater. func (c *ChainConfig) IsEIP158(num *big.Int) bool { return isForked(c.EIP158Block, num) } +// IsByzantium returns whether num is either equal to the IsByzantium fork block or greater. func (c *ChainConfig) IsByzantium(num *big.Int) bool { return isForked(c.ByzantiumBlock, num) } +// IsConstantinople returns whether num is either equal to the IsConstantinople fork block or greater. func (c *ChainConfig) IsConstantinople(num *big.Int) bool { return isForked(c.ConstantinopleBlock, num) } @@ -251,7 +257,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.EIP158Block, newcfg.EIP158Block, head) { return newCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) } - if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) { + if c.IsEIP158(head) && !configNumEqual(c.ChainID, newcfg.ChainID) { return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) } if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) { @@ -324,15 +330,16 @@ func (err *ConfigCompatError) Error() string { // Rules is a one time interface meaning that it shouldn't be used in between transition // phases. type Rules struct { - ChainId *big.Int + ChainID *big.Int IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool IsByzantium bool } +// Rules ensures c's ChainID is not nil. func (c *ChainConfig) Rules(num *big.Int) Rules { - chainId := c.ChainId - if chainId == nil { - chainId = new(big.Int) + chainID := c.ChainID + if chainID == nil { + chainID = new(big.Int) } - return Rules{ChainId: new(big.Int).Set(chainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num)} + return Rules{ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num)} } diff --git a/params/denomination.go b/params/denomination.go index 9e1b52506f..1a309827da 100644 --- a/params/denomination.go +++ b/params/denomination.go @@ -16,12 +16,12 @@ package params +// These are the multipliers for ether denominations. +// Example: To get the wei value of an amount in 'douglas', use +// +// new(big.Int).Mul(value, big.NewInt(params.Douglas)) +// const ( - // These are the multipliers for ether denominations. - // Example: To get the wei value of an amount in 'douglas', use - // - // new(big.Int).Mul(value, big.NewInt(params.Douglas)) - // Wei = 1 Ada = 1e3 Babbage = 1e6 diff --git a/params/gas_table.go b/params/gas_table.go index 4969382b1b..d33bebbe53 100644 --- a/params/gas_table.go +++ b/params/gas_table.go @@ -16,6 +16,7 @@ package params +// GasTable organizes gas prices for different ethereum phases. type GasTable struct { ExtcodeSize uint64 ExtcodeCopy uint64 @@ -34,6 +35,7 @@ type GasTable struct { CreateBySuicide uint64 } +// Variables containing gas prices for different ethereum phases. var ( // GasTableHomestead contain the gas prices for // the homestead phase. @@ -47,8 +49,8 @@ var ( ExpByte: 10, } - // GasTableHomestead contain the gas re-prices for - // the homestead phase. + // GasTableEIP150 contain the gas re-prices for + // the EIP150 phase. GasTableEIP150 = GasTable{ ExtcodeSize: 700, ExtcodeCopy: 700, @@ -60,7 +62,8 @@ var ( CreateBySuicide: 25000, } - + // GasTableEIP158 contain the gas re-prices for + // the EIP15* phase. GasTableEIP158 = GasTable{ ExtcodeSize: 700, ExtcodeCopy: 700, diff --git a/params/protocol_params.go b/params/protocol_params.go index 5a0b14d61a..1ea9c58138 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -19,7 +19,7 @@ package params import "math/big" var ( - TargetGasLimit uint64 = GenesisGasLimit // The artificial target + TargetGasLimit = GenesisGasLimit // The artificial target ) const ( diff --git a/params/version.go b/params/version.go index 8689ccba7f..8eca60465f 100644 --- a/params/version.go +++ b/params/version.go @@ -20,6 +20,7 @@ import ( "fmt" ) +// Version components of the current release. const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release diff --git a/tests/block_test_util.go b/tests/block_test_util.go index a72799f6e2..2db47da57f 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -42,6 +42,7 @@ type BlockTest struct { json btJSON } +// UnmarshalJSON implements json.Unmarshaler interface. func (t *BlockTest) UnmarshalJSON(in []byte) error { return json.Unmarshal(in, &t.json) } diff --git a/tests/init.go b/tests/init.go index 0bea5ccd63..af65f92069 100644 --- a/tests/init.go +++ b/tests/init.go @@ -26,26 +26,26 @@ import ( // Forks table defines supported forks and their chain config. var Forks = map[string]*params.ChainConfig{ "Frontier": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), }, "Homestead": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), }, "EIP150": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), }, "EIP158": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), }, "Byzantium": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), EIP155Block: big.NewInt(0), @@ -54,22 +54,22 @@ var Forks = map[string]*params.ChainConfig{ ByzantiumBlock: big.NewInt(0), }, "FrontierToHomesteadAt5": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(5), }, "HomesteadToEIP150At5": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(5), }, "HomesteadToDaoAt5": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: big.NewInt(5), DAOForkSupport: true, }, "EIP158ToByzantiumAt5": { - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), EIP155Block: big.NewInt(0), diff --git a/tests/transaction_test.go b/tests/transaction_test.go index c743996c2a..42ad81877e 100644 --- a/tests/transaction_test.go +++ b/tests/transaction_test.go @@ -35,7 +35,7 @@ func TestTransaction(t *testing.T) { EIP150Block: big.NewInt(0), EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), }) txt.config(`^Byzantium/`, params.ChainConfig{ HomesteadBlock: big.NewInt(0), From 067dd9700ff68ca1f0d94b7e194d853b6c4b48fb Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Thu, 31 May 2018 16:54:12 -0700 Subject: [PATCH 2/4] params: golint warnings, comments --- tests/difficulty_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/difficulty_test.go b/tests/difficulty_test.go index 6006373009..20294cc9d5 100644 --- a/tests/difficulty_test.go +++ b/tests/difficulty_test.go @@ -27,7 +27,7 @@ import ( var ( mainnetChainConfig = params.ChainConfig{ - ChainId: big.NewInt(1), + ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(1150000), DAOForkBlock: big.NewInt(1920000), DAOForkSupport: true, From 97ae8b5c5c00054139901be6909b0ee86ac40347 Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Tue, 5 Jun 2018 15:22:23 -0700 Subject: [PATCH 3/4] rpc: golint comments --- rpc/client.go | 19 ++++++++++++++----- rpc/http.go | 14 +++++++++++--- rpc/json.go | 41 ++++++++++++++++++++--------------------- rpc/json_test.go | 4 ++-- rpc/server.go | 12 ++++++------ rpc/server_test.go | 4 ++-- rpc/subscription.go | 4 ++-- rpc/types.go | 1 + rpc/utils.go | 10 +++++----- 9 files changed, 63 insertions(+), 46 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 77b4d5ee01..5cdeb241e9 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -36,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/log" ) +// Vars hardcodes custom error messages. var ( ErrClientQuit = errors.New("client is closed") ErrNoResult = errors.New("no result in JSON-RPC response") @@ -191,29 +192,37 @@ func (io StdIOConn) Write(b []byte) (n int, err error) { return os.Stdout.Write(b) } +// Close is a noop. func (io StdIOConn) Close() error { return nil } +// LocalAddr sets the address of a Unix domain socket end point. func (io StdIOConn) LocalAddr() net.Addr { return &net.UnixAddr{Name: "stdio", Net: "stdio"} } +// RemoteAddr sets the remote address of a Unix domain socket end point. func (io StdIOConn) RemoteAddr() net.Addr { return &net.UnixAddr{Name: "stdio", Net: "stdio"} } +// SetDeadline sets the operation, network type, and address of an error. func (io StdIOConn) SetDeadline(t time.Time) error { return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")} } +// SetReadDeadline sets the operation, network type, and address of an error. func (io StdIOConn) SetReadDeadline(t time.Time) error { return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")} } +// SetWriteDeadline sets the operation, network type, and address of an error. func (io StdIOConn) SetWriteDeadline(t time.Time) error { return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")} } + +// DialStdIO returns a new client instance with ctx values. func DialStdIO(ctx context.Context) (*Client, error) { return newClient(ctx, func(_ context.Context) (net.Conn, error) { return StdIOConn{}, nil @@ -329,7 +338,7 @@ func (c *Client) BatchCall(b []BatchElem) error { return c.BatchCallContext(ctx, b) } -// BatchCall sends all given requests as a single batch and waits for the server +// BatchCallContext sends all given requests as a single batch and waits for the server // to return a response for all of them. The wait duration is bounded by the // context's deadline. // @@ -781,7 +790,7 @@ func (sub *ClientSubscription) start() { sub.quitWithError(sub.forward()) } -func (sub *ClientSubscription) forward() (err error, unsubscribeServer bool) { +func (sub *ClientSubscription) forward() (unsubscribeServer bool, err error) { cases := []reflect.SelectCase{ {Dir: reflect.SelectRecv, Chan: reflect.ValueOf(sub.quit)}, {Dir: reflect.SelectRecv, Chan: reflect.ValueOf(sub.in)}, @@ -803,14 +812,14 @@ func (sub *ClientSubscription) forward() (err error, unsubscribeServer bool) { switch chosen { case 0: // <-sub.quit - return nil, false + return false, nil case 1: // <-sub.in val, err := sub.unmarshal(recv.Interface().(json.RawMessage)) if err != nil { - return err, true + return true, err } if buffer.Len() == maxClientSubscriptionBuffer { - return ErrSubscriptionQueueOverflow, true + return true, ErrSubscriptionQueueOverflow } buffer.PushBack(val) case 2: // sub.channel<- diff --git a/rpc/http.go b/rpc/http.go index 6388d68961..eef1eb8393 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -173,6 +173,11 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server { } } +type contextKey string +func contextString(c contextKey) string { + return string(c) +} + // ServeHTTP serves JSON-RPC requests over HTTP. func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Permit dumb empty requests for remote health-checks (AWS) @@ -183,13 +188,16 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), code) return } + + rem, sch, loc := contextKey("remote"), contextKey("scheme"), contextKey("local") + // All checks passed, create a codec that reads direct from the request body // untilEOF and writes the response to w and order the server to process a // single request. ctx := r.Context() - ctx = context.WithValue(ctx, "remote", r.RemoteAddr) - ctx = context.WithValue(ctx, "scheme", r.Proto) - ctx = context.WithValue(ctx, "local", r.Host) + ctx = context.WithValue(ctx, remote, r.RemoteAddr) + ctx = context.WithValue(ctx, sch, r.Proto) + ctx = context.WithValue(ctx, loc, r.Host) body := io.LimitReader(r.Body, maxRequestContentLength) codec := NewJSONCodec(&httpReadWriteNopCloser{body, w}) diff --git a/rpc/json.go b/rpc/json.go index 837011f51b..dd4e0edeec 100644 --- a/rpc/json.go +++ b/rpc/json.go @@ -40,13 +40,13 @@ const ( type jsonRequest struct { Method string `json:"method"` Version string `json:"jsonrpc"` - Id json.RawMessage `json:"id,omitempty"` + ID json.RawMessage `json:"id,omitempty"` Payload json.RawMessage `json:"params,omitempty"` } type jsonSuccessResponse struct { Version string `json:"jsonrpc"` - Id interface{} `json:"id,omitempty"` + ID interface{} `json:"id,omitempty"` Result interface{} `json:"result"` } @@ -58,7 +58,7 @@ type jsonError struct { type jsonErrResponse struct { Version string `json:"jsonrpc"` - Id interface{} `json:"id,omitempty"` + ID interface{} `json:"id,omitempty"` Error jsonError `json:"error"` } @@ -150,17 +150,17 @@ func (c *jsonCodec) ReadRequestHeaders() ([]rpcRequest, bool, Error) { return parseRequest(incomingMsg) } -// checkReqId returns an error when the given reqId isn't valid for RPC method calls. +// checkReqID returns an error when the given reqID isn't valid for RPC method calls. // valid id's are strings, numbers or null -func checkReqId(reqId json.RawMessage) error { - if len(reqId) == 0 { +func checkReqID(reqID json.RawMessage) error { + if len(reqID) == 0 { return fmt.Errorf("missing request id") } - if _, err := strconv.ParseFloat(string(reqId), 64); err == nil { + if _, err := strconv.ParseFloat(string(reqID), 64); err == nil { return nil } var str string - if err := json.Unmarshal(reqId, &str); err == nil { + if err := json.Unmarshal(reqID, &str); err == nil { return nil } return fmt.Errorf("invalid request id") @@ -175,13 +175,13 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) { return nil, false, &invalidMessageError{err.Error()} } - if err := checkReqId(in.Id); err != nil { + if err := checkReqID(in.ID); err != nil { return nil, false, &invalidMessageError{err.Error()} } // subscribe are special, they will always use `subscribeMethod` as first param in the payload if strings.HasSuffix(in.Method, subscribeMethodSuffix) { - reqs := []rpcRequest{{id: &in.Id, isPubSub: true}} + reqs := []rpcRequest{{id: &in.ID, isPubSub: true}} if len(in.Payload) > 0 { // first param must be subscription name var subscribeMethod [1]string @@ -198,7 +198,7 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) { } if strings.HasSuffix(in.Method, unsubscribeMethodSuffix) { - return []rpcRequest{{id: &in.Id, isPubSub: true, + return []rpcRequest{{id: &in.ID, isPubSub: true, method: in.Method, params: in.Payload}}, false, nil } @@ -209,10 +209,10 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) { // regular RPC call if len(in.Payload) == 0 { - return []rpcRequest{{service: elems[0], method: elems[1], id: &in.Id}}, false, nil + return []rpcRequest{{service: elems[0], method: elems[1], id: &in.ID}}, false, nil } - return []rpcRequest{{service: elems[0], method: elems[1], id: &in.Id, params: in.Payload}}, false, nil + return []rpcRequest{{service: elems[0], method: elems[1], id: &in.ID, params: in.Payload}}, false, nil } // parseBatchRequest will parse a batch request into a collection of requests from the given RawMessage, an indication @@ -225,11 +225,11 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) requests := make([]rpcRequest, len(in)) for i, r := range in { - if err := checkReqId(r.Id); err != nil { + if err := checkReqID(r.ID); err != nil { return nil, false, &invalidMessageError{err.Error()} } - id := &in[i].Id + id := &in[i].ID // subscribe are special, they will always use `subscriptionMethod` as first param in the payload if strings.HasSuffix(r.Method, subscribeMethodSuffix) { @@ -275,9 +275,8 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) func (c *jsonCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) { if args, ok := params.(json.RawMessage); !ok { return nil, &invalidParamsError{"Invalid params supplied"} - } else { - return parsePositionalArguments(args, argTypes) } + return parsePositionalArguments(args, argTypes) } // parsePositionalArguments tries to parse the given args to an array of values with the @@ -321,20 +320,20 @@ func parsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([] // CreateResponse will create a JSON-RPC success response with the given id and reply as result. func (c *jsonCodec) CreateResponse(id interface{}, reply interface{}) interface{} { if isHexNum(reflect.TypeOf(reply)) { - return &jsonSuccessResponse{Version: jsonrpcVersion, Id: id, Result: fmt.Sprintf(`%#x`, reply)} + return &jsonSuccessResponse{Version: jsonrpcVersion, ID: id, Result: fmt.Sprintf(`%#x`, reply)} } - return &jsonSuccessResponse{Version: jsonrpcVersion, Id: id, Result: reply} + return &jsonSuccessResponse{Version: jsonrpcVersion, ID: id, Result: reply} } // CreateErrorResponse will create a JSON-RPC error response with the given id and error. func (c *jsonCodec) CreateErrorResponse(id interface{}, err Error) interface{} { - return &jsonErrResponse{Version: jsonrpcVersion, Id: id, Error: jsonError{Code: err.ErrorCode(), Message: err.Error()}} + return &jsonErrResponse{Version: jsonrpcVersion, ID: id, Error: jsonError{Code: err.ErrorCode(), Message: err.Error()}} } // CreateErrorResponseWithInfo will create a JSON-RPC error response with the given id and error. // info is optional and contains additional information about the error. When an empty string is passed it is ignored. func (c *jsonCodec) CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{} { - return &jsonErrResponse{Version: jsonrpcVersion, Id: id, + return &jsonErrResponse{Version: jsonrpcVersion, ID: id, Error: jsonError{Code: err.ErrorCode(), Message: err.Error(), Data: info}} } diff --git a/rpc/json_test.go b/rpc/json_test.go index 5048d2f7a0..d121c8297f 100644 --- a/rpc/json_test.go +++ b/rpc/json_test.go @@ -69,8 +69,8 @@ func TestJSONRequestParsing(t *testing.T) { t.Fatalf("Expected method 'Add' but got '%s'", requests[0].method) } - if rawId, ok := requests[0].id.(*json.RawMessage); ok { - id, e := strconv.ParseInt(string(*rawId), 0, 64) + if rawID, ok := requests[0].id.(*json.RawMessage); ok { + id, e := strconv.ParseInt(string(*rawID), 0, 64) if e != nil { t.Fatalf("%v", e) } diff --git a/rpc/server.go b/rpc/server.go index 7f304d8d93..9f7ff36584 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -29,7 +29,7 @@ import ( "gopkg.in/fatih/set.v0" ) -const MetadataApi = "rpc" +const MetadataAPI = "rpc" // CodecOption specifies which type of messages this codec supports type CodecOption int @@ -52,20 +52,20 @@ func NewServer() *Server { // register a default service which will provide meta information about the RPC service such as the services and // methods it offers. - rpcService := &RPCService{server} - server.RegisterName(MetadataApi, rpcService) + rpcService := &Service{server} + server.RegisterName(MetadataAPI, rpcService) return server } -// RPCService gives meta information about the server. +// Service gives meta information about the server. // e.g. gives information about the loaded modules. -type RPCService struct { +type Service struct { server *Server } // Modules returns the list of RPC services with their version number -func (s *RPCService) Modules() map[string]string { +func (s *Service) Modules() map[string]string { modules := make(map[string]string) for name := range s.server.services { modules[name] = "1.0" diff --git a/rpc/server_test.go b/rpc/server_test.go index 90d62f26d8..0f76826084 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -59,8 +59,8 @@ func (s *Service) Rets() (string, error) { return "", nil } -func (s *Service) InvalidRets1() (error, string) { - return nil, "" +func (s *Service) InvalidRets1() (string, error) { + return "", nil } func (s *Service) InvalidRets2() (string, string) { diff --git a/rpc/subscription.go b/rpc/subscription.go index 6ce7befa1d..6ee9337f5a 100644 --- a/rpc/subscription.go +++ b/rpc/subscription.go @@ -25,14 +25,14 @@ import ( var ( // ErrNotificationsUnsupported is returned when the connection doesn't support notifications ErrNotificationsUnsupported = errors.New("notifications not supported") - // ErrNotificationNotFound is returned when the notification for the given id is not found + // ErrSubscriptionNotFound is returned when the notification for the given id is not found ErrSubscriptionNotFound = errors.New("subscription not found") ) // ID defines a pseudo random number that is used to identify RPC subscriptions. type ID string -// a Subscription is created by a notifier and tight to that notifier. The client can use +// Subscription is created by a notifier and tight to that notifier. The client can use // this subscription to wait for an unsubscribe request for the client, see Err(). type Subscription struct { ID ID diff --git a/rpc/types.go b/rpc/types.go index f2375604ed..312c9fca4e 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -160,6 +160,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error { return nil } +// Int64 casts the bn into int64. func (bn BlockNumber) Int64() int64 { return (int64)(bn) } diff --git a/rpc/utils.go b/rpc/utils.go index 9315cab591..065c33345f 100644 --- a/rpc/utils.go +++ b/rpc/utils.go @@ -230,12 +230,12 @@ func NewID() ID { } } - rpcId := hex.EncodeToString(id) + rpcID := hex.EncodeToString(id) // rpc ID's are RPC quantities, no leading zero's and 0 is 0x0 - rpcId = strings.TrimLeft(rpcId, "0") - if rpcId == "" { - rpcId = "0" + rpcID = strings.TrimLeft(rpcID, "0") + if rpcID == "" { + rpcID = "0" } - return ID("0x" + rpcId) + return ID("0x" + rpcID) } From b11ac960cd2db9b3fdda20430ea6d8cca152728a Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Tue, 5 Jun 2018 16:44:51 -0700 Subject: [PATCH 4/4] rpc: golint comments and warnings --- rpc/client.go | 6 +++--- rpc/http.go | 5 +++-- rpc/json.go | 3 ++- rpc/server.go | 8 ++++---- rpc/server_test.go | 4 ++-- rpc/subscription_test.go | 6 +++--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 5cdeb241e9..ceb60fafed 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -631,7 +631,7 @@ func (c *Client) closeRequestOps(err error) { } for id, sub := range c.subs { delete(c.subs, id) - sub.quitWithError(err, false) + sub.quitWithError(false, err) } } @@ -755,11 +755,11 @@ func (sub *ClientSubscription) Err() <-chan error { // Unsubscribe unsubscribes the notification and closes the error channel. // It can safely be called more than once. func (sub *ClientSubscription) Unsubscribe() { - sub.quitWithError(nil, true) + sub.quitWithError(true, nil) sub.errOnce.Do(func() { close(sub.err) }) } -func (sub *ClientSubscription) quitWithError(err error, unsubscribeServer bool) { +func (sub *ClientSubscription) quitWithError(unsubscribeServer bool, err error) { sub.quitOnce.Do(func() { // The dispatch loop won't be able to execute the unsubscribe call // if it is blocked on deliver. Close sub.quit first because it diff --git a/rpc/http.go b/rpc/http.go index eef1eb8393..04f2c67c4c 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -174,8 +174,9 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server { } type contextKey string + func contextString(c contextKey) string { - return string(c) + return string(c) } // ServeHTTP serves JSON-RPC requests over HTTP. @@ -195,7 +196,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // untilEOF and writes the response to w and order the server to process a // single request. ctx := r.Context() - ctx = context.WithValue(ctx, remote, r.RemoteAddr) + ctx = context.WithValue(ctx, rem, r.RemoteAddr) ctx = context.WithValue(ctx, sch, r.Proto) ctx = context.WithValue(ctx, loc, r.Host) diff --git a/rpc/json.go b/rpc/json.go index dd4e0edeec..ac054ffff5 100644 --- a/rpc/json.go +++ b/rpc/json.go @@ -275,8 +275,9 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) func (c *jsonCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) { if args, ok := params.(json.RawMessage); !ok { return nil, &invalidParamsError{"Invalid params supplied"} + } else { + return parsePositionalArguments(args, argTypes) } - return parsePositionalArguments(args, argTypes) } // parsePositionalArguments tries to parse the given args to an array of values with the diff --git a/rpc/server.go b/rpc/server.go index 9f7ff36584..9901f9b220 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -52,20 +52,20 @@ func NewServer() *Server { // register a default service which will provide meta information about the RPC service such as the services and // methods it offers. - rpcService := &Service{server} + rpcService := &RPCService{server} server.RegisterName(MetadataAPI, rpcService) return server } -// Service gives meta information about the server. +// RPCService gives meta information about the server. // e.g. gives information about the loaded modules. -type Service struct { +type RPCService struct { server *Server } // Modules returns the list of RPC services with their version number -func (s *Service) Modules() map[string]string { +func (s *RPCService) Modules() map[string]string { modules := make(map[string]string) for name := range s.server.services { modules[name] = "1.0" diff --git a/rpc/server_test.go b/rpc/server_test.go index 0f76826084..90d62f26d8 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -59,8 +59,8 @@ func (s *Service) Rets() (string, error) { return "", nil } -func (s *Service) InvalidRets1() (string, error) { - return "", nil +func (s *Service) InvalidRets1() (error, string) { + return nil, "" } func (s *Service) InvalidRets2() (string, string) { diff --git a/rpc/subscription_test.go b/rpc/subscription_test.go index 0ba177e63b..96c80b74ae 100644 --- a/rpc/subscription_test.go +++ b/rpc/subscription_test.go @@ -195,7 +195,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces if _, found := msg["result"]; found { successes <- jsonSuccessResponse{ Version: msg["jsonrpc"].(string), - Id: msg["id"], + ID: msg["id"], Result: msg["result"], } continue @@ -204,7 +204,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces params := msg["params"].(map[string]interface{}) failures <- jsonErrResponse{ Version: msg["jsonrpc"].(string), - Id: msg["id"], + ID: msg["id"], Error: jsonError{int(params["subscription"].(float64)), params["message"].(string), params["data"]}, } continue @@ -304,7 +304,7 @@ func TestSubscriptionMultipleNamespaces(t *testing.T) { case err := <-errors: t.Fatal(err) case suc := <-successes: // subscription created - subids[namespaces[int(suc.Id.(float64))]] = suc.Result.(string) + subids[namespaces[int(suc.ID.(float64))]] = suc.Result.(string) case failure := <-failures: t.Errorf("received error: %v", failure.Error) case notification := <-notifications: