From f9a0a13fa97a969b23d98c8dddc63bf8047450d3 Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Sun, 14 Jun 2015 18:07:03 -0400 Subject: [PATCH 01/10] eth_pushTx send raw signed encoded TX data to the chain through RPC --- rpc/api.go | 11 +++++++++++ rpc/api/eth.go | 21 +++++++++++++++++++++ rpc/api/utils.go | 1 + 3 files changed, 33 insertions(+) diff --git a/rpc/api.go b/rpc/api.go index e35395734..64d27df2e 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -170,6 +170,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } *reply = v + case "eth_pushTx": + args := new(NewSigArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + v, err := api.xeth().PushTx(args.encodedTx) + if err != nil { + return err + } + *reply = v + case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { diff --git a/rpc/api/eth.go b/rpc/api/eth.go index a0b9dad86..c5de2cd3b 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -46,6 +46,7 @@ var ( "eth_getData": (*ethApi).GetData, "eth_getCode": (*ethApi).GetData, "eth_sign": (*ethApi).Sign, + "eth_pushTx": (*ethApi).PushTx, "eth_sendTransaction": (*ethApi).SendTransaction, "eth_transact": (*ethApi).SendTransaction, "eth_estimateGas": (*ethApi).EstimateGas, @@ -247,6 +248,26 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) { return v, nil } + +func (self *ethApi) PushTx(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() + } + + v, err := self.xeth.PushTx(args.encodedTx) + if err != nil { + return nil, err + } + return v, nil +} + func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) { args := new(NewTxArgs) if err := self.codec.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 318d7c39b..13f580f58 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -51,6 +51,7 @@ var ( "getData", "getCode", "sign", + "pushTx", "sendTransaction", "transact", "estimateGas", From d6233c7d2daca8f1c757740e04ba1a8d64588fc0 Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Mon, 15 Jun 2015 10:07:32 -0400 Subject: [PATCH 02/10] Changed variable names --- rpc/api.go | 2 +- rpc/api/eth.go | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 64d27df2e..01f3007cf 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -175,7 +175,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err if err := json.Unmarshal(req.Params, &args); err != nil { return err } - v, err := api.xeth().PushTx(args.encodedTx) + v, err := api.xeth().PushTx(args.Data) if err != nil { return err } diff --git a/rpc/api/eth.go b/rpc/api/eth.go index c5de2cd3b..2857202dd 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -255,13 +255,7 @@ func (self *ethApi) PushTx(req *shared.Request) (interface{}, error) { return nil, shared.NewDecodeParamError(err.Error()) } - // nonce may be nil ("guess" mode) - var nonce string - if args.Nonce != nil { - nonce = args.Nonce.String() - } - - v, err := self.xeth.PushTx(args.encodedTx) + v, err := self.xeth.PushTx(args.Data) if err != nil { return nil, err } From f9f9352ceb2655cdf10010b6e8c30797ac97ae25 Mon Sep 17 00:00:00 2001 From: Nick Dodson Date: Mon, 15 Jun 2015 10:50:07 -0400 Subject: [PATCH 03/10] Change eth_pushTx case to eth_sendRawTransaction --- rpc/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api.go b/rpc/api.go index 01f3007cf..943d50119 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -170,7 +170,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } *reply = v - case "eth_pushTx": + case "eth_sendRawTransaction": args := new(NewSigArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err From c3b80123e3099eaf0eef5ed7ee43eb5605fc8e6f Mon Sep 17 00:00:00 2001 From: Nick Dodson Date: Mon, 15 Jun 2015 11:10:24 -0400 Subject: [PATCH 04/10] Update eth.go --- rpc/api/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 2857202dd..1e392a63d 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -46,7 +46,7 @@ var ( "eth_getData": (*ethApi).GetData, "eth_getCode": (*ethApi).GetData, "eth_sign": (*ethApi).Sign, - "eth_pushTx": (*ethApi).PushTx, + "eth_sendRawTransaction": (*ethApi).PushTx, "eth_sendTransaction": (*ethApi).SendTransaction, "eth_transact": (*ethApi).SendTransaction, "eth_estimateGas": (*ethApi).EstimateGas, From ad56aef5d2a5e04f528f85c2d29b6574991d5e79 Mon Sep 17 00:00:00 2001 From: Nick Dodson Date: Mon, 15 Jun 2015 11:10:40 -0400 Subject: [PATCH 05/10] Update utils.go --- rpc/api/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 13f580f58..dcd5b0089 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -51,7 +51,7 @@ var ( "getData", "getCode", "sign", - "pushTx", + "eth_sendRawTransaction", "sendTransaction", "transact", "estimateGas", From 2642e091e95f7c74c04502dfd05af0d9d1217158 Mon Sep 17 00:00:00 2001 From: Nick Dodson Date: Mon, 15 Jun 2015 16:01:01 -0400 Subject: [PATCH 06/10] NewSigArgs arg change. --- rpc/api/eth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 1e392a63d..bb89615cf 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -250,7 +250,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) { func (self *ethApi) PushTx(req *shared.Request) (interface{}, error) { - args := new(NewTxArgs) + args := new(NewSigArgs) if err := self.codec.Decode(req.Params, &args); err != nil { return nil, shared.NewDecodeParamError(err.Error()) } From e952bb65e7f74dc023a983415821b3522cc30746 Mon Sep 17 00:00:00 2001 From: Nick Dodson Date: Tue, 16 Jun 2015 00:06:28 -0400 Subject: [PATCH 07/10] thanks subtly :) --- rpc/api/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/api/utils.go b/rpc/api/utils.go index dcd5b0089..40bcae52f 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -51,7 +51,7 @@ var ( "getData", "getCode", "sign", - "eth_sendRawTransaction", + "sendRawTransaction", "sendTransaction", "transact", "estimateGas", From 7ec8c257ffd90ba4b63e5419ac9b9011af79be07 Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Tue, 16 Jun 2015 12:28:10 -0400 Subject: [PATCH 08/10] New DataArgs and eth_sendRawTransaction --- rpc/api.go | 2 +- rpc/api/eth.go | 2 +- rpc/api/eth_args.go | 29 +++++++++++++++++++++++++++++ rpc/args.go | 29 +++++++++++++++++++++++++++++ xeth/xeth.go | 5 ++++- 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 943d50119..e825accfd 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -171,7 +171,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = v case "eth_sendRawTransaction": - args := new(NewSigArgs) + args := new(NewDataArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } diff --git a/rpc/api/eth.go b/rpc/api/eth.go index bb89615cf..e1e7381f5 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -250,7 +250,7 @@ func (self *ethApi) Sign(req *shared.Request) (interface{}, error) { func (self *ethApi) PushTx(req *shared.Request) (interface{}, error) { - args := new(NewSigArgs) + args := new(NewDataArgs) if err := self.codec.Decode(req.Params, &args); err != nil { return nil, shared.NewDecodeParamError(err.Error()) } diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index ad9a35fa2..70fb18289 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -226,6 +226,35 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) { return nil } +type NewDataArgs struct { + Data string +} + +func (args *NewDataArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + // Check for sufficient params + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + + data, ok := obj[0].(string) + if !ok { + return shared.NewInvalidTypeError("data", "not a string") + } + args.Data = data + + if len(args.Data) == 0 { + return shared.NewValidationError("data", "is required") + } + + return nil +} + type NewSigArgs struct { From string Data string diff --git a/rpc/args.go b/rpc/args.go index 65f0f6043..aa7d20549 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -154,6 +154,35 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) { return nil } +type NewDataArgs struct { + Data string +} + +func (args *NewDataArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + + if err := json.Unmarshal(b, &obj); err != nil { + return NewDecodeParamError(err.Error()) + } + + // Check for sufficient params + if len(obj) < 1 { + return NewInsufficientParamsError(len(obj), 1) + } + + data, ok := obj[0].(string) + if !ok { + return NewInvalidTypeError("data", "not a string") + } + args.Data = data + + if len(args.Data) == 0 { + return NewValidationError("data", "is required") + } + + return nil +} + type NewTxArgs struct { From string To string diff --git a/xeth/xeth.go b/xeth/xeth.go index d2f992084..c64ae71e3 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -787,6 +787,9 @@ func (self *XEth) FromNumber(str string) string { func (self *XEth) PushTx(encodedTx string) (string, error) { tx := types.NewTransactionFromBytes(common.FromHex(encodedTx)) + + glog.V(logger.Info).Infof("Tx(%x) gas: %x\n", tx.Hash(), tx.Gas()) + err := self.backend.TxPool().Add(tx) if err != nil { return "", err @@ -965,7 +968,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS return core.AddressFromMessage(tx).Hex(), nil } else { - glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To()) + glog.V(logger.Info).Infof("YEYEYE!! Tx(%x) to: %x\n, gas: %x", tx.Hash(), tx.To(), tx.Gas()) } return tx.Hash().Hex(), nil } From 6add45cd10a8f33e838a8922e694db7181c06fd9 Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Tue, 16 Jun 2015 12:30:07 -0400 Subject: [PATCH 09/10] Remove Extra Loggers --- xeth/xeth.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xeth/xeth.go b/xeth/xeth.go index c64ae71e3..d2f992084 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -787,9 +787,6 @@ func (self *XEth) FromNumber(str string) string { func (self *XEth) PushTx(encodedTx string) (string, error) { tx := types.NewTransactionFromBytes(common.FromHex(encodedTx)) - - glog.V(logger.Info).Infof("Tx(%x) gas: %x\n", tx.Hash(), tx.Gas()) - err := self.backend.TxPool().Add(tx) if err != nil { return "", err @@ -968,7 +965,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS return core.AddressFromMessage(tx).Hex(), nil } else { - glog.V(logger.Info).Infof("YEYEYE!! Tx(%x) to: %x\n, gas: %x", tx.Hash(), tx.To(), tx.Gas()) + glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To()) } return tx.Hash().Hex(), nil } From 1f34daccc33d7d4edd3fdf27efbc0c29445f2f1f Mon Sep 17 00:00:00 2001 From: SilentCicero Date: Tue, 16 Jun 2015 12:47:34 -0400 Subject: [PATCH 10/10] Added glog messages like Transaction --- xeth/xeth.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xeth/xeth.go b/xeth/xeth.go index d2f992084..f0ba91ba7 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -794,8 +794,12 @@ func (self *XEth) PushTx(encodedTx string) (string, error) { if tx.To() == nil { addr := core.AddressFromMessage(tx) + glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr) return addr.Hex(), nil + } else { + glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To()) } + return tx.Hash().Hex(), nil }