diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-29 20:10:34 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-29 20:10:34 +0800 |
commit | 84adf77bf3492351de82f0ec820a1d280e85a5cd (patch) | |
tree | e841925b72cbef95cde5d6c8763d145812486336 | |
parent | f75dcc7f4c60800055f6d15c5e6660ed76465eb6 (diff) | |
download | go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar.gz go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar.bz2 go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar.lz go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar.xz go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.tar.zst go-tangerine-84adf77bf3492351de82f0ec820a1d280e85a5cd.zip |
Added RPC "Call" for JS calls to contracts
-rw-r--r-- | cmd/mist/assets/qml/main.qml | 3 | ||||
-rw-r--r-- | javascript/javascript_runtime.go | 3 | ||||
-rw-r--r-- | rpc/args.go | 11 | ||||
-rw-r--r-- | rpc/packages.go | 19 | ||||
-rw-r--r-- | vm/vm.go | 2 | ||||
-rw-r--r-- | xeth/xeth.go | 28 |
6 files changed, 55 insertions, 11 deletions
diff --git a/cmd/mist/assets/qml/main.qml b/cmd/mist/assets/qml/main.qml index 240d95d5f..1a8885e58 100644 --- a/cmd/mist/assets/qml/main.qml +++ b/cmd/mist/assets/qml/main.qml @@ -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) diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go index c780eb754..398daf43a 100644 --- a/javascript/javascript_runtime.go +++ b/javascript/javascript_runtime.go @@ -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() diff --git a/rpc/args.go b/rpc/args.go index 0c3087151..ff4974792 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -28,11 +28,12 @@ func (obj *GetBlockArgs) requirements() error { } type NewTxArgs struct { - Recipient string `json:"recipient"` - Value string `json:"value"` - Gas string `json:"gas"` - GasPrice string `json:"gasprice"` - Data string `json:"data"` + From string `json:"from"` + To string `json:"to"` + Value string `json:"value"` + Gas string `json:"gas"` + GasPrice string `json:"gasPrice"` + Data string `json:"data"` } // type TxResponse struct { diff --git a/rpc/packages.go b/rpc/packages.go index 3eaa71a7f..4302f6018 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -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))) diff --git a/xeth/xeth.go b/xeth/xeth.go index 89b2459b0..382a1f285 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -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 ( |