2022-03-01 03:57:40 +00:00
|
|
|
package paych
|
|
|
|
|
|
|
|
import (
|
2022-04-21 16:19:20 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2022-03-01 03:57:40 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-11-08 04:55:56 +00:00
|
|
|
|
|
|
|
paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2022-04-20 21:34:28 +00:00
|
|
|
builtin8 "github.com/filecoin-project/go-state-types/builtin"
|
|
|
|
init8 "github.com/filecoin-project/go-state-types/builtin/v8/init"
|
|
|
|
paych8 "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
2022-03-01 03:57:40 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type message8 struct{ from address.Address }
|
|
|
|
|
|
|
|
func (m message8) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
2022-04-21 16:19:20 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
actorCodeID, ok := actors.GetActorCodeID(actorstypes.Version8, "paymentchannel")
|
2022-04-21 16:19:20 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, xerrors.Errorf("error getting actor paymentchannel code id for actor version %d", 8)
|
|
|
|
}
|
|
|
|
|
2022-03-01 03:57:40 +00:00
|
|
|
params, aerr := actors.SerializeParams(&paych8.ConstructorParams{From: m.from, To: to})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
enc, aerr := actors.SerializeParams(&init8.ExecParams{
|
2022-04-21 16:19:20 +00:00
|
|
|
CodeCID: actorCodeID,
|
2022-03-01 03:57:40 +00:00
|
|
|
ConstructorParams: params,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
|
|
|
From: m.from,
|
|
|
|
Value: initialAmount,
|
|
|
|
Method: builtin8.MethodsInit.Exec,
|
|
|
|
Params: enc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m message8) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) {
|
2022-03-01 03:57:40 +00:00
|
|
|
params, aerr := actors.SerializeParams(&paych8.UpdateChannelStateParams{
|
2022-04-07 18:46:23 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
Sv: *sv,
|
2022-04-07 18:46:23 +00:00
|
|
|
|
2022-03-01 03:57:40 +00:00
|
|
|
Secret: secret,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin8.MethodsPaych.UpdateChannelState,
|
|
|
|
Params: params,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message8) Settle(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin8.MethodsPaych.Settle,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message8) Collect(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin8.MethodsPaych.Collect,
|
|
|
|
}, nil
|
|
|
|
}
|