Skip to content
Snippets Groups Projects
Commit a3f39a29 authored by Silas Davis's avatar Silas Davis Committed by GitHub
Browse files

Merge pull request #292 from benjaminbollen/eris-client-part6

client: ListValidators, GetName
parents a7086aa1 3a3fff19
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......@@ -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
}
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment