Skip to content

Commit

Permalink
Used registry when checking the state of wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Jun 11, 2024
1 parent 88f3bf6 commit 95c56bb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/tbtc/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,17 +1103,29 @@ func (n *node) archiveClosedWallets() error {
for _, walletPublicKey := range walletPublicKeys {
walletPublicKeyHash := bitcoin.PublicKeyHash(walletPublicKey)

walletChainData, err := n.chain.GetWallet(walletPublicKeyHash)
walletID, err := n.chain.CalculateWalletID(walletPublicKey)
if err != nil {
return fmt.Errorf(
"could not get wallet data for wallet [0x%x]: [%v]",
"could not calculate wallet ID for wallet with public key "+
"hash [0x%x]: [%v]",
walletPublicKeyHash,
err,
)
}

if walletChainData.State == StateClosed ||
walletChainData.State == StateTerminated {
isRegistered, err := n.chain.IsWalletRegistered(walletID)
if err != nil {
return fmt.Errorf(
"could not check if wallet is registered for wallet with ID "+
"[0x%x]: [%v]",
walletPublicKeyHash,
err,
)
}

if !isRegistered {
// If the wallet is no longer registered it means the wallet has
// been closed or terminated.
err := n.walletRegistry.archiveWallet(walletPublicKeyHash)
if err != nil {
return fmt.Errorf(
Expand Down

0 comments on commit 95c56bb

Please sign in to comment.