Skip to content

Commit

Permalink
undo spvWallet.acctNum removal
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Jan 4, 2024
1 parent b4129a8 commit 2decf1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,9 @@ func OpenSPVWallet(cfg *BTCCloneCFG, walletConstructor BTCWalletConstructor) (*E
spvw.wallet = walletConstructor(spvw.dir, spvw.cfg, spvw.chainParams, spvw.log)
btc.setNode(spvw)

// Set account number for easy reference.
spvw.acctNum = spvw.wallet.AccountInfo().AccountNumber

w := &ExchangeWalletSPV{
intermediaryWallet: &intermediaryWallet{
baseWallet: btc,
Expand Down
1 change: 1 addition & 0 deletions client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ func tNewWallet(segwit bool, walletType string) (*intermediaryWallet, *testData,
cfg: &WalletConfig{},
wallet: &tBtcWallet{data},
cl: neutrinoClient,
acctNum: 0,
tipChan: make(chan *BlockVector, 1),
txBlocks: data.dbBlockForTx,
checkpoints: data.checkpoints,
Expand Down
12 changes: 6 additions & 6 deletions client/asset/btc/spv_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ type spvWallet struct {
cfg *WalletConfig
wallet BTCWallet
cl SPVService
acctNum uint32
dir string
decodeAddr dexbtc.AddressDecoder

Expand Down Expand Up @@ -613,8 +614,7 @@ func (w *spvWallet) listTransactionsSinceBlock(blockHeight int32) ([]btcjson.Lis
// balances retrieves a wallet's balance details.
func (w *spvWallet) balances() (*GetBalancesResult, error) {
// Determine trusted vs untrusted coins with listunspent.
acctInfo := w.wallet.AccountInfo()
unspents, err := w.wallet.ListUnspent(0, math.MaxInt32, acctInfo.AccountName)
unspents, err := w.wallet.ListUnspent(0, math.MaxInt32, w.wallet.AccountInfo().AccountName)
if err != nil {
return nil, fmt.Errorf("error listing unspent outputs: %w", err)
}
Expand All @@ -628,7 +628,7 @@ func (w *spvWallet) balances() (*GetBalancesResult, error) {
}

// listunspent does not include immature coinbase outputs or locked outputs.
bals, err := w.wallet.CalculateAccountBalances(acctInfo.AccountNumber, 0 /* confs */)
bals, err := w.wallet.CalculateAccountBalances(w.acctNum, 0 /* confs */)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -730,13 +730,13 @@ func (w *spvWallet) listLockUnspent() ([]*RPCOutpoint, error) {
// changeAddress gets a new internal address from the wallet. The address will
// be bech32-encoded (P2WPKH).
func (w *spvWallet) changeAddress() (btcutil.Address, error) {
return w.wallet.NewChangeAddress(w.wallet.AccountInfo().AccountNumber, waddrmgr.KeyScopeBIP0084)
return w.wallet.NewChangeAddress(w.acctNum, waddrmgr.KeyScopeBIP0084)
}

// externalAddress gets a new bech32-encoded (P2WPKH) external address from the
// wallet.
func (w *spvWallet) externalAddress() (btcutil.Address, error) {
return w.wallet.NewAddress(w.wallet.AccountInfo().AccountNumber, waddrmgr.KeyScopeBIP0084)
return w.wallet.NewAddress(w.acctNum, waddrmgr.KeyScopeBIP0084)
}

// signTx attempts to have the wallet sign the transaction inputs.
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func copyDir(src, dst string) error {
// numDerivedAddresses returns the number of internal and external addresses
// that the wallet has derived.
func (w *spvWallet) numDerivedAddresses() (internal, external uint32, err error) {
props, err := w.wallet.AccountProperties(waddrmgr.KeyScopeBIP0084, w.wallet.AccountInfo().AccountNumber)
props, err := w.wallet.AccountProperties(waddrmgr.KeyScopeBIP0084, w.acctNum)
if err != nil {
return 0, 0, err
}
Expand Down

0 comments on commit 2decf1c

Please sign in to comment.