2020-09-16 04:06:04 +00:00
|
|
|
package paych
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"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/go-state-types/cbor"
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-09-19 03:46:03 +00:00
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-09-23 04:48:35 +00:00
|
|
|
paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
2020-09-19 03:46:03 +00:00
|
|
|
builtin1 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
2020-09-16 04:06:04 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
2020-09-24 00:40:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2020-09-16 04:06:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2020-09-24 00:40:29 +00:00
|
|
|
func init() {
|
|
|
|
builtin.RegisterActorState(builtin0.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
|
|
|
return load0(store, root)
|
|
|
|
})
|
|
|
|
builtin.RegisterActorState(builtin1.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
|
|
|
return load1(store, root)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-16 04:06:04 +00:00
|
|
|
// Load returns an abstract copy of payment channel state, irregardless of actor version
|
|
|
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
|
|
|
switch act.Code {
|
2020-09-18 21:59:27 +00:00
|
|
|
case builtin0.PaymentChannelActorCodeID:
|
2020-09-24 00:40:29 +00:00
|
|
|
return load0(store, act.Head)
|
2020-09-19 03:46:03 +00:00
|
|
|
case builtin1.PaymentChannelActorCodeID:
|
2020-09-24 00:40:29 +00:00
|
|
|
return load1(store, act.Head)
|
2020-09-16 04:06:04 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
// State is an abstract version of payment channel state that works across
|
|
|
|
// versions
|
|
|
|
type State interface {
|
|
|
|
cbor.Marshaler
|
|
|
|
// Channel owner, who has funded the actor
|
2020-09-23 05:19:43 +00:00
|
|
|
From() (address.Address, error)
|
2020-09-16 04:06:04 +00:00
|
|
|
// Recipient of payouts from channel
|
2020-09-23 05:19:43 +00:00
|
|
|
To() (address.Address, error)
|
2020-09-16 04:06:04 +00:00
|
|
|
|
|
|
|
// Height at which the channel can be `Collected`
|
2020-09-23 05:19:43 +00:00
|
|
|
SettlingAt() (abi.ChainEpoch, error)
|
2020-09-16 04:06:04 +00:00
|
|
|
|
|
|
|
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
2020-09-23 05:19:43 +00:00
|
|
|
ToSend() (abi.TokenAmount, error)
|
2020-09-16 04:06:04 +00:00
|
|
|
|
|
|
|
// Get total number of lanes
|
|
|
|
LaneCount() (uint64, error)
|
|
|
|
|
|
|
|
// Iterate lane states
|
|
|
|
ForEachLaneState(cb func(idx uint64, dl LaneState) error) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// LaneState is an abstract copy of the state of a single lane
|
|
|
|
type LaneState interface {
|
2020-09-23 05:19:43 +00:00
|
|
|
Redeemed() (big.Int, error)
|
|
|
|
Nonce() (uint64, error)
|
2020-09-16 04:06:04 +00:00
|
|
|
}
|
2020-09-23 04:48:35 +00:00
|
|
|
|
|
|
|
type SignedVoucher = paych0.SignedVoucher
|
|
|
|
type ModVerifyParams = paych0.ModVerifyParams
|