Skip to content

Commit

Permalink
feat: utility to get miner address from datastore (#1595)
Browse files Browse the repository at this point in the history
* feat: utility to get miner address from datastore

* Update cmd/boostx/boostd.go

Co-authored-by: dirkmc <[email protected]>

---------

Co-authored-by: dirkmc <[email protected]>
  • Loading branch information
LexLuthr and dirkmc authored Jul 26, 2023
1 parent 9196679 commit 200c5a8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
70 changes: 70 additions & 0 deletions cmd/boostx/boostd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"fmt"

"github.com/filecoin-project/boost/node/repo"
"github.com/filecoin-project/go-address"
lotus_repo "github.com/filecoin-project/lotus/node/repo"
"github.com/ipfs/go-datastore"
"github.com/urfave/cli/v2"
)

const metadataNamespace = "/metadata"

var minerCmd = &cli.Command{
Name: "boostd",
Usage: "boostd utilities",
Subcommands: []*cli.Command{
minerAddressCmd,
},
}

var minerAddressCmd = &cli.Command{
Name: "miner-address",
Usage: "boostx boostd miner-address",
Description: "Fetch the miner address from the datastore. Boostd process must be stopped before running this command.",
Action: func(cctx *cli.Context) error {

boostRepoPath := cctx.String(FlagBoostRepo)

r, err := lotus_repo.NewFS(boostRepoPath)
if err != nil {
return err
}
ok, err := r.Exists()
if err != nil {
return err
}
if !ok {
return fmt.Errorf("repo at '%s' is not initialized", cctx.String(FlagBoostRepo))
}

lr, err := r.LockRO(repo.Boost)
if err != nil {
return fmt.Errorf("locking repo: %w. Please stop the boostd process to proceed", err)
}
defer lr.Close()

mds, err := lr.Datastore(cctx.Context, metadataNamespace)
if err != nil {
return fmt.Errorf("getting metadata datastore: %w", err)
}

var minerAddrDSKey = datastore.NewKey("miner-address")

addr, err := mds.Get(cctx.Context, minerAddrDSKey)
if err != nil {
return fmt.Errorf("getting miner address from legacy datastore: %w", err)
}

minerAddr, err := address.NewFromBytes(addr)
if err != nil {
return fmt.Errorf("parsing miner address from legacy datastore: %w", err)
}

fmt.Printf("Miner Address from datastore: %s\n", minerAddr.String())

return nil
},
}
14 changes: 12 additions & 2 deletions cmd/boostx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"io"
"os"

llog "log"
"os"

logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
Expand All @@ -14,6 +13,10 @@ import (
"github.com/filecoin-project/boostd-data/shared/cliutil"
)

const (
FlagBoostRepo = "boost-repo"
)

var log = logging.Logger("boostx")

func init() {
Expand All @@ -27,6 +30,12 @@ func main() {
EnableBashCompletion: true,
Version: build.UserVersion(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: FlagBoostRepo,
EnvVars: []string{"BOOST_PATH"},
Usage: "boostd repo path",
Value: "~/.boost",
},
cliutil.FlagVeryVerbose,
cmd.FlagRepo,
},
Expand All @@ -38,6 +47,7 @@ func main() {
marketWithdrawCmd,
statsCmd,
sectorCmd,
minerCmd,
},
}
app.Setup()
Expand Down

0 comments on commit 200c5a8

Please sign in to comment.