Example #1
0
 /// <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);
 }
Example #2
0
        /// <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);
        }
Example #3
0
        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);
            }
        }
Example #4
0
 public Money(long amount, MoneyUnit unit)
 {
     // sanity check. Only valid units are allowed
     CheckMoneyUnit(unit, nameof(unit));
     checked
     {
         Satoshi = amount * (int)unit;
     }
 }
Example #5
0
        public static int GetMaximumPriceLimit(MoneyUnit unit)
        {
            if (unit == MoneyUnit.UnSpecified)
            {
                throw new BusinessRuleBrokenException("Money Unit is not defined !");
            }

            return(_maximumPriceLimits[unit]);
        }
Example #6
0
 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;
        }
Example #8
0
        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));
        }
Example #9
0
 /// <summary>
 /// Convert Money to decimal (same as ToUnit)
 /// </summary>
 /// <param name="unit"></param>
 /// <returns></returns>
 public decimal ToDecimal(MoneyUnit unit)
 {
     return(ToUnit(unit));
 }
Example #10
0
 public static Money FromUnit(decimal amount, MoneyUnit unit)
 {
     return(new Money(amount, unit));
 }
Example #11
0
 public Asset(string id, int accuracy, MoneyUnit unit) => (Id, Accuracy, Unit) = (id, accuracy, unit);
 public static string GetSymbol(MoneyUnit moneyUnit)
 {
     return(_symbols[moneyUnit].ToString());
 }