add fromAddress argument to Call and CallCode rpc methods

This commit is contained in:
Ethan Buchman
2015-07-22 18:43:20 -04:00
parent c13b67253c
commit 290b74d8f1
5 changed files with 27 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import (
rpc "github.com/tendermint/tendermint/rpc/server"
)
// TODO: eliminate redundancy between here and reading code from core/
var Routes = map[string]*rpc.RPCFunc{
"status": rpc.NewRPCFunc(Status, []string{}),
"net_info": rpc.NewRPCFunc(NetInfo, []string{}),
@@ -12,8 +13,8 @@ var Routes = map[string]*rpc.RPCFunc{
"get_block": rpc.NewRPCFunc(GetBlock, []string{"height"}),
"get_account": rpc.NewRPCFunc(GetAccount, []string{"address"}),
"get_storage": rpc.NewRPCFunc(GetStorage, []string{"address", "key"}),
"call": rpc.NewRPCFunc(Call, []string{"address", "data"}),
"call_code": rpc.NewRPCFunc(CallCode, []string{"code", "data"}),
"call": rpc.NewRPCFunc(Call, []string{"fromAddress", "toAddress", "data"}),
"call_code": rpc.NewRPCFunc(CallCode, []string{"fromAddress", "code", "data"}),
"list_validators": rpc.NewRPCFunc(ListValidators, []string{}),
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, []string{}),
"dump_storage": rpc.NewRPCFunc(DumpStorage, []string{"address"}),

View File

@@ -25,15 +25,15 @@ func toVMAccount(acc *acm.Account) *vm.Account {
// Run a contract's code on an isolated and unpersisted state
// Cannot be used to create new contracts
func Call(address, data []byte) (*ctypes.ResponseCall, error) {
func Call(fromAddress, toAddress, data []byte) (*ctypes.ResponseCall, error) {
st := consensusState.GetState() // performs a copy
cache := state.NewBlockCache(st)
outAcc := cache.GetAccount(address)
outAcc := cache.GetAccount(toAddress)
if outAcc == nil {
return nil, fmt.Errorf("Account %x does not exist", address)
return nil, fmt.Errorf("Account %x does not exist", toAddress)
}
callee := toVMAccount(outAcc)
caller := &vm.Account{Address: Zero256}
caller := &vm.Account{Address: LeftPadWord256(fromAddress)}
txCache := state.NewTxCache(cache)
params := vm.Params{
BlockHeight: int64(st.LastBlockHeight),
@@ -53,12 +53,12 @@ func Call(address, data []byte) (*ctypes.ResponseCall, error) {
// Run the given code on an isolated and unpersisted state
// Cannot be used to create new contracts
func CallCode(code, data []byte) (*ctypes.ResponseCall, error) {
func CallCode(fromAddress, code, data []byte) (*ctypes.ResponseCall, error) {
st := consensusState.GetState() // performs a copy
cache := mempoolReactor.Mempool.GetCache()
callee := &vm.Account{Address: Zero256}
caller := &vm.Account{Address: Zero256}
callee := &vm.Account{Address: LeftPadWord256(fromAddress)}
caller := &vm.Account{Address: LeftPadWord256(fromAddress)}
txCache := state.NewTxCache(cache)
params := vm.Params{
BlockHeight: int64(st.LastBlockHeight),