From 056e9dd393eeb7ddb4f6bf3e508228e1874bc94e Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 24 Jun 2015 13:53:37 +0200 Subject: added eth.pendingTransactions --- rpc/api/eth_args.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index bf8ffead6..39c003f66 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -5,8 +5,11 @@ import ( "fmt" "math/big" + "strconv" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc/shared" ) @@ -858,3 +861,34 @@ func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) { return nil } + +type tx struct { + tx *types.Transaction + + To string + From string + Nonce string + Value string + Data string + GasLimit string + GasPrice string +} + +func newTx(t *types.Transaction) *tx { + from, _ := t.From() + var to string + if t := t.To(); t != nil { + to = t.Hex() + } + + return &tx{ + tx: t, + To: to, + From: from.Hex(), + Value: t.Amount.String(), + Nonce: strconv.Itoa(int(t.Nonce())), + Data: "0x" + common.Bytes2Hex(t.Data()), + GasLimit: t.GasLimit.String(), + GasPrice: t.GasPrice().String(), + } +} -- cgit v1.2.3 From ec866b066ace5d80c3c6a69349dbb1fac4503b46 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 24 Jun 2015 14:56:53 +0200 Subject: added eth.resend --- rpc/api/eth_args.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 39c003f66..a75fdbdee 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -892,3 +892,53 @@ func newTx(t *types.Transaction) *tx { GasPrice: t.GasPrice().String(), } } + +type ResendArgs struct { + Tx *tx + GasPrice string + GasLimit string +} + +func (args *ResendArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err = json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + + data, err := json.Marshal(obj[0]) + if err != nil { + return shared.NewDecodeParamError("Unable to parse transaction object") + } + + trans := new(tx) + err = json.Unmarshal(data, trans) + if err != nil { + return shared.NewDecodeParamError("Unable to parse transaction object.") + } + + gasLimit, gasPrice := trans.GasLimit, trans.GasPrice + + if len(obj) > 1 && obj[1] != nil { + if gp, ok := obj[1].(string); ok { + gasPrice = gp + } else { + return shared.NewInvalidTypeError("gasPrice", "not a string") + } + } + if len(obj) > 2 && obj[2] != nil { + if gl, ok := obj[2].(string); ok { + gasLimit = gl + } else { + return shared.NewInvalidTypeError("gasLimit", "not a string") + } + } + args.Tx = trans + args.GasPrice = gasPrice + args.GasLimit = gasLimit + + return nil +} -- cgit v1.2.3 From 6fdddc5ac940b6241596e0a2622461148e8a57a0 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 29 Jun 2015 11:13:28 +0200 Subject: improved error handling in parsing request --- rpc/api/eth_args.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index a75fdbdee..88fc00a6c 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -917,7 +917,11 @@ func (args *ResendArgs) UnmarshalJSON(b []byte) (err error) { trans := new(tx) err = json.Unmarshal(data, trans) if err != nil { - return shared.NewDecodeParamError("Unable to parse transaction object.") + return shared.NewDecodeParamError("Unable to parse transaction object") + } + + if trans == nil || trans.tx == nil { + return shared.NewDecodeParamError("Unable to parse transaction object") } gasLimit, gasPrice := trans.GasLimit, trans.GasPrice @@ -936,6 +940,7 @@ func (args *ResendArgs) UnmarshalJSON(b []byte) (err error) { return shared.NewInvalidTypeError("gasLimit", "not a string") } } + args.Tx = trans args.GasPrice = gasPrice args.GasLimit = gasLimit -- cgit v1.2.3 From 7ffabf1d399989618470794600e25764bdd9954b Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 29 Jun 2015 12:32:01 +0200 Subject: add json parsing method for resend transaction --- rpc/api/eth_args.go | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 88fc00a6c..203171d58 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" "math/big" - "strconv" + "strings" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -899,6 +899,81 @@ type ResendArgs struct { GasLimit string } +func (tx *tx) UnmarshalJSON(b []byte) (err error) { + var fields map[string]interface{} + if err := json.Unmarshal(b, &fields); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + trans := new(types.Transaction) + + if val, found := fields["To"]; found { + if strVal, ok := val.(string); ok && len(strVal) > 0 { + tx.To = strVal + to := common.StringToAddress(strVal) + trans.Recipient = &to + } + } + + if val, found := fields["From"]; found { + if strVal, ok := val.(string); ok { + tx.From = strVal + } + } + + if val, found := fields["Nonce"]; found { + if strVal, ok := val.(string); ok { + tx.Nonce = strVal + if trans.AccountNonce, err = strconv.ParseUint(strVal, 10, 64); err != nil { + return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err)) + } + } + } + + var parseOk bool + if val, found := fields["Value"]; found { + if strVal, ok := val.(string); ok { + tx.Value = strVal + if trans.Amount, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err)) + } + } + } + + if val, found := fields["Data"]; found { + if strVal, ok := val.(string); ok { + tx.Data = strVal + if strings.HasPrefix(strVal, "0x") { + trans.Payload = common.Hex2Bytes(strVal[2:]) + } else { + trans.Payload = common.Hex2Bytes(strVal) + } + } + } + + if val, found := fields["GasLimit"]; found { + if strVal, ok := val.(string); ok { + tx.GasLimit = strVal + if trans.GasLimit, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err)) + } + } + } + + if val, found := fields["GasPrice"]; found { + if strVal, ok := val.(string); ok { + tx.GasPrice = strVal + if trans.Price, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err)) + } + } + } + + tx.tx = trans + + return nil +} + func (args *ResendArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err = json.Unmarshal(b, &obj); err != nil { -- cgit v1.2.3 From 57dff6f1d7e8402d2849205cb44daaffcc40cc23 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 29 Jun 2015 12:42:47 +0200 Subject: initialize fields to prevent nil pointer exception --- rpc/api/eth_args.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 203171d58..b5507832d 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -906,6 +906,9 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { } trans := new(types.Transaction) + trans.Amount = new(big.Int) + trans.GasLimit = new(big.Int) + trans.Price = new(big.Int) if val, found := fields["To"]; found { if strVal, ok := val.(string); ok && len(strVal) > 0 { @@ -928,13 +931,15 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err)) } } + } else { + return shared.NewDecodeParamError("tx.Nonce not found") } var parseOk bool if val, found := fields["Value"]; found { if strVal, ok := val.(string); ok { tx.Value = strVal - if trans.Amount, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.Amount.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err)) } } @@ -954,7 +959,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasLimit"]; found { if strVal, ok := val.(string); ok { tx.GasLimit = strVal - if trans.GasLimit, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.GasLimit.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err)) } } @@ -963,7 +968,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasPrice"]; found { if strVal, ok := val.(string); ok { tx.GasPrice = strVal - if trans.Price, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { + if _, parseOk = trans.Price.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err)) } } -- cgit v1.2.3 From a5d5387dee984b0d3712379998c200d2c6fe89e5 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Tue, 30 Jun 2015 15:27:27 +0200 Subject: rebase with develop --- rpc/api/eth_args.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index b5507832d..8f64280d3 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -885,10 +885,10 @@ func newTx(t *types.Transaction) *tx { tx: t, To: to, From: from.Hex(), - Value: t.Amount.String(), + Value: t.Value().String(), Nonce: strconv.Itoa(int(t.Nonce())), Data: "0x" + common.Bytes2Hex(t.Data()), - GasLimit: t.GasLimit.String(), + GasLimit: t.Gas().String(), GasPrice: t.GasPrice().String(), } } @@ -905,16 +905,21 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { return shared.NewDecodeParamError(err.Error()) } - trans := new(types.Transaction) - trans.Amount = new(big.Int) - trans.GasLimit = new(big.Int) - trans.Price = new(big.Int) + var ( + nonce uint64 + to common.Address + amount = new(big.Int).Set(common.Big0) + gasLimit = new(big.Int).Set(common.Big0) + gasPrice = new(big.Int).Set(common.Big0) + data []byte + contractCreation = true + ) if val, found := fields["To"]; found { if strVal, ok := val.(string); ok && len(strVal) > 0 { tx.To = strVal - to := common.StringToAddress(strVal) - trans.Recipient = &to + to = common.HexToAddress(strVal) + contractCreation = false } } @@ -927,7 +932,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["Nonce"]; found { if strVal, ok := val.(string); ok { tx.Nonce = strVal - if trans.AccountNonce, err = strconv.ParseUint(strVal, 10, 64); err != nil { + if nonce, err = strconv.ParseUint(strVal, 10, 64); err != nil { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err)) } } @@ -939,7 +944,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["Value"]; found { if strVal, ok := val.(string); ok { tx.Value = strVal - if _, parseOk = trans.Amount.SetString(strVal, 0); !parseOk { + if _, parseOk = amount.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err)) } } @@ -949,9 +954,9 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if strVal, ok := val.(string); ok { tx.Data = strVal if strings.HasPrefix(strVal, "0x") { - trans.Payload = common.Hex2Bytes(strVal[2:]) + data = common.Hex2Bytes(strVal[2:]) } else { - trans.Payload = common.Hex2Bytes(strVal) + data = common.Hex2Bytes(strVal) } } } @@ -959,7 +964,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasLimit"]; found { if strVal, ok := val.(string); ok { tx.GasLimit = strVal - if _, parseOk = trans.GasLimit.SetString(strVal, 0); !parseOk { + if _, parseOk = gasLimit.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err)) } } @@ -968,13 +973,17 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { if val, found := fields["GasPrice"]; found { if strVal, ok := val.(string); ok { tx.GasPrice = strVal - if _, parseOk = trans.Price.SetString(strVal, 0); !parseOk { + if _, parseOk = gasPrice.SetString(strVal, 0); !parseOk { return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err)) } } } - tx.tx = trans + if contractCreation { + tx.tx = types.NewContractCreation(nonce, amount, gasLimit, gasPrice, data) + } else { + tx.tx = types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data) + } return nil } -- cgit v1.2.3 From ea54283b304a1d308141d21e3ef75b7de0f4519d Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 Jul 2015 02:54:22 +0200 Subject: all: update license information --- rpc/api/eth_args.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'rpc/api/eth_args.go') diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 8f64280d3..f63b43334 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.go @@ -1,3 +1,19 @@ +// Copyright 2015 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with go-ethereum. If not, see . + package api import ( -- cgit v1.2.3