Exemplo n.º 1
0
        public Task <BitCoin> GetAddressBalance(BitcoinPubKeyAddress address)
        {
            var tcs = new TaskCompletionSource <BitCoin>();


            var addressModelTask = GetAddressBalanceModel(address);

            addressModelTask.ContinueWith((task, bm) =>
            {
                var satoshi = task.Result.Operations.Where(x => x.Confirmations >= minimumConfirmations)
                              .Sum(x => x.Amount.Satoshi);
                var balance = BitCoin.FromSatoshi((ulong)satoshi);
                tcs.SetResult(balance);
            }, TaskContinuationOptions.NotOnFaulted);


            addressModelTask.ContinueWith((task, bm) =>
            {
                if (task.IsFaulted && task.Exception != null)
                {
                    tcs.TrySetException(task.Exception);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);

            return(tcs.Task);
        }
Exemplo n.º 2
0
        private async Task <KeysWithCoins> LoadInputTransactionsUntilAmount(BitCoin amountToSpent)
        {
            var result = new KeysWithCoins();

            var accumulatedOnTransactions = BitCoin.Zero;

            foreach (var secret in secrets)
            {
                var client       = new QBitNinjaClient(network);
                var balanceModel =
                    await client.GetBalance(new BitcoinPubKeyAddress(secret.PubKey.ToString(Network.Main)), true);


                foreach (var operation in balanceModel.Operations.Where(t =>
                                                                        t.Amount > 0 && t.Confirmations >= MinConfirmations))
                {
                    accumulatedOnTransactions = accumulatedOnTransactions + BitCoin.FromSatoshi(operation.Amount);
                    result.Append(secret, operation.ReceivedCoins);

                    if (accumulatedOnTransactions >= amountToSpent)
                    {
                        return(result);
                    }
                }
            }

            throw new PrepareTransferException("Not enough coins");
        }
Exemplo n.º 3
0
        public void OneBtcShouldBeMoreThan100Satoshi()
        {
            var oneBtcValue  = BitCoin.FromBtc(1);
            var satoshiValue = BitCoin.FromSatoshi(100);

            oneBtcValue.Should().BeGreaterThan(satoshiValue);
        }
Exemplo n.º 4
0
        public void AddingTwoBitcoinsShouldBeCorrect()
        {
            var oneBtcValue = BitCoin.FromBtc(1);
            var sum         = oneBtcValue + BitCoin.FromBtc(1);

            sum.Should().Be(BitCoin.FromBtc(2));
        }
        /// <summary>
        /// Доступен ли способ оплаты
        /// </summary>
        /// <param name="PaymentTypeId"></param>
        /// <returns></returns>
        public bool PaymentTypeTestConnection(int PaymentTypeId)
        {
            ICryptoCurrency cryptoCurrency;

            //способ оплаты при получении. не трубует проверки
            if (ConstantVariable.PaymentTypeVariable.PaymentOnReceipt == PaymentTypeId)
            {
                return(true);
            }

            //есть ли настройки для выбранного метода оплаты
            var PaymentTypeCfg = db.PaymentTypeConfig.Where(p => p.PaymentId == PaymentTypeId).LastOrDefault();

            if (PaymentTypeCfg == null)
            {
                return(false);
            }

            if (PaymentTypeCfg != null && PaymentTypeCfg.PaymentId == ConstantVariable.PaymentTypeVariable.QIWI ||
                PaymentTypeCfg != null && PaymentTypeCfg.PaymentId == ConstantVariable.PaymentTypeVariable.DebitCardForYandexKassa)
            {
                return(true);
            }

            if (ConstantVariable.PaymentTypeVariable.Bitcoin == PaymentTypeId ||
                ConstantVariable.PaymentTypeVariable.BitcoinCash == PaymentTypeId ||
                ConstantVariable.PaymentTypeVariable.Litecoin == PaymentTypeId ||
                ConstantVariable.PaymentTypeVariable.Doge == PaymentTypeId)
            {
                if (PaymentTypeCfg != null)
                {
                    cryptoCurrency = new BitCoin(PaymentTypeCfg.Login, PaymentTypeCfg.Pass, PaymentTypeCfg.Host, PaymentTypeCfg.Port);

                    //подключаемся к ноде и вытаскиваем инфу
                    var block = cryptoCurrency.GetInfo <Services.BitCoinCore.GetInfo>();

                    if (block != null && block.result != null && block.result.blocks > 0)
                    {
                        return(true);
                    }

                    else
                    {
                        return(false);
                    }
                }

                else
                {
                    return(false);
                }
            }

            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        public void LessComparatorOfBitCoinShouldWorkProper()
        {
            var oneBtc = BitCoin.FromBtc(1);
            var twoBtc = BitCoin.FromBtc(2);


            oneBtc.Should().BeLessThan(twoBtc);
            Assert.IsTrue(oneBtc < twoBtc);
        }
Exemplo n.º 7
0
        public void GreaterComparatorOfBitCoinShouldWorkProper()
        {
            var oneBtc = BitCoin.FromBtc(1);
            var twoBtc = BitCoin.FromBtc(2);


            twoBtc.Should().BeGreaterThan(oneBtc);
            Assert.IsTrue(twoBtc > oneBtc);
        }
Exemplo n.º 8
0
        public void SumOfBitcoinEnumerableShouldBe100500Satoshi()
        {
            var btcList = new List <BitCoin>()
            {
                BitCoin.FromSatoshi(100_000),
                BitCoin.FromSatoshi(500)
            };

            btcList.Sum(b => b).Should().Be(BitCoin.FromSatoshi(100_500));
        }
Exemplo n.º 9
0
        public void btcOutput()
        {
            StockMarket stockmarket = new StockMarket("MWSOY45W94DB1V3J");
            string      finalOutputString;



            try
            {
                List <BitCoin> GetBTCInfo = stockmarket.GetBitCoinInfo();

                BitCoin latestData = GetBTCInfo[0];


                string outputString = string.Format("The current open price of {0} in China is {1:C2}, highest it has been" +
                                                    "is {2:C2}, lower it has been is {3:C2}, close is {4}. The current open price of {5} in US is {6:C2}, highest it has been" +
                                                    "is {7:C2}, lower it has been is {8:C2}, close is {9}. Market Volume is {10}, and Market Cap is {11} BTC info is pulled at {12}, " +
                                                    "current time is {13:d} at {13:t}", latestData.GetType().Name, latestData.OpenCNY, latestData.HighCNY, latestData.LowCNY,
                                                    latestData.CloseCNY, latestData.GetType().Name, latestData.OpenUSD, latestData.HighUSD, latestData.LowUSD,
                                                    latestData.CloseUSD, latestData.Volume, latestData.MarketCap, latestData.Timestamp, DateTime.Now);
                finalOutputString = outputString;

                foreach (BitCoin bit in GetBTCInfo)
                {
                    string historicalString = String.Format("" +
                                                            "CNY Open: {1:C2} \r\n " +
                                                            "CNY Highest: {2:C2} \r\n " +
                                                            "CNY Lowest: {3:C2} \r\n " +
                                                            "CNY Close: {4} \r\n " +
                                                            "USD Open: {5:C2} \r\n " +
                                                            "USD Highest: {6:C2} \r\n " +
                                                            "USD Lowest: {7:C2} \r\n " +
                                                            "USD Close: {8} \r\n " +
                                                            "Market Volume: {9} \r\n " +
                                                            "Market Cap: {10} \r\n " +
                                                            "BTC info is pulled at:  {11}, \r\n  " +
                                                            "Current time: {12:d} at {12:t}", bit.GetType().Name, bit.OpenCNY,
                                                            bit.HighCNY, bit.LowCNY, bit.CloseCNY, latestData.OpenUSD, latestData.HighUSD, latestData.LowUSD,
                                                            latestData.CloseUSD, latestData.Volume, latestData.MarketCap, bit.Timestamp, DateTime.Now);

                    finalOutputString += "\r\n" + "\r\n" + historicalString;
                }

                resultBox.AppendText(finalOutputString);
                stockPriceBox.Text = latestData.OpenUSD.ToString();
            }
            catch (APICallLimitReachedException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception Eex)
            {
                MessageBox.Show(Eex.Message);
            }
        }
Exemplo n.º 10
0
        public void TwoSameBitcoinAmountShouldBeEqual()
        {
            //Arrange
            var oneBtcValue        = BitCoin.FromBtc(1);
            var anotherOneBtcValue = BitCoin.FromBtc(1);


            //Assert
            oneBtcValue.Should().Be(anotherOneBtcValue);
            Assert.IsTrue(oneBtcValue == anotherOneBtcValue);
        }
Exemplo n.º 11
0
        public void CallService()
        {
            var bitCoin = new BitCoin(_endpointBitcoin);

            using (SolidDocTestEntities db = new SolidDocTestEntities())
            {
                var bitcoinPriceHistory = new BitcoinPriceHistory();
                bitcoinPriceHistory.CreateDate = bitCoin.CreateDate;
                bitcoinPriceHistory.LastPrice  = bitCoin.LastPrice;
                bitcoinPriceHistory.LastChange = bitCoin.LastChange;
                bitcoinPriceHistory.Volume     = bitCoin.Volume;
                bitcoinPriceHistory.HighPrice  = bitCoin.HighPrice;
                bitcoinPriceHistory.LowPrice   = bitCoin.LowPrice;

                db.BitcoinPriceHistories.Add(bitcoinPriceHistory);
                db.SaveChanges();
            }
        }
Exemplo n.º 12
0
        private Payment CheckCryptoCurrency(Invoice invoice)
        {
            var config = db.PaymentTypeConfig.Where(p => p.PaymentId == invoice.PaymentTypeId).OrderByDescending(p => p.Id).FirstOrDefault();

            double balance = 0;

            if (config != null)
            {
                CryptoCurrency = new BitCoin(config.Login, config.Pass, config.Host, config.Port);
                balance        = CryptoCurrency.GetBalance(invoice.AccountNumber);

                if (balance >= invoice.Value)
                {
                    var transaction = CryptoCurrency.GetListTransactions <TransactionInfoList>();
                    var txinfo      = transaction.result.Where(t => t.address == invoice.AccountNumber).LastOrDefault();

                    if (txinfo != null && txinfo.confirmations >= ConfirmAmount) // нашли транзакцию. Проверям кол-во подтверждений
                    {
                        return(AddPayment(invoice.Id, txinfo.txid, balance, UnixTimeStampToDateTime(txinfo.timereceived)));
                    }

                    if (txinfo == null)
                    {
                        return(AddPayment(invoice.Id, "", balance, DateTime.Now));
                    }

                    return(null);
                }

                else
                {
                    return(null);
                }
            }

            else
            {
                return(null);
            }
        }
Exemplo n.º 13
0
 public void BasicPercentageCalculationsShouldWorkProperly()
 {
     BitCoin.FromSatoshi(100).TakePercent(Percent.Fifty).ShouldBeEquivalentTo(BitCoin.FromSatoshi(50));
     BitCoin.FromSatoshi(100).TakePercent(Percent.Zero).ShouldBeEquivalentTo(BitCoin.FromSatoshi(0));
 }
Exemplo n.º 14
0
        public void FiftyPercentFromHundredSatoshiShouldBeFiftySasoshi()
        {
            var amount = BitCoin.FromSatoshi(100).TakePercent(Percent.Fifty);

            amount.ShouldBeEquivalentTo(BitCoin.FromSatoshi(50));
        }
Exemplo n.º 15
0
        public void OnePercentFromHundredSatoshiShouldBeOneSatoshi()
        {
            var amount = BitCoin.FromSatoshi(100).TakePercent(Percent.One);

            amount.ShouldBeEquivalentTo(BitCoin.FromSatoshi(1));
        }
Exemplo n.º 16
0
        public void OnePercentFromOneSatoshiShouldBeZero()
        {
            var amount = BitCoin.FromSatoshi(1).TakePercent(Percent.One);

            amount.ShouldBeEquivalentTo(BitCoin.Zero);
        }
Exemplo n.º 17
0
        public static string FormatUsingExchangeInfo(this BitCoin b, BitcoinExchangeRecord s)
        {
            var balance = (b.ToBtc() * (decimal)s.sell).ToString("0.000");

            return($"{b} / {s.CurrencyCode}: ~{balance}{s.symbol}");
        }