Skip to content

Commit 7e65e0e

Browse files
committed
Remove unneeded accountName param from nextAddress
To ensure nextAddress is returning valid and helpful information, retrieve the real account name from the database rather than just blindly returning whatever account name was passed as a param (this was often a fake/placeholder value anyway).
1 parent 93661c8 commit 7e65e0e

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

wallet/addresses.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ func (s accountBranchChildUpdates) UpdateDB(ctx context.Context, w *Wallet, mayb
504504
// nextAddress returns the next address of an account branch.
505505
func (w *Wallet) nextAddress(ctx context.Context, op errors.Op,
506506
updates *accountBranchChildUpdates, maybeDBTX walletdb.ReadWriteTx,
507-
accountName string, account, branch uint32,
507+
account, branch uint32,
508508
callOpts ...NextAddressCallOption) (a stdaddr.Address, rerr error) {
509509

510510
if updates != nil && maybeDBTX != nil {
@@ -633,6 +633,12 @@ func (w *Wallet) nextAddress(ctx context.Context, op errors.Op,
633633
} else {
634634
return nil, errors.E(op, errors.Bug, "no method to update DB with addresses")
635635
}
636+
637+
accountName, err := w.AccountName(ctx, account)
638+
if err != nil {
639+
return nil, errors.E(op, err)
640+
}
641+
636642
alb.cursor++
637643
addr := &xpubAddress{
638644
AddressPubKeyHashEcdsaSecp256k1V0: apkh,
@@ -751,10 +757,8 @@ func (w *Wallet) NewExternalAddress(ctx context.Context, account uint32, callOpt
751757
if err := w.notVotingAcct(ctx, op, account); err != nil {
752758
return nil, err
753759
}
754-
755-
accountName, _ := w.AccountName(ctx, account)
756760
return w.nextAddress(ctx, op, nil, nil,
757-
accountName, account, udb.ExternalBranch, callOpts...)
761+
account, udb.ExternalBranch, callOpts...)
758762
}
759763

760764
// NewInternalAddress returns an internal address.
@@ -765,10 +769,8 @@ func (w *Wallet) NewInternalAddress(ctx context.Context, account uint32, callOpt
765769
if err := w.notVotingAcct(ctx, op, account); err != nil {
766770
return nil, err
767771
}
768-
769-
accountName, _ := w.AccountName(ctx, account)
770772
return w.nextAddress(ctx, op, nil, nil,
771-
accountName, account, udb.InternalBranch, callOpts...)
773+
account, udb.InternalBranch, callOpts...)
772774
}
773775

774776
// notVotingAcct errors if an account is a special voting type. This account
@@ -793,7 +795,7 @@ func (w *Wallet) notVotingAcct(ctx context.Context, op errors.Op, account uint32
793795
}
794796

795797
func (w *Wallet) newChangeAddress(ctx context.Context, op errors.Op, updates *accountBranchChildUpdates,
796-
maybeDBTX walletdb.ReadWriteTx, accountName string, account uint32, gap gapPolicy) (stdaddr.Address, error) {
798+
maybeDBTX walletdb.ReadWriteTx, account uint32, gap gapPolicy) (stdaddr.Address, error) {
797799

798800
// Imported voting accounts must not be used for change.
799801
if err := w.notVotingAcct(ctx, op, account); err != nil {
@@ -807,7 +809,7 @@ func (w *Wallet) newChangeAddress(ctx context.Context, op errors.Op, updates *ac
807809
if account == udb.ImportedAddrAccount {
808810
account = udb.DefaultAccountNum
809811
}
810-
return w.nextAddress(ctx, op, updates, maybeDBTX, accountName, account, udb.InternalBranch, withGapPolicy(gap))
812+
return w.nextAddress(ctx, op, updates, maybeDBTX, account, udb.InternalBranch, withGapPolicy(gap))
811813
}
812814

813815
// NewChangeAddress returns an internal address. This is identical to
@@ -816,8 +818,7 @@ func (w *Wallet) newChangeAddress(ctx context.Context, op errors.Op, updates *ac
816818
// policy.
817819
func (w *Wallet) NewChangeAddress(ctx context.Context, account uint32) (stdaddr.Address, error) {
818820
const op errors.Op = "wallet.NewChangeAddress"
819-
accountName, _ := w.AccountName(ctx, account)
820-
return w.newChangeAddress(ctx, op, nil, nil, accountName, account, gapPolicyWrap)
821+
return w.newChangeAddress(ctx, op, nil, nil, account, gapPolicyWrap)
821822
}
822823

823824
// BIP0044BranchNextIndexes returns the next external and internal branch child
@@ -949,9 +950,8 @@ type p2PKHChangeSource struct {
949950
}
950951

951952
func (src *p2PKHChangeSource) Script() ([]byte, uint16, error) {
952-
const accountName = "" // not returned, so can be faked.
953953
changeAddress, err := src.wallet.newChangeAddress(src.ctx, "", nil, src.dbtx,
954-
accountName, src.account, src.gapPolicy)
954+
src.account, src.gapPolicy)
955955
if err != nil {
956956
return nil, 0, err
957957
}
@@ -977,9 +977,8 @@ type p2PKHTreasuryChangeSource struct {
977977
// Script returns the treasury change script and is required for change source
978978
// interface.
979979
func (src *p2PKHTreasuryChangeSource) Script() ([]byte, uint16, error) {
980-
const accountName = "" // not returned, so can be faked.
981980
changeAddress, err := src.wallet.newChangeAddress(src.ctx, "", nil, src.dbtx,
982-
accountName, src.account, src.gapPolicy)
981+
src.account, src.gapPolicy)
983982
if err != nil {
984983
return nil, 0, err
985984
}

wallet/createtx.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,8 @@ func (w *Wallet) compressWalletInternal(ctx context.Context, op errors.Op, dbtx
808808

809809
// Check if output address is default, and generate a new address if needed
810810
if changeAddr == nil {
811-
const accountName = "" // not used, so can be faked.
812811
changeAddr, err = w.newChangeAddress(ctx, op, nil, dbtx,
813-
accountName, account, gapPolicyIgnore)
812+
account, gapPolicyIgnore)
814813
if err != nil {
815814
return nil, errors.E(op, err)
816815
}
@@ -1168,8 +1167,7 @@ func (w *Wallet) purchaseTickets(ctx context.Context, op errors.Op,
11681167
}
11691168

11701169
stakeAddrFunc := func(op errors.Op, account, branch uint32) (stdaddr.StakeAddress, uint32, error) {
1171-
const accountName = "" // not used, so can be faked.
1172-
a, err := w.nextAddress(ctx, op, nil, nil, accountName,
1170+
a, err := w.nextAddress(ctx, op, nil, nil,
11731171
account, branch, WithGapPolicyIgnore())
11741172
if err != nil {
11751173
return nil, 0, err

wallet/mixing.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2024 The Decred developers
1+
// Copyright (c) 2019-2025 The Decred developers
22
// Use of this source code is governed by an ISC
33
// license that can be found in the LICENSE file.
44

@@ -56,9 +56,8 @@ func (w *Wallet) makeGen(ctx context.Context, account, branch uint32) mixclient.
5656
updates := make(accountBranchChildUpdates, 0, mcount)
5757

5858
for i := uint32(0); i < mcount; i++ {
59-
const accountName = "" // not used, so can be faked.
6059
mixAddr, err := w.nextAddress(ctx, op, &updates, nil,
61-
accountName, account, branch, WithGapPolicyIgnore())
60+
account, branch, WithGapPolicyIgnore())
6261
if err != nil {
6362
return nil, err
6463
}
@@ -390,9 +389,8 @@ SplitPoints:
390389
var change *wire.TxOut
391390
if changeValue > 0 {
392391
updates := make(accountBranchChildUpdates, 0, 1)
393-
const accountName = "" // not used, so can be faked.
394392
addr, err := w.nextAddress(ctx, op, &updates, nil,
395-
accountName, changeAccount, udb.InternalBranch, WithGapPolicyIgnore())
393+
changeAccount, udb.InternalBranch, WithGapPolicyIgnore())
396394
if err != nil {
397395
return errors.E(op, err)
398396
}

0 commit comments

Comments
 (0)