/
feeer_json.go
95 lines (77 loc) · 2.27 KB
/
feeer_json.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package types
import (
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/encoder"
"github.com/ProtoconNet/mitum2/util/hint"
)
func (fa NilFeeer) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(hint.BaseHinter{
HT: fa.Hint(),
})
}
func (fa *NilFeeer) UnmarsahlJSON(b []byte) error {
e := util.StringError("unmarshal json of NilFeeer")
var ht hint.BaseHinter
if err := util.UnmarshalJSON(b, &ht); err != nil {
return e.Wrap(err)
}
fa.BaseHinter = ht
return nil
}
type FixedFeeerJSONMarshaler struct {
hint.BaseHinter
Receiver base.Address `json:"receiver"`
Amount string `json:"amount"`
}
func (fa FixedFeeer) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(FixedFeeerJSONMarshaler{
BaseHinter: fa.BaseHinter,
Receiver: fa.receiver,
Amount: fa.amount.String(),
})
}
type FixedFeeerJSONUnmarshaler struct {
Hint hint.Hint `json:"_hint"`
Receiver string `json:"receiver"`
Amount string `json:"amount"`
}
func (fa *FixedFeeer) DecodeJSON(b []byte, enc encoder.Encoder) error {
e := util.StringError("decode json of FixedFeeer")
var ufa FixedFeeerJSONUnmarshaler
if err := enc.Unmarshal(b, &ufa); err != nil {
return e.Wrap(err)
}
return fa.unpack(enc, ufa.Hint, ufa.Receiver, ufa.Amount)
}
type RatioFeeerJSONMarshaler struct {
hint.BaseHinter
Receiver base.Address `json:"receiver"`
Ratio float64 `json:"ratio"`
Min string `json:"min"`
Max string `json:"max"`
}
func (fa RatioFeeer) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(RatioFeeerJSONMarshaler{
BaseHinter: fa.BaseHinter,
Receiver: fa.receiver,
Ratio: fa.ratio,
Min: fa.min.String(),
Max: fa.max.String(),
})
}
type RatioFeeerJSONUnmarshaler struct {
Hint hint.Hint `json:"_hint"`
Receiver string `json:"receiver"`
Ratio float64 `json:"ratio"`
Min string `json:"min"`
Max string `json:"max"`
}
func (fa *RatioFeeer) DecodeJSON(b []byte, enc encoder.Encoder) error {
e := util.StringError("decode json of RatioFeeer")
var ufa RatioFeeerJSONUnmarshaler
if err := enc.Unmarshal(b, &ufa); err != nil {
return e.Wrap(err)
}
return fa.unpack(enc, ufa.Hint, ufa.Receiver, ufa.Ratio, ufa.Min, ufa.Max)
}