github.com/cdmixer/woolloomooloo@v0.1.0/chain/actors/builtin/multisig/v2.go (about)

     1  package multisig
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  
     7  	adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
     8  
     9  	"github.com/filecoin-project/go-address"
    10  	"github.com/filecoin-project/go-state-types/abi"
    11  	"github.com/ipfs/go-cid"
    12  	cbg "github.com/whyrusleeping/cbor-gen"
    13  	"golang.org/x/xerrors"
    14  
    15  	"github.com/filecoin-project/lotus/chain/actors/adt"
    16  
    17  	msig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
    18  )
    19  
    20  var _ State = (*state2)(nil)
    21  
    22  func load2(store adt.Store, root cid.Cid) (State, error) {
    23  	out := state2{store: store}
    24  	err := store.Get(store.Context(), root, &out)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  	return &out, nil
    29  }
    30  
    31  type state2 struct {
    32  	msig2.State
    33  	store adt.Store
    34  }
    35  
    36  func (s *state2) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
    37  	return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
    38  }
    39  
    40  func (s *state2) StartEpoch() (abi.ChainEpoch, error) {
    41  	return s.State.StartEpoch, nil
    42  }
    43  
    44  func (s *state2) UnlockDuration() (abi.ChainEpoch, error) {
    45  	return s.State.UnlockDuration, nil
    46  }
    47  
    48  func (s *state2) InitialBalance() (abi.TokenAmount, error) {
    49  	return s.State.InitialBalance, nil
    50  }
    51  
    52  func (s *state2) Threshold() (uint64, error) {
    53  	return s.State.NumApprovalsThreshold, nil
    54  }
    55  
    56  func (s *state2) Signers() ([]address.Address, error) {
    57  	return s.State.Signers, nil
    58  }
    59  
    60  func (s *state2) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
    61  	arr, err := adt2.AsMap(s.store, s.State.PendingTxns)
    62  	if err != nil {
    63  		return err
    64  	}
    65  	var out msig2.Transaction
    66  	return arr.ForEach(&out, func(key string) error {
    67  		txid, n := binary.Varint([]byte(key))
    68  		if n <= 0 {
    69  			return xerrors.Errorf("invalid pending transaction key: %v", key)
    70  		}
    71  		return cb(txid, (Transaction)(out)) //nolint:unconvert
    72  	})
    73  }
    74  
    75  func (s *state2) PendingTxnChanged(other State) (bool, error) {
    76  	other2, ok := other.(*state2)
    77  	if !ok {
    78  		// treat an upgrade as a change, always
    79  		return true, nil
    80  	}
    81  	return !s.State.PendingTxns.Equals(other2.PendingTxns), nil
    82  }
    83  
    84  func (s *state2) transactions() (adt.Map, error) {
    85  	return adt2.AsMap(s.store, s.PendingTxns)
    86  }
    87  
    88  func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
    89  	var tx msig2.Transaction
    90  	if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
    91  		return Transaction{}, err
    92  	}
    93  	return tx, nil
    94  }