rpc: test CallCode and Call

This commit is contained in:
Ethan Buchman
2015-04-07 00:34:27 -05:00
parent ade13daec1
commit 5a2ff3d45b
6 changed files with 198 additions and 8 deletions
+25
View File
@@ -51,6 +51,31 @@ func Call(address, data []byte) (*ResponseCall, error) {
return &ResponseCall{Return: ret}, nil
}
// Run the given code on an isolated and unpersisted state
// Cannot be used to create new contracts
func CallCode(code, data []byte) (*ResponseCall, error) {
st := consensusState.GetState() // performs a copy
cache := mempoolReactor.Mempool.GetCache()
callee := &vm.Account{Address: Zero256}
caller := &vm.Account{Address: Zero256}
txCache := state.NewTxCache(cache)
params := vm.Params{
BlockHeight: uint64(st.LastBlockHeight),
BlockHash: RightPadWord256(st.LastBlockHash),
BlockTime: st.LastBlockTime.Unix(),
GasLimit: 10000000,
}
vmach := vm.NewVM(txCache, params, caller.Address)
gas := uint64(1000000000)
ret, err := vmach.Call(caller, callee, code, data, 0, &gas)
if err != nil {
return nil, err
}
return &ResponseCall{Return: ret}, nil
}
//-----------------------------------------------------------------------------
func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ResponseSignTx, error) {