list names rpc
This commit is contained in:
parent
6eb8386c7c
commit
231a7330e2
|
@ -4,13 +4,26 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
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
|
st := consensusState.GetState() // performs a copy
|
||||||
entry := st.GetNameRegEntry(name)
|
entry := st.GetNameRegEntry(name)
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return nil, fmt.Errorf("Name %s not found", name)
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||||
"broadcast_tx": rpc.NewRPCFunc(BroadcastTx, []string{"tx"}),
|
"broadcast_tx": rpc.NewRPCFunc(BroadcastTx, []string{"tx"}),
|
||||||
"list_unconfirmed_txs": rpc.NewRPCFunc(ListUnconfirmedTxs, []string{}),
|
"list_unconfirmed_txs": rpc.NewRPCFunc(ListUnconfirmedTxs, []string{}),
|
||||||
"list_accounts": rpc.NewRPCFunc(ListAccounts, []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/gen_priv_account": rpc.NewRPCFunc(GenPrivAccount, []string{}),
|
||||||
"unsafe/sign_tx": rpc.NewRPCFunc(SignTx, []string{"tx", "privAccounts"}),
|
"unsafe/sign_tx": rpc.NewRPCFunc(SignTx, []string{"tx", "privAccounts"}),
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ type ResponseDumpConsensusState struct {
|
||||||
PeerRoundStates []string `json:"peer_round_states"`
|
PeerRoundStates []string `json:"peer_round_states"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseNameRegEntry struct {
|
type ResponseListNames struct {
|
||||||
Entry *types.NameRegEntry `json:"entry"`
|
BlockHeight uint `json:"block_height"`
|
||||||
|
Names []*types.NameRegEntry `json:"names"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue