diff --git a/client/client.go b/client/client.go index d2674c01c51347331909986fc2a710c7d3a1720c..fb0de81fd7f2f4ffbda0e28fd03429cc50505851 100644 --- a/client/client.go +++ b/client/client.go @@ -23,7 +23,9 @@ import ( acc "github.com/eris-ltd/eris-db/account" tendermint_client "github.com/eris-ltd/eris-db/rpc/tendermint/client" + tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/txs" + core_types "github.com/eris-ltd/eris-db/core/types" ) type NodeClient interface { @@ -137,9 +139,18 @@ func (erisNodeClient *ErisNodeClient) GetAccount(address []byte) (*acc.Account, return account.Copy(), nil } -// DumpStorage -func (erisNodeClient *ErisNodeClient) DumpStorage(address []byte) (storageRoot []byte) +// DumpStorage returns the full storage for an account. +func (erisNodeClient *ErisNodeClient) DumpStorage(address []byte) (*core_types.Storage) { + client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) + resultStorage, err := tendermint_client.DumpStorage(client, address) + if err != nil { + } + // UnwrapResultDumpStorage is an inefficient full deep copy, + // to transform the type to /core/types.Storage + // TODO: removing go-wire and go-rpc allows us to collapse these types + return tendermint_types.UnwrapResultDumpStorage(resultStorage) +} //-------------------------------------------------------------------------------------------- // Name registry @@ -153,9 +164,12 @@ func (erisNodeClient *ErisNodeClient) GetName(name string) (owner []byte, data [ return nil, nil, 0, err } // unwrap return results - owner = *entryResult.Owner + owner = make([]byte, len(entryResult.Owner)) + copy(owner, entryResult.Owner) data = []byte(entryResult.Data) expirationBlock = entryResult.Expires return } + + diff --git a/rpc/tendermint/core/types/responses_util.go b/rpc/tendermint/core/types/responses_util.go new file mode 100644 index 0000000000000000000000000000000000000000..b41d738d5aa52a089ab1dd3794ebc4888471f73c --- /dev/null +++ b/rpc/tendermint/core/types/responses_util.go @@ -0,0 +1,45 @@ +// Copyright 2015, 2016 Eris Industries (UK) Ltd. +// This file is part of Eris-RT + +// Eris-RT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Eris-RT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. + +package core_types + +import ( + "github.com/eris-ltd/eris-db/core/types" +) + +// UnwrapResultDumpStorage does a deep copy to remove /rpc/tendermint/core/types +// and expose /core/types instead. This is largely an artefact to be removed once +// go-wire and go-rpc are deprecated. +// This is not an efficient code, especially given Storage can be big. +func UnwrapResultDumpStorage(result *ResultDumpStorage) (*types.Storage) { + storageRoot := make([]byte, len(result.StorageRoot)) + copy(storageRoot, result.StorageRoot) + storageItems := make([]types.StorageItem, len(result.StorageItems)) + for i, item := range result.StorageItems { + key := make([]byte, len(item.Key)) + value := make([]byte, len(item.Value)) + copy(key, item.Key) + copy(value, item.Value) + storageItems[i] = types.StorageItem{ + Key: key, + Value: value, + } + } + return &types.Storage{ + StorageRoot: storageRoot, + StorageItems: storageItems, + } +}