/// <summary> /// Convert Money to decimal (same as ToDecimal) /// </summary> /// <param name="unit"></param> /// <returns></returns> public decimal ToUnit(MoneyUnit unit) { CheckMoneyUnit(unit, nameof(unit)); // overflow safe because (long / int) always fit in decimal // decimal operations are checked by default return((decimal)Satoshi / (int)unit); }
/// <summary> /// Initializes an instance of the <see cref="Vout"/> class. /// </summary> /// <param name="n">The index of the output.</param> /// <param name="txout">A <see cref="TxOut"/></param> /// <param name="network">The network where the transaction occured.</param> public Vout(int n, TxOut txout, Network network) { MoneyUnit moneyUnitBTC = new MoneyUnit("BTC", 100000000); this.N = n; this.Value = txout.Value.ToDecimal(moneyUnitBTC); this.ScriptPubKey = new ScriptPubKey(txout.ScriptPubKey, network); }
private static void CheckMoneyUnit(MoneyUnit value, string paramName) { var typeOfMoneyUnit = typeof(MoneyUnit); if (!Enum.IsDefined(typeOfMoneyUnit, value)) { throw new ArgumentException("Invalid value for MoneyUnit", paramName); } }
public Money(long amount, MoneyUnit unit) { // sanity check. Only valid units are allowed CheckMoneyUnit(unit, nameof(unit)); checked { Satoshi = amount * (int)unit; } }
public static int GetMaximumPriceLimit(MoneyUnit unit) { if (unit == MoneyUnit.UnSpecified) { throw new BusinessRuleBrokenException("Money Unit is not defined !"); } return(_maximumPriceLimits[unit]); }
public Money(decimal amount, MoneyUnit unit) { // sanity check. Only valid units are allowed CheckMoneyUnit(unit, nameof(unit)); checked { var satoshi = amount * (int)unit; Satoshi = (long)satoshi; } }
public Price(int amount, MoneyUnit unit) { if (MoneyUnit.UnSpecified == unit) { throw new BusinessRuleBrokenException("You must supply a valid money unit!"); } Amount = amount; Unit = unit; }
public decimal GetBalance(MoneyUnit unit = MoneyUnit.BTC) { WalletTransactionsCollection transactions = null; Money amount = Money.Zero; try { transactions = _wallet.GetTransactions(); } catch { } if (transactions != null && transactions.Count > 0) { amount = transactions.Summary.Spendable.Amount; } return(amount.ToUnit(unit)); }
/// <summary> /// Convert Money to decimal (same as ToUnit) /// </summary> /// <param name="unit"></param> /// <returns></returns> public decimal ToDecimal(MoneyUnit unit) { return(ToUnit(unit)); }
public static Money FromUnit(decimal amount, MoneyUnit unit) { return(new Money(amount, unit)); }
public Asset(string id, int accuracy, MoneyUnit unit) => (Id, Accuracy, Unit) = (id, accuracy, unit);
public static string GetSymbol(MoneyUnit moneyUnit) { return(_symbols[moneyUnit].ToString()); }