2021-04-26 14:48:20 +00:00
|
|
|
package paych
|
|
|
|
|
|
|
|
import (
|
2022-04-21 16:19:13 +00:00
|
|
|
{{if (ge .v 8)}}
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
{{end}}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
"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"
|
|
|
|
{{if (le .v 7)}}
|
|
|
|
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"
|
|
|
|
{{else}}
|
|
|
|
builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin"
|
|
|
|
paych{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
|
|
|
init{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/init"
|
|
|
|
{{end}}
|
|
|
|
|
2021-04-26 14:48:20 +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 message{{.v}} struct{ from address.Address }
|
|
|
|
|
|
|
|
func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
2022-04-21 16:19:13 +00:00
|
|
|
{{if (le .v 7)}}
|
|
|
|
actorCodeID := builtin{{.v}}.PaymentChannelActorCodeID
|
|
|
|
{{else}}
|
|
|
|
actorCodeID, ok := actors.GetActorCodeID(actors.Version{{.v}}, "paymentchannel")
|
|
|
|
if !ok {
|
|
|
|
return nil, xerrors.Errorf("error getting actor paymentchannel code id for actor version %d", {{.v}})
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
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{
|
2022-04-21 16:19:13 +00:00
|
|
|
CodeCID: actorCodeID,
|
2021-04-26 14:48:20 +00:00
|
|
|
ConstructorParams: params,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
|
|
|
From: m.from,
|
|
|
|
Value: initialAmount,
|
|
|
|
Method: builtin{{.v}}.MethodsInit.Exec,
|
|
|
|
Params: enc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m message{{.v}}) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) {
|
2021-04-26 14:48:20 +00:00
|
|
|
params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{
|
2022-04-20 21:34:28 +00:00
|
|
|
{{if (le .v 6)}}
|
|
|
|
Sv: toV0SignedVoucher(*sv),
|
2021-12-20 01:44:19 +00:00
|
|
|
{{else}}
|
2021-04-26 14:48:20 +00:00
|
|
|
Sv: *sv,
|
2021-12-20 01:44:19 +00:00
|
|
|
{{end}}
|
2021-04-26 14:48:20 +00:00
|
|
|
Secret: secret,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin{{.v}}.MethodsPaych.UpdateChannelState,
|
|
|
|
Params: params,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message{{.v}}) Settle(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin{{.v}}.MethodsPaych.Settle,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m message{{.v}}) Collect(paych address.Address) (*types.Message, error) {
|
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
|
|
|
From: m.from,
|
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin{{.v}}.MethodsPaych.Collect,
|
|
|
|
}, nil
|
|
|
|
}
|