diff --git a/client/client.go b/client/client.go index b1bfd146452d730b88f3a237cdf8308cdfd6e7b7..4e8349595616ceb500a01182a1ffc0953b8efcf0 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 { @@ -71,23 +73,6 @@ func (erisNodeClient *ErisNodeClient) Broadcast(tx txs.Tx) (*txs.Receipt, error) //------------------------------------------------------------------------------------ // RPC requests other than transaction related -// GetAccount returns a copy of the account -func (erisNodeClient *ErisNodeClient) GetAccount(address []byte) (*acc.Account, error) { - client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) - account, err := tendermint_client.GetAccount(client, address) - if err != nil { - err = fmt.Errorf("Error connecting to node (%s) to fetch account (%X): %s", - erisNodeClient.broadcastRPC, address, err.Error()) - return nil, err - } - if account == nil { - err = fmt.Errorf("Unknown account %X at node (%s)", address, erisNodeClient.broadcastRPC) - return nil, err - } - - return account.Copy(), nil -} - // Status returns the ChainId (GenesisHash), validator's PublicKey, latest block hash // the block height and the latest block time. func (erisNodeClient *ErisNodeClient) Status() (ChainId []byte, ValidatorPublicKey []byte, LatestBlockHash []byte, LatestBlockHeight int, LatestBlockTime int64, err error) { @@ -137,3 +122,57 @@ func (erisNodeClient *ErisNodeClient) QueryContractCode(address, code, data []by return callResult.Return, callResult.GasUsed, nil } +// GetAccount returns a copy of the account +func (erisNodeClient *ErisNodeClient) GetAccount(address []byte) (*acc.Account, error) { + client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) + account, err := tendermint_client.GetAccount(client, address) + if err != nil { + err = fmt.Errorf("Error connecting to node (%s) to fetch account (%X): %s", + erisNodeClient.broadcastRPC, address, err.Error()) + return nil, err + } + if account == nil { + err = fmt.Errorf("Unknown account %X at node (%s)", address, erisNodeClient.broadcastRPC) + return nil, err + } + + return account.Copy(), nil +} + +// DumpStorage returns the full storage for an account. +func (erisNodeClient *ErisNodeClient) DumpStorage(address []byte) (storage *core_types.Storage, err error) { + client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) + resultStorage, err := tendermint_client.DumpStorage(client, address) + if err != nil { + err = fmt.Errorf("Error connecting to node (%s) to get storage for account (%X): %s", + erisNodeClient.broadcastRPC, address, err.Error()) + return nil, err + } + // 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 + storage = tendermint_types.UnwrapResultDumpStorage(resultStorage) + return +} + +//-------------------------------------------------------------------------------------------- +// Name registry + +func (erisNodeClient *ErisNodeClient) GetName(name string) (owner []byte, data []byte, expirationBlock int, err error) { + client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) + entryResult, err := tendermint_client.GetName(client, name) + if err != nil { + err = fmt.Errorf("Error connecting to node (%s) to get name registrar entry for name (%s)", + erisNodeClient.broadcastRPC, name) + return nil, nil, 0, err + } + // unwrap return results + owner = make([]byte, len(entryResult.Owner)) + copy(owner, entryResult.Owner) + data = []byte(entryResult.Data) + expirationBlock = entryResult.Expires + return +} + + + diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index 73c6f5c2814b182a9588f960b2504acab1a9d910..92400243f22f1b670d6fef5968db87f37f5dcee2 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -184,30 +184,6 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, return tx, nil } -// type NameGetter struct { -// client cclient.Client -// } - -// func (n NameGetter) GetNameRegEntry(name string) *txs.NameRegEntry { -// entry, err := n.client.GetName(name) -// if err != nil { -// panic(err) -// } -// return entry.Entry -// } - -/* -func coreNewAccount(nodeAddr, pubkey, chainID string) (*types.NewAccountTx, error) { - pub, _, _, err := checkCommon(nodeAddr, pubkey, "", "0", "0") - if err != nil { - return nil, err - } - - client := cclient.NewClient(nodeAddr, "HTTP") - return types.NewNewAccountTx(NameGetter{client}, pub, chainID) -} -*/ - // func Bond(nodeAddr, signAddr, pubkey, unbondAddr, amtS, nonceS string) (*txs.BondTx, error) { // pub, amt, nonce, err := checkCommon(nodeAddr, signAddr, pubkey, "", amtS, nonceS) // if err != nil { diff --git a/rpc/tendermint/core/types/responses_util.go b/rpc/tendermint/core/types/responses_util.go new file mode 100644 index 0000000000000000000000000000000000000000..0dcc9ddd337c1d384e512a78753fc6b334e5da44 --- /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 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, + } +}