aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-06-29 18:32:01 +0800
committerBas van Kervel <bas@ethdev.com>2015-06-29 18:32:01 +0800
commitf9264e87ec4c612f647a05ea11d5640709577a7f (patch)
tree4b2549ec6004d5735a795d80727d50d7be5368c5 /rpc/api
parenta355777ff8531ba91fbdfb093532e7314c15710b (diff)
downloadgo-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar.gz
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar.bz2
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar.lz
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar.xz
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.tar.zst
go-tangerine-f9264e87ec4c612f647a05ea11d5640709577a7f.zip
add json parsing method for resend transaction
Diffstat (limited to 'rpc/api')
-rw-r--r--rpc/api/eth.go1
-rw-r--r--rpc/api/eth_args.go77
2 files changed, 76 insertions, 2 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go
index 0735754b5..6c071569c 100644
--- a/rpc/api/eth.go
+++ b/rpc/api/eth.go
@@ -12,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/fatih/set.v0"
- "fmt"
)
const (
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 {