2021-01-16 07:09:19 +00:00
|
|
|
package paych
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
|
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
|
|
init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init"
|
|
|
|
paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych"
|
|
|
|
|
|
|
|
"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 message3 struct{ from address.Address }
|
|
|
|
|
|
|
|
func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
2022-04-21 16:19:20 +00:00
|
|
|
|
|
|
|
actorCodeID := builtin3.PaymentChannelActorCodeID
|
|
|
|
|
2021-01-16 07:09:19 +00:00
|
|
|
params, aerr := actors.SerializeParams(&paych3.ConstructorParams{From: m.from, To: to})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
enc, aerr := actors.SerializeParams(&init3.ExecParams{
|
2022-04-21 16:19:20 +00:00
|
|
|
CodeCID: actorCodeID,
|
2021-01-16 07:09:19 +00:00
|
|
|
ConstructorParams: params,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
|
|
|
From: m.from,
|
|
|
|
Value: initialAmount,
|
|
|
|
Method: builtin3.MethodsInit.Exec,
|
|
|
|
Params: enc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message3) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
|
|
|
params, aerr := actors.SerializeParams(&paych3.UpdateChannelStateParams{
|
2021-12-20 01:44:19 +00:00
|
|
|
|
|
|
|
Sv: *sv,
|
|
|
|
|
2021-01-16 07:09:19 +00:00
|
|
|
Secret: secret,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin3.MethodsPaych.UpdateChannelState,
|
|
|
|
Params: params,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message3) Settle(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin3.MethodsPaych.Settle,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message3) Collect(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin3.MethodsPaych.Collect,
|
|
|
|
}, nil
|
|
|
|
}
|