2015-03-26 21:30:42 -07:00
|
|
|
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"
|
2015-03-31 04:53:34 -07:00
|
|
|
. "github.com/tendermint/tendermint2/common"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
2015-03-28 23:10:05 -07:00
|
|
|
func GenPrivAccount() (*ResponseGenPrivAccount, error) {
|
|
|
|
return &ResponseGenPrivAccount{account.GenPrivAccount()}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2015-03-31 14:08:21 -07:00
|
|
|
func GetAccount(addr []byte) (*ResponseGetAccount, error) {
|
2015-03-29 18:43:27 -07:00
|
|
|
cache := mempoolReactor.Mempool.GetCache()
|
2015-03-31 14:08:21 -07:00
|
|
|
return &ResponseGetAccount{cache.GetAccount(addr)}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2015-03-31 04:53:34 -07:00
|
|
|
func GetStorage(address, slot []byte) (*ResponseGetStorage, error) {
|
|
|
|
state := consensusState.GetState()
|
|
|
|
account := state.GetAccount(address)
|
|
|
|
if account == nil {
|
|
|
|
return nil, fmt.Errorf("Unknown address: %X", address)
|
|
|
|
}
|
|
|
|
storageRoot := account.StorageRoot
|
|
|
|
storage := state.LoadStorage(storageRoot)
|
|
|
|
|
|
|
|
_, value := storage.Get(RightPadWord256(slot).Bytes())
|
|
|
|
if value == nil {
|
|
|
|
return &ResponseGetStorage{slot, nil}, nil
|
|
|
|
}
|
|
|
|
return &ResponseGetStorage{slot, value.([]byte)}, nil
|
|
|
|
}
|
|
|
|
|
2015-03-28 23:10:05 -07:00
|
|
|
func ListAccounts() (*ResponseListAccounts, error) {
|
2015-03-26 21:30:42 -07:00
|
|
|
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
|
|
|
|
})
|
2015-03-28 23:10:05 -07:00
|
|
|
return &ResponseListAccounts{blockHeight, accounts}, nil
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
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
|
|
|
|
}
|