Пример #1
0
        static void Main(string[] args)
        {
            var exp         = new BlockExplorer();
            var latestBlock = exp.GetLatestBlockAsync().Result;

            var apiCode    = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
            var httpClient = new ApiHttpClient(apiCode, "http://127.0.0.1:3000");

            using (ApiHelper apiHelper = new ApiHelper(apiCode: apiCode, serviceHttpClient: httpClient, serviceUrl: "http://127.0.0.1:3000/"))
            {
                var walletCreator = new Wallet.WalletCreator(httpClient);
                var walletCreated = walletCreator.CreateAsync("password").Result;

                var wallet      = apiHelper.InitializeWallet(walletCreated.Identifier, "password");
                var addressList = wallet.ListAddressesAsync().Result;
                var address     = wallet.GetAddressAsync(walletCreated.Address).Result;
                var balance     = wallet.GetBalanceAsync().Result;

                for (var i = 0; i < 3; i++)
                {
                    var addr = wallet.NewAddressAsync("Label " + i).Result;
                }
                var addressListFinal = wallet.ListAddressesAsync().Result;
            }

            Console.ReadLine();
        }
Пример #2
0
        public void GetBalanceTest()
        {
            IAddress provider = new BlockExplorer();
            Decimal  actual   = provider.GetBalance("1CbHR646cj6jMKMav1VR66aW2NXuBFag4b", 6);

            Assert.AreEqual(actual, 0);
        }
Пример #3
0
        public async void GetBalanceTest()
        {
            var explorer = new BlockExplorer("localhost:3001");
            var balance  = await explorer.GetAccountBalance(1, 10);

            Console.WriteLine("{0}", balance);
        }
Пример #4
0
        private async Task <object> IfLatestBlock(object obj, BlockExplorer explorer)
        {
            var latestBlock = obj as LatestBlock;

            if (latestBlock == null)
            {
                return(obj);
            }
            return(await explorer.GetBlockByHashAsync(latestBlock.Hash));
        }
Пример #5
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;
        }
Пример #6
0
        /// <summary>
        /// NEW!!  So far alright?
        /// </summary>
        public void SegwitTestNet()
        {
            //The faucet: https://testnet.manu.backend.hamburg/faucet
            //https://bitcoin.stackexchange.com/questions/59231/how-to-sign-a-segwit-transaction-via-nbitcoin
            var           net      = NBitcoin.Network.TestNet;
            BlockExplorer explorer = new BlockExplorer("https://testnet.blockexplorer.com/");
            HDWallet      wallet   = new HDWallet("seed12345678ryan12345678", net);
            uint          path     = 0;
            var           extkey   = wallet.GetPrivateKey(path);
            Key           k        = extkey.PrivateKey;

            //This gives you a Bech32 address (currently not really interoperable in wallets, so you need to convert it into P2SH)
            var address = k.PubKey.WitHash.GetAddress(net);

            var p2sh = address.GetScriptAddress();
            //p2sh is now an interoperable P2SH segwit address

            //SENT TO: 2NGSoYM3yLi9SXvZc5yYcSwHWyCWzgBrP9X
            //TXID 1397a4cc480879eae604ce871c47a4d690c6ea6a6dcfd7e38d95f31b81593556

            var response = explorer.GetUnspent(p2sh.ToString());
            List <ExplorerUnspent> unspent      = response.Convert <List <ExplorerUnspent> >();
            List <Transaction>     transactions = new List <Transaction>();

            foreach (var item in unspent)
            {
                string           txcontent  = "{\"txid\":\"6636b3fedb57be81232f92f80fa8d3df9a0f07305af2c7f705a7f353e516b1d7\",\"version\":1,\"locktime\":0,\"vin\":[{\"txid\":\"50b7d9a5fa1281e7020fa8a152835756e0d57d6b4d634b4251ab500e8630bc3e\",\"vout\":1,\"scriptSig\":{\"asm\":\"0014a16f4ba22e84c364ec4f8fe19d8a48762156b41e\",\"hex\":\"160014a16f4ba22e84c364ec4f8fe19d8a48762156b41e\"},\"sequence\":4294967295,\"n\":0,\"addr\":\"2N9viNVJ5MsAM8MXdUuATDwKeMjMLQkaXyR\",\"valueSat\":193987962850,\"value\":1939.8796285,\"doubleSpentTxID\":null}],\"vout\":[{\"value\":\"2.00000000\",\"n\":0,\"scriptPubKey\":{\"hex\":\"a9142f672b3ea4af55d9da43e507e3c060d2e34521ba87\",\"asm\":\"OP_HASH160 2f672b3ea4af55d9da43e507e3c060d2e34521ba OP_EQUAL\",\"addresses\":[\"2MwZsLbuB328gxHRfr1VDrfDrK6aWicQcAW\"],\"type\":\"scripthash\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null},{\"value\":\"1937.87862850\",\"n\":1,\"scriptPubKey\":{\"hex\":\"a914859695c2cb37ee30bf6a18943c8c27a3ac0e6faa87\",\"asm\":\"OP_HASH160 859695c2cb37ee30bf6a18943c8c27a3ac0e6faa OP_EQUAL\",\"addresses\":[\"2N5RaFdK3rgsNayXnkTQaSLKVBB3brW7G4m\"],\"type\":\"scripthash\"},\"spentTxId\":\"892e6facc4fc596852d41af367dd41f7a7ec1b11a319a202bc0d4c5b8f792f2f\",\"spentIndex\":0,\"spentHeight\":1255964}],\"blockhash\":\"000000000007dbc3ffd03559f2192b299bc0c20aa0aea8e1939f2731e01103e8\",\"blockheight\":1255946,\"confirmations\":123,\"time\":1514228293,\"blocktime\":1514228293,\"valueOut\":1939.8786285,\"size\":138,\"valueIn\":1939.8796285,\"fees\":0.001}";
                ExplorerResponse txResponse = explorer.GetTransaction(item.txid);
                RawFormat        format     = RawFormat.Satoshi;
                var tx = Transaction.Parse(txResponse.data, format, net);
                transactions.Add(tx);
            }
            //For spending, it works the same as a a normal P2SH
            //You need to get the ScriptCoin, the RedeemScript of you script coin should be k.PubKey.WitHash.ScriptPubKey.            var redeemScript = k.PubKey.WitHash.ScriptPubKey;
            var         redeemScript = k.PubKey.WitHash.ScriptPubKey;
            Transaction received     = transactions[0];
            ScriptCoin  coin         = received.Outputs.AsCoins().First().ToScriptCoin(redeemScript);
            //1397a4cc480879eae604ce871c47a4d690c6ea6a6dcfd7e38d95f31b81593556

            BitcoinAddress     destination = BitcoinAddress.Create("2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF"); //the faucet return address
            TransactionBuilder builder     = new TransactionBuilder();

            builder.AddCoins(coin);
            builder.AddKeys(k);
            builder.Send(destination, Money.Coins(1.99m));
            builder.SendFees(Money.Coins(0.001m));
            builder.SetChange(p2sh);
            var signedTx = builder.BuildTransaction(true);

            Console.WriteLine(signedTx.ToHex());
            string x = ";;";
            //Assert.True(builder.Verify(signedTx));
        }
 public Transaction[] GetReceivedTransactions(Script scriptPubKey)
 {
     if (scriptPubKey == null)
     {
         throw new ArgumentNullException(nameof(scriptPubKey));
     }
     return
         (BlockExplorer.GetTransactionsAsync(scriptPubKey, false).GetAwaiter().GetResult()
          .Where(t => t.Transaction.Outputs.Any(o => o.ScriptPubKey == scriptPubKey))
          .Select(t => t.Transaction)
          .ToArray());
 }
Пример #8
0
        public async void PrepareTxTest()
        {
            var explorer = new BlockExplorer("localhost:3001");
            await explorer.CancelUnsignedTx(1);

            var tx = await explorer.PrepareUnsignedTx(1, "ztestsapling1zhu3ppsnhhjt0p262cynnshdduucrq4eu73fp65mwyvhn0nr2phvh9n0alym9huzzvrxjvuaqgd", 1, 1000000);

            var formatter = new JsonFormatter(JsonFormatter.Settings.Default);
            var txStr     = formatter.Format(tx);
            await explorer.CancelUnsignedTx(tx.Id);

            Console.WriteLine(">> {0}", txStr);
        }
Пример #9
0
        private async Task <object> DoAction(string paramValue, MethodInfo action)
        {
            var explorer  = new BlockExplorer();
            var param     = action.GetParameters().FirstOrDefault();
            var paramsObj = param == null ? new object[] { } : new[] { ConvertValue(paramValue, param.ParameterType) };
            var task      = action.Invoke(explorer, paramsObj) as Task;
            await task.ConfigureAwait(false);

            var resultProperty = task.GetType().GetProperty("Result");
            var obj            = resultProperty.GetValue(task);

            obj = IfCollection(obj);
            obj = await IfLatestBlock(obj, explorer);

            return(obj);
        }
Пример #10
0
        public ApiHelper(string apiCode = null, IHttpClient baseHttpClient = null, string serviceUrl = null, IHttpClient serviceHttpClient = null)
        {
            if (baseHttpClient == null)
            {
                baseHttpClient = new ApiHttpClient(apiCode);
            }
            else
            {
                this.baseHttpClient = baseHttpClient;
                if (apiCode != null)
                {
                    baseHttpClient.ApiCode = apiCode;
                }
            }

            if (serviceHttpClient == null && serviceUrl != null)
            {
                serviceHttpClient = new ApiHttpClient(apiCode, serviceUrl);
            }
            else if (serviceHttpClient != null)
            {
                this.serviceHttpClient = serviceHttpClient;
                if (apiCode != null)
                {
                    serviceHttpClient.ApiCode = apiCode;
                }
            }
            else
            {
                serviceHttpClient = null;
            }

            this.blockExplorer          = new BlockExplorer(baseHttpClient);
            this.transactionBroadcaster = new TransactionPusher(baseHttpClient);
            this.exchangeRateExplorer   = new ExchangeRateExplorer(baseHttpClient);
            this.statisticsExplorer     = new StatisticsExplorer(new ApiHttpClient("https://api.blockchain.info"));

            if (serviceHttpClient != null)
            {
                walletCreator = new WalletCreator(serviceHttpClient);
            }
            else
            {
                walletCreator = null;
            }
        }
Пример #11
0
        public async void SignTest()
        {
            var signer   = new Signer("localhost:3002");
            var assembly = Assembly.GetExecutingAssembly();
            var reader   = new StreamReader(assembly.GetManifestResourceStream("ZcashLib.Tests.tx.json"));
            var txJson   = reader.ReadToEnd();
            var parser   = new JsonParser(JsonParser.Settings.Default);
            var tx       = parser.Parse <Zams.UnsignedTx>(txJson);

            var sk       = "secret-extended-key-test1qtcgwxn8yl3qzqxjhr937awugvs3gl4hrpx6u7258l3pfpz0nuu8kx090rxrx33nyecgundmrr2nz788yw9tt43dy5zlxfhkw08g84vxu7jkxenj40ysyww5gupnxgt47jeywwca7pcskyj3cqc0kwyj66ejfhsd8jaz8hsyrqqyefz83daf2gvtvtpqkrg7ahzym0m674m4xmkc739696ptmql968ecdsr5us6pcud5dl6wurc78jer56c57c5eqktp0dpvjuty2xgdyge6r";
            var signedTx = await signer.SignTx(sk, tx);

            var explorer = new BlockExplorer("localhost:3001");
            var res      = await explorer.BroadcastSignedTx(signedTx);

            Console.WriteLine(res);
        }
Пример #12
0
        private double GetStoredBtc()
        {
            double storedBtc = 0;

            if (!Directory.Exists(WorkFolderPath))
            {
                Directory.CreateDirectory(WorkFolderPath);
            }
            if (File.Exists(FilePathNotEmptyAddresses))
            {
                File.Delete(FilePathNotEmptyAddresses);
            }
            using (StreamWriter sw = File.CreateText(FilePathNotEmptyAddresses))
            {
                try
                {
                    var blockExplorer = new BlockExplorer();
                    foreach (var a in File.ReadAllLines(FilePathAddresses))
                    {
                        long currAddrSatoshi = blockExplorer.GetAddress(a).FinalBalance;

                        if (currAddrSatoshi > 0)
                        {
                            storedBtc += (double)currAddrSatoshi / 100000000;
                            foreach (var pubsec in File.ReadAllLines(FilePathSecretKeys))
                            {
                                if (pubsec.StartsWith(a))
                                {
                                    sw.WriteLine(pubsec);
                                }
                            }
                            sw.Flush();
                        }
                    }
                }
                catch (APIException e)
                {
                    MessageBox.Show(this, @"Blockchain exception: " + e.Message);
                }
            }

            return(storedBtc);
        }
Пример #13
0
        private async void GetBalance()
        {
            Status      = "Updating Balances...";
            Errors      = string.Empty;
            IsReceiving = true;

            BalanceApi api = null;

            switch (SettingsInstance.SelectedBalanceApi)
            {
            case BalanceServiceNames.BlockchainInfo:
                api = new BlockchainInfo();
                break;

            case BalanceServiceNames.BlockExplorer:
                api = new BlockExplorer();
                break;

            default:
                api = new BlockchainInfo();
                break;
            }

            Response resp = await api.UpdateBalancesAsync(AddressList.ToList());

            if (resp.Errors.Any())
            {
                Errors = resp.Errors.GetErrors();
                Status = "Encountered an error!";
            }
            else
            {
                DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
                RaisePropertyChanged("BitcoinBalance");
                Status = "Balance Update Success!";
            }

            IsReceiving = false;
        }
Пример #14
0
        public async void AccountTests()
        {
            var explorer = new BlockExplorer("localhost:3001");
            var height   = await explorer.GetCurrentHeight();

            Console.WriteLine("{0}", height);

            var fvk    = "zxviewtestsapling1qtcgwxn8yl3qzqxjhr937awugvs3gl4hrpx6u7258l3pfpz0nuu8kx090rxrx33nyeayxahrsv6e9wcmhcdvsqa6dcms976s8uwflycn7xw060du2zfdhj3l7eddusgnknveua0a7gw2jxrjm2uy6vcwd7qvsmj37zyzxyxtrqqyefz83daf2gvtvtpqkrg7ahzym0m674m4xmkc739696ptmql968ecdsr5us6pcud5dl6wurc78jer56c57c5eqktp0dpvjuty2xgrz0mlt";
            var pubkey = new Zams.PubKey();

            pubkey.Fvk = fvk;
            var id = await explorer.ImportPublicKeyPackage(pubkey);

            Console.WriteLine("{0}", id);

            var accountA = await explorer.NewSaplingAccount(id);

            Console.WriteLine("{0}", accountA.Address);

            var accountB = await explorer.NewSaplingAccount(id);

            Console.WriteLine("{0}", accountB.Address);
        }
Пример #15
0
        public static void Serialize(walletManagement wallet, int minUnusedKeys = 4)
        {
            if (MainWindow.CheckForInternetConnection())
            {
                var walletData = JsonConvert.DeserializeObject <Data>(
                    File.ReadAllText(walletFileSerializer.Deserialize(wallet.WalletFilePath).walletTransactionsPath));

                var addresses = walletData.addresses.change.ToList();
                addresses.AddRange(walletData.addresses.receiving);

                explorer = new BlockExplorer();

                var addressesData = explorer.GetMultiAddressAsync(addresses).Result;

                foreach (var tx in addressesData.Transactions)
                {
                    if (walletData.txData.Keys.Contains(tx.Hash))
                    {
                        continue;
                    }

                    var InputsPerAddress  = new List <Inputs>();
                    var OutputsPerAddress = new List <Outputs>();

                    tx.Inputs.ToList().ForEach(inp =>
                    {
                        InputsPerAddress.Add(new Inputs
                        {
                            address = inp.PreviousOutput.Address,
                            index   = inp.PreviousOutput.N,
                            value   = inp.PreviousOutput.Value.GetBtc()
                        });
                        if (walletData.addresses.receiving.Contains(inp.PreviousOutput.Address))
                        {
                            walletData.usedAddresses.Add(inp.PreviousOutput.Address);
                        }
                        if (walletData.addresses.change.Contains(inp.PreviousOutput.Address))
                        {
                            walletData.usedAddresses.Add(inp.PreviousOutput.Address);
                        }
                    });
                    tx.Outputs.ToList().ForEach(outp =>
                    {
                        OutputsPerAddress.Add(new Outputs
                        {
                            address = outp.Address,
                            index   = outp.N,
                            value   = outp.Value.GetBtc()
                        });
                        if (walletData.addresses.receiving.Contains(outp.Address))
                        {
                            walletData.usedAddresses.Add(outp.Address);
                        }
                        if (walletData.addresses.change.Contains(outp.Address))
                        {
                            walletData.usedAddresses.Add(outp.Address);
                        }
                    });
                    walletData.txData.Add(tx.Hash,
                                          new TxData
                    {
                        hash     = tx.Hash,
                        date     = tx.Time,
                        lockTime = tx.BlockHeight,
                        size     = tx.Size,
                        fee      = NB.Money.Satoshis(tx.Fee).ToDecimal(NB.MoneyUnit.BTC),
                        value    = NB.Money.Satoshis(tx.Result).ToDecimal(NB.MoneyUnit.BTC),
                        inputs   = InputsPerAddress,
                        outputs  = OutputsPerAddress
                    });
                }

                var unusedreceivingKeysCount = walletData.addresses.receiving.Count;
                walletData.addresses.receiving.ForEach(key =>
                {
                    if (walletData.usedAddresses.Contains(key))
                    {
                        unusedreceivingKeysCount--;
                    }
                });
                if (unusedreceivingKeysCount < minUnusedKeys)
                {
                    var receivingKeysStartIndex = walletData.addresses.receiving.Count;
                    for (var i = 0; i < minUnusedKeys; i++)
                    {
                        walletData.addresses.receiving.Add(wallet
                                                           .GetAddress(receivingKeysStartIndex++, HdPathType.Receive).ToString());
                    }
                }

                var unusedchangeKeysCount = walletData.addresses.change.Count;
                walletData.addresses.change.ForEach(key =>
                {
                    if (walletData.usedAddresses.Contains(key))
                    {
                        unusedreceivingKeysCount--;
                    }
                });
                if (unusedchangeKeysCount < minUnusedKeys)
                {
                    var changeKeysStartIndex = walletData.addresses.change.Count;
                    for (var i = 0; i < minUnusedKeys; i++)
                    {
                        walletData.addresses.receiving.Add(wallet.GetAddress(changeKeysStartIndex++, HdPathType.Change)
                                                           .ToString());
                    }
                }

                walletData.unspent_Outputs = new List <Unspent_Outputs>();

                var unspentChange = explorer.GetUnspentOutputsAsync(walletData.addresses.change).Result;

                foreach (var outp in unspentChange)
                {
                    var existsOuts = walletData.unspent_Outputs.FirstOrDefault(x =>
                                                                               x.hash == outp.tx_hash_big_endian && x.confirmations == outp.Confirmations &&
                                                                               x.index == outp.N);
                    if (existsOuts == null)
                    {
                        var tx = walletData.txData.FirstOrDefault(x => x.Key == outp.tx_hash_big_endian);
                        tx.Value.outputs.ForEach(output =>
                        {
                            if (output.index == outp.N)
                            {
                                walletData.unspent_Outputs.Add(new Unspent_Outputs
                                {
                                    hash          = outp.tx_hash_big_endian,
                                    address       = output.address,
                                    confirmations = outp.Confirmations,
                                    index         = outp.N,
                                    value         = outp.Value.GetBtc()
                                });
                            }
                        });
                    }
                }

                var unspentReceiving = explorer.GetUnspentOutputsAsync(walletData.addresses.receiving).Result;

                foreach (var outp in unspentReceiving)
                {
                    var existsOuts = walletData.unspent_Outputs.FirstOrDefault(x =>
                                                                               x.hash == outp.tx_hash_big_endian && x.confirmations == outp.Confirmations &&
                                                                               x.index == outp.N);
                    if (existsOuts == null)
                    {
                        var tx = walletData.txData.FirstOrDefault(x => x.Key == outp.tx_hash_big_endian);
                        tx.Value.outputs.ForEach(output =>
                        {
                            if (output.index == outp.N)
                            {
                                walletData.unspent_Outputs.Add(new Unspent_Outputs
                                {
                                    hash          = outp.tx_hash_big_endian,
                                    address       = output.address,
                                    confirmations = outp.Confirmations,
                                    index         = outp.N,
                                    value         = outp.Value.GetBtc()
                                });
                            }
                        });
                    }
                }

                foreach (var tx in walletData.txData.Values)
                {
                    if (tx.value > 0)
                    {
                        foreach (var outp in tx.outputs)
                        {
                            if (walletData.usedAddresses.Contains(outp.address))
                            {
                                tx.address = outp.address;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var inp in tx.inputs)
                        {
                            if (walletData.usedAddresses.Contains(inp.address))
                            {
                                tx.address = inp.address;
                                break;
                            }
                        }
                    }
                }

                File.WriteAllText(walletFileSerializer.Deserialize(wallet.WalletFilePath).walletTransactionsPath,
                                  JsonConvert.SerializeObject(walletData));
            }
        }
Пример #16
0
 // It is recommended to load a checkpoint before this test
 public async void SyncTest()
 {
     var explorer = new BlockExplorer("localhost:3001");
     await explorer.Sync();
 }
Пример #17
0
        public MainWindow()
        {
            InitializeComponent();

            if (walletPasswordCancel)
            {
                Model = null;
                Backup_Wallet.Visibility = Visibility.Collapsed;
                Delete.Visibility        = Visibility.Collapsed;
                Tools.Visibility         = Visibility.Collapsed;
                Wallet.Visibility        = Visibility.Collapsed;
            }

            else
            {
                if (Model != null)
                {
                    MainFrame.NavigationService.Navigate(new overview(Model));
                    explorer = new BlockExplorer();

                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;

                        if (CheckForInternetConnection())
                        {
                            walletData.Serialize(Model.Wallet);
                            Model.Update();
                        }

                        while (true)
                        {
                            if (CheckForInternetConnection())
                            {
                                var Addresses = explorer.GetMultiAddressAsync(Model.Addresses).Result.Addresses;
                                var TxsCount  = Model.TxRecords == null ? 0 : Model.TxRecords.Count;
                                if (explorer.GetMultiAddressAsync(Model.Addresses).Result.Transactions.Count() >
                                    TxsCount)
                                {
                                    walletData.Serialize(Model.Wallet);
                                    Model.Update();
                                }

                                foreach (var tx in Model.TxRecords)
                                {
                                    if (tx.lockTime < 0)
                                    {
                                        var txAsync = explorer.GetTransactionByHashAsync(tx.hash).Result;
                                        if (txAsync.BlockHeight > 0)
                                        {
                                            var data = JsonConvert.DeserializeObject <Data>(
                                                File.ReadAllText(walletFileSerializer
                                                                 .Deserialize(Model.Wallet.WalletFilePath).walletTransactionsPath));
                                            data.txData[tx.hash].lockTime = txAsync.BlockHeight;
                                            File.WriteAllText(
                                                walletFileSerializer.Deserialize(Model.Wallet.WalletFilePath)
                                                .walletTransactionsPath, JsonConvert.SerializeObject(data));
                                            Model.Update();
                                        }
                                    }
                                }

                                using (var client = new HttpClient())
                                {
                                    const string url = @"https://api.blockcypher.com/v1/btc/main";
                                    var result       = client.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result;
                                    var asyncData    = new FileInfo(Model.Wallet.WalletFilePath).Directory.FullName +
                                                       Path.DirectorySeparatorChar + "asyncData.json";
                                    if (result.IsSuccessStatusCode)
                                    {
                                        File.WriteAllText(asyncData, result.Content.ReadAsStringAsync().Result);
                                    }
                                    Model.Update();
                                }
                            }

                            Thread.Sleep(15000);
                        }
                    }).Start();
                }

                else
                {
                    var defaultWallet = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                        Path.DirectorySeparatorChar + "ArGo" + Path.DirectorySeparatorChar +
                                        "default_wallet.json";
                    if (File.Exists(defaultWallet))
                    {
                        var walletPasswordWindow = new walletPasswordWindow(defaultWallet);
                        walletPasswordWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        walletPasswordWindow.Show();
                        Close();
                    }
                    else
                    {
                        var walletWizard = new walletWizard();
                        walletWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        walletWizard.Show();
                        Close();
                    }
                }
            }
        }
Пример #18
0
        public void GetUnspent()
        {
            BlockExplorer explorer = new BlockExplorer();

            explorer.GetUnspent("3K1ZqF1W3X81S1GUcNysS74p5ar4JZWdjJ");
        }
Пример #19
0
 /// <summary>
 /// Transactions confirmations
 /// </summary>
 /// <param name="TxHash">Transaction hash or Transaction ID</param>
 /// <returns>Returns the amount of transaction confirmation.</returns>
 public static TxStatus TxConfirmation(string TxHash)
 {
     return(BlockExplorer.TxConfirmation(TxHash));
 }
 public BlockchainApiClient(BlockExplorer blockExplorer, decimal threshold)
 {
     _blockExplorer = blockExplorer;
     _threshold     = threshold;
 }
Пример #21
0
        private async void GetBalance()
        {
            if (!AddressList.ToList().TrueForAll(x => !x.HasErrors))
            {
                Errors = "Fix the errors in addresses first!";
                return;
            }
            Status      = "Updating Balances...";
            Errors      = string.Empty;
            IsReceiving = true;

            BalanceApi api = null;

            switch (SettingsInstance.SelectedBalanceApi)
            {
            case BalanceServiceNames.BlockchainInfo:
                api = new BlockchainInfo();
                break;

            case BalanceServiceNames.BlockExplorer:
                api = new BlockExplorer();
                break;

            case BalanceServiceNames.BlockCypher:
                api = new BlockCypher();
                break;

            case BalanceServiceNames.Blockonomics:
                api = new Blockonomics();
                break;

            default:
                api = new BlockchainInfo();
                break;
            }

            // Not all exchanges support Bech32 addresses!
            // The following "if" is to solve that.
            bool hasSegWit = AddressList.Any(x => x.Address.StartsWith("bc1", System.StringComparison.InvariantCultureIgnoreCase));

            if (hasSegWit && !SettingsInstance.SelectedBalanceApi.Equals(BalanceServiceNames.Blockonomics))
            {
                BalanceApi            segApi      = new Blockonomics();
                List <BitcoinAddress> legacyAddrs = new List <BitcoinAddress>(AddressList.Where(x =>
                                                                                                !x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase)));
                List <BitcoinAddress> segWitAddrs = new List <BitcoinAddress>(AddressList.Where(x =>
                                                                                                x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase)));

                Response respSW = await segApi.UpdateBalancesAsync(segWitAddrs);

                if (respSW.Errors.Any())
                {
                    Errors = "SegWit API error: " + respSW.Errors.GetErrors();
                    Status = "Error in SegWit API! Continue updating legacy balances...";
                }
                Response resp = await api.UpdateBalancesAsync(legacyAddrs);

                if (resp.Errors.Any())
                {
                    Errors = resp.Errors.GetErrors();
                    Status = "Encountered an error!";
                }
                else
                {
                    DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
                    RaisePropertyChanged("BitcoinBalance");
                    Status = "Balance Update Success!";
                }
            }
            else
            {
                Response resp = await api.UpdateBalancesAsync(AddressList.ToList());

                if (resp.Errors.Any())
                {
                    Errors = resp.Errors.GetErrors();
                    Status = "Encountered an error!";
                }
                else
                {
                    DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
                    RaisePropertyChanged("BitcoinBalance");
                    Status = "Balance Update Success!";
                }
            }

            IsReceiving = false;
        }