private void ButtonOK_Click(object sender, EventArgs e) { var loginForm = new LoginForm(); SetChildFormCenter(loginForm); loginForm.ShowDialog(); if (BitcoinAddress.ValidateBitcoinAddress(loginForm.Btc)) { ConfigManager.GeneralConfig.BitcoinAddress = loginForm.Btc; ConfigManager.GeneralConfigFileCommit(); Close(); } }
public static void SetCredentials(string btc, string worker) { var data = new NicehashCredentials { btc = btc, worker = worker }; if (BitcoinAddress.ValidateBitcoinAddress(data.btc) && BitcoinAddress.ValidateWorkerName(worker)) { var sendData = JsonConvert.SerializeObject(data); // Send as task since SetCredentials is called from UI threads Task.Factory.StartNew(() => _socket?.SendData(sendData)); } }
// this one is bulletproof, takes 2s for 1MB string public static string FindBtcInText2(string text) { // 2 is for testnet btc others are 1, 3 and bc1 const string btcStartAlphabet = "123bc"; const int min = 26; const int max = 35; if (string.IsNullOrEmpty(text) || text.Length < min) { return(""); // nope } for (int i = 0; i < text.Length - min; i++) { char startC = text[i]; if (!btcStartAlphabet.Contains(startC)) { continue; } var left = text.Length - i; var subText = text.Substring(i, left > max ? max : left); var btc = ""; foreach (char c in subText) { if (!btcAlphabet.Contains(c) || btc.Length > max) { break; } btc += c; if (btc.Length > min && BitcoinAddress.ValidateBitcoinAddress(btc)) { return(btc); } } } return(""); }