Ejemplo n.º 1
0
        private void DebugInfo()
        {
            try
            {
                Debug.WriteLine("\n\nConnecting to {0} {1}Net via RPC at {2}...", CoinService.Parameters.CoinLongName, (CoinService.Parameters.UseTestnet ? "Test" : "Main"), CoinService.Parameters.SelectedDaemonUrl);

                //  Network difficulty
                var networkDifficulty = CoinService.GetDifficulty();
                Debug.WriteLine("[OK]\n\n{0} Network Difficulty: {1}", CoinService.Parameters.CoinLongName, networkDifficulty.ToString("#,###", CultureInfo.InvariantCulture));

                // Mining info
                var miningInfo = CoinService.GetMiningInfo();
                Debug.WriteLine("[OK]\n\n{0} NetworkHashPS: {1}", CoinService.Parameters.CoinLongName, miningInfo.NetworkHashPS.ToString("#,###", CultureInfo.InvariantCulture));

                //  My balance
                var myBalance = CoinService.GetBalance();
                Debug.WriteLine("\nMy balance: {0} {1}", myBalance, CoinService.Parameters.CoinShortName);

                //  Current block
                Debug.WriteLine("Current block: {0}",
                                CoinService.GetBlockCount().ToString("#,#", CultureInfo.InvariantCulture));

                //  Wallet state
                Debug.WriteLine("Wallet state: {0}", CoinService.IsWalletEncrypted() ? "Encrypted" : "Unencrypted");

                //  Keys and addresses
                if (myBalance > 0)
                {
                    //  My non-empty addresses
                    Debug.WriteLine("\n\nMy non-empty addresses:");

                    var myNonEmptyAddresses = CoinService.ListReceivedByAddress();

                    foreach (var address in myNonEmptyAddresses)
                    {
                        Debug.WriteLine("\n--------------------------------------------------");
                        Debug.WriteLine("Account: " + (string.IsNullOrWhiteSpace(address.Account) ? "(no label)" : address.Account));
                        Debug.WriteLine("Address: " + address.Address);
                        Debug.WriteLine("Amount: " + address.Amount);
                        Debug.WriteLine("Confirmations: " + address.Confirmations);
                        Debug.WriteLine("--------------------------------------------------");
                    }

                    //  My private keys
                    if (bool.Parse(ConfigurationManager.AppSettings["ExtractMyPrivateKeys"]) && myNonEmptyAddresses.Count > 0 && CoinService.IsWalletEncrypted())
                    {
                        const short secondsToUnlockTheWallet = 30;

                        Debug.Write("\nWill now unlock the wallet for " + secondsToUnlockTheWallet + ((secondsToUnlockTheWallet > 1) ? " seconds" : " second") + "...");
                        CoinService.WalletPassphrase(CoinService.Parameters.WalletPassword, secondsToUnlockTheWallet);
                        Debug.WriteLine("[OK]\n\nMy private keys for non-empty addresses:\n");

                        foreach (var address in myNonEmptyAddresses)
                        {
                            Debug.WriteLine("Private Key for address " + address.Address + ": " + CoinService.DumpPrivKey(address.Address));
                        }

                        Debug.Write("\nLocking wallet...");
                        CoinService.WalletLock();
                        Debug.WriteLine("[OK]");
                    }

                    //  My transactions
                    Debug.WriteLine("\n\nMy transactions: ");
                    var myTransactions = CoinService.ListTransactions(null, int.MaxValue, 0);

                    foreach (var transaction in myTransactions)
                    {
                        Debug.WriteLine("\n---------------------------------------------------------------------------");
                        Debug.WriteLine("Account: " + (string.IsNullOrWhiteSpace(transaction.Account) ? "(no label)" : transaction.Account));
                        Debug.WriteLine("Address: " + transaction.Address);
                        Debug.WriteLine("Category: " + transaction.Category);
                        Debug.WriteLine("Amount: " + transaction.Amount);
                        Debug.WriteLine("Fee: " + transaction.Fee);
                        Debug.WriteLine("Confirmations: " + transaction.Confirmations);
                        Debug.WriteLine("BlockHash: " + transaction.BlockHash);
                        Debug.WriteLine("BlockIndex: " + transaction.BlockIndex);
                        Debug.WriteLine("BlockTime: " + transaction.BlockTime + " - " + UnixTime.UnixTimeToDateTime(transaction.BlockTime));
                        Debug.WriteLine("TxId: " + transaction.TxId);
                        Debug.WriteLine("Time: " + transaction.Time + " - " + UnixTime.UnixTimeToDateTime(transaction.Time));
                        Debug.WriteLine("TimeReceived: " + transaction.TimeReceived + " - " + UnixTime.UnixTimeToDateTime(transaction.TimeReceived));

                        if (!string.IsNullOrWhiteSpace(transaction.Comment))
                        {
                            Debug.WriteLine("Comment: " + transaction.Comment);
                        }

                        if (!string.IsNullOrWhiteSpace(transaction.OtherAccount))
                        {
                            Debug.WriteLine("Other Account: " + transaction.OtherAccount);
                        }

                        if (transaction.WalletConflicts != null && transaction.WalletConflicts.Any())
                        {
                            Debug.Write("Conflicted Transactions: ");

                            foreach (var conflictedTxId in transaction.WalletConflicts)
                            {
                                Debug.Write(conflictedTxId + " ");
                            }

                            Debug.WriteLine("");
                        }

                        Debug.WriteLine("---------------------------------------------------------------------------");
                    }

                    //  Transaction Details
                    Debug.WriteLine("\n\nMy transactions' details:");
                    foreach (var transaction in myTransactions)
                    {
                        // Move transactions don't have a txId, which this logic fails for
                        if (transaction.Category == "move")
                        {
                            continue;
                        }

                        var localWalletTransaction = CoinService.GetTransaction(transaction.TxId);
                        IEnumerable <PropertyInfo>            localWalletTrasactionProperties   = localWalletTransaction.GetType().GetProperties();
                        IList <GetTransactionResponseDetails> localWalletTransactionDetailsList = localWalletTransaction.Details.ToList();

                        Debug.WriteLine("\nTransaction\n-----------");

                        foreach (var propertyInfo in localWalletTrasactionProperties)
                        {
                            var propertyInfoName = propertyInfo.Name;

                            if (propertyInfoName != "Details" && propertyInfoName != "WalletConflicts")
                            {
                                Debug.WriteLine(propertyInfoName + ": " + propertyInfo.GetValue(localWalletTransaction, null));
                            }
                        }

                        foreach (var details in localWalletTransactionDetailsList)
                        {
                            IEnumerable <PropertyInfo> detailsProperties = details.GetType().GetProperties();
                            Debug.WriteLine("\nTransaction details " + (localWalletTransactionDetailsList.IndexOf(details) + 1) + " of total " + localWalletTransactionDetailsList.Count + "\n--------------------------------");

                            foreach (var propertyInfo in detailsProperties)
                            {
                                Debug.WriteLine(propertyInfo.Name + ": " + propertyInfo.GetValue(details, null));
                            }
                        }
                    }

                    //  Unspent transactions
                    Debug.WriteLine("\nMy unspent transactions:");
                    var unspentList = CoinService.ListUnspent();

                    foreach (var unspentResponse in unspentList)
                    {
                        IEnumerable <PropertyInfo> detailsProperties = unspentResponse.GetType().GetProperties();

                        Debug.WriteLine("\nUnspent transaction " + (unspentList.IndexOf(unspentResponse) + 1) + " of " + unspentList.Count + "\n--------------------------------");

                        foreach (var propertyInfo in detailsProperties)
                        {
                            Debug.WriteLine(propertyInfo.Name + " : " + propertyInfo.GetValue(unspentResponse, null));
                        }
                    }
                }

                //Debug.ReadLine();
            }
            catch (RpcInternalServerErrorException exception)
            {
                var errorCode    = 0;
                var errorMessage = string.Empty;

                if (exception.RpcErrorCode.GetHashCode() != 0)
                {
                    errorCode    = exception.RpcErrorCode.GetHashCode();
                    errorMessage = exception.RpcErrorCode.ToString();
                }

                Debug.WriteLine("[Failed] {0} {1} {2}", exception.Message, errorCode != 0 ? "Error code: " + errorCode : string.Empty, !string.IsNullOrWhiteSpace(errorMessage) ? errorMessage : string.Empty);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("[Failed]\n\nPlease check your configuration and make sure that the daemon is up and running and that it is synchronized. \n\nException: " + exception);
            }
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            Console.Write("\n\nConnecting to {0} {1}Net via RPC at {2}...", CoinService.Parameters.CoinLongName, (CoinService.Parameters.UseTestnet ? "Test" : "Main"), CoinService.Parameters.SelectedDaemonUrl);

            //  Network difficulty
            try
            {
                Double networkDifficulty = CoinService.GetDifficulty();
                Console.WriteLine("[OK]\n\n{0} Network Difficulty: {1}", CoinService.Parameters.CoinLongName, networkDifficulty.ToString("#,###", CultureInfo.InvariantCulture));
            }
            catch (Exception exception)
            {
                Console.WriteLine("[Failed]\n\nPlease check your configuration and make sure that the daemon is up and running and that it is synchronized. \n\nException: " + exception);
                return;
            }

            //  My balance
            Decimal myBalance = CoinService.GetBalance();

            Console.WriteLine("\nMy balance: {0} {1}", myBalance, CoinService.Parameters.CoinShortName);

            //  Current block
            Console.WriteLine("Current block: {0}", CoinService.GetBlockCount().ToString("#,#", CultureInfo.InvariantCulture));

            //  Wallet state
            Console.WriteLine("Wallet state: {0}", CoinService.IsWalletEncrypted() ? "Encrypted" : "Unencrypted");

            //  Keys and addresses
            if (myBalance > 0)
            {
                //  My non-empty addresses
                Console.WriteLine("\n\nMy non-empty addresses:");

                List <ListReceivedByAddressResponse> myNonEmptyAddresses = CoinService.ListReceivedByAddress();

                foreach (ListReceivedByAddressResponse address in myNonEmptyAddresses)
                {
                    Console.WriteLine("\n--------------------------------------------------");
                    Console.WriteLine("Account: " + (String.IsNullOrWhiteSpace(address.Account) ? "(no label)" : address.Account));
                    Console.WriteLine("Address: " + address.Address);
                    Console.WriteLine("Amount: " + address.Amount);
                    Console.WriteLine("Confirmations: " + address.Confirmations);
                    Console.WriteLine("--------------------------------------------------");
                }

                //  My private keys
                if (Boolean.Parse(ConfigurationManager.AppSettings["ExtractMyPrivateKeys"]) && myNonEmptyAddresses.Count > 0 && CoinService.IsWalletEncrypted())
                {
                    const Int16 secondsToUnlockTheWallet = 3;

                    try
                    {
                        Console.Write("\nWill now unlock the wallet for " + secondsToUnlockTheWallet + ((secondsToUnlockTheWallet > 1) ? " seconds" : " second") + "...");
                        BitcoinService.WalletPassphrase(CoinService.Parameters.WalletPassword, secondsToUnlockTheWallet);
                        Console.WriteLine("[OK]\n\nMy private keys for non-empty addresses:\n");

                        foreach (ListReceivedByAddressResponse address in myNonEmptyAddresses)
                        {
                            Console.WriteLine("Private Key for address " + address.Address + ": " + CoinService.DumpPrivKey(address.Address));
                        }
                    }
                    catch (NullReferenceException)
                    {
                        Console.WriteLine("[Failed]. The wallet could not be unlocked, did you use the correct password?\n");
                        throw;
                    }
                    finally
                    {
                        Console.Write("\nLocking wallet...");
                        CoinService.WalletLock();
                        Console.WriteLine("[OK]");
                    }
                }

                //  My transactions
                Console.WriteLine("\n\nMy transactions: ");
                List <ListTransactionsResponse> myTransactions = CoinService.ListTransactions(null, Int32.MaxValue, 0);

                foreach (ListTransactionsResponse transaction in myTransactions)
                {
                    Console.WriteLine("\n---------------------------------------------------------------------------");
                    Console.WriteLine("Account: " + (String.IsNullOrWhiteSpace(transaction.Account) ? "(no label)" : transaction.Account));
                    Console.WriteLine("Address: " + transaction.Address);
                    Console.WriteLine("Category: " + transaction.Category);
                    Console.WriteLine("Amount: " + transaction.Amount);
                    Console.WriteLine("Confirmations: " + transaction.Confirmations);
                    Console.WriteLine("BlockHash: " + transaction.BlockHash);
                    Console.WriteLine("BlockIndex: " + transaction.BlockIndex);
                    Console.WriteLine("BlockTime: " + transaction.BlockTime + " - " + UnixTime.UnixTimeToDateTime(transaction.BlockTime));
                    Console.WriteLine("TxId: " + transaction.TxId);
                    Console.WriteLine("Time: " + transaction.Time + " - " + UnixTime.UnixTimeToDateTime(transaction.Time));
                    Console.WriteLine("TimeReceived: " + transaction.TimeReceived + " - " + UnixTime.UnixTimeToDateTime(transaction.TimeReceived));
                    Console.WriteLine("---------------------------------------------------------------------------");
                }

                //  Transaction Details
                Console.WriteLine("\n\nMy transactions' details:");
                foreach (ListTransactionsResponse transaction in myTransactions)
                {
                    GetTransactionResponse                localWalletTransaction            = CoinService.GetTransaction(transaction.TxId);
                    IEnumerable <PropertyInfo>            localWalletTrasactionProperties   = localWalletTransaction.GetType().GetProperties();
                    IList <GetTransactionResponseDetails> localWalletTransactionDetailsList = localWalletTransaction.Details.ToList();

                    Console.WriteLine("\nTransaction\n-----------");
                    foreach (PropertyInfo propertyInfo in localWalletTrasactionProperties)
                    {
                        String propertyInfoName = propertyInfo.Name;

                        if (propertyInfoName != "Details" && propertyInfoName != "WalletConflicts")
                        {
                            Console.WriteLine(propertyInfoName + ": " + propertyInfo.GetValue(localWalletTransaction, null));
                        }
                    }

                    foreach (GetTransactionResponseDetails details in localWalletTransactionDetailsList)
                    {
                        IEnumerable <PropertyInfo> detailsProperties = details.GetType().GetProperties();
                        Console.WriteLine("\nTransaction details " + (localWalletTransactionDetailsList.IndexOf(details) + 1) + " of total " + localWalletTransactionDetailsList.Count + "\n--------------------------------");

                        foreach (PropertyInfo propertyInfo in detailsProperties)
                        {
                            Console.WriteLine(propertyInfo.Name + ": " + propertyInfo.GetValue(details, null));
                        }
                    }
                }

                //  Unspent transactions
                Console.WriteLine("My unspent transactions:");
                List <ListUnspentResponse> unspentList = CoinService.ListUnspent();

                foreach (ListUnspentResponse unspentResponse in unspentList)
                {
                    IEnumerable <PropertyInfo> detailsProperties = unspentResponse.GetType().GetProperties();

                    Console.WriteLine("\nUnspent transaction " + (unspentList.IndexOf(unspentResponse) + 1) + " of " + unspentList.Count + "\n--------------------------------");

                    foreach (PropertyInfo propertyInfo in detailsProperties)
                    {
                        Console.WriteLine(propertyInfo.Name + " : " + propertyInfo.GetValue(unspentResponse, null));
                    }
                }
            }
            Console.ReadLine();
        }
 /// <summary>
 /// Check the balance for LTC
 /// </summary>
 /// <param name="currency"></param>
 /// <returns></returns>
 public decimal CheckBalance(string currency)
 {
     return(_litecoinService.GetBalance());
 }
        private void tscbWallets_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <WalletSettings> wallets = Utils.GetWalletSettings();

            foreach (WalletSettings wallet in wallets)
            {
                if (wallet.walletName == tscbWallets.ComboBox.Text)
                {
                    // this is the wallet we want to use.
                    try
                    {
                        xayaCoinService = new XAYAService(wallet.daemonUrl,
                                                          wallet.rpcUsername,
                                                          wallet.rpcPassword,
                                                          wallet.walletPassword,
                                                          wallet.rpcRequestTimeoutInSeconds);
                        this.Text = tscbWallets.Text + " wallet balance: " + string.Format("{0:0,0.00000000}", xayaCoinService.GetBalance()).ToString();
                    }
                    catch
                    {
                        this.Text = "Failed to load default wallet.";
                        MessageBox.Show("Failed to load default wallet. \r\n\r\nMake corrections in settings & try again. \r\n\r\n(Probably username & password are wrong or blank.)");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        static void GetBalance()
        {
            var balance = CoinService.GetBalance();

            Console.WriteLine("My balance: " + balance);
        }