aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-08-16 05:51:31 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-11-18 00:51:05 +0800
commit6ea05f5a54c2db009e4379ce917590568b950f42 (patch)
tree5ec4ca0451363dfcb34b4bc094b5fb9baf456c11 /xeth
parent9422eec55460aaca300cabd52124ed0cbd8dedd3 (diff)
downloaddexon-6ea05f5a54c2db009e4379ce917590568b950f42.tar.gz
dexon-6ea05f5a54c2db009e4379ce917590568b950f42.tar.zst
dexon-6ea05f5a54c2db009e4379ce917590568b950f42.zip
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.
Diffstat (limited to 'xeth')
-rw-r--r--xeth/xeth.go54
1 files changed, 54 insertions, 0 deletions
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)