2020-09-19 03:46:03 +00:00
|
|
|
package multisig
|
|
|
|
|
|
|
|
import (
|
2020-09-23 22:36:56 +00:00
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-19 03:46:03 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-09-23 22:36:56 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
msig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
|
|
|
|
adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
2020-09-19 03:46:03 +00:00
|
|
|
)
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
var _ State = (*state2)(nil)
|
2020-09-19 03:46:03 +00:00
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func load2(store adt.Store, root cid.Cid) (State, error) {
|
|
|
|
out := state2{store: store}
|
2020-09-24 00:40:29 +00:00
|
|
|
err := store.Get(store.Context(), root, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
type state2 struct {
|
|
|
|
msig2.State
|
2020-09-19 03:46:03 +00:00
|
|
|
store adt.Store
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
2020-09-19 03:46:03 +00:00
|
|
|
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) StartEpoch() (abi.ChainEpoch, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
return s.State.StartEpoch, nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) UnlockDuration() (abi.ChainEpoch, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
return s.State.UnlockDuration, nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) InitialBalance() (abi.TokenAmount, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
return s.State.InitialBalance, nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) Threshold() (uint64, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
return s.State.NumApprovalsThreshold, nil
|
2020-09-19 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) Signers() ([]address.Address, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
return s.State.Signers, nil
|
2020-09-19 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
func (s *state2) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
|
|
|
arr, err := adt2.AsMap(s.store, s.State.PendingTxns)
|
2020-09-23 22:36:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-28 20:13:18 +00:00
|
|
|
var out msig2.Transaction
|
2020-09-23 22:36:56 +00:00
|
|
|
return arr.ForEach(&out, func(key string) error {
|
|
|
|
txid, n := binary.Varint([]byte(key))
|
|
|
|
if n <= 0 {
|
|
|
|
return xerrors.Errorf("invalid pending transaction key: %v", key)
|
|
|
|
}
|
|
|
|
return cb(txid, (Transaction)(out))
|
|
|
|
})
|
2020-09-19 03:46:03 +00:00
|
|
|
}
|