/
datacap_state.go
40 lines (34 loc) · 1.04 KB
/
datacap_state.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
package datacap
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v12/util/adt"
)
type State struct {
Governor address.Address
Token TokenState
}
type TokenState struct {
Supply abi.TokenAmount
Balances cid.Cid // HAMT abi.ActorID[abi.TokenAmount]
Allowances cid.Cid // HAMT abi.ActorID[abi.ActorID[abi.TokenAmount]]
HamtBitWidth uint64 // uint32 in builtin-actors. uint64 here to satisfy cbor-gen
}
func ConstructState(store adt.Store, governor address.Address, bitWidth uint64) (*State, error) {
emptyMapCid, err := adt.StoreEmptyMap(store, int(bitWidth))
if err != nil {
return nil, xerrors.Errorf("failed to create empty map: %w", err)
}
return &State{
Governor: governor,
Token: TokenState{
Supply: big.Zero(),
Balances: emptyMapCid,
Allowances: emptyMapCid,
HamtBitWidth: bitWidth,
},
}, nil
}