Exemplo n.º 1
0
        public void GetDefaultWalletBalance_Call_Success()
        {
            var wc1 = new WalletContext();

            wc1.Tag       = "btccliwebsrv";
            wc1.Url       = "http://192.168.56.101:11111";
            wc1.User      = "******";
            wc1.Passsword = "btcpwd";
            var ops = new BtcCliOperations(wc1);

            var dwb = ops.GetDefaultWalletBalance();
        }
Exemplo n.º 2
0
        public void SendToAddress_Call_Success()
        {
            var wc1 = new WalletContext();

            wc1.Tag       = "btccliwebsrv";
            wc1.Url       = "http://192.168.56.101:11111";
            wc1.User      = "******";
            wc1.Passsword = "btcpwd";
            var ops = new BtcCliOperations(wc1);

            var total = ops.GetDefaultWalletBalance();

            var addrs = ops.GetAddresses();

            var addr = addrs.ToArray();

            var testAmount = total / addrs.Count();

            ops.SendToAddress(addr[0], testAmount.Value);
        }
Exemplo n.º 3
0
        public void InitWalletsInfo_Call_Success()
        {
            //add hot wallets manually

            var wc1 = new WalletContext();

            wc1.Tag       = "btccliwebsrv";
            wc1.Url       = "http://192.168.0.45:11111";
            wc1.User      = "******";
            wc1.Passsword = "btcpwd";



            var wc2 = new WalletContext();

            wc2.Tag       = "btccliwebsrv2";
            wc2.Url       = "http://192.168.0.45:11112";
            wc2.User      = "******";
            wc2.Passsword = "btcpwd";

            var provider = new WebAppConnectionStringProvider();

            var wcops = new WalletContextOperations(provider);

            var waops = new WalletAddressOperations(provider);

            var trops = new TransactionOperations(provider);

            if (!wcops.Exist(wc1))
            {
                wcops.Add(wc1);
            }

            if (!wcops.Exist(wc2))
            {
                wcops.Add(wc2);
            }

            //sync hot wallet's adresses
            var wallets = wcops.GetAll();

            foreach (var w in wallets)
            {
                var btcops = new BtcCliOperations(w);

                try {
                    var walletAddressCount = 0;

                    try { walletAddressCount = btcops.GetAddresses().Count(); } catch (Exception ex) { /*if no addresses in wallet*/ Debug.WriteLine(ex.ToString()); }

                    //add initial addresses in wallets if
                    while (walletAddressCount < 5)
                    {
                        try
                        {
                            var a = btcops.GetNewAddressForLabel();


                            walletAddressCount++;

                            Debug.WriteLine($"gen address {a} for wallet with tag:{w.Tag}");
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }

                    //sync with db

                    IEnumerable <string> addrs = new List <string>();

                    try
                    {
                        addrs = btcops.GetAddresses();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    foreach (var a in addrs)
                    {
                        if (!waops.Exist(a))
                        {
                            waops.Add(new WalletAddress()
                            {
                                address   = a,
                                wallettag = w.Tag,
                                walleturl = w.Url,
                                updated   = DateTime.Now
                            });
                        }
                    }

                    //fill test balances if zeroes and node total exits
                    double?total = null;

                    try
                    {
                        total = btcops.GetDefaultWalletBalance();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    if (!total.HasValue || total.Value == 0.0)
                    {
                        btcops.GenTestCoins();
                    }
                    var retries = 3;
                    while (total == 0.0 && retries-- >= 3)
                    {
                        try
                        {
                            total = btcops.GetDefaultWalletBalance();

                            break;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }

                    if (total.HasValue && total.Value > 0)
                    {
                        foreach (var wadr in waops.GetAll(w.Tag, w.Url))
                        {
                            if (wadr.balance != 0)
                            {
                                continue;
                            }

                            var testAmount = total / addrs.Count();

                            try
                            {
                                btcops.SendToAddress(wadr.address, testAmount.Value);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.ToString());
                            }
                        }
                    }


                    //sync transactions with db
                    List <Transaction> trList = new List <Transaction>();
                    try
                    {
                        trList = btcops.ListTransactions().ToList();

                        trops.AddOrUpdateConfirmations(trList);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }
                catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
            }

            //test sending coins
            foreach (var fromwallet in wallets)
            {
                var btcops = new BtcCliOperations(fromwallet);

                foreach (var to_wallet in wallets.Where(i => i.Tag != fromwallet.Tag && i.Url != fromwallet.Url).ToArray())
                {
                    var fromwallet_balance = btcops.GetDefaultWalletBalance();

                    if (fromwallet_balance == 0)
                    {
                        continue;
                    }

                    var testAmount = 0.001;

                    var to_addresses = waops.GetAll(to_wallet.Tag, to_wallet.Url);

                    foreach (var a in to_addresses)
                    {
                        try
                        {
                            btcops.SendToAddress(a.address, testAmount);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                        }
                    }
                }
            }
        }