-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
message3.go
79 lines (66 loc) · 2.08 KB
/
message3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package paych
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init"
paych3 "github.com/filecoin-project/specs-actors/v3/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 message3 struct{ from address.Address }
func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
actorCodeID := builtin3.PaymentChannelActorCodeID
params, aerr := actors.SerializeParams(&paych3.ConstructorParams{From: m.from, To: to})
if aerr != nil {
return nil, aerr
}
enc, aerr := actors.SerializeParams(&init3.ExecParams{
CodeCID: actorCodeID,
ConstructorParams: params,
})
if aerr != nil {
return nil, aerr
}
return &types.Message{
To: init_.Address,
From: m.from,
Value: initialAmount,
Method: builtin3.MethodsInit.Exec,
Params: enc,
}, nil
}
func (m message3) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) {
params, aerr := actors.SerializeParams(&paych3.UpdateChannelStateParams{
Sv: toV0SignedVoucher(*sv),
Secret: secret,
})
if aerr != nil {
return nil, aerr
}
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin3.MethodsPaych.UpdateChannelState,
Params: params,
}, nil
}
func (m message3) Settle(paych address.Address) (*types.Message, error) {
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin3.MethodsPaych.Settle,
}, nil
}
func (m message3) Collect(paych address.Address) (*types.Message, error) {
return &types.Message{
To: paych,
From: m.from,
Value: abi.NewTokenAmount(0),
Method: builtin3.MethodsPaych.Collect,
}, nil
}