Exemple #1
0
        private void BW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bwalert.Dismiss();
            TxnResponse resp      = e.Result as TxnResponse;
            TextView    tbMessage = FindViewById \ \ (Resource.Id.tvMessage);

            tbMessage.Text = "";
            secr           = "";
            kbstr          = "";
            string message = "Sent!";

            if (resp.success == false)
            {
                message = "Error. " + resp.error_message;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(this).SetTitle("")
                                          .SetMessage(message)
                                          .SetCancelable(false)
                                          .SetPositiveButton("ok", (EventHandler \ \)null);
            AlertDialog alert = builder.Create();

            alert.Show();

            var okBtn = alert.GetButton((int)DialogButtonType.Positive);

            okBtn.Click += (asender, args) = \ > \ {
                alert.Dismiss();
                if (resp.success)
                {
                    NoxDispose();
                }
            };
        }
 public TxnResponse SendMessage(string uri, string message, NBitcoin.BitcoinSecret sec)
 {
     try
     {
         Network net       = Network.Main;
         string  Signature = sec.PrivateKey.SignMessage(message);
         string  rawtxn    = BuildMsgTxn(sec.PubKey.GetAddress(net).ToString(), message, Signature, "");
         return(POST(uri, rawtxn));
     }
     catch
     {
         TxnResponse txnResponse = new TxnResponse();
         txnResponse.success       = false;
         txnResponse.error_message = "Unexpected result, please check connection.";
         return(txnResponse);
     }
 }
Exemple #3
0
        public static TxnResponse POST(string url, string obj)
        {
            try
            {
                WebRequest request = WebRequest.Create(url);
                request.Method      = "POST";
                request.Timeout     = 5000;
                request.ContentType = "application/text";
                byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(obj);
                request.ContentLength = byteArray.Length;

                using (System.IO.Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
                }

                using (WebResponse response = request.GetResponse())
                    using (System.IO.Stream stream = response.GetResponseStream())
                    {
                        System.IO.StreamReader sr = new System.IO.StreamReader(stream);
                        var result = sr.ReadToEnd();
                        return(JsonConvert.DeserializeObject <TxnResponse>(result));
                    }
            }
            catch (WebException)
            {
                TxnResponse txnResponse = new TxnResponse();
                txnResponse.success       = false;
                txnResponse.error_message = "Please check connection.";
                return(txnResponse);
            }
            catch (Exception)
            {
                TxnResponse txnResponse = new TxnResponse();
                txnResponse.success       = false;
                txnResponse.error_message = "Please check connection.";
                return(txnResponse);
            }
        }