mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-28 05:31:20 +00:00
add fromAddress argument to Call and CallCode rpc methods
This commit is contained in:
parent
c13b67253c
commit
290b74d8f1
@ -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"}),
|
||||
|
@ -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),
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
type Client interface {
|
||||
BlockchainInfo(minHeight int, maxHeight int) (*ctypes.ResponseBlockchainInfo, error)
|
||||
BroadcastTx(tx types.Tx) (*ctypes.Receipt, error)
|
||||
Call(address []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
Call(fromAddress []byte, toAddress []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
CallCode(fromAddress []byte, code []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
|
||||
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
|
||||
GenPrivAccount() (*acm.PrivAccount, error)
|
||||
@ -96,8 +96,8 @@ func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) Call(address []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
values, err := argsToURLValues([]string{"address", "data"}, address, data)
|
||||
func (c *ClientHTTP) Call(fromAddress []byte, toAddress []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
values, err := argsToURLValues([]string{"fromAddress", "toAddress", "data"}, fromAddress, toAddress, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -126,8 +126,8 @@ func (c *ClientHTTP) Call(address []byte, data []byte) (*ctypes.ResponseCall, er
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
values, err := argsToURLValues([]string{"code", "data"}, code, data)
|
||||
func (c *ClientHTTP) CallCode(fromAddress []byte, code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
values, err := argsToURLValues([]string{"fromAddress", "code", "data"}, fromAddress, code, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -660,11 +660,11 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.Receipt, error) {
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) Call(address []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
func (c *ClientJSON) Call(fromAddress []byte, toAddress []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["Call"],
|
||||
Params: []interface{}{address, data},
|
||||
Params: []interface{}{fromAddress, toAddress, data},
|
||||
Id: 0,
|
||||
}
|
||||
body, err := c.RequestResponse(request)
|
||||
@ -687,11 +687,11 @@ func (c *ClientJSON) Call(address []byte, data []byte) (*ctypes.ResponseCall, er
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
func (c *ClientJSON) CallCode(fromAddress []byte, code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||
request := rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["CallCode"],
|
||||
Params: []interface{}{code, data},
|
||||
Params: []interface{}{fromAddress, code, data},
|
||||
Id: 0,
|
||||
}
|
||||
body, err := c.RequestResponse(request)
|
||||
|
@ -182,8 +182,8 @@ func getStorage(t *testing.T, typ string, addr, key []byte) []byte {
|
||||
return resp.Value
|
||||
}
|
||||
|
||||
func callCode(t *testing.T, client cclient.Client, code, data, expected []byte) {
|
||||
resp, err := client.CallCode(code, data)
|
||||
func callCode(t *testing.T, client cclient.Client, fromAddress, code, data, expected []byte) {
|
||||
resp, err := client.CallCode(fromAddress, code, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -194,8 +194,8 @@ func callCode(t *testing.T, client cclient.Client, code, data, expected []byte)
|
||||
}
|
||||
}
|
||||
|
||||
func callContract(t *testing.T, client cclient.Client, address, data, expected []byte) {
|
||||
resp, err := client.Call(address, data)
|
||||
func callContract(t *testing.T, client cclient.Client, fromAddress, toAddress, data, expected []byte) {
|
||||
resp, err := client.Call(fromAddress, toAddress, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -139,13 +139,13 @@ func testCallCode(t *testing.T, typ string) {
|
||||
code := []byte{0x60, 0x5, 0x60, 0x6, 0x1, 0x60, 0x0, 0x52, 0x60, 0x20, 0x60, 0x0, 0xf3}
|
||||
data := []byte{}
|
||||
expected := []byte{0xb}
|
||||
callCode(t, client, code, data, expected)
|
||||
callCode(t, client, user[0].PubKey.Address(), code, data, expected)
|
||||
|
||||
// pass two ints as calldata, add, and return the result
|
||||
code = []byte{0x60, 0x0, 0x35, 0x60, 0x20, 0x35, 0x1, 0x60, 0x0, 0x52, 0x60, 0x20, 0x60, 0x0, 0xf3}
|
||||
data = append(LeftPadWord256([]byte{0x5}).Bytes(), LeftPadWord256([]byte{0x6}).Bytes()...)
|
||||
expected = []byte{0xb}
|
||||
callCode(t, client, code, data, expected)
|
||||
callCode(t, client, user[0].PubKey.Address(), code, data, expected)
|
||||
}
|
||||
|
||||
func testCall(t *testing.T, typ string) {
|
||||
@ -183,7 +183,7 @@ func testCall(t *testing.T, typ string) {
|
||||
// run a call through the contract
|
||||
data := []byte{}
|
||||
expected := []byte{0xb}
|
||||
callContract(t, client, contractAddr, data, expected)
|
||||
callContract(t, client, user[0].PubKey.Address(), contractAddr, data, expected)
|
||||
}
|
||||
|
||||
func testNameReg(t *testing.T, typ string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user