fix(storage): acquire wallet lock before load and before CloseWallet

Three improvements to WalletLock integration:

1. OpenExisting acquires the lock before decrypting the file — no point
   attempting a potentially expensive PBKDF2 derivation for a wallet
   already held by another instance.

2. OpenFromPath acquires the lock before CloseWallet — if the new wallet
   is unavailable, the current session stays intact instead of being
   silently destroyed.

3. OpenLoaded now receives an already-acquired WalletLock from the caller
   instead of acquiring it internally; TryAcquireWalletLock is removed.
   Callers that fail to open (wrong password, I/O error) dispose the lock
   in their catch blocks.

Also fix CoinAmount.Of() to throw ArgumentException for unknown units
instead of silently falling back to PLM.
This commit is contained in:
2026-06-13 20:50:17 +02:00
parent 008e9c395a
commit 58645bd7a7
2 changed files with 30 additions and 23 deletions
+3 -2
View File
@@ -16,10 +16,11 @@ public static class CoinAmount
/// <summary>(satoshi per unità, decimali mostrati) di ciascuna unità.</summary>
private static (long Factor, int Decimals) Of(string unit) => unit switch
{
"PLM" => (SatsPerCoin, 8),
"mPLM" => (100_000, 5),
"µPLM" => (100, 2),
"sat" => (1, 0),
_ => (SatsPerCoin, 8), // PLM
"sat" => (1, 0),
_ => throw new ArgumentException($"Unknown coin unit: {unit}", nameof(unit)),
};
public static string Format(long sats, string unit = "") =>