diff --git a/rpc/core/names.go b/rpc/core/names.go index 5c238b44..7f0d872e 100644 --- a/rpc/core/names.go +++ b/rpc/core/names.go @@ -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 } diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 198c76f6..6e8fe249 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -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"}), } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index f9ac1a10..297a83b9 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -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"` }