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