Beispiel #1
0
        private string GetBalanceFromJson(string info)
        {
            string  result = "";
            JObject json   = JObject.Parse(info);

            if (json.ContainsKey("result"))
            {
                JObject json_result = json["result"] as JObject;
                JArray  stack       = json_result["stack"] as JArray;

                if (stack != null && stack.Count >= 2)
                {
                    string balance  = ZoroHelper.GetJsonValue(stack[0] as JObject);
                    string decimals = ZoroHelper.GetJsonValue(stack[1] as JObject);

                    Decimal value = Decimal.Parse(balance) / new Decimal(Math.Pow(10, int.Parse(decimals)));
                    string  fmt   = "{0:N" + decimals + "}";
                    result = string.Format(fmt, value);
                }
            }
            else if (json.ContainsKey("error"))
            {
                JObject json_error_obj = json["error"] as JObject;
                result = json_error_obj.ToString();
            }

            return(result);
        }
Beispiel #2
0
        private void QueryUnlockAmount(string method)
        {
            string api = accountFrmLock.RpcUrl;

            if (!CheckLockParameter())
            {
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            sb.EmitAppCall(UInt160.Parse(tbxLockContract.Text), method, ZoroHelper.GetPublicKeyHashFromAddress(tbxLockerAddress.Text), Genesis.BcpContractAddress);

            try
            {
                var info = ZoroHelper.InvokeScript(api, sb.ToArray(), "");

                JObject json = JObject.Parse(info);
                if (json.ContainsKey("result"))
                {
                    JObject json_result = json["result"] as JObject;
                    JArray  stack       = json_result["stack"] as JArray;

                    string  result = ZoroHelper.GetJsonValue(stack[0] as JObject);
                    decimal value  = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, 8), 8);

                    rtbxLockReturnResult.Text = "金额:" + value.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #3
0
        private void btnNep5Refresh_Click(object sender, EventArgs e)
        {
            string api = nep5AccountFrm.RpcUrl;

            if (string.IsNullOrEmpty(tbxNep5Hash.Text))
            {
                MessageBox.Show("合约 Hash 不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(tbxMyAddress.Text))
            {
                MessageBox.Show("查询地址不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                var           addressHash = ZoroHelper.GetPublicKeyHashFromAddress(tbxMyAddress.Text);
                ScriptBuilder sb          = new ScriptBuilder();

                if (tbxNep5Hash.Text == "0x0000000000000000000000000000000000000001" || tbxNep5Hash.Text == "0x0000000000000000000000000000000000000002")
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", UInt160.Parse(tbxNep5Hash.Text), addressHash);
                }
                else
                {
                    sb.EmitAppCall(UInt160.Parse(tbxNep5Hash.Text), "balanceOf", addressHash);
                }

                var info = ZoroHelper.InvokeScript(api, sb.ToArray(), "");

                JObject json = JObject.Parse(info);
                if (json.ContainsKey("result"))
                {
                    JObject json_result = json["result"] as JObject;
                    JArray  stack       = json_result["stack"] as JArray;

                    string  result = ZoroHelper.GetJsonValue(stack[0] as JObject);
                    decimal value  = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, 8), 8);

                    lblNep5Balance.Text = value.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #4
0
        private void GetLockTimestamp(string method)
        {
            string api = accountFrmLock.RpcUrl;

            if (!CheckLockParameter())
            {
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            sb.EmitAppCall(UInt160.Parse(tbxLockContract.Text), method, ZoroHelper.GetPublicKeyHashFromAddress(tbxLockerAddress.Text), Genesis.BcpContractAddress);

            try
            {
                var info = ZoroHelper.InvokeScript(api, sb.ToArray(), "");

                JObject json = JObject.Parse(info);
                if (json.ContainsKey("result"))
                {
                    JObject json_result = json["result"] as JObject;
                    JArray  stack       = json_result["stack"] as JArray;

                    string result = ZoroHelper.GetJsonValue(stack[0] as JObject);
                    long   value  = long.Parse(result);

                    DateTime dtStart  = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                    long     lTime    = long.Parse(value + "0000000");
                    TimeSpan toNow    = new TimeSpan(lTime);
                    DateTime targetDt = dtStart.Add(toNow);

                    rtbxLockReturnResult.Text = "上次解锁时间:" + targetDt.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #5
0
        private void GetUnlockInterval(string method)
        {
            string api = accountFrmLock.RpcUrl;

            if (!CheckLockParameter())
            {
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            sb.EmitAppCall(UInt160.Parse(tbxLockContract.Text), method, ZoroHelper.GetPublicKeyHashFromAddress(tbxLockerAddress.Text), Genesis.BcpContractAddress);

            try
            {
                var info = ZoroHelper.InvokeScript(api, sb.ToArray(), "");

                JObject json = JObject.Parse(info);
                if (json.ContainsKey("result"))
                {
                    JObject json_result = json["result"] as JObject;
                    JArray  stack       = json_result["stack"] as JArray;

                    string result = ZoroHelper.GetJsonValue(stack[0] as JObject);
                    long   value  = long.Parse(result);

                    TimeSpan timeSpan = new TimeSpan(value * 10000000);

                    rtbxLockReturnResult.Text = "解锁时间间隔:" + timeSpan.ToString() + " S";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }