Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var user             = username.Text;
                var walletConnection = new WalletConnector(host.Text, int.Parse(port.Text), username.Text, password.Text);
                var result           = walletConnection.GenerateAddress("adam");
                MessageBox.Show(result);

                var result2 = walletConnection.ValidateAddress(result);
                MessageBox.Show(result2.ToString());

                var result3 = walletConnection.GetTransactions();
                MessageBox.Show(result3.Count().ToString());

                var result4 = walletConnection.GetTransactions("d5325c49c3c11a1907cf431f31b1295bf092406fd442d8a1119e43f4ea6b5cc6");
                MessageBox.Show(result4.Count().ToString());

                var result5 = walletConnection.GetBalance();
                MessageBox.Show(result5.ToString("F8"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// Validates the address against the wallet.
        /// </summary>
        /// <param name="walletId">The wallet id.</param>
        /// <param name="address">The address.</param>
        /// <returns>true if the address is a valid address for the wallet, otherwise false</returns>
        public async Task <bool> ValidateAddress(int walletId, string address)
        {
            try
            {
                using (var currencyRepo = new Repository <Currency>())
                {
                    var currency = await currencyRepo.GetOrDefaultAsync(x => x.Id == walletId);

                    if (currency == null)
                    {
                        return(false);
                    }

                    var wallet = new WalletConnector(currency.WalletHost, currency.WalletPort, currency.WalletUser, currency.WalletPass);
                    if (wallet == null)
                    {
                        Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' not found.", walletId);
                        return(false);
                    }

                    if (!wallet.ValidateAddress(address))
                    {
                        Log.Message(LogLevel.Error, "[ValidateAddress] - Address '{0}' is not a valid address for CurrencyId: {1}", address, walletId);
                        return(false);
                    }

                    Log.Message(LogLevel.Info, "[ValidateAddress] - Address '{0}' successfully validated for CurrencyId: {1}", address, walletId);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[ValidateAddress] - An exception occured validating address, WalletId: {0}, Address: {1}", ex, walletId, address);
            }
            return(false);
        }