예제 #1
0
        public GetsendMoneyResult sendMoney(string BurstAddress, string amountNQT, string feeNQT, string secretPhrase, string message, bool encrypmf)
        {
            GetsendMoneyResult SMR = new GetsendMoneyResult();

            BNWalletAPIClasses.ErrorCodes er;

            Dictionary <string, string> fpDict = new Dictionary <string, string>()
            {
                { "requestType", "sendMoney" },
                { "secretPhrase", secretPhrase },
                { "recipient", BurstAddress },
                { "amountNQT", amountNQT },
                { "feeNQT", "100000000" },
                { "deadline", "60" }
            };

            if (encrypmf)
            {
                fpDict.Add("messageToEncrypt", message);
            }
            else
            {
                fpDict.Add("message", message);
            }
            fp = new FormUrlEncodedContent(fpDict);

            HttpResponseMessage resp = client.PostAsync("burst", fp).Result;
            string respStr           = resp.Content.ReadAsStringAsync().Result;

            if (!string.IsNullOrEmpty(respStr))
            {
                if (respStr.Contains("\"errorCode\":"))
                {
                    er           = JsonConvert.DeserializeObject <BNWalletAPIClasses.ErrorCodes>(respStr);
                    SMR.success  = false;
                    SMR.errorMsg = er.errorDescription;
                    //GAIR.errorMsg = fp;
                }
                else
                {
                    BNWalletAPIClasses.sendMoneyResponse smr = JsonConvert.DeserializeObject <BNWalletAPIClasses.sendMoneyResponse>(respStr);
                    SMR.success       = true;
                    SMR.signatureHash = smr.signatureHash;
                    SMR.transaction   = smr.transaction;
                }
            }
            else
            {
                SMR.success  = false;
                SMR.errorMsg = "Receive blank response from API call";
            }
            return(SMR);
        }
예제 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SendBurstScreen);
            MobileBarcodeScanner.Initialize(Application);
            scanner = new MobileBarcodeScanner();

            RuntimeVar   RT   = new RuntimeVar();
            RuntimeVarDB RTDB = new RuntimeVarDB();

            RT = RTDB.Get();


            burstAddress = Intent.GetStringExtra("BurstAddress");


            RecipientBurstAddress = FindViewById <EditText>(Resource.Id.sendBurstAddress);
            Message   = FindViewById <EditText>(Resource.Id.sendMessage);
            Amount    = FindViewById <EditText>(Resource.Id.sendAmount);
            Fee       = FindViewById <EditText>(Resource.Id.sendFee);
            cbEncrypt = FindViewById <CheckBox>(Resource.Id.cbEncryptMessage);

            CreateQRCode = FindViewById <Button>(Resource.Id.btnViewQRCode);

            UARDB = new UserAccountRuntimeDB();
            UAR   = UARDB.Get();
            string password     = UAR.Password;
            string SecretPhrase = StringCipher.Decrypt(RT.CurrentPassphrase, password);



            CreateQRCode.Click += delegate
            {
                Intent intent = new Intent(this, typeof(QRCodeView));
                intent.SetFlags(ActivityFlags.SingleTop);
                StartActivity(intent);
            };

            Button btnsend = FindViewById <Button>(Resource.Id.btnSend);

            btnsend.Click += delegate
            {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                alertDialog.SetTitle("Confirmation");
                alertDialog.SetMessage("Are you sure all the details are correct?");
                alertDialog.SetPositiveButton("Yes", delegate
                {
                    double amntdbl = Convert.ToDouble(Amount.Text);
                    amntdbl        = amntdbl * 100000000;
                    amount         = amntdbl.ToString();

                    double amntdblconf = Convert.ToDouble(amount);
                    amntdblconf        = amntdblconf / 100000000;
                    Amount.Text        = amntdblconf.ToString("#,0.00000000");

                    double feeamnt = Convert.ToDouble(Fee.Text);
                    feeamnt        = feeamnt * 100000000;
                    fee            = feeamnt.ToString();

                    double feeamntconf = Convert.ToDouble(fee);
                    feeamntconf        = feeamntconf / 100000000;
                    Fee.Text           = feeamntconf.ToString("#,0.00000000");

                    BNWAPI = new BNWalletAPI();
                    GetsendMoneyResult gsmr = BNWAPI.sendMoney(RecipientBurstAddress.Text, amount, fee, SecretPhrase, Message.Text, cbEncrypt.Checked);
                    if (gsmr.success)
                    {
                        GetTransactionResult gtr = BNWAPI.getTransaction(gsmr.transaction);
                        if (gtr.success)
                        {
                            AlertDialog.Builder ConfirmationDetailsDialog = new AlertDialog.Builder(this);
                            ConfirmationDetailsDialog.SetTitle("Confirmation Details");
                            ConfirmationDetailsDialog.SetMessage("Sender Address: " + gtr.senderRS + "\n" + "Amount of Burst sent: " + Amount.Text + "\n" + "Fee: " + Fee.Text + "\n" + "Recipient Address: " + gtr.recipientRS + "\n" + "Signature Hash: " + gsmr.signatureHash
                                                                 + "\n" + "Transaction ID: " + gsmr.transaction + "\n" + "Block Height: " + gtr.ecBlockHeight);

                            ConfirmationDetailsDialog.SetPositiveButton("OK", delegate
                            {
                                GetAccountResult gar = BNWAPI.getAccount(gtr.senderRS);
                                if (gar.success)
                                {
                                    Intent intent = new Intent(this, typeof(InfoScreen));
                                    intent.PutExtra("WalletAddress", gar.accountRS);
                                    intent.PutExtra("WalletName", gar.name);
                                    intent.PutExtra("WalletBalance", gar.balanceNQT);
                                    intent.SetFlags(ActivityFlags.SingleTop);
                                    StartActivity(intent);
                                    Finish();
                                }
                            });
                            ConfirmationDetailsDialog.Show();
                        }
                    }
                    else
                    {
                        toast = Toast.MakeText(this, "Received API Error: " + gsmr.errorMsg, ToastLength.Long);
                        toast.Show();
                    }
                });
                alertDialog.SetNegativeButton("No", delegate
                {
                    alertDialog.Dispose();
                });
                alertDialog.Show();
            };



            Button ScanQRCode = FindViewById <Button>(Resource.Id.btnSendQRCode);

            ScanQRCode.Click += async delegate
            {
                await ScanFunction();
            };



            // Create your application here
        }