-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
95 lines (79 loc) · 2.44 KB
/
types.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package market
import (
"github.com/chenjianmei111/go-state-types/abi"
. "github.com/chenjianmei111/specs-actors/v2/actors/util/adt"
"github.com/ipfs/go-cid"
)
// A specialization of a array to deals.
// It is an error to query for a key that doesn't exist.
type DealArray struct {
*Array
}
// Interprets a store as balance table with root `r`.
func AsDealProposalArray(s Store, r cid.Cid) (*DealArray, error) {
a, err := AsArray(s, r)
if err != nil {
return nil, err
}
return &DealArray{a}, nil
}
// Returns the root cid of underlying AMT.
func (t *DealArray) Root() (cid.Cid, error) {
return t.Array.Root()
}
// Gets the deal for a key. The entry must have been previously initialized.
func (t *DealArray) Get(id abi.DealID) (*DealProposal, bool, error) {
var value DealProposal
found, err := t.Array.Get(uint64(id), &value)
return &value, found, err
}
func (t *DealArray) Set(k abi.DealID, value *DealProposal) error {
return t.Array.Set(uint64(k), value)
}
func (t *DealArray) Delete(key uint64) error {
return t.Array.Delete(key)
}
// A specialization of a array to deals.
// It is an error to query for a key that doesn't exist.
type DealMetaArray struct {
*Array
}
type DealState struct {
SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector
LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated
SlashEpoch abi.ChainEpoch // -1 if deal never slashed
}
// Interprets a store as balance table with root `r`.
func AsDealStateArray(s Store, r cid.Cid) (*DealMetaArray, error) {
dsa, err := AsArray(s, r)
if err != nil {
return nil, err
}
return &DealMetaArray{dsa}, nil
}
// Returns the root cid of underlying AMT.
func (t *DealMetaArray) Root() (cid.Cid, error) {
return t.Array.Root()
}
// Gets the deal for a key. The entry must have been previously initialized.
func (t *DealMetaArray) Get(id abi.DealID) (*DealState, bool, error) {
var value DealState
found, err := t.Array.Get(uint64(id), &value)
if err != nil {
return nil, false, err // The errors from Map carry good information, no need to wrap here.
}
if !found {
return &DealState{
SectorStartEpoch: epochUndefined,
LastUpdatedEpoch: epochUndefined,
SlashEpoch: epochUndefined,
}, false, nil
}
return &value, true, nil
}
func (t *DealMetaArray) Set(k abi.DealID, value *DealState) error {
return t.Array.Set(uint64(k), value)
}
func (t *DealMetaArray) Delete(id abi.DealID) error {
return t.Array.Delete(uint64(id))
}