lotus/chain/gen/genesis/t05_market.go

43 lines
946 B
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"context"
2020-02-21 16:57:40 +00:00
"github.com/ipfs/go-hamt-ipld"
2020-02-11 20:48:03 +00:00
2020-02-25 20:54:58 +00:00
"github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/specs-actors/actors/builtin"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/specs-actors/actors/builtin/market"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/types"
)
2020-02-12 07:44:20 +00:00
func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) {
2020-02-11 20:48:03 +00:00
cst := cbor.NewCborStore(bs)
2020-02-21 16:57:40 +00:00
a, err := amt.NewAMT(cst).Flush(context.TODO())
2020-02-11 20:48:03 +00:00
if err != nil {
2020-02-12 00:58:55 +00:00
return nil, err
2020-02-11 20:48:03 +00:00
}
2020-02-21 16:57:40 +00:00
h, err := cst.Put(context.TODO(), hamt.NewNode(cst, hamt.UseTreeBitWidth(5)))
if err != nil {
return nil, err
}
sms := market.ConstructState(a, h, h)
2020-02-11 20:48:03 +00:00
stcid, err := cst.Put(context.TODO(), sms)
if err != nil {
2020-02-12 00:58:55 +00:00
return nil, err
2020-02-11 20:48:03 +00:00
}
act := &types.Actor{
2020-02-25 20:54:58 +00:00
Code: builtin.StorageMarketActorCodeID,
2020-02-11 20:48:03 +00:00
Head: stcid,
Balance: types.NewInt(0),
}
2020-02-12 00:58:55 +00:00
return act, nil
2020-02-11 20:48:03 +00:00
}