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(); }
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); } }
public void FindPassword() { // We're going to use an address for testing below. This gets an address with coins in it. List <List <BitcoinLib.Responses.ListAddressGroupingsResponse> > listAddressGroupings = xayaCoinService.ListAddressGroupings(); string address = string.Empty; foreach (var v in listAddressGroupings) { foreach (var a in v) { if (a.Balance > 0) { address = a.Address; break; } } if (address != string.Empty) { break; } } // possible to stop if there are no coins in the wallet // Create a unique file name for the wallet dump test if you want to use that method // string dumpfile = "Dump file test - " + DateTime.Now.Ticks.ToString(); // Create a string to hold the private key for the address we got above. // This is for testing to see if we got the password right. string privatekey = string.Empty; // Create a string for a file name. We'll write the password to that file if we find it. string found_password_file = "XAYA PASSWORD FOUND - " + DateTime.Now.Ticks.ToString() + "- xaya.txt"; // Keep track of time Stopwatch s = Stopwatch.StartNew(); long previous_elapsed_time = 0; long current_elapsed_time = 0; foreach (string password in txtDictionary.Lines) { if (CancelAttack) { break; } current_elapsed_time = s.ElapsedMilliseconds; // Try the password string result = xayaCoinService.WalletPassphrase(password, 10000000); // We need to test to see if the password actually unlocked the wallet. // There is no actual method for this, so we use another method to see if it worked, // and if it worked, then the wallet is unlocked. // If it didn't work, the wallet is still locked. privatekey = xayaCoinService.DumpPrivKey(address); this.SafeInvoke(d => d.UpdatePasswordFinding(password + "\t" + result + " (" + current_elapsed_time.ToString() + "s :: +" + (current_elapsed_time - previous_elapsed_time).ToString() + "s)" + Environment.NewLine)); if (privatekey != null && privatekey != string.Empty) { // We've got it! We found the password! File.WriteAllText(found_password_file, password); this.SafeInvoke(d => d.UpdatePasswordFinding("FOUND THE PASSWORD! It is: " + password + Environment.NewLine + "Your password is saved in the '" + found_password_file + "' file. It is located in the same folder as this program. " + Environment.NewLine)); // Stop processing at this point. break; } previous_elapsed_time = current_elapsed_time; } s.Stop(); this.SafeInvoke(d => d.UpdatePasswordFinding("Finished in " + s.ElapsedMilliseconds.ToString() + "s")); }