Skip to content

Commit ae34178

Browse files
committed
Used registry when checking the state of wallets
1 parent 88f3bf6 commit ae34178

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/tbtc/node.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,17 +1103,29 @@ func (n *node) archiveClosedWallets() error {
11031103
for _, walletPublicKey := range walletPublicKeys {
11041104
walletPublicKeyHash := bitcoin.PublicKeyHash(walletPublicKey)
11051105

1106-
walletChainData, err := n.chain.GetWallet(walletPublicKeyHash)
1106+
walletID, err := n.chain.CalculateWalletID(walletPublicKey)
11071107
if err != nil {
11081108
return fmt.Errorf(
1109-
"could not get wallet data for wallet [0x%x]: [%v]",
1109+
"could not calculate wallet ID for wallet with public key "+
1110+
"hash [0x%x]: [%v]",
11101111
walletPublicKeyHash,
11111112
err,
11121113
)
11131114
}
11141115

1115-
if walletChainData.State == StateClosed ||
1116-
walletChainData.State == StateTerminated {
1116+
isRegistered, err := n.chain.IsWalletRegistered(walletID)
1117+
if err != nil {
1118+
return fmt.Errorf(
1119+
"could not check if wallet is registered for wallet with ID "+
1120+
"[0x%x]: [%v]",
1121+
walletPublicKeyHash,
1122+
err,
1123+
)
1124+
}
1125+
1126+
if !isRegistered {
1127+
// If the wallet is no longer registered it means the wallet has
1128+
// been closed or terminated.
11171129
err := n.walletRegistry.archiveWallet(walletPublicKeyHash)
11181130
if err != nil {
11191131
return fmt.Errorf(
@@ -1124,7 +1136,9 @@ func (n *node) archiveClosedWallets() error {
11241136
}
11251137

11261138
logger.Infof(
1127-
"successfully archived wallet with public key hash [0x%x]",
1139+
"successfully archived wallet with ID [0x%x] and public key "+
1140+
"hash [0x%x]",
1141+
walletID,
11281142
walletPublicKeyHash,
11291143
)
11301144
}

0 commit comments

Comments
 (0)