tendermint/rpc/core/accounts.go

45 lines
1.3 KiB
Go
Raw Normal View History

package core
import (
2015-03-31 14:08:21 -07:00
"fmt"
2015-03-30 22:50:27 -07:00
"github.com/tendermint/tendermint2/account"
)
func GenPrivAccount() (*ResponseGenPrivAccount, error) {
return &ResponseGenPrivAccount{account.GenPrivAccount()}, nil
}
2015-03-31 14:08:21 -07:00
func GetAccount(addr []byte) (*ResponseGetAccount, error) {
cache := mempoolReactor.Mempool.GetCache()
2015-03-31 14:08:21 -07:00
return &ResponseGetAccount{cache.GetAccount(addr)}, nil
}
func ListAccounts() (*ResponseListAccounts, error) {
var blockHeight uint
var accounts []*account.Account
state := consensusState.GetState()
blockHeight = state.LastBlockHeight
state.GetAccounts().Iterate(func(key interface{}, value interface{}) bool {
accounts = append(accounts, value.(*account.Account))
return false
})
return &ResponseListAccounts{blockHeight, accounts}, nil
}
2015-03-31 14:08:21 -07:00
func DumpStorage(addr []byte) (*ResponseDumpStorage, error) {
state := consensusState.GetState()
account := state.GetAccount(addr)
if account == nil {
return nil, fmt.Errorf("Unknown address: %X", addr)
}
storageRoot := account.StorageRoot
storage := state.LoadStorage(storageRoot)
storageItems := []StorageItem{}
storage.Iterate(func(key interface{}, value interface{}) bool {
storageItems = append(storageItems, StorageItem{
key.([]byte), value.([]byte)})
return false
})
return &ResponseDumpStorage{storageRoot, storageItems}, nil
}