Пример #1
0
        public PaymentResponse Send(string recipientWallet, decimal amount, decimal fee)
        {
            BlockchainApiSettings blockchainApiSettings = GetSettings();
            var httpClient = new BlockchainHttpClient(blockchainApiSettings.ApiKey, blockchainApiSettings.ServiceUrl);

            using (BlockchainApiHelper apiHelper = new BlockchainApiHelper(apiCode: blockchainApiSettings.ApiKey,
                                                                           serviceUrl: blockchainApiSettings.ServiceUrl, serviceHttpClient: httpClient))
            {
                try
                {
                    BitcoinValue _fee    = BitcoinValue.FromBtc(fee);
                    BitcoinValue _amount = BitcoinValue.FromBtc(amount);

                    Wallet wallet = apiHelper.InitializeWallet(blockchainApiSettings.WalletID,
                                                               blockchainApiSettings.WalletPassword);
                    PaymentResponse payment = wallet.SendAsync(recipientWallet, _amount, fee: _fee).Result;

                    return(payment);
                }
                catch (ClientApiException e)
                {
                    throw new ArgumentException("Blockchain exception: " + e.Message);
                }
            }
        }
        public async Task <ActionResult> SendPayment_SendBtc_NoFreeOutputs()
        {
            var emailaddress  = Session["Email_Address"];
            var walletdetails = db.AspNetUsers.Join(db.WalletDetails, u => u.Id, uir => uir.UserId, (u, uir) => new { u, uir }).Where(w => w.u.Email == emailaddress.ToString()).Select(s => new { s.uir.Address, s.uir.GuidIdentifier }).FirstOrDefault();



            string WALLET_ID       = walletdetails.GuidIdentifier;
            string Form_Address    = walletdetails.Address;
            string WALLET_PASSWORD = "******";
            string FIRST_ADDRESS   = "16RQNCzpCQAyTQkj2Bp43vuBu5D822bGAn";



            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() =>
            {
                BlockchainHttpClient httpClient = new BlockchainHttpClient(apicode, ApiURL);
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper(apicode, httpClient, ApiURL, httpClient))
                {
                    Wallet wallet = apiHelper.InitializeWallet(WALLET_ID, WALLET_PASSWORD);
                    await wallet.SendAsync(FIRST_ADDRESS, BitcoinValue.FromBtc(1), Form_Address, BitcoinValue.FromBtc(0));
                }
            });

            Assert.Contains("No free", apiException.Message);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async void SendPayment_SendBtc_NoFreeOutputs()
        {
            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() => {
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
                {
                    WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                    await walletHelper.SendAsync(WalletTests.FIRST_ADDRESS, BitcoinValue.FromBtc(1));
                }
            });

            Assert.Contains("No free", apiException.Message);
        }
Пример #4
0
        public void BitcoinValue_Add_Valid()
        {
            const decimal btc1   = 1.23456789m;
            const decimal btc2   = 9.87654321m;
            BitcoinValue  value1 = BitcoinValue.FromBtc(btc1);
            BitcoinValue  value2 = BitcoinValue.FromBtc(btc2);
            BitcoinValue  value3 = value1 + value2;

            Assert.Equal(value3.Btc, btc1 + btc2);

            value3 = value2 + value1;
            Assert.Equal(value3.Btc, btc1 + btc2);
        }
Пример #5
0
        public async void SendPayment_SendMultiBtc_NoFreeOutputs()
        {
            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() => {
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
                {
                    WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                    Dictionary <string, BitcoinValue> recipients = new Dictionary <string, BitcoinValue>()
                    {
                        { "17VYDFsDxBMovM1cKGEytgeqdijNcr4L5", BitcoinValue.FromBtc(1) }
                    };
                    await walletHelper.SendManyAsync(recipients);
                }
            });

            Assert.Contains("No free", apiException.Message);
        }
Пример #6
0
        public void BitcoinValue_ConvertBtc_ValidConversion()
        {
            const decimal btc          = 1.23456789m;
            BitcoinValue  bitcoinValue = BitcoinValue.FromBtc(btc);

            Assert.Equal(bitcoinValue.Satoshis, btc * 100000000m);
            Assert.Equal(bitcoinValue.Bits, btc * 1000000m);
            Assert.Equal(bitcoinValue.MilliBits, btc * 1000m);
            Assert.Equal(bitcoinValue.Btc, btc);

            bitcoinValue = new BitcoinValue(btc);
            Assert.Equal(bitcoinValue.Satoshis, btc * 100000000m);
            Assert.Equal(bitcoinValue.Bits, btc * 1000000m);
            Assert.Equal(bitcoinValue.MilliBits, btc * 1000m);
            Assert.Equal(bitcoinValue.Btc, btc);
        }
Пример #7
0
        public void BitcoinValue_Subtract_Valid()
        {
            const decimal btc1   = 1.23456789m;
            const decimal btc2   = 9.87654321m;
            BitcoinValue  value1 = BitcoinValue.FromBtc(btc1);
            BitcoinValue  value2 = BitcoinValue.FromBtc(btc2);
            BitcoinValue  value3 = value1 - value2;

            Assert.Equal(value3.Btc, btc1 - btc2);

            value3 = value2 - value1;
            Assert.Equal(value3.Btc, btc2 - btc1);
            Assert.NotEqual(value3.Btc, btc1 - btc2);

            value3 = value1 - value1;
            Assert.Equal(value3.Btc, 0);
        }
Пример #8
0
        public async void Send_BadParameters_ArgumentExceptions()
        {
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendAsync(null, BitcoinValue.Zero);
                }
            });

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendAsync("Test", BitcoinValue.FromBtc(-1));
                }
            });
        }
Пример #9
0
        public async Task <IHttpActionResult> SendBtc([FromBody] BitcoinRequest request)
        {
            var operations = new BitcoinOperations(WalletId, WalletPassword1, WalletPassword2);

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            BitcoinQuery query = Mapper.Map <BitcoinRequest, BitcoinQuery>(request);

            var bitcoinSend = await operations.Send(query.Address, BitcoinValue.FromBtc(query.Amount), WalletId);

            // This is fake bitcoin service but can be use as real

            if (bitcoinSend.TxHash != null)
            {
                await _dbExecutor.SaveTransactions(query);
            }

            return(Ok());
        }
Пример #10
0
        public void BitcoinValue_ToString_Valid()
        {
            BitcoinValue value = BitcoinValue.FromBtc(1.34567m);

            Assert.Equal(value.ToString(), "1.34567");
        }