add function to check entire state tree balance
This commit is contained in:
parent
4308d37c84
commit
b3a31d8823
@ -336,3 +336,15 @@ func (st *StateTree) MutateActor(addr address.Address, f func(*types.Actor) erro
|
|||||||
|
|
||||||
return st.SetActor(addr, act)
|
return st.SetActor(addr, act)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error {
|
||||||
|
var act types.Actor
|
||||||
|
return st.root.ForEach(&act, func(k string) error {
|
||||||
|
addr, err := address.NewFromBytes([]byte(k))
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("invalid address (%x) found in state tree key: %w", []byte(k), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f(addr, &act)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -658,3 +658,21 @@ func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Addres
|
|||||||
|
|
||||||
return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr)
|
return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) {
|
||||||
|
str, err := state.LoadStateTree(sm.ChainStore().Store(ctx), ts.ParentState())
|
||||||
|
if err != nil {
|
||||||
|
return abi.TokenAmount{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sum := types.NewInt(0)
|
||||||
|
err = str.ForEach(func(a address.Address, act *types.Actor) error {
|
||||||
|
sum = types.BigAdd(sum, act.Balance)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return abi.TokenAmount{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user