-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_currency_json.go
63 lines (50 loc) · 1.73 KB
/
update_currency_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
package currency
import (
"encoding/json"
"github.com/ProtoconNet/mitum-currency/v3/common"
"github.com/ProtoconNet/mitum-currency/v3/types"
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/encoder"
)
type UpdateCurrencyFactJSONMarshaler struct {
base.BaseFactJSONMarshaler
Currency types.CurrencyID `json:"currency"`
Policy types.CurrencyPolicy `json:"policy"`
}
func (fact UpdateCurrencyFact) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(UpdateCurrencyFactJSONMarshaler{
BaseFactJSONMarshaler: fact.BaseFact.JSONMarshaler(),
Currency: fact.currency,
Policy: fact.policy,
})
}
type UpdateCurrencyFactJSONUnMarshaler struct {
base.BaseFactJSONUnmarshaler
Currency string `json:"currency"`
Policy json.RawMessage `json:"policy"`
}
func (fact *UpdateCurrencyFact) DecodeJSON(b []byte, enc encoder.Encoder) error {
var uf UpdateCurrencyFactJSONUnMarshaler
if err := enc.Unmarshal(b, &uf); err != nil {
return common.DecorateError(err, common.ErrDecodeJson, *fact)
}
fact.BaseFact.SetJSONUnmarshaler(uf.BaseFactJSONUnmarshaler)
if err := fact.unpack(enc, uf.Currency, uf.Policy); err != nil {
return common.DecorateError(err, common.ErrDecodeJson, *fact)
}
return nil
}
func (op UpdateCurrency) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(BaseOperationMarshaler{
BaseOperationJSONMarshaler: op.BaseOperation.JSONMarshaler(),
})
}
func (op *UpdateCurrency) DecodeJSON(b []byte, enc encoder.Encoder) error {
var ubo common.BaseNodeOperation
if err := ubo.DecodeJSON(b, enc); err != nil {
return common.DecorateError(err, common.ErrDecodeJson, *op)
}
op.BaseNodeOperation = ubo
return nil
}