list names rpc

This commit is contained in:
Ethan Buchman 2015-05-30 11:13:09 -04:00
parent 6eb8386c7c
commit 231a7330e2
3 changed files with 20 additions and 5 deletions

View File

@ -4,13 +4,26 @@ import (
"fmt"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
func NameRegEntry(name string) (*ctypes.ResponseNameRegEntry, error) {
func GetName(name string) (*types.NameRegEntry, error) {
st := consensusState.GetState() // performs a copy
entry := st.GetNameRegEntry(name)
if entry == nil {
return nil, fmt.Errorf("Name %s not found", name)
}
return &ctypes.ResponseNameRegEntry{entry}, nil
return entry, nil
}
func ListNames() (*ctypes.ResponseListNames, error) {
var blockHeight uint
var names []*types.NameRegEntry
state := consensusState.GetState()
blockHeight = state.LastBlockHeight
state.GetNames().Iterate(func(key interface{}, value interface{}) bool {
names = append(names, value.(*types.NameRegEntry))
return false
})
return &ctypes.ResponseListNames{blockHeight, names}, nil
}

View File

@ -20,7 +20,8 @@ var Routes = map[string]*rpc.RPCFunc{
"broadcast_tx": rpc.NewRPCFunc(BroadcastTx, []string{"tx"}),
"list_unconfirmed_txs": rpc.NewRPCFunc(ListUnconfirmedTxs, []string{}),
"list_accounts": rpc.NewRPCFunc(ListAccounts, []string{}),
"name_reg_entry": rpc.NewRPCFunc(NameRegEntry, []string{"name"}),
"get_name": rpc.NewRPCFunc(GetName, []string{"name"}),
"list_names": rpc.NewRPCFunc(ListNames, []string{}),
"unsafe/gen_priv_account": rpc.NewRPCFunc(GenPrivAccount, []string{}),
"unsafe/sign_tx": rpc.NewRPCFunc(SignTx, []string{"tx", "privAccounts"}),
}

View File

@ -101,6 +101,7 @@ type ResponseDumpConsensusState struct {
PeerRoundStates []string `json:"peer_round_states"`
}
type ResponseNameRegEntry struct {
Entry *types.NameRegEntry `json:"entry"`
type ResponseListNames struct {
BlockHeight uint `json:"block_height"`
Names []*types.NameRegEntry `json:"names"`
}