Added RPC "Call" for JS calls to contracts

This commit is contained in:
obscuren 2015-01-29 13:10:34 +01:00
parent f75dcc7f4c
commit 84adf77bf3
6 changed files with 55 additions and 11 deletions

@ -45,8 +45,7 @@ ApplicationWindow {
mainSplit.setView(wallet.view, wallet.menuItem);
//newBrowserTab("http://etherian.io");
newBrowserTab("file:///users/jeffrey/test.html");
newBrowserTab("http://etherian.io");
// Command setup
gui.sendCommand(0)

@ -58,8 +58,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
re.Vm.Run(jsLib)
// Load extra javascript files
re.LoadIntFile("string.js")
re.LoadIntFile("big.js")
re.LoadIntFile("bignumber.min.js")
// Subscribe to events
mux := ethereum.EventMux()

@ -28,10 +28,11 @@ func (obj *GetBlockArgs) requirements() error {
}
type NewTxArgs struct {
Recipient string `json:"recipient"`
From string `json:"from"`
To string `json:"to"`
Value string `json:"value"`
Gas string `json:"gas"`
GasPrice string `json:"gasprice"`
GasPrice string `json:"gasPrice"`
Data string `json:"data"`
}

@ -67,8 +67,17 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
if err != nil {
return err
}
result, _ := p.xeth.Transact( /* TODO specify account */ args.Recipient, args.Value, args.Gas, args.GasPrice, args.Data)
fmt.Println("result:", result)
result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
*reply = result
return nil
}
func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
result, err := p.xeth.Call( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
if err != nil {
return err
}
*reply = result
return nil
}
@ -206,6 +215,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return err
}
return p.Transact(args, reply)
case "eth_call":
args, err := req.ToNewTxArgs()
if err != nil {
return err
}
return p.Call(args, reply)
case "web3_sha3":
args, err := req.ToSha3Args()
if err != nil {

@ -634,6 +634,8 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
continue
}
self.Printf(" ~> false")
case JUMPDEST:
case PC:
stack.Push(big.NewInt(int64(pc)))

@ -204,6 +204,34 @@ func (self *XEth) PushTx(encodedTx string) (string, error) {
return toHex(tx.Hash()), nil
}
func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
if len(gasStr) == 0 {
gasStr = "100000"
}
if len(gasPriceStr) == 0 {
gasPriceStr = "1"
}
var (
statedb = self.chainManager.TransState()
initiator = state.NewStateObject(self.eth.KeyManager().KeyPair().Address(), self.eth.Db())
block = self.chainManager.CurrentBlock()
to = statedb.GetOrNewStateObject(fromHex(toStr))
data = fromHex(dataStr)
gas = ethutil.Big(gasStr)
price = ethutil.Big(gasPriceStr)
value = ethutil.Big(valueStr)
)
vmenv := NewEnv(self.chainManager, statedb, block, value, initiator.Address())
res, err := vmenv.Call(initiator, to.Address(), data, gas, price, value)
if err != nil {
return "", err
}
return toHex(res), nil
}
func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
var (