/
init.go
45 lines (37 loc) · 1.22 KB
/
init.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
package nv4
import (
"context"
"github.com/chenjianmei111/go-state-types/big"
init0 "github.com/chenjianmei111/specs-actors/actors/builtin/init"
cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
init2 "github.com/chenjianmei111/specs-actors/v2/actors/builtin/init"
)
type initMigrator struct {
}
func (m initMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, head cid.Cid, _ MigrationInfo) (*StateMigrationResult, error) {
var inState init0.State
if err := store.Get(ctx, head, &inState); err != nil {
return nil, err
}
// Migrate address resolution map
addrMapRoot, err := m.migrateAddrs(ctx, store, inState.AddressMap)
if err != nil {
return nil, xerrors.Errorf("migrate addrs: %w", err)
}
outState := init2.State{
AddressMap: addrMapRoot,
NextID: inState.NextID,
NetworkName: inState.NetworkName,
}
newHead, err := store.Put(ctx, &outState)
return &StateMigrationResult{
NewHead: newHead,
Transfer: big.Zero(),
}, err
}
func (m *initMigrator) migrateAddrs(ctx context.Context, store cbor.IpldStore, root cid.Cid) (cid.Cid, error) {
// The HAMT has changed, but the value type (Address) is identical.
return migrateHAMTRaw(ctx, store, root)
}