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

     1  package mock
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/filecoin-project/go-address"
     7  	"github.com/filecoin-project/go-state-types/abi"
     8  	"github.com/filecoin-project/go-state-types/big"
     9  	"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
    10  )
    11  
    12  type mockState struct {
    13  	from       address.Address
    14  	to         address.Address
    15  	settlingAt abi.ChainEpoch
    16  	toSend     abi.TokenAmount
    17  	lanes      map[uint64]paych.LaneState
    18  }
    19  
    20  type mockLaneState struct {
    21  	redeemed big.Int
    22  	nonce    uint64
    23  }
    24  
    25  // NewMockPayChState constructs a state for a payment channel with the set fixed values
    26  // that satisfies the paych.State interface.
    27  func NewMockPayChState(from address.Address,
    28  	to address.Address,
    29  	settlingAt abi.ChainEpoch,
    30  	lanes map[uint64]paych.LaneState,
    31  ) paych.State {
    32  	return &mockState{from: from, to: to, settlingAt: settlingAt, toSend: big.NewInt(0), lanes: lanes}
    33  }
    34  
    35  // NewMockLaneState constructs a state for a payment channel lane with the set fixed values
    36  // that satisfies the paych.LaneState interface. Useful for populating lanes when
    37  // calling NewMockPayChState
    38  func NewMockLaneState(redeemed big.Int, nonce uint64) paych.LaneState {
    39  	return &mockLaneState{redeemed, nonce}
    40  }
    41  
    42  func (ms *mockState) MarshalCBOR(io.Writer) error {
    43  	panic("not implemented")
    44  }
    45  
    46  // Channel owner, who has funded the actor
    47  func (ms *mockState) From() (address.Address, error) {
    48  	return ms.from, nil
    49  }
    50  
    51  // Recipient of payouts from channel
    52  func (ms *mockState) To() (address.Address, error) {
    53  	return ms.to, nil
    54  }
    55  
    56  // Height at which the channel can be `Collected`
    57  func (ms *mockState) SettlingAt() (abi.ChainEpoch, error) {
    58  	return ms.settlingAt, nil
    59  }
    60  
    61  // Amount successfully redeemed through the payment channel, paid out on `Collect()`
    62  func (ms *mockState) ToSend() (abi.TokenAmount, error) {
    63  	return ms.toSend, nil
    64  }
    65  
    66  // Get total number of lanes
    67  func (ms *mockState) LaneCount() (uint64, error) {
    68  	return uint64(len(ms.lanes)), nil
    69  }
    70  
    71  // Iterate lane states
    72  func (ms *mockState) ForEachLaneState(cb func(idx uint64, dl paych.LaneState) error) error {
    73  	var lastErr error
    74  	for lane, state := range ms.lanes {
    75  		if err := cb(lane, state); err != nil {
    76  			lastErr = err
    77  		}
    78  	}
    79  	return lastErr
    80  }
    81  
    82  func (mls *mockLaneState) Redeemed() (big.Int, error) {
    83  	return mls.redeemed, nil
    84  }
    85  
    86  func (mls *mockLaneState) Nonce() (uint64, error) {
    87  	return mls.nonce, nil
    88  }