Merge pull request #327 from filecoin-project/feat/get-genesis
Add get genesis api endpoint
This commit is contained in:
commit
1b96c6488b
@ -60,6 +60,7 @@ type FullNode interface {
|
|||||||
ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet) (*types.TipSet, error)
|
ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet) (*types.TipSet, error)
|
||||||
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
||||||
ChainSetHead(context.Context, *types.TipSet) error
|
ChainSetHead(context.Context, *types.TipSet) error
|
||||||
|
ChainGetGenesis(context.Context) (*types.TipSet, error)
|
||||||
|
|
||||||
// syncer
|
// syncer
|
||||||
SyncState(context.Context) (*SyncState, error)
|
SyncState(context.Context) (*SyncState, error)
|
||||||
|
@ -48,6 +48,7 @@ type FullNodeStruct struct {
|
|||||||
ChainGetTipSetByHeight func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) `perm:"read"`
|
ChainGetTipSetByHeight func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) `perm:"read"`
|
||||||
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
||||||
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
|
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
|
||||||
|
ChainGetGenesis func(context.Context) (*types.TipSet, error) `perm:"read"`
|
||||||
|
|
||||||
SyncState func(context.Context) (*SyncState, error) `perm:"read"`
|
SyncState func(context.Context) (*SyncState, error) `perm:"read"`
|
||||||
|
|
||||||
@ -308,6 +309,10 @@ func (c *FullNodeStruct) ChainSetHead(ctx context.Context, ts *types.TipSet) err
|
|||||||
return c.Internal.ChainSetHead(ctx, ts)
|
return c.Internal.ChainSetHead(ctx, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
|
||||||
|
return c.Internal.ChainGetGenesis(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) SyncState(ctx context.Context) (*SyncState, error) {
|
func (c *FullNodeStruct) SyncState(ctx context.Context) (*SyncState, error) {
|
||||||
return c.Internal.SyncState(ctx)
|
return c.Internal.SyncState(ctx)
|
||||||
}
|
}
|
||||||
|
26
cli/chain.go
26
cli/chain.go
@ -210,6 +210,12 @@ var chainGetMsgCmd = &cli.Command{
|
|||||||
var chainSetHeadCmd = &cli.Command{
|
var chainSetHeadCmd = &cli.Command{
|
||||||
Name: "sethead",
|
Name: "sethead",
|
||||||
Usage: "manually set the local nodes head tipset (Caution: normally only used for recovery)",
|
Usage: "manually set the local nodes head tipset (Caution: normally only used for recovery)",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "genesis",
|
||||||
|
Usage: "reset head to genesis",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -218,13 +224,25 @@ var chainSetHeadCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
if !cctx.Args().Present() {
|
gen := cctx.Bool("genesis")
|
||||||
|
|
||||||
|
if !cctx.Args().Present() && !gen {
|
||||||
return fmt.Errorf("must pass cids for tipset to set as head")
|
return fmt.Errorf("must pass cids for tipset to set as head")
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := parseTipSet(api, ctx, cctx.Args().Slice())
|
var ts *types.TipSet
|
||||||
if err != nil {
|
if gen {
|
||||||
return err
|
gents, err := api.ChainGetGenesis(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ts = gents
|
||||||
|
} else {
|
||||||
|
parsedts, err := parseTipSet(api, ctx, cctx.Args().Slice())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ts = parsedts
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.ChainSetHead(ctx, ts); err != nil {
|
if err := api.ChainSetHead(ctx, ts); err != nil {
|
||||||
|
@ -161,3 +161,12 @@ func (a *ChainAPI) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, error
|
|||||||
func (a *ChainAPI) ChainSetHead(ctx context.Context, ts *types.TipSet) error {
|
func (a *ChainAPI) ChainSetHead(ctx context.Context, ts *types.TipSet) error {
|
||||||
return a.Chain.SetHead(ts)
|
return a.Chain.SetHead(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ChainAPI) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
|
||||||
|
genb, err := a.Chain.GetGenesis()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.NewTipSet([]*types.BlockHeader{genb})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user