diff --git a/client/client.go b/client/client.go index 806e1181a4da0b03530cf4498a8a2682082c0e70..b5f66c69a3e3928360db09e4a6855f55c7ae9367 100644 --- a/client/client.go +++ b/client/client.go @@ -22,6 +22,7 @@ import ( "github.com/tendermint/go-rpc/client" acc "github.com/eris-ltd/eris-db/account" + consensus_types "github.com/eris-ltd/eris-db/consensus/types" 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" @@ -36,6 +37,10 @@ type NodeClient interface { GetAccount(address []byte) (*acc.Account, error) QueryContract(callerAddress, calleeAddress, data []byte) (ret []byte, gasUsed int64, err error) QueryContractCode(address, code, data []byte) (ret []byte, gasUsed int64, err error) + + DumpStorage(address []byte) (storage *core_types.Storage, err error) + GetName(name string) (owner []byte, data string, expirationBlock int, err error) + ListValidators() (blockHeight int, bondedValidators, unbondingValidators []consensus_types.Validator, err error) } // NOTE [ben] Compiler check to ensure ErisNodeClient successfully implements @@ -155,21 +160,37 @@ func (erisNodeClient *ErisNodeClient) DumpStorage(address []byte) (storage *core //-------------------------------------------------------------------------------------------- // Name registry -func (erisNodeClient *ErisNodeClient) GetName(name string) (owner []byte, data []byte, expirationBlock int, err error) { +func (erisNodeClient *ErisNodeClient) GetName(name string) (owner []byte, data string, 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 + return nil, "", 0, err } // unwrap return results owner = make([]byte, len(entryResult.Owner)) copy(owner, entryResult.Owner) - data = []byte(entryResult.Data) + data = entryResult.Data expirationBlock = entryResult.Expires return } +//-------------------------------------------------------------------------------------------- +func (erisNodeClient *ErisNodeClient) ListValidators() (blockHeight int, + bondedValidators []consensus_types.Validator, unbondingValidators []consensus_types.Validator, err error) { + client := rpcclient.NewClientURI(erisNodeClient.broadcastRPC) + validatorsResult, err := tendermint_client.ListValidators(client) + if err != nil { + err = fmt.Errorf("Error connecting to node (%s) to get validators", + erisNodeClient.broadcastRPC) + return 0, nil, nil, err + } + // unwrap return results + blockHeight = validatorsResult.BlockHeight + bondedValidators = validatorsResult.BondedValidators + unbondingValidators = validatorsResult.UnbondingValidators + return +} diff --git a/client/mock/client_mock.go b/client/mock/client_mock.go index 08b481e4725a85587b2efc487e5491b0199c04a7..24a94e93a37e04b6a84cf1a59c34963fc0fcc998 100644 --- a/client/mock/client_mock.go +++ b/client/mock/client_mock.go @@ -19,6 +19,8 @@ package mock import ( "github.com/tendermint/go-crypto" + consensus_types "github.com/eris-ltd/eris-db/consensus/types" + core_types "github.com/eris-ltd/eris-db/core/types" acc "github.com/eris-ltd/eris-db/account" . "github.com/eris-ltd/eris-db/client" "github.com/eris-ltd/eris-db/txs" @@ -100,3 +102,16 @@ func (mock *MockNodeClient) QueryContractCode(address, code, data []byte) (ret [ ret = make([]byte, 0) return ret, 0, nil } + + +func (mock *MockNodeClient) DumpStorage(address []byte) (storage *core_types.Storage, err error) { + return nil, nil +} + +func (mock *MockNodeClient) GetName(name string) (owner []byte, data string, expirationBlock int, err error) { + return nil, "", 0, nil +} + +func (mock *MockNodeClient) ListValidators() (blockHeight int, bondedValidators, unbondingValidators []consensus_types.Validator, err error){ + return 0, nil, nil, nil +} diff --git a/consensus/types/validator.go b/consensus/types/validator.go index f5567bbbb0692daea3593d2b6feaf081cbbf793b..8feefb1f3563c5f690f20448c1056dc1c249c0c1 100644 --- a/consensus/types/validator.go +++ b/consensus/types/validator.go @@ -12,6 +12,7 @@ var _ = wire.RegisterInterface( type Validator interface { AssertIsValidator() + Address() []byte } // Anticipating moving to our own definition of Validator, or at least @@ -20,11 +21,18 @@ type TendermintValidator struct { *tendermint_types.Validator `json:"validator"` } -func (validator *TendermintValidator) AssertIsValidator() { +var _ Validator = (*TendermintValidator)(nil) + +func (tendermintValidator *TendermintValidator) AssertIsValidator() { } -var _ Validator = (*TendermintValidator)(nil) +func (tendermintValidator *TendermintValidator) Address() []byte { + return tendermintValidator.Address() +} + +//------------------------------------------------------------------------------------- +// Helper function for TendermintValidator func FromTendermintValidators(tmValidators []*tendermint_types.Validator) []Validator { validators := make([]Validator, len(tmValidators))