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

77 lines
1.9 KiB
Go
Raw Normal View History

2020-09-30 17:04:10 +00:00
package paych
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
init0 "github.com/filecoin-project/specs-actors/actors/builtin/init"
paych0 "github.com/filecoin-project/specs-actors/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 message0 struct{ from address.Address }
2020-09-30 17:04:10 +00:00
func (m message0) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
params, aerr := actors.SerializeParams(&paych0.ConstructorParams{From: m.from, To: to})
2020-09-30 17:04:10 +00:00
if aerr != nil {
return nil, aerr
}
enc, aerr := actors.SerializeParams(&init0.ExecParams{
CodeCID: builtin0.PaymentChannelActorCodeID,
ConstructorParams: params,
})
if aerr != nil {
return nil, aerr
}
return &types.Message{
To: init_.Address,
From: m.from,
2020-09-30 17:04:10 +00:00
Value: initialAmount,
Method: builtin0.MethodsInit.Exec,
Params: enc,
}, nil
}
func (m message0) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
2020-09-30 17:04:10 +00:00
params, aerr := actors.SerializeParams(&paych0.UpdateChannelStateParams{
2022-04-07 18:46:23 +00:00
Sv: *sv,
2020-09-30 17:04:10 +00:00
Secret: secret,
})
if aerr != nil {
return nil, aerr
}
return &types.Message{
To: paych,
From: m.from,
2020-09-30 17:04:10 +00:00
Value: abi.NewTokenAmount(0),
Method: builtin0.MethodsPaych.UpdateChannelState,
Params: params,
}, nil
}
func (m message0) Settle(paych address.Address) (*types.Message, error) {
2020-09-30 17:04:10 +00:00
return &types.Message{
To: paych,
From: m.from,
2020-09-30 17:04:10 +00:00
Value: abi.NewTokenAmount(0),
Method: builtin0.MethodsPaych.Settle,
}, nil
}
func (m message0) Collect(paych address.Address) (*types.Message, error) {
2020-09-30 17:04:10 +00:00
return &types.Message{
To: paych,
From: m.from,
2020-09-30 17:04:10 +00:00
Value: abi.NewTokenAmount(0),
Method: builtin0.MethodsPaych.Collect,
}, nil
}