Ejemplo n.º 1
0
        private void RenameKey(AccountKey extendedKey)
        {
            try
            {
                NameWindow newNameWindow = new NameWindow();

                newNameWindow.NamespaceKey = extendedKey.KeyNamespace;
                newNameWindow.KeyName      = extendedKey.KeyName;

                if (newNameWindow.ShowDialog() == true)
                {
                    extendedKey.KeyNamespace = tcBitcoin.RenameKey(extendedKey.KeyName, newNameWindow.KeyName);
                    extendedKey.KeyName      = newNameWindow.KeyName;
                    textNamespace.Text       = extendedKey.KeyNamespace;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"{err.Message}", $"{err.Source}.{err.TargetSite.Name}", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void NewChildKey(AccountKey extendedKey)
        {
            try
            {
                NameWindow newNameWindow = new NameWindow();

                newNameWindow.NamespaceKey = extendedKey.KeyNamespace;

                if (newNameWindow.ShowDialog() == true)
                {
                    string     hdPath = tcBitcoin.NewKeyPath(extendedKey.KeyName, newNameWindow.KeyName);
                    AccountKey newKey = new AccountKey(hdPath, $"{extendedKey.KeyNamespace}.{newNameWindow.KeyName.ToUpper().Replace(' ', '_')}", newNameWindow.KeyName, 0, 0);
                    newKey.Key = tcBitcoin.GetExtendedKey(hdPath);
                    extendedKey.Items.Add(newKey);
                    extendedKey.IsExpanded = true;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"{err.Message}", $"{err.Source}.{err.TargetSite.Name}", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        private void MenuItemAssignReceipt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AccountKey      extendedKey = (AccountKey)tvWallet.SelectedItem;
                var             invoice     = (vwInvoicedReceipts)dgInvoices.SelectedItem;
                AssignKeyWindow assignKey   = new AssignKeyWindow();
                assignKey.InvoiceNumber             = invoice.InvoiceNumber;
                assignKey.dgReceiptKeys.ItemsSource = tcBitcoin.NodeCash.fnChangeUnassigned(tcBitcoin.CashAccountCode);

                if (assignKey.ShowDialog() == true)
                {
                    if (tcBitcoin.AssignReceiptKey(assignKey.KeyName, assignKey.PaymentAddress, assignKey.InvoiceNumber, assignKey.Note))
                    {
                        Refresh();
                        OnBalance?.Invoke(this, new EventArgs());
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"{err.Message}", $"{err.Source}.{err.TargetSite.Name}", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
        AccountKey GetKey(string keyName, AccountKey root = null)
        {
            try
            {
                AccountKey accountKey = null;

                if (root == null)
                {
                    root = (AccountKey)tvWallet.Items[0];
                }

                foreach (AccountKey key in root.Items)
                {
                    if (key.KeyName == keyName)
                    {
                        accountKey = key;
                        return(accountKey);
                    }
                    else if (accountKey == null)
                    {
                        accountKey = GetKey(keyName, key);
                    }
                    else
                    {
                        return(accountKey);
                    }
                }

                return(accountKey);
            }
            catch (Exception err)
            {
                MessageBox.Show($"{err.Message}", $"{err.Source}.{err.TargetSite.Name}", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
        }
Ejemplo n.º 5
0
        public async Task <SpendTx> KeyTransferTx(AccountKey fromKey, AccountKey toKey, decimal transferAmount, int minersRate, string txMessage, string cashCodeFrom, string cashCodeTo)
        {
            try
            {
                int?addressIndex = 0;

                if (!NodeCash.vwTransferCashCodes.Where(tb => tb.CashCode == cashCodeFrom).Any() || !NodeCash.vwTransferCashCodes.Where(tb => tb.CashCode == cashCodeTo).Any())
                {
                    return(null);
                }

                string toAddress = NewChangeKey(toKey.KeyName, toKey.HDPath, CoinChangeType.Receipt, ref addressIndex);
                if (!AddReceiptKey(toKey.KeyName, toAddress, (int)addressIndex, txMessage))
                {
                    return(null);
                }

                string changeAddress  = string.Empty;
                double accountBalance = await KeyNameBalance(fromKey.KeyName);

                if ((decimal)accountBalance > transferAmount)
                {
                    changeAddress = NewChangeKey(fromKey.KeyName, fromKey.HDPath, CoinChangeType.Change, ref addressIndex);

                    if (!AddChangeKey(fromKey.KeyName, changeAddress, (int)addressIndex, null))
                    {
                        return(null);
                    }
                }

                string changePath = $"{fromKey.HDPath}{(short)CoinChangeType.Change}/{addressIndex}/";

                Money spendAmount = new Money(transferAmount, MoneyUnit.MilliBTC);

                SpendTx spend = new SpendTx(BlockchainApi)
                {
                    ToAddress      = toAddress,
                    ChangeAddress  = changeAddress,
                    FromKey        = fromKey.KeyName,
                    ChangeKey      = fromKey.KeyName,
                    MinerRate      = minersRate,
                    TxMessage      = txMessage,
                    TargetAmount   = spendAmount,
                    AccountBalance = new Money((decimal)accountBalance, MoneyUnit.MilliBTC)
                };

                var keyAddresses = NodeCash.fnKeyAddresses(CashAccountCode, fromKey.KeyName)
                                   .OrderBy(tb => tb.AddressIndex)
                                   .Select(tb => tb);

                foreach (var key in keyAddresses)
                {
                    spend.AddKey(GetExtendedKey(key.HDPath), GetExtendedKey(changePath));

                    if (spend.IsSatisfied)
                    {
                        break;
                    }
                }

                return(spend);
            }
            catch (Exception err)
            {
                Console.WriteLine($"Error: {err.Message}");
                return(null);
            }
        }