Skip to content

Commit 88f3bf6

Browse files
committed
Simplified wallet archiving
1 parent ce85a89 commit 88f3bf6

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

Diff for: pkg/tbtc/node.go

+16-43
Original file line numberDiff line numberDiff line change
@@ -1097,59 +1097,32 @@ func processCoordinationResult(node *node, result *coordinationResult) {
10971097

10981098
// archiveClosedWallets archives closed or terminated wallets.
10991099
func (n *node) archiveClosedWallets() error {
1100-
getClosedWallets := func(walletPublicKeyHashes [][20]byte) (
1101-
closedWallets [][20]byte,
1102-
) {
1103-
for _, walletPublicKeyHash := range walletPublicKeyHashes {
1104-
walletChainData, err := n.chain.GetWallet(walletPublicKeyHash)
1105-
if err != nil {
1106-
// Continue if there was an error getting wallet data. Try to
1107-
// get as many closed wallets as possible.
1108-
logger.Errorf(
1109-
"could not get wallet data for wallet [0x%x]: [%v]",
1110-
walletPublicKeyHash,
1111-
err,
1112-
)
1113-
continue
1114-
}
1115-
1116-
if walletChainData.State == StateClosed ||
1117-
walletChainData.State == StateTerminated {
1118-
closedWallets = append(closedWallets, walletPublicKeyHash)
1119-
}
1120-
}
1121-
1122-
return
1123-
}
1124-
11251100
// Get all the wallets controlled by the node.
11261101
walletPublicKeys := n.walletRegistry.getWalletsPublicKeys()
11271102

1128-
walletPublicKeyHashes := [][20]byte{}
11291103
for _, walletPublicKey := range walletPublicKeys {
1130-
walletPublicKeyHashes = append(
1131-
walletPublicKeyHashes,
1132-
bitcoin.PublicKeyHash(walletPublicKey),
1133-
)
1134-
}
1135-
1136-
// Find the wallets that are closed.
1137-
closedWallets := getClosedWallets(walletPublicKeyHashes)
1138-
if len(closedWallets) == 0 {
1139-
logger.Infof("there are no closed wallets to archive")
1140-
return nil
1141-
}
1104+
walletPublicKeyHash := bitcoin.PublicKeyHash(walletPublicKey)
11421105

1143-
// Archive the closed wallets.
1144-
for _, walletPublicKeyHash := range closedWallets {
1145-
err := n.walletRegistry.archiveWallet(walletPublicKeyHash)
1106+
walletChainData, err := n.chain.GetWallet(walletPublicKeyHash)
11461107
if err != nil {
11471108
return fmt.Errorf(
1148-
"could not archive wallet with public key hash [0x%x]: [%v]",
1109+
"could not get wallet data for wallet [0x%x]: [%v]",
11491110
walletPublicKeyHash,
11501111
err,
11511112
)
1152-
} else {
1113+
}
1114+
1115+
if walletChainData.State == StateClosed ||
1116+
walletChainData.State == StateTerminated {
1117+
err := n.walletRegistry.archiveWallet(walletPublicKeyHash)
1118+
if err != nil {
1119+
return fmt.Errorf(
1120+
"could not archive wallet with public key hash [0x%x]: [%v]",
1121+
walletPublicKeyHash,
1122+
err,
1123+
)
1124+
}
1125+
11531126
logger.Infof(
11541127
"successfully archived wallet with public key hash [0x%x]",
11551128
walletPublicKeyHash,

0 commit comments

Comments
 (0)