diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-21 04:36:56 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-21 04:36:56 +0800 |
commit | 6bb29aebeefc64c765f0a2b5ab66f85d928f56cd (patch) | |
tree | 220bcd3f4866b94cc9b790e23b2cbb3ec6b04b1e /xeth | |
parent | 314c031ff226c2ea623228d23fe5d5cc866f7980 (diff) | |
parent | 6ea05f5a54c2db009e4379ce917590568b950f42 (diff) | |
download | dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar.gz dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar.bz2 dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar.lz dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar.xz dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.tar.zst dexon-6bb29aebeefc64c765f0a2b5ab66f85d928f56cd.zip |
Merge pull request #1666 from obscuren/create-transaction
rpc/api, xeth: added signTransaction method
Diffstat (limited to 'xeth')
-rw-r--r-- | xeth/xeth.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go index ae9f1fe47..19c42a9a3 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -879,6 +879,60 @@ func (self *XEth) Frontend() Frontend { return self.frontend } +func (self *XEth) SignTransaction(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (*types.Transaction, error) { + if len(toStr) > 0 && toStr != "0x" && !isAddress(toStr) { + return nil, errors.New("Invalid address") + } + + var ( + from = common.HexToAddress(fromStr) + to = common.HexToAddress(toStr) + value = common.Big(valueStr) + gas *big.Int + price *big.Int + data []byte + contractCreation bool + ) + + if len(gasStr) == 0 { + gas = DefaultGas() + } else { + gas = common.Big(gasStr) + } + + if len(gasPriceStr) == 0 { + price = self.DefaultGasPrice() + } else { + price = common.Big(gasPriceStr) + } + + data = common.FromHex(codeStr) + if len(toStr) == 0 { + contractCreation = true + } + + var nonce uint64 + if len(nonceStr) != 0 { + nonce = common.Big(nonceStr).Uint64() + } else { + state := self.backend.TxPool().State() + nonce = state.GetNonce(from) + } + var tx *types.Transaction + if contractCreation { + tx = types.NewContractCreation(nonce, value, gas, price, data) + } else { + tx = types.NewTransaction(nonce, to, value, gas, price, data) + } + + signed, err := self.sign(tx, from, false) + if err != nil { + return nil, err + } + + return signed, nil +} + func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { // this minimalistic recoding is enough (works for natspec.js) |