adding actors for genesis msig addresses
This commit is contained in:
parent
8cae101c04
commit
88fbc044b3
@ -211,7 +211,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = createAccount(ctx, bs, cst, state, ida, info); err != nil {
|
if err = createAccount(ctx, bs, cst, state, ida, info, keyIDs); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = createAccount(ctx, bs, cst, state, vregroot, template.VerifregRootKey); err != nil {
|
if err = createAccount(ctx, bs, cst, state, vregroot, template.VerifregRootKey, keyIDs); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return state, keyIDs, nil
|
return state, keyIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor) error {
|
func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor, keyIDs map[address.Address]address.Address) error {
|
||||||
if info.Type == genesis.TAccount {
|
if info.Type == genesis.TAccount {
|
||||||
var ainfo genesis.AccountMeta
|
var ainfo genesis.AccountMeta
|
||||||
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
||||||
@ -294,6 +294,22 @@ func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore
|
|||||||
return xerrors.Errorf("failed to create empty map: %v", err)
|
return xerrors.Errorf("failed to create empty map: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, e := range ainfo.Signers {
|
||||||
|
idAddress, _ := keyIDs[e]
|
||||||
|
st, err := cst.Put(ctx, &account.State{Address: e})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = state.SetActor(idAddress, &types.Actor{
|
||||||
|
Code: builtin.AccountActorCodeID,
|
||||||
|
Balance: types.NewInt(0),
|
||||||
|
Head: st,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("setting account from actmap: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
st, err := cst.Put(ctx, &multisig.State{
|
st, err := cst.Put(ctx, &multisig.State{
|
||||||
Signers: ainfo.Signers,
|
Signers: ainfo.Signers,
|
||||||
NumApprovalsThreshold: uint64(ainfo.Threshold),
|
NumApprovalsThreshold: uint64(ainfo.Threshold),
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
@ -33,8 +34,30 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
|
|
||||||
keyToId := map[address.Address]address.Address{}
|
keyToId := map[address.Address]address.Address{}
|
||||||
|
|
||||||
for i, a := range initialActors {
|
counter := int64(AccountStart)
|
||||||
|
|
||||||
|
for _, a := range initialActors {
|
||||||
if a.Type == genesis.TMultisig {
|
if a.Type == genesis.TMultisig {
|
||||||
|
var ainfo genesis.MultisigMeta
|
||||||
|
if err := json.Unmarshal(a.Meta, &ainfo); err != nil {
|
||||||
|
return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
|
}
|
||||||
|
for _, e := range ainfo.Signers {
|
||||||
|
fmt.Printf("init set %s t0%d\n", e, counter)
|
||||||
|
|
||||||
|
value := cbg.CborInt(counter)
|
||||||
|
if err := amap.Put(adt.AddrKey(e), &value); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
counter = counter + 1
|
||||||
|
var err error
|
||||||
|
keyToId[e], err = address.NewIDAddress(uint64(value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// Need to add actors for all multisigs too
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,12 +70,13 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("init set %s t0%d\n", ainfo.Owner, AccountStart+int64(i))
|
fmt.Printf("init set %s t0%d\n", ainfo.Owner, counter)
|
||||||
|
|
||||||
value := cbg.CborInt(AccountStart + int64(i))
|
value := cbg.CborInt(counter)
|
||||||
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
keyToId[ainfo.Owner], err = address.NewIDAddress(uint64(value))
|
keyToId[ainfo.Owner], err = address.NewIDAddress(uint64(value))
|
||||||
@ -70,6 +94,26 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
} else if rootVerifier.Type == genesis.TMultisig {
|
||||||
|
var ainfo genesis.MultisigMeta
|
||||||
|
if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil {
|
||||||
|
return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
|
}
|
||||||
|
for _, e := range ainfo.Signers {
|
||||||
|
fmt.Printf("init set %s t0%d\n", e, counter)
|
||||||
|
|
||||||
|
value := cbg.CborInt(counter)
|
||||||
|
if err := amap.Put(adt.AddrKey(e), &value); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
counter = counter + 1
|
||||||
|
var err error
|
||||||
|
keyToId[e], err = address.NewIDAddress(uint64(value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
amapaddr, err := amap.Root()
|
amapaddr, err := amap.Root()
|
||||||
|
Loading…
Reference in New Issue
Block a user