// GET: /<controller>/
        public WalletCreator CreateWallet()
        {
            var httpClient    = new BlockchainHttpClient("api-code", "http://127.0.0.1:3000");
            var walletCreator = new WalletCreator(httpClient);

            return(walletCreator);
        }
Beispiel #2
0
        /// <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);
                }
            }
        }
Beispiel #3
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> 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"));
        }
        private async Task <decimal> GetResultOfTransaction(string transactionHash, string againstAddress)
        {
            using (var client = new BlockchainHttpClient())
            {
                var result = await client.GetAsync <long>($"q/txresult/{transactionHash}/{againstAddress}");

                return(BitcoinValue.FromSatoshis(result).GetBtc());
            }
        }
Beispiel #7
0
        public BlockchainInfoApi(BitcoinBasedCurrency currency)
        {
            _currency = currency ?? throw new ArgumentNullException(nameof(currency));

            var baseUrl = _currency.Network == Network.Main
                 ? "https://blockchain.info/"
                 : "https://testnet.blockchain.info/";

            _client   = new BlockchainHttpClient(apiCode: _apiCode, uri: baseUrl);
            _explorer = new BlockchainApiHelper(apiCode: _apiCode, baseHttpClient: new BlockchainHttpClient(uri: baseUrl)).blockExplorer;
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            try
            {
                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("config.json");
                Config = builder.Build();

                var httpClient    = new BlockchainHttpClient(Config["BlockChainInfo:ApiCode"], Config["BlockChainInfo:WalletServiceLink"]);
                var walletCreator = new WalletCreator(httpClient);
                CreateWalletResponse walletResponce = walletCreator.CreateAsync(Config["BlockChainInfo:MainPassword"], null, Config["BlockChainInfo:Label"]).Result;

                StreamWriter w = new StreamWriter(Config["WritePath"]);
                w.Write(JsonConvert.SerializeObject(walletResponce));
                w.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Beispiel #9
0
 public BitCoinUsdPriceProvider()
 {
     _blockchainHttpClient = new BlockchainHttpClient();
 }