2020-09-16 04:06:04 +00:00
|
|
|
package paych
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
big "github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
2020-09-18 21:59:27 +00:00
|
|
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
2020-09-16 04:06:04 +00:00
|
|
|
)
|
|
|
|
|
2020-09-21 06:19:32 +00:00
|
|
|
var _ State = (*state0)(nil)
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type state0 struct {
|
2020-09-16 04:06:04 +00:00
|
|
|
paych.State
|
|
|
|
store adt.Store
|
2020-09-18 21:59:27 +00:00
|
|
|
lsAmt *adt0.Array
|
2020-09-16 04:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Channel owner, who has funded the actor
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) From() address.Address {
|
2020-09-16 04:06:04 +00:00
|
|
|
return s.State.From
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recipient of payouts from channel
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) To() address.Address {
|
2020-09-17 16:14:07 +00:00
|
|
|
return s.State.To
|
2020-09-16 04:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Height at which the channel can be `Collected`
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) SettlingAt() abi.ChainEpoch {
|
2020-09-16 04:06:04 +00:00
|
|
|
return s.State.SettlingAt
|
|
|
|
}
|
|
|
|
|
|
|
|
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) ToSend() abi.TokenAmount {
|
2020-09-16 04:06:04 +00:00
|
|
|
return s.State.ToSend
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) getOrLoadLsAmt() (*adt0.Array, error) {
|
2020-09-16 04:06:04 +00:00
|
|
|
if s.lsAmt != nil {
|
|
|
|
return s.lsAmt, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the lane state from the chain
|
2020-09-18 21:59:27 +00:00
|
|
|
lsamt, err := adt0.AsArray(s.store, s.State.LaneStates)
|
2020-09-16 04:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.lsAmt = lsamt
|
|
|
|
return lsamt, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get total number of lanes
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) LaneCount() (uint64, error) {
|
2020-09-16 04:06:04 +00:00
|
|
|
lsamt, err := s.getOrLoadLsAmt()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return lsamt.Length(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate lane states
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
|
2020-09-16 04:06:04 +00:00
|
|
|
// Get the lane state from the chain
|
|
|
|
lsamt, err := s.getOrLoadLsAmt()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we use a map instead of an array to store laneStates because the
|
|
|
|
// client sets the lane ID (the index) and potentially they could use a
|
|
|
|
// very large index.
|
|
|
|
var ls paych.LaneState
|
|
|
|
return lsamt.ForEach(&ls, func(i int64) error {
|
2020-09-18 21:59:27 +00:00
|
|
|
return cb(uint64(i), &laneState0{ls})
|
2020-09-16 04:06:04 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type laneState0 struct {
|
2020-09-16 04:06:04 +00:00
|
|
|
paych.LaneState
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (ls *laneState0) Redeemed() big.Int {
|
2020-09-16 04:06:04 +00:00
|
|
|
return ls.LaneState.Redeemed
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (ls *laneState0) Nonce() uint64 {
|
2020-09-16 04:06:04 +00:00
|
|
|
return ls.LaneState.Nonce
|
|
|
|
}
|