Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: utility to get miner address from datastore #1595

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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