/// <summary> /// Constructor /// </summary> /// <param name="apiCode">Specific apicode after create base url</param> /// <param name="serviceUrl">Specific for service url</param> public ClientApi(string apiCode, Uri baseUrl = null, Uri serviceUrl = null) { ApiCode = apiCode; ServiceUrl = serviceUrl; if (baseUrl == null && serviceUrl == null) { _blockchainApi = new BlockchainApiHelper(ApiCode); } else { if (BaseUrl != null) { BaseUrl = new BlockchainHttpClient(ApiCode, baseUrl.AbsoluteUri); // Only pro service = Create new wallet // second param autocreate baseUrl with https://blockchain.info _blockchainApi = new BlockchainApiHelper(ApiCode, BaseUrl, ServiceUrl.AbsoluteUri); // TODO mozna dopsat jeste dalsi metody } else { _blockchainApi = new BlockchainApiHelper(ApiCode, null, ServiceUrl.AbsoluteUri); } } }
public BlockchainProvider(string path, string credPath = "", IView view = null, bool useInternet = true) { if (view != null) { AddLoggingLink(view.PublishLogMessage); } BlockchainPath = path + "\\BlockchainData\\"; if (!Directory.Exists(BlockchainPath)) { Directory.CreateDirectory(BlockchainPath); } UseInternet = useInternet; foreach (Currency ccy in AvailableCryptoCurrencies) { FeesMemory[ccy] = new SortedDictionary <DateTime, Tuple <string, BitcoinValue> >(); } string apiKey = null; if (credPath != "") { List <string[]> credFile = StaticLibrary.LoadCsvFile(credPath + "BlockchainKeys.txt"); apiKey = credFile[0][0]; } BlockChainApi = new BlockchainApiHelper(apiKey); ReadFeesMemory(); foreach (Currency ccy in AvailableCryptoCurrencies) { UpdateMemory[ccy] = false; } }
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> CreateWallet() { try { BlockchainHttpClient httpClient = new BlockchainHttpClient(apicode, ApiURL); using (BlockchainApiHelper apiHelper = new BlockchainApiHelper(apicode, httpClient, "ApiURL", httpClient)) { var emailaddress = Session["Email_Address"] == null ? null : Session["Email_Address"].ToString(); var password = Session["Password"] == null ? null : Session["Password"].ToString(); if (string.IsNullOrEmpty(emailaddress) && string.IsNullOrEmpty(password)) { return(RedirectToAction("Login", "Account")); } else { WalletDetail ObjWalletViewModel = new WalletDetail(); var userid = db.AspNetUsers.Where(w => w.Email == emailaddress).Select(s => s.Id).FirstOrDefault(); CreateWalletResponse walletResponse = await apiHelper.walletCreator.CreateAsync(password, null, null, emailaddress); //apiHelper.walletCreator.CreateAsync("Kindle@123"); ObjWalletViewModel.GuidIdentifier = walletResponse.Identifier; ObjWalletViewModel.UserId = userid; ObjWalletViewModel.Address = walletResponse.Address; db.WalletDetails.Add(ObjWalletViewModel); db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception ex) { throw; } }
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")); }
public async void ToBtc_FromUs_HasValue() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { double btcValue = await apiHelper.ExchangeRateExplorer.ToBtcAsync("USD", 1000); Assert.True(btcValue > 0); } }
public async void GetStatistics_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { StatisticsResponse statisticsResponse = await apiHelper.StatisticsExplorer.GetAsync(); Assert.NotNull(statisticsResponse); } }
public async void GetPools_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { var chartResponse = await apiHelper.statisticsExplorer.GetPoolsAsync(); Assert.NotNull(chartResponse); } }
public async void GetUnconfirmedTransaction_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { ReadOnlyCollection <Transaction> unconfirmedTransactions = await apiHelper.BlockExpolorer.GetUnconfirmedTransactionsAsync(); Assert.NotNull(unconfirmedTransactions); } }
public async void GetLatestBlock_NotNull() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { LatestBlock latestBlock = await apiHelper.BlockExpolorer.GetLatestBlockAsync(); Assert.NotNull(latestBlock); } }
public async void GetAddress_BadParameters_ArgumentException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetBase58AddressAsync(""); } }); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetBase58AddressAsync("some-address", 60); } }); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetBase58AddressAsync("some-address", offset: -1); } }); await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetMultiAddressAsync(new List <string>()); } }); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetMultiAddressAsync(new List <string>() { "address" }, offset: -1); } }); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetMultiAddressAsync(new List <string>() { "address" }, 101); } }); }
public async void GetAddress_NegativeTransactions_ArgumentOutOfRangeException() { await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.BlockExpolorer.GetAddressAsync("test", -1); } }); }
public async void CreateWallet_NullApiCode_ArgumentNullException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.WalletCreator.Create("password"); } }); }
public async void GetBlocks_ByPool_IsValid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { const string poolName = "AntPool"; ReadOnlyCollection <SimpleBlock> receivedBlocks = await apiHelper.blockExplorer.GetBlocksByPoolNameAsync(poolName); Assert.NotNull(receivedBlocks); } }
public async void ToBtc_NegativeValue_ArgumentOutOfRangeException() { await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.exchangeRateExplorer.ToBtcAsync("USD", -1); } }); }
public async void GetBlocks_ByPool_IsValid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { const string poolName = "AntPool"; ReadOnlyCollection <SimpleBlock> receivedBlocks = await apiHelper.BlockExpolorer.GetBlocksAsync(poolName); receivedBlocks.ShouldNotBeNull(); } }
public async void GetTicker_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { Dictionary <string, Currency> currencies = await apiHelper.ExchangeRateExplorer.GetTickerAsync(); Assert.NotNull(currencies); Assert.True(currencies.Count > 0); } }
public async void GetBlocksByHeight_BadParameters_ArgumentException() { await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetBlocksAtHeightAsync(-1); } }); }
public async void CreateWallet_BadCredentials_ServerApiException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { await apiHelper.walletCreator.CreateAsync("badpassword"); } }); }
public async void GetTransaction_ByIndex_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { Transaction knownTransaction = ReflectionUtil.DeserializeFile <Transaction>("single_transaction"); Transaction receivedTransaction = await apiHelper.BlockExpolorer.GetTransactionByIndexAsync(knownTransaction.Index); knownTransaction.ShouldBe(receivedTransaction); } }
public async void GetXpub_NullXpub_ArgumentNullException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.blockExplorer.GetXpub(null); } }); }
public async void GetAddress_NullHash_ArgumentNullException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.BlockExpolorer.GetAddressAsync(null); } }); }
public async void GetTransaction_BadIds_ArgumentExecption() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.transactionBroadcaster.PushTransactionAsync(null); } }); }
public async void FromBtc_ToGbp_HasValue() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { var btc = new BitcoinValue(new decimal(0.4)); double btcValue = await apiHelper.exchangeRateExplorer.FromBtcAsync(btc, "GBP"); Assert.True(btcValue > 0); } }
public async void GetXpub_IsValid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { const string xpub = "xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn"; Xpub response = await apiHelper.blockExplorer.GetXpub(xpub); Assert.NotNull(response); } }
public async void GetChart_WrongName_OutOfRangeException() { await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.statisticsExplorer.GetChartAsync("wrong-chart-name"); } }); }
public async void GetUnspent_ByAdress_Valid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { const string address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"; ReadOnlyCollection <UnspentOutput> outputs = await apiHelper.blockExplorer.GetUnspentOutputsAsync(new List <string>() { address }); Assert.NotNull(outputs); } }
public async void CreateWallet_NullPassword_ArgumentNullException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper("APICODE")) { await apiHelper.walletCreator.CreateAsync(null); } }); }
public async void ToBtc_NullCurrency_ArgumentNullException() { await Assert.ThrowsAsync <ArgumentNullException>(async() => { using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper()) { await apiHelper.exchangeRateExplorer.ToBtcAsync(null, 1); } }); }
public async void GetAddress_Hash160_IsValid() { using (BlockchainApiHelper apiHelper = new BlockchainApiHelper()) { const string addr = "79b9dd10b535eee0d23530efbd99eb77f1f86a6e"; var addrResponse = await apiHelper.blockExplorer.GetHash160AddressAsync(addr); Assert.NotNull(addrResponse); } }