From 1b51016589414f02325471cda149963fb232f7ea Mon Sep 17 00:00:00 2001 From: Benjamin Bollen <ben@erisindustries.com> Date: Sun, 18 Sep 2016 16:11:01 +0200 Subject: [PATCH] client: add GetName() --- client/client.go | 56 +++++++++++++++++++++--------- client/core/transaction_factory.go | 24 ------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/client/client.go b/client/client.go index b1bfd146..d2674c01 100644 --- a/client/client.go +++ b/client/client.go @@ -71,23 +71,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 +120,42 @@ 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 +func (erisNodeClient *ErisNodeClient) DumpStorage(address []byte) (storageRoot []byte) + + +//-------------------------------------------------------------------------------------------- +// 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 = *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 73c6f5c2..92400243 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 { -- GitLab