From 6ea05f5a54c2db009e4379ce917590568b950f42 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 15 Aug 2015 23:51:31 +0200 Subject: rpc/api, xeth: added signTransaction method SignTransaction creates a transaction but does submit it to the network. SignTransaction returns a structure which includes the transaction object details as well as the RLP encoded transaction that could possibly be submitted by the SendRawTransaction method. --- xeth/xeth.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 35e6dd52d..04fdea1d2 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -912,6 +912,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) -- cgit