feat(wallet): coin selection, tx factory, wallet loader

This commit is contained in:
2026-06-11 10:47:40 +02:00
parent 4d2ae1fd13
commit 3d6597a3b2
3 changed files with 213 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
using System.Globalization;
namespace PalladiumWallet.Core.Wallet;
/// <summary>
/// Conversione satoshi ↔ unità coin (8 decimali) per visualizzazione e input.
/// Si lavora sempre in satoshi internamente; la stringa è solo presentazione.
/// </summary>
public static class CoinAmount
{
public const long SatsPerCoin = 100_000_000;
public static string Format(long sats, string unit = "") =>
(sats / (decimal)SatsPerCoin).ToString("0.00000000", CultureInfo.InvariantCulture)
+ (unit.Length > 0 ? " " + unit : "");
/// <summary>Parsa un importo in coin (punto o virgola decimale) in satoshi.</summary>
public static bool TryParseCoins(string text, out long sats)
{
sats = 0;
text = text.Trim().Replace(',', '.');
if (!decimal.TryParse(text, NumberStyles.Number, CultureInfo.InvariantCulture, out var coins)
|| coins < 0)
return false;
try
{
sats = (long)(coins * SatsPerCoin);
}
catch (OverflowException)
{
return false;
}
return true;
}
}