lotus/chain/actors/builtin/paych/message5.go

82 lines
2.1 KiB
Go
Raw Normal View History

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