aboutsummaryrefslogtreecommitdiffstats
path: root/tests/gen_sttransaction.go
blob: e3f2e304cc355fb21d4e06c11c46c1f0157b6d72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.

package tests

import (
    "encoding/json"
    "math/big"

    "github.com/dexon-foundation/dexon/common/hexutil"
    "github.com/dexon-foundation/dexon/common/math"
)

var _ = (*stTransactionMarshaling)(nil)

func (s stTransaction) MarshalJSON() ([]byte, error) {
    type stTransaction struct {
        GasPrice   *math.HexOrDecimal256 `json:"gasPrice"`
        Nonce      math.HexOrDecimal64   `json:"nonce"`
        To         string                `json:"to"`
        Data       []string              `json:"data"`
        GasLimit   []math.HexOrDecimal64 `json:"gasLimit"`
        Value      []string              `json:"value"`
        PrivateKey hexutil.Bytes         `json:"secretKey"`
    }
    var enc stTransaction
    enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
    enc.Nonce = math.HexOrDecimal64(s.Nonce)
    enc.To = s.To
    enc.Data = s.Data
    if s.GasLimit != nil {
        enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
        for k, v := range s.GasLimit {
            enc.GasLimit[k] = math.HexOrDecimal64(v)
        }
    }
    enc.Value = s.Value
    enc.PrivateKey = s.PrivateKey
    return json.Marshal(&enc)
}

func (s *stTransaction) UnmarshalJSON(input []byte) error {
    type stTransaction struct {
        GasPrice   *math.HexOrDecimal256 `json:"gasPrice"`
        Nonce      *math.HexOrDecimal64  `json:"nonce"`
        To         *string               `json:"to"`
        Data       []string              `json:"data"`
        GasLimit   []math.HexOrDecimal64 `json:"gasLimit"`
        Value      []string              `json:"value"`
        PrivateKey *hexutil.Bytes        `json:"secretKey"`
    }
    var dec stTransaction
    if err := json.Unmarshal(input, &dec); err != nil {
        return err
    }
    if dec.GasPrice != nil {
        s.GasPrice = (*big.Int)(dec.GasPrice)
    }
    if dec.Nonce != nil {
        s.Nonce = uint64(*dec.Nonce)
    }
    if dec.To != nil {
        s.To = *dec.To
    }
    if dec.Data != nil {
        s.Data = dec.Data
    }
    if dec.GasLimit != nil {
        s.GasLimit = make([]uint64, len(dec.GasLimit))
        for k, v := range dec.GasLimit {
            s.GasLimit[k] = uint64(v)
        }
    }
    if dec.Value != nil {
        s.Value = dec.Value
    }
    if dec.PrivateKey != nil {
        s.PrivateKey = *dec.PrivateKey
    }
    return nil
}