-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_json.go
53 lines (45 loc) · 1.3 KB
/
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
package types
import (
"encoding/json"
"github.com/ProtoconNet/mitum2/base"
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/encoder"
"github.com/ProtoconNet/mitum2/util/hint"
"github.com/ProtoconNet/mitum2/util/valuehash"
)
type AccountJSONMarshaler struct {
hint.BaseHinter
Hash util.Hash `json:"hash"`
Address base.Address `json:"address"`
Keys AccountKeys `json:"keys"`
}
func (ac Account) EncodeJSON() AccountJSONMarshaler {
return AccountJSONMarshaler{
BaseHinter: ac.BaseHinter,
Hash: ac.h,
Address: ac.address,
Keys: ac.keys,
}
}
func (ac Account) MarshalJSON() ([]byte, error) {
return util.MarshalJSON(AccountJSONMarshaler{
BaseHinter: ac.BaseHinter,
Hash: ac.h,
Address: ac.address,
Keys: ac.keys,
})
}
type AccountJSONUnmarshaler struct {
Hint hint.Hint `json:"_hint"`
Hash valuehash.HashDecoder `json:"hash"`
Address string `json:"address"`
Keys json.RawMessage `json:"keys"`
}
func (ac *Account) DecodeJSON(b []byte, enc encoder.Encoder) error {
e := util.StringError("Decode json of Account")
var uac AccountJSONUnmarshaler
if err := enc.Unmarshal(b, &uac); err != nil {
return e.Wrap(err)
}
return ac.unpack(enc, uac.Hint, uac.Hash, uac.Address, uac.Keys)
}