diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-10 01:04:40 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-10 06:08:46 +0800 |
commit | b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3 (patch) | |
tree | cfc4b47a97d854f388fd935b836089051be01246 /xeth | |
parent | 2ee88a220ac22a814def1d568f80d7f29ede7095 (diff) | |
download | dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar.gz dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar.bz2 dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar.lz dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar.xz dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.tar.zst dexon-b4fa94c4b1459e71d4f11a3178cf56edf2b4aed3.zip |
xeth: don't sign transactions for tx call
This should make calls faster and removes interaction
with account manager.
Diffstat (limited to 'xeth')
-rw-r--r-- | xeth/xeth.go | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go index afe680f34..956b8cd01 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -7,6 +7,7 @@ package xeth import ( "bytes" "encoding/json" + "math/big" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/core" @@ -243,7 +244,7 @@ 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) { +func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { if len(gasStr) == 0 { gasStr = "100000" } @@ -251,34 +252,20 @@ func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (st gasPriceStr = "1" } - acct, err := self.accountManager.Default() - if err != nil { - return "", err - } - var ( - statedb = self.State().State() //self.chainManager.TransState() - from = statedb.GetOrNewStateObject(acct.Address) - block = self.chainManager.CurrentBlock() - to = statedb.GetOrNewStateObject(fromHex(toStr)) - data = fromHex(dataStr) - gas = ethutil.Big(gasStr) - price = ethutil.Big(gasPriceStr) - value = ethutil.Big(valueStr) - ) - - msg := types.NewTransactionMessage(fromHex(toStr), value, gas, price, data) - sig, err := self.accountManager.Sign(acct, msg.Hash()) - if err != nil { - return "", err + statedb := self.State().State() //self.chainManager.TransState() + msg := callmsg{ + from: statedb.GetOrNewStateObject(fromHex(fromStr)), + to: fromHex(toStr), + gas: ethutil.Big(gasStr), + gasPrice: ethutil.Big(gasPriceStr), + value: ethutil.Big(valueStr), + data: fromHex(dataStr), } - msg.SetSignatureValues(sig) + block := self.chainManager.CurrentBlock() vmenv := core.NewEnv(statedb, self.chainManager, msg, block) - res, err := vmenv.Call(from, to.Address(), data, gas, price, value) - if err != nil { - return "", err - } - return toHex(res), nil + res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value) + return toHex(res), err } func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { @@ -334,3 +321,21 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt return toHex(tx.Hash()), nil } + +// callmsg is the message type used for call transations. +type callmsg struct { + from *state.StateObject + to []byte + gas, gasPrice *big.Int + value *big.Int + data []byte +} + +// accessor boilerplate to implement core.Message +func (m callmsg) From() []byte { return m.from.Address() } +func (m callmsg) Nonce() uint64 { return m.from.Nonce() } +func (m callmsg) To() []byte { return m.to } +func (m callmsg) GasPrice() *big.Int { return m.gasPrice } +func (m callmsg) Gas() *big.Int { return m.gas } +func (m callmsg) Value() *big.Int { return m.value } +func (m callmsg) Data() []byte { return m.data } |