Skip to content
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
3 changes: 3 additions & 0 deletions cmd/goal/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,19 @@ const (
infoPrintedBackupPhrase = "Your backup phrase is printed below.\nKeep this information safe -- never share it with anyone!"
infoBackupPhrase = "\n%s"
infoNoWallets = "No wallets found. You can create a wallet with `goal wallet new`"
infoRenamedWallet = "Renamed wallet '%s' to '%s'"
errorCouldntCreateWallet = "Couldn't create wallet: %s"
errorCouldntInitializeWallet = "Couldn't initialize wallet: %s"
errorCouldntExportMDK = "Couldn't export master derivation key: %s"
errorCouldntMakeMnemonic = "Couldn't make mnemonic: %s"
errorCouldntListWallets = "Couldn't list wallets: %s"
errorCouldntFindWallet = "Couldn't find wallet: %s"
errorPasswordConfirmation = "Password confirmation did not match"
errorBadMnemonic = "Problem with mnemonic: %s"
errorBadRecoveredKey = "Recovered invalid key"
errorFailedToReadResponse = "Couldn't read response: %s"
errorFailedToReadPassword = "Couldn't read password: %s"
errorCouldntRenameWallet = "Couldn't rename wallet: %s"

// Commands
infoPasswordPrompt = "Please enter the password for wallet '%s': "
Expand Down
48 changes: 48 additions & 0 deletions cmd/goal/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
func init() {
walletCmd.AddCommand(newWalletCmd)
walletCmd.AddCommand(listWalletsCmd)
walletCmd.AddCommand(renameWalletCmd)

// Default wallet to use when -w not specified
walletCmd.Flags().StringVarP(&defaultWalletName, "default", "f", "", "Set the wallet with this name to be the default wallet")
Expand Down Expand Up @@ -200,6 +201,53 @@ var listWalletsCmd = &cobra.Command{
},
}

var renameWalletCmd = &cobra.Command{
Use: "rename [wallet name] [new wallet name]",
Short: "Rename wallet",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
dataDir := datadir.EnsureSingleDataDir()

client := ensureKmdClient(dataDir)

walletName := []byte(args[0])
newWalletName := []byte(args[1])

wid, duplicate, err := client.FindWalletIDByName(walletName)

if wid == nil {
reportErrorf(errorCouldntFindWallet, string(walletName))
}

if err != nil {
reportErrorf(errorCouldntRenameWallet, err)
}

if duplicate {
reportErrorf(errorCouldntRenameWallet, "Multiple wallets by the same name are not supported")
}

if bytes.Equal(walletName, newWalletName) {
reportErrorf(errorCouldntRenameWallet, "new name is identical to current name")
}

walletPassword := []byte{}

// if wallet is encrypted, fetch the password
if !client.WalletIsUnencrypted(wid) {
fmt.Printf(infoPasswordPrompt, walletName)
walletPassword = ensurePassword()
}

err = client.RenameWallet(wid, newWalletName, walletPassword)
if err != nil {
reportErrorf(errorCouldntRenameWallet, err)
}

reportInfof(infoRenamedWallet, walletName, newWalletName)
},
}

func printWallets(dataDir string, wallets []kmdapi.APIV1Wallet) {
accountList := makeAccountsList(dataDir)
defaultWalletID := string(accountList.getDefaultWalletID())
Expand Down
11 changes: 11 additions & 0 deletions daemon/kmd/client/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func (kcl KMDClient) CreateWallet(walletName []byte, walletDriverName string, wa
return
}

// RenameWallet wraps kmdapi.APIV1POSTWalletRenameRequest
func (kcl KMDClient) RenameWallet(walletID []byte, newWalletName []byte, walletPassword []byte) (resp kmdapi.APIV1POSTWalletRenameResponse, err error) {
req := kmdapi.APIV1POSTWalletRenameRequest{
WalletID: string(walletID),
NewWalletName: string(newWalletName),
WalletPassword: string(walletPassword),
Comment thread
tasosbit marked this conversation as resolved.
}
err = kcl.DoV1Request(req, &resp)
return
}

// InitWallet wraps kmdapi.APIV1POSTWalletInitRequest
func (kcl KMDClient) InitWallet(walletID []byte, walletPassword []byte) (resp kmdapi.APIV1POSTWalletInitResponse, err error) {
req := kmdapi.APIV1POSTWalletInitRequest{
Expand Down
18 changes: 18 additions & 0 deletions libgoal/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ func (c *Client) CreateWallet(name []byte, password []byte, mdk crypto.MasterDer
return []byte(resp.Wallet.ID), nil
}

// RenameWallet renames a kmd wallet
func (c *Client) RenameWallet(wid []byte, name []byte, password []byte) error {
// Pull the list of all wallets from kmd
kmd, err := c.ensureKmdClient()
if err != nil {
return err
}

// Rename the wallet
_, err = kmd.RenameWallet(wid, name, password)

if err != nil {
return err
}

return nil
}

// GetWalletHandleToken inits the wallet with the given id, returning a wallet handle token
func (c *Client) GetWalletHandleToken(wid, pw []byte) ([]byte, error) {
kmd, err := c.ensureKmdClient()
Expand Down