-
Notifications
You must be signed in to change notification settings - Fork 1
/
state.go
118 lines (101 loc) · 2.82 KB
/
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"bytes"
"context"
"fmt"
"sync"
"sync/atomic"
filaddr "github.com/filecoin-project/go-address"
filabi "github.com/filecoin-project/go-state-types/abi"
filbig "github.com/filecoin-project/go-state-types/big"
filstore "github.com/filecoin-project/go-state-types/store"
lbi "github.com/filecoin-project/lotus/chain/actors/builtin"
lbimsig "github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
lchstate "github.com/filecoin-project/lotus/chain/state"
lchtypes "github.com/filecoin-project/lotus/chain/types"
ipldcbor "github.com/ipfs/go-ipld-cbor"
)
func getCoins(ctx context.Context, bg *blockGetter, ts *lchtypes.TipSet, addr filaddr.Address) error {
cbs := ipldcbor.NewCborStore(bg)
var mx sync.Mutex
foundAttoFil := filabi.NewTokenAmount(0)
actorAddrID, err := lookupID(cbs, ts, addr)
if err != nil {
return err
}
ast := filstore.WrapStore(ctx, cbs)
if err := iterateActors(ctx, cbs, ts, func(actorID filaddr.Address, act lchtypes.Actor) error {
if ctx.Err() != nil {
return ctx.Err()
}
switch {
case lbi.IsMultisigActor(act.Code):
ms, err := lbimsig.Load(ast, &act)
if err != nil {
return err
}
tr, _ := ms.Threshold()
actors, err := ms.Signers()
if err != nil {
return err
}
foundActor := false
for _, a := range actors {
if bytes.Equal(a.Bytes(), actorAddrID.Bytes()) {
foundActor = true
break
}
}
if foundActor && tr == 1 {
// msig balance needs calculating for epoch in question
lb, err := ms.LockedBalance(ts.Height())
if err != nil {
return err
}
bal := filbig.Sub(act.Balance, lb)
mx.Lock()
foundAttoFil.Add(foundAttoFil.Int, bal.Int)
mx.Unlock()
fmt.Printf("found msig %v\n", actorID)
} else if foundActor {
fmt.Printf("found msig %v: more than just you is needed to claim the coins\n", actorID)
}
return err
default:
return nil
}
}); err != nil {
return err
}
fmt.Printf("total attofil: %s\n", foundAttoFil)
return nil
}
func getActors(ctx context.Context, bg *blockGetter, ts *lchtypes.TipSet, countOnly bool) error {
var numActors uint64
if err := iterateActors(ctx, ipldcbor.NewCborStore(bg), ts, func(actorID filaddr.Address, act lchtypes.Actor) error {
if ctx.Err() != nil {
return ctx.Err()
}
atomic.AddUint64(&numActors, 1)
if !countOnly {
fmt.Printf("%v\n", actorID)
}
return nil
}); err != nil {
return err
}
fmt.Printf("total actors found: %d\n", numActors)
return nil
}
func getBalance(_ context.Context, bg *blockGetter, ts *lchtypes.TipSet, addr filaddr.Address) error {
stateTree, err := lchstate.LoadStateTree(ipldcbor.NewCborStore(bg), ts.ParentState())
if err != nil {
return err
}
act, err := stateTree.GetActor(addr)
if err != nil {
return err
}
fmt.Printf("total actor balance: %s\n", act.Balance)
return nil
}