Skip to content

Commit

Permalink
Added wallet archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Jun 6, 2024
1 parent 4e19c4d commit 849019d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/tbtc/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,45 @@ func (wr *walletRegistry) getWalletByPublicKeyHash(
return wallet{}, false
}

func (wr *walletRegistry) archiveWallet(

Check failure on line 159 in pkg/tbtc/registry.go

View workflow job for this annotation

GitHub Actions / client-lint

func (*walletRegistry).archiveWallet is unused (U1000)
walletPublicKeyHash [20]byte,
) error {
wr.mutex.Lock()
defer wr.mutex.Unlock()

var walletPublicKey *ecdsa.PublicKey

for _, value := range wr.walletCache {
if value.walletPublicKeyHash == walletPublicKeyHash {
// All signers belong to one wallet. Take the wallet public key from
// the first signer.
walletPublicKey = value.signers[0].wallet.publicKey
}
}

if walletPublicKey == nil {
logger.Infof(
"node does not control wallet with public key hash [0x%x]; "+
"quitting wallet archiving",
walletPublicKeyHash,
)
return nil
}

walletStorageKey := getWalletStorageKey(walletPublicKey)

// Archive the entire wallet storage.
err := wr.walletStorage.archiveWallet(walletStorageKey)
if err != nil {
return fmt.Errorf("could not archive wallet: [%v]", err)
}

// Remove the wallet from the wallet cache.
delete(wr.walletCache, walletStorageKey)

return nil
}

// walletStorage is the component that persists data of the wallets managed
// by the given node using the underlying persistence layer. It should be
// used directly only by the walletRegistry.
Expand Down Expand Up @@ -194,6 +233,19 @@ func (ws *walletStorage) saveSigner(signer *signer) error {
return nil
}

func (ws *walletStorage) archiveWallet(walletStoragePath string) error {

Check failure on line 236 in pkg/tbtc/registry.go

View workflow job for this annotation

GitHub Actions / client-lint

func (*walletStorage).archiveWallet is unused (U1000)
err := ws.persistence.Archive(walletStoragePath)
if err != nil {
return fmt.Errorf(
"could not archive wallet storage using the "+
"underlying persistence layer: [%w]",
err,
)
}

return nil
}

// loadSigners loads all signers stored using the underlying persistence layer.
// This function should not be called from any other place than walletRegistry.
func (ws *walletStorage) loadSigners() map[string][]*signer {
Expand Down

0 comments on commit 849019d

Please sign in to comment.