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 /rpc/api/eth.go | |
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 'rpc/api/eth.go')
-rw-r--r-- | rpc/api/eth.go | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go index b84ae31da..db7a643d8 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/natspec" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/xeth" @@ -70,8 +71,10 @@ var ( "eth_getCode": (*ethApi).GetData, "eth_getNatSpec": (*ethApi).GetNatSpec, "eth_sign": (*ethApi).Sign, - "eth_sendRawTransaction": (*ethApi).SendRawTransaction, + "eth_sendRawTransaction": (*ethApi).SubmitTransaction, + "eth_submitTransaction": (*ethApi).SubmitTransaction, "eth_sendTransaction": (*ethApi).SendTransaction, + "eth_signTransaction": (*ethApi).SignTransaction, "eth_transact": (*ethApi).SendTransaction, "eth_estimateGas": (*ethApi).EstimateGas, "eth_call": (*ethApi).Call, @@ -285,7 +288,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) { return v, nil } -func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error) { +func (self *ethApi) SubmitTransaction(req *shared.Request) (interface{}, error) { args := new(NewDataArgs) if err := self.codec.Decode(req.Params, &args); err != nil { return nil, shared.NewDecodeParamError(err.Error()) @@ -298,6 +301,45 @@ func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error) return v, nil } +// JsonTransaction is returned as response by the JSON RPC. It contains the +// signed RLP encoded transaction as Raw and the signed transaction object as Tx. +type JsonTransaction struct { + Raw string `json:"raw"` + Tx *tx `json:"tx"` +} + +func (self *ethApi) SignTransaction(req *shared.Request) (interface{}, error) { + args := new(NewTxArgs) + if err := self.codec.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + // nonce may be nil ("guess" mode) + var nonce string + if args.Nonce != nil { + nonce = args.Nonce.String() + } + + var gas, price string + if args.Gas != nil { + gas = args.Gas.String() + } + if args.GasPrice != nil { + price = args.GasPrice.String() + } + tx, err := self.xeth.SignTransaction(args.From, args.To, nonce, args.Value.String(), gas, price, args.Data) + if err != nil { + return nil, err + } + + data, err := rlp.EncodeToBytes(tx) + if err != nil { + return nil, err + } + + return JsonTransaction{"0x" + common.Bytes2Hex(data), newTx(tx)}, nil +} + func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) { args := new(NewTxArgs) if err := self.codec.Decode(req.Params, &args); err != nil { |