-
Notifications
You must be signed in to change notification settings - Fork 0
/
paych.go
60 lines (50 loc) · 1.73 KB
/
paych.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
package nv4
import (
"context"
addr "github.com/chenjianmei111/go-address"
"github.com/chenjianmei111/go-state-types/big"
paych0 "github.com/chenjianmei111/specs-actors/actors/builtin/paych"
cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
paych2 "github.com/chenjianmei111/specs-actors/v2/actors/builtin/paych"
)
type paychMigrator struct {
}
func (m paychMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, head cid.Cid, _ MigrationInfo) (*StateMigrationResult, error) {
var inState paych0.State
if err := store.Get(ctx, head, &inState); err != nil {
return nil, err
}
// Migrate lane states map
laneStatesRoot, err := m.migrateLaneStates(ctx, store, inState.LaneStates)
if err != nil {
return nil, xerrors.Errorf("lane state: %w", err)
}
// Verify parties are all ID addrs
if inState.From.Protocol() != addr.ID {
return nil, xerrors.Errorf("unexpected non-ID from address %s", inState.From)
}
if inState.To.Protocol() != addr.ID {
return nil, xerrors.Errorf("unexpected non-ID to address %s", inState.To)
}
outState := paych2.State{
From: inState.From,
To: inState.To,
ToSend: inState.ToSend,
SettlingAt: inState.SettlingAt,
MinSettleHeight: inState.MinSettleHeight,
LaneStates: laneStatesRoot,
}
newHead, err := store.Put(ctx, &outState)
return &StateMigrationResult{
NewHead: newHead,
Transfer: big.Zero(),
}, err
}
func (m *paychMigrator) migrateLaneStates(_ context.Context, _ cbor.IpldStore, root cid.Cid) (cid.Cid, error) {
// AMT and both the key and value type unchanged between v0 and v2.
// Verify that the value type is identical.
var _ = paych2.LaneState(paych0.LaneState{})
return root, nil
}