-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_account_json.go
65 lines (52 loc) · 1.71 KB
/
create_account_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
package currency
import (
"encoding/json"
"github.com/ProtoconNet/mitum-currency/v3/common"
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/encoder"
)
type CreateAccountFactJSONMarshaler struct {
base.BaseFactJSONMarshaler
Sender base.Address `json:"sender"`
Items []CreateAccountItem `json:"items"`
}
func (fact CreateAccountFact) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(CreateAccountFactJSONMarshaler{
BaseFactJSONMarshaler: fact.BaseFact.JSONMarshaler(),
Sender: fact.sender,
Items: fact.items,
})
}
type CreateAccountFactJSONUnMarshaler struct {
base.BaseFactJSONUnmarshaler
Sender string `json:"sender"`
Items json.RawMessage `json:"items"`
}
func (fact *CreateAccountFact) DecodeJSON(b []byte, enc encoder.Encoder) error {
var uf CreateAccountFactJSONUnMarshaler
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.Sender, uf.Items); err != nil {
return common.DecorateError(err, common.ErrDecodeJson, *fact)
}
return nil
}
type BaseOperationMarshaler struct {
common.BaseOperationJSONMarshaler
}
func (op CreateAccount) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(BaseOperationMarshaler{
BaseOperationJSONMarshaler: op.BaseOperation.JSONMarshaler(),
})
}
func (op *CreateAccount) DecodeJSON(b []byte, enc encoder.Encoder) error {
var ubo common.BaseOperation
if err := ubo.DecodeJSON(b, enc); err != nil {
return common.DecorateError(err, common.ErrDecodeJson, *op)
}
op.BaseOperation = ubo
return nil
}