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

Return error if wallet already exists for xpub key #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 22 additions & 1 deletion cgo/walletloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,28 @@ func createWatchOnlyWallet(cName, cDataDir, cNet, cPub *C.char) *C.char {

walletCtx, cancel := context.WithCancel(mainCtx)

w, err := dcr.CreateWatchOnlyWallet(walletCtx, goString(cPub), params)
xpub := goString(cPub)
// Ensure wallet does not already exists.
for name, w := range wallets {
walletAccountNumber, err := w.AccountNumber(walletCtx, defaultAccount)
if err != nil {
cancel()
return errCResponse(err.Error())
}

walletXpub, err := w.AccountXpub(walletCtx, walletAccountNumber)
if err != nil {
cancel()
return errCResponse(err.Error())
}

if walletXpub.String() == xpub {
cancel()
return errCResponse(fmt.Sprintf("a wallet (%s) with an identical extended public key already exists", name))
}
}

w, err := dcr.CreateWatchOnlyWallet(walletCtx, xpub, params)
if err != nil {
cancel()
return errCResponse(err.Error())
Expand Down
Loading