Skip to content

Commit

Permalink
fix: adding password option to the start commands (pactus-project#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed May 25, 2023
1 parent 8228c3e commit 2c1f33c
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 19 deletions.
3 changes: 3 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func PactusHomeDir() string {
} else {
home = path.Join(usr.HomeDir, "pactus")
}

// TODO: remove it before the mainnet launch
home = path.Join(home, "testnet")
}
return home
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Init() func(c *cli.Cmd) {
return func(c *cli.Cmd) {
workingDirOpt := c.String(cli.StringOpt{
Name: "w working-dir",
Desc: "Working directory to save node configuration and genesis files.",
Desc: "A path to the working directory to save the wallet and node files",
Value: cmd.PactusHomeDir(),
})
testnetOpt := c.Bool(cli.BoolOpt{
Expand All @@ -24,7 +24,7 @@ func Init() func(c *cli.Cmd) {
Value: true, // TODO: make it false after mainnet launch
})

c.LongDesc = "Initializing the working directory by new validator's private key and genesis file."
c.LongDesc = "Initializing the working directory by new validator's private key and genesis file"
c.Before = func() { fmt.Println(cmd.Pactus) }
c.Action = func() {
workingDir, _ := filepath.Abs(*workingDirOpt)
Expand Down
6 changes: 3 additions & 3 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
func main() {
app := cli.App("pactus-daemon", "Pactus daemon")

app.Command("init", "Initialize the pactus blockchain", Init())
app.Command("start", "Start the pactus blockchain", Start())
app.Command("version", "Print the pactus version", Version())
app.Command("init", "Initialize the Pactus blockchain", Init())
app.Command("start", "Start the Pactus blockchain", Start())
app.Command("version", "Print the Pactus version", Version())

if err := app.Run(os.Args); err != nil {
panic(err)
Expand Down
17 changes: 14 additions & 3 deletions cmd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ func Start() func(c *cli.Cmd) {
return func(c *cli.Cmd) {
workingDirOpt := c.String(cli.StringOpt{
Name: "w working-dir",
Desc: "Working directory to read node configuration and genesis files",
Value: ".",
Desc: "A path to the working directory to read the wallet and node files",
Value: cmd.PactusHomeDir(),
})
passwordOpt := c.String(cli.StringOpt{
Name: "p password",
Desc: "The wallet password",
})
// TODO: do we need this?
pprofOpt := c.String(cli.StringOpt{
Name: "pprof",
Desc: "debug pprof server address(not recommended to expose to internet)",
Expand Down Expand Up @@ -56,7 +61,13 @@ func Start() func(c *cli.Cmd) {
if !wallet.IsEncrypted() {
return "", true
}
password := cmd.PromptPassword("Wallet password", false)

var password string
if *passwordOpt != "" {
password = *passwordOpt
} else {
password = cmd.PromptPassword("Wallet password", false)
}
return password, true
}
gen, conf, signers, rewardAddrs, _, err := cmd.GetKeys(
Expand Down
9 changes: 7 additions & 2 deletions cmd/gtk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ const appID = "com.github.pactus-project.pactus.pactus-gui"

var (
workingDirOpt *string
passwordOpt *string
testnetOpt *bool
)

func init() {
workingDirOpt = flag.String("working-dir", cmd.PactusHomeDir(), "working directory")
testnetOpt = flag.Bool("testnet", true, "working directory") // TODO: make it false after mainnet launch
workingDirOpt = flag.String("working-dir", cmd.PactusHomeDir(), "working directory path")
passwordOpt = flag.String("password", "", "wallet password")
testnetOpt = flag.Bool("testnet", true, "initializing for the testnet") // TODO: make it false after mainnet launch

gtk.Init(nil)
}
Expand Down Expand Up @@ -76,6 +78,9 @@ func main() {

func startingNode(workingDir string) (*node.Node, *config.Config, *time.Time, *wallet.Wallet, error) {
passwordFetcher := func(wallet *wallet.Wallet) (string, bool) {
if *passwordOpt != "" {
return *passwordOpt, true
}
return getWalletPassword(wallet)
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/log/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ func (m *Messages) voteSet(voteType vote.Type) *voteset.VoteSet {
return m.changeProposerVotes
}

logger.Panic("unexpected vote type %d", voteType)
logger.Panic("unexpected vote type", "voteType", voteType)
return nil
}
2 changes: 1 addition & 1 deletion network/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newDHTService(ctx context.Context, host lp2phost.Host, protocolID lp2pcore.

kademlia, err := lp2pdht.New(ctx, host, opts...)
if err != nil {
logger.Panic("unable to start DHT service: %v", err)
logger.Panic("unable to start DHT service", "err", err)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Even
logger *logger.Logger) *gossipService {
pubsub, err := lp2pps.NewGossipSub(ctx, host)
if err != nil {
logger.Panic("unable to start Gossip service: %v", err)
logger.Panic("unable to start Gossip service", "err", err)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions store/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (as *accountStore) iterateAccounts(consumer func(crypto.Address, *account.A

acc, err := account.FromBytes(value)
if err != nil {
logger.Panic("unable to decode account: %v", err)
logger.Panic("unable to decode account", "err", err)
}

stopped := consumer(addr, acc)
Expand All @@ -78,7 +78,7 @@ func (as *accountStore) iterateAccounts(consumer func(crypto.Address, *account.A
func (as *accountStore) updateAccount(batch *leveldb.Batch, addr crypto.Address, acc *account.Account) {
data, err := acc.Bytes()
if err != nil {
logger.Panic("unable to encode account: %v", err)
logger.Panic("unable to encode account", "err", err)
}
if !as.hasAccount(addr) {
as.total++
Expand Down
4 changes: 2 additions & 2 deletions store/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func newBlockStore(db *leveldb.DB) *blockStore {
func (bs *blockStore) saveBlock(batch *leveldb.Batch, height uint32, block *block.Block) []blockRegion {
if height > 1 {
if !bs.hasBlock(height - 1) {
logger.Panic("previous block not found: %v", height)
logger.Panic("previous block not found", "height", height)
}
}
if bs.hasBlock(height) {
logger.Panic("duplicated block: %v", height)
logger.Panic("duplicated block", "height", height)
}

blockHash := block.Hash()
Expand Down
4 changes: 2 additions & 2 deletions store/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (vs *validatorStore) iterateValidators(consumer func(*validator.Validator)

val, err := validator.FromBytes(value)
if err != nil {
logger.Panic("unable to decode validator: %v", err)
logger.Panic("unable to decode validator", "err", err)
}

stopped := consumer(val)
Expand All @@ -91,7 +91,7 @@ func (vs *validatorStore) iterateValidators(consumer func(*validator.Validator)
func (vs *validatorStore) updateValidator(batch *leveldb.Batch, val *validator.Validator) {
data, err := val.Bytes()
if err != nil {
logger.Panic("unable to encode validator: %v", err)
logger.Panic("unable to encode validator", "err", err)
}
if !vs.hasValidator(val.Address()) {
vs.total++
Expand Down

0 comments on commit 2c1f33c

Please sign in to comment.