Exemple #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>
        /// Creates an address for the specified wallet with the userid.
        /// </summary>
        /// <param name="walletId">The wallet id.</param>
        /// <param name="userId">The user id.</param>
        /// <returns>the new address and private key created in the wallet</returns>
        public async Task <string[]> CreateAddress(int walletId, Guid userId)
        {
            try
            {
                using (var currencyRepo = new Repository <Currency>())
                {
                    var currency = await currencyRepo.GetOrDefaultAsync(x => x.Id == walletId);

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

                    //var wallet = new WalletConnector("127.0.0.1", 33113, "sa_ddam213.3", "213bit");
                    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(null);
                    }

                    string address = wallet.GenerateAddress(userId.ToString());
                    if (string.IsNullOrEmpty(address))
                    {
                        Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' failed to generate address.", walletId);
                        return(null);
                    }
                    Log.Message(LogLevel.Debug, "[CreateAddress] - Address '{0}' generated for CurrencyId: {1}, UserId: {2}", address, walletId, userId);

                    string privateKey = wallet.DumpPrivKey(address);
                    if (string.IsNullOrEmpty(privateKey))
                    {
                        Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' failed to dump privatekey.", walletId);
                        return(null);
                    }
                    Log.Message(LogLevel.Debug, "[CreateAddress] - Private key '{0}' dumped for CurrencyId: {1}, UserId: {2}", privateKey, walletId, userId);

                    Log.Message(LogLevel.Info, "[CreateAddress] - New address '{0}' created for CurrencyId: {1}, UserId: {2}", address, walletId, userId);
                    return(new string[] { address, privateKey });
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[CreateAddress] - An exception occured creating address, WalletId: {0}, UserId: {1}", ex, walletId, userId);
            }
            return(null);
        }
Exemple #3
0
        public async Task <AddressModel> GenerateAddress(string userId, string ipAddress, int port, string username, string password)
        {
            try
            {
                var wallerConnector = new WalletConnector(ipAddress, port, username, password);
                var address         = wallerConnector.GenerateAddress(userId, true);
                var privateKey      = await wallerConnector.DumpPrivKeyAsync(address);

                return(new AddressModel
                {
                    Address = address,
                    PrivateKey = privateKey
                });
            }
            catch (Exception)
            {
                return(null);
            }
        }