@@ -26,6 +26,7 @@ import (
2626 "github.com/ethereum/go-ethereum/common"
2727 "github.com/ethereum/go-ethereum/common/natspec"
2828 "github.com/ethereum/go-ethereum/eth"
29+ "github.com/ethereum/go-ethereum/rlp"
2930 "github.com/ethereum/go-ethereum/rpc/codec"
3031 "github.com/ethereum/go-ethereum/rpc/shared"
3132 "github.com/ethereum/go-ethereum/xeth"
7071 "eth_getCode" : (* ethApi ).GetData ,
7172 "eth_getNatSpec" : (* ethApi ).GetNatSpec ,
7273 "eth_sign" : (* ethApi ).Sign ,
73- "eth_sendRawTransaction" : (* ethApi ).SendRawTransaction ,
74+ "eth_sendRawTransaction" : (* ethApi ).SubmitTransaction ,
75+ "eth_submitTransaction" : (* ethApi ).SubmitTransaction ,
7476 "eth_sendTransaction" : (* ethApi ).SendTransaction ,
77+ "eth_signTransaction" : (* ethApi ).SignTransaction ,
7578 "eth_transact" : (* ethApi ).SendTransaction ,
7679 "eth_estimateGas" : (* ethApi ).EstimateGas ,
7780 "eth_call" : (* ethApi ).Call ,
@@ -285,7 +288,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) {
285288 return v , nil
286289}
287290
288- func (self * ethApi ) SendRawTransaction (req * shared.Request ) (interface {}, error ) {
291+ func (self * ethApi ) SubmitTransaction (req * shared.Request ) (interface {}, error ) {
289292 args := new (NewDataArgs )
290293 if err := self .codec .Decode (req .Params , & args ); err != nil {
291294 return nil , shared .NewDecodeParamError (err .Error ())
@@ -298,6 +301,45 @@ func (self *ethApi) SendRawTransaction(req *shared.Request) (interface{}, error)
298301 return v , nil
299302}
300303
304+ // JsonTransaction is returned as response by the JSON RPC. It contains the
305+ // signed RLP encoded transaction as Raw and the signed transaction object as Tx.
306+ type JsonTransaction struct {
307+ Raw string `json:"raw"`
308+ Tx * tx `json:"tx"`
309+ }
310+
311+ func (self * ethApi ) SignTransaction (req * shared.Request ) (interface {}, error ) {
312+ args := new (NewTxArgs )
313+ if err := self .codec .Decode (req .Params , & args ); err != nil {
314+ return nil , shared .NewDecodeParamError (err .Error ())
315+ }
316+
317+ // nonce may be nil ("guess" mode)
318+ var nonce string
319+ if args .Nonce != nil {
320+ nonce = args .Nonce .String ()
321+ }
322+
323+ var gas , price string
324+ if args .Gas != nil {
325+ gas = args .Gas .String ()
326+ }
327+ if args .GasPrice != nil {
328+ price = args .GasPrice .String ()
329+ }
330+ tx , err := self .xeth .SignTransaction (args .From , args .To , nonce , args .Value .String (), gas , price , args .Data )
331+ if err != nil {
332+ return nil , err
333+ }
334+
335+ data , err := rlp .EncodeToBytes (tx )
336+ if err != nil {
337+ return nil , err
338+ }
339+
340+ return JsonTransaction {"0x" + common .Bytes2Hex (data ), newTx (tx )}, nil
341+ }
342+
301343func (self * ethApi ) SendTransaction (req * shared.Request ) (interface {}, error ) {
302344 args := new (NewTxArgs )
303345 if err := self .codec .Decode (req .Params , & args ); err != nil {
0 commit comments