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"
|
|
|
|
|
2020-10-05 16:51:04 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
|
|
|
|
paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych"
|
2020-09-30 17:04:10 +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"
|
|
|
|
)
|
|
|
|
|
2020-09-30 17:58:34 +00:00
|
|
|
type message2 struct{ from address.Address }
|
2020-09-30 17:04:10 +00:00
|
|
|
|
2020-09-30 17:58:34 +00:00
|
|
|
func (m message2) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
|
|
|
params, aerr := actors.SerializeParams(&paych2.ConstructorParams{From: m.from, To: to})
|
2020-09-30 17:04:10 +00:00
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
enc, aerr := actors.SerializeParams(&init2.ExecParams{
|
|
|
|
CodeCID: builtin2.PaymentChannelActorCodeID,
|
|
|
|
ConstructorParams: params,
|
|
|
|
})
|
|
|
|
if aerr != nil {
|
|
|
|
return nil, aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
2020-09-30 17:58:34 +00:00
|
|
|
From: m.from,
|
2020-09-30 17:04:10 +00:00
|
|
|
Value: initialAmount,
|
|
|
|
Method: builtin2.MethodsInit.Exec,
|
|
|
|
Params: enc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-30 17:58:34 +00:00
|
|
|
func (m message2) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
2020-09-30 17:04:10 +00:00
|
|
|
params, aerr := actors.SerializeParams(&paych2.UpdateChannelStateParams{
|
2021-12-20 01:44:19 +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,
|
2020-09-30 17:58:34 +00:00
|
|
|
From: m.from,
|
2020-09-30 17:04:10 +00:00
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin2.MethodsPaych.UpdateChannelState,
|
|
|
|
Params: params,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-30 17:58:34 +00:00
|
|
|
func (m message2) Settle(paych address.Address) (*types.Message, error) {
|
2020-09-30 17:04:10 +00:00
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
2020-09-30 17:58:34 +00:00
|
|
|
From: m.from,
|
2020-09-30 17:04:10 +00:00
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin2.MethodsPaych.Settle,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-30 17:58:34 +00:00
|
|
|
func (m message2) Collect(paych address.Address) (*types.Message, error) {
|
2020-09-30 17:04:10 +00:00
|
|
|
return &types.Message{
|
|
|
|
To: paych,
|
2020-09-30 17:58:34 +00:00
|
|
|
From: m.from,
|
2020-09-30 17:04:10 +00:00
|
|
|
Value: abi.NewTokenAmount(0),
|
|
|
|
Method: builtin2.MethodsPaych.Collect,
|
|
|
|
}, nil
|
|
|
|
}
|