-
Notifications
You must be signed in to change notification settings - Fork 29
/
tokenpool.go
47 lines (39 loc) · 1.06 KB
/
tokenpool.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
package magmasc
import (
"encoding/json"
"github.com/0chain/gosdk/core/util"
)
type (
// TokenPool represents token pool implementation.
TokenPool struct {
ID string `json:"id"`
Balance int64 `json:"balance"`
HolderID string `json:"holder_id"`
PayerID string `json:"payer_id"`
PayeeID string `json:"payee_id"`
Transfers []TokenPoolTransfer `json:"transfers,omitempty"`
}
)
var (
// Make sure tokenPool implements Serializable interface.
_ util.Serializable = (*TokenPool)(nil)
)
// Decode implements util.Serializable interface.
func (m *TokenPool) Decode(blob []byte) error {
var pool TokenPool
if err := json.Unmarshal(blob, &pool); err != nil {
return errDecodeData.Wrap(err)
}
m.ID = pool.ID
m.Balance = pool.Balance
m.HolderID = pool.HolderID
m.PayerID = pool.PayerID
m.PayeeID = pool.PayeeID
m.Transfers = pool.Transfers
return nil
}
// Encode implements util.Serializable interface.
func (m *TokenPool) Encode() []byte {
blob, _ := json.Marshal(m)
return blob
}