private void set_credentials()
{
//TODO this is only valid for local. When remote is introduced,
// this info will have to be entered manually.
if (bitcoin_is_running)
{
string user_app_data_path= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string[] bitcoin_path = new string[] { user_app_data_path, "Bitcoin", "bitcoin.conf" };
string path = Path.Combine(bitcoin_path);
if (!File.Exists(path))
{
TopMostMessageBox.Show("Unable to read config. Ensure the file exists, then restart bitcoin.\n\n" + path, "Bitcoin QR Popup", MessageBoxButtons.OK); //TODO translate
can_exit = true;
return;
}
string[] lines = File.ReadAllLines(path);
string rpcuser = "";
string rpcpassword = "";
foreach (string line in lines)
{
string tidy_line = line.Trim();
if (tidy_line.StartsWith("rpcuser") && line.Contains("="))
{
rpcuser = tidy_line.Split('=')[1];
}
else if (tidy_line.StartsWith("rpcpassword") && line.Contains("="))
{
rpcpassword = tidy_line.Split('=')[1];
}
if (rpcuser.Length > 0 && rpcpassword.Length > 0)
{
break;
}
}
if (rpcuser == "" || rpcpassword == "")
{
TopMostMessageBox.Show("Unable to read rpc user and password. Ensure the file contains the following text (substituting your own values for 'bob' and 'secret').\n\nrpcuser=bob\nrpcpassword=secret", "Bitcoin QR Popup", MessageBoxButtons.OK); //TODO translate
can_exit = true;
return;
}
//TODO check that this wallet has a password on it
bc.Credentials = new NetworkCredential(rpcuser, rpcpassword);
}
}