From 7356556938be11b8d62d34aad79922957ed853f8 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Wed, 8 Apr 2015 12:30:49 -0700 Subject: [PATCH] Some renames and small fixes. --- blockchain/reactor.go | 2 +- consensus/reactor.go | 2 +- daemon/daemon.go | 6 +++--- events/events.go | 2 +- mempool/reactor.go | 2 +- p2p/pex_reactor.go | 2 +- rpc/client_methods.go | 12 ++++++------ rpc/core/accounts.go | 12 ++++++------ rpc/handlers.go | 4 ++-- rpc/test/helpers.go | 4 ++-- vm/stack.go | 6 +++--- vm/vm.go | 2 +- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index f389f3c91..7a213b0f0 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -242,7 +242,7 @@ func (bcR *BlockchainReactor) BroadcastStatus() error { } // implements events.Eventable -func (bcR *BlockchainReactor) AddEventSwitch(evsw *events.EventSwitch) { +func (bcR *BlockchainReactor) SetEventSwitch(evsw *events.EventSwitch) { bcR.evsw = evsw } diff --git a/consensus/reactor.go b/consensus/reactor.go index da358e594..0e264714c 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -234,7 +234,7 @@ func (conR *ConsensusReactor) ResetToState(state *sm.State) { } // implements events.Eventable -func (conR *ConsensusReactor) AddEventSwitch(evsw *events.EventSwitch) { +func (conR *ConsensusReactor) SetEventSwitch(evsw *events.EventSwitch) { conR.evsw = evsw } diff --git a/daemon/daemon.go b/daemon/daemon.go index ceaafaa5c..0c1c2a1e0 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -82,7 +82,7 @@ func NewNode() *Node { // add the event switch to all services // they should all satisfy events.Eventable - AddEventSwitch(eventSwitch, pexReactor, bcReactor, mempoolReactor, consensusReactor) + SetEventSwitch(eventSwitch, pexReactor, bcReactor, mempoolReactor, consensusReactor) return &Node{ sw: sw, @@ -116,9 +116,9 @@ func (n *Node) Stop() { } // Add the event switch to reactors, mempool, etc. -func AddEventSwitch(evsw *events.EventSwitch, eventables ...events.Eventable) { +func SetEventSwitch(evsw *events.EventSwitch, eventables ...events.Eventable) { for _, e := range eventables { - e.AddEventSwitch(evsw) + e.SetEventSwitch(evsw) } } diff --git a/events/events.go b/events/events.go index 73d1935fe..46f01cb57 100644 --- a/events/events.go +++ b/events/events.go @@ -8,7 +8,7 @@ import ( // reactors and other modules should export // this interface to become eventable type Eventable interface { - AddEventSwitch(*EventSwitch) + SetEventSwitch(*EventSwitch) } type EventSwitch struct { diff --git a/mempool/reactor.go b/mempool/reactor.go index f6d66f67f..ae469da41 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -114,7 +114,7 @@ func (memR *MempoolReactor) BroadcastTx(tx types.Tx) error { } // implements events.Eventable -func (memR *MempoolReactor) AddEventSwitch(evsw *events.EventSwitch) { +func (memR *MempoolReactor) SetEventSwitch(evsw *events.EventSwitch) { memR.evsw = evsw } diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 2c0033958..20e175fc5 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -211,7 +211,7 @@ func (pexR *PEXReactor) ensurePeers() { } // implements events.Eventable -func (pexR *PEXReactor) AddEventSwitch(evsw *events.EventSwitch) { +func (pexR *PEXReactor) SetEventSwitch(evsw *events.EventSwitch) { pexR.evsw = evsw } diff --git a/rpc/client_methods.go b/rpc/client_methods.go index 4f8a6b9f4..b9af5ff19 100644 --- a/rpc/client_methods.go +++ b/rpc/client_methods.go @@ -21,7 +21,7 @@ type Client interface { GenPrivAccount() (*core.ResponseGenPrivAccount, error) GetAccount(address []byte) (*core.ResponseGetAccount, error) GetBlock(height uint) (*core.ResponseGetBlock, error) - GetStorage(address []byte, storage []byte) (*core.ResponseGetStorage, error) + GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) ListAccounts() (*core.ResponseListAccounts, error) ListValidators() (*core.ResponseListValidators, error) NetInfo() (*core.ResponseNetInfo, error) @@ -269,8 +269,8 @@ func (c *ClientHTTP) GetBlock(height uint) (*core.ResponseGetBlock, error) { return response.Result, nil } -func (c *ClientHTTP) GetStorage(address []byte, storage []byte) (*core.ResponseGetStorage, error) { - values, err := argsToURLValues([]string{"address", "storage"}, address, storage) +func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) { + values, err := argsToURLValues([]string{"address", "key"}, address, key) if err != nil { return nil, err } @@ -390,7 +390,7 @@ func (c *ClientHTTP) NetInfo() (*core.ResponseNetInfo, error) { } func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) { - values, err := argsToURLValues([]string{"tx", "privAccounts"}, tx, privAccounts) + values, err := argsToURLValues([]string{"tx", "priv_accounts"}, tx, privAccounts) if err != nil { return nil, err } @@ -665,11 +665,11 @@ func (c *ClientJSON) GetBlock(height uint) (*core.ResponseGetBlock, error) { return response.Result, nil } -func (c *ClientJSON) GetStorage(address []byte, storage []byte) (*core.ResponseGetStorage, error) { +func (c *ClientJSON) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) { request := RPCRequest{ JSONRPC: "2.0", Method: reverseFuncMap["GetStorage"], - Params: []interface{}{address, storage}, + Params: []interface{}{address, key}, Id: 0, } body, err := c.RequestResponse(request) diff --git a/rpc/core/accounts.go b/rpc/core/accounts.go index 2cf2b6a14..6aee90d78 100644 --- a/rpc/core/accounts.go +++ b/rpc/core/accounts.go @@ -15,7 +15,7 @@ func GetAccount(address []byte) (*ResponseGetAccount, error) { return &ResponseGetAccount{cache.GetAccount(address)}, nil } -func GetStorage(address, storage []byte) (*ResponseGetStorage, error) { +func GetStorage(address, key []byte) (*ResponseGetStorage, error) { state := consensusState.GetState() account := state.GetAccount(address) if account == nil { @@ -24,11 +24,11 @@ func GetStorage(address, storage []byte) (*ResponseGetStorage, error) { storageRoot := account.StorageRoot storageTree := state.LoadStorage(storageRoot) - _, value := storageTree.Get(RightPadWord256(storage).Bytes()) + _, value := storageTree.Get(RightPadWord256(key).Bytes()) if value == nil { - return &ResponseGetStorage{storage, nil}, nil + return &ResponseGetStorage{key, nil}, nil } - return &ResponseGetStorage{storage, value.([]byte)}, nil + return &ResponseGetStorage{key, value.([]byte)}, nil } func ListAccounts() (*ResponseListAccounts, error) { @@ -50,9 +50,9 @@ func DumpStorage(addr []byte) (*ResponseDumpStorage, error) { return nil, fmt.Errorf("Unknown address: %X", addr) } storageRoot := account.StorageRoot - storage := state.LoadStorage(storageRoot) + storageTree := state.LoadStorage(storageRoot) storageItems := []StorageItem{} - storage.Iterate(func(key interface{}, value interface{}) bool { + storageTree.Iterate(func(key interface{}, value interface{}) bool { storageItems = append(storageItems, StorageItem{ key.([]byte), value.([]byte)}) return false diff --git a/rpc/handlers.go b/rpc/handlers.go index 7462180c4..2354a2e17 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -24,7 +24,7 @@ var funcMap = map[string]*FuncWrapper{ "blockchain": funcWrap(core.BlockchainInfo, []string{"min_height", "max_height"}), "get_block": funcWrap(core.GetBlock, []string{"height"}), "get_account": funcWrap(core.GetAccount, []string{"address"}), - "get_storage": funcWrap(core.GetStorage, []string{"address", "storage"}), + "get_storage": funcWrap(core.GetStorage, []string{"address", "key"}), "call": funcWrap(core.Call, []string{"address", "data"}), "call_code": funcWrap(core.CallCode, []string{"code", "data"}), "list_validators": funcWrap(core.ListValidators, []string{}), @@ -32,7 +32,7 @@ var funcMap = map[string]*FuncWrapper{ "broadcast_tx": funcWrap(core.BroadcastTx, []string{"tx"}), "list_accounts": funcWrap(core.ListAccounts, []string{}), "unsafe/gen_priv_account": funcWrap(core.GenPrivAccount, []string{}), - "unsafe/sign_tx": funcWrap(core.SignTx, []string{"tx", "privAccounts"}), + "unsafe/sign_tx": funcWrap(core.SignTx, []string{"tx", "priv_accounts"}), } // maps camel-case function names to lower case rpc version diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 5d399cf57..27505bc00 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -209,9 +209,9 @@ func dumpStorage(t *testing.T, addr []byte) core.ResponseDumpStorage { return *resp } -func getStorage(t *testing.T, typ string, addr, slot []byte) []byte { +func getStorage(t *testing.T, typ string, addr, key []byte) []byte { client := clients[typ] - resp, err := client.GetStorage(addr, slot) + resp, err := client.GetStorage(addr, key) if err != nil { t.Fatal(err) } diff --git a/vm/stack.go b/vm/stack.go index 7219051fd..41d50c702 100644 --- a/vm/stack.go +++ b/vm/stack.go @@ -32,9 +32,9 @@ func (st *Stack) useGas(gasToUse uint64) { } func (st *Stack) setErr(err error) { - //if *st.err != nil { - *st.err = err - //} + if *st.err == nil { + *st.err = err + } } func (st *Stack) Push(d Word256) { diff --git a/vm/vm.go b/vm/vm.go index e21a914f8..cbf68729d 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -659,7 +659,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value uint64, ga case RETURN: // 0xF3 offset, size := stack.Pop64(), stack.Pop64() ret, ok := subslice(memory, offset, size, false) - if !ok || err != nil { + if !ok { return nil, firstErr(err, ErrMemoryOutOfBounds) } dbg.Printf(" => [%v, %v] (%d) 0x%X\n", offset, size, len(ret), ret)