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