public Subscribe ( string address, int num_confirmations_required, string pingback_url ) : bool | ||
address | string | |
num_confirmations_required | int | |
pingback_url | string | |
return | bool |
public bool Subscribe(string address, int num_confirmations_required, string pingback_url)
{
if (address == "") {
//print "Could not subscribe, address not set.";
return false;
}
if (!InitializeAgent(num_confirmations_required, pingback_url)) {
//print "Could not initialize agent";
return false;
}
string url = SubscriptionURL(num_confirmations_required);
if (url == "") {
//print "Could not make URL";
return false;
}
string data = "address="+address;
m_log.Info("[FreeMoney] Planning to hit remote service to set up a notification for the address "+address);
//Console.WriteLine(url);
//Console.WriteLine(data);
//string useragent = "Bitcoin payment module for OpenSim - https://github.com/edmundedgar/Mod-Bitcoin";
HttpWebRequest httpWebRequest=(HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Headers.Add("Authorization: "+ m_config["bitcoin_ping_service_1_accesskey"]);
httpWebRequest.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (data);
//httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = byte1.Length;
Stream newStream = httpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
newStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse ();
/*
string response;
using (StreamReader streamReader = new StreamReader (httpWebResponse.GetResponseStream ())) {
response = streamReader.ReadToEnd ();
streamReader.Close ();
}
*/
return (httpWebResponse.StatusCode == HttpStatusCode.OK);
}
public bool Initialize(Dictionary <string, string> transaction_params, int num_confirmations_required) { m_transaction_code = transaction_params["item_number"]; m_payee = transaction_params["payee"]; m_payee_email = transaction_params["business"]; m_item_name = transaction_params["item_name"]; m_original_amount = Decimal.Parse(transaction_params["amount"]); m_original_currency_code = transaction_params["currency_code"]; m_notify_url = transaction_params["notify_url"]; m_num_confirmations_required = num_confirmations_required; string pingback_url = (m_config["bitcoin_external_url"] != "") ? m_config["bitcoin_external_url"] : m_base_url; // TODO:: Probably shouldn'thard-code this... pingback_url += "/btcping/?service=bitcoinmonitor"; /* * if (!$this->_mysqli) { * print_simple_and_exit( "No mysqli" ); * return false; * } */ if (m_transaction_code == "") { m_has_errors = true; return(false); } if (!(Populate("transaction_code") || Create())) { m_has_errors = true; m_log.Warn("[FreeMoney] Unable to find an existing Bitcoin transaction or create a new one."); return(false); } m_log.Info("[FreeMoney] Contacting notification service."); BitcoinNotificationService notification_service = new BitcoinNotificationService(m_config); if (!notification_service.Subscribe(m_btc_address, m_num_confirmations_required, pingback_url)) { m_has_errors = true; return(false); } return(true); }