예제 #1
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;
            }
        }
예제 #2
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;
            }
        }
예제 #3
0
        //Invoke
        private void btnInvoke_Click(object sender, EventArgs e)
        {
            string api = invokeAccountFrm.RpcUrl;

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

            if (string.IsNullOrEmpty(tbxMethodName.Text))
            {
                MessageBox.Show("调用接口不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            if (!string.IsNullOrEmpty(rtbxParameterJson.Text))
            {
                try
                {
                    List <dynamic> paraList = GetParameterArray(rtbxParameterJson.Text);
                    sb.EmitAppCall(UInt160.Parse(tbxContractScriptHash.Text), tbxMethodName.Text, paraList.ToArray());
                }
                catch
                {
                    MessageBox.Show("参数格式错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                sb.EmitAppCall(UInt160.Parse(tbxContractScriptHash.Text), tbxMethodName.Text);
            }

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

                rtbxReturnJson.Text = info;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #4
0
        private void GetBalance()
        {
            try
            {
                UInt160 bcpAssetId = Genesis.BcpContractAddress;
                UInt160 bctAssetId = Genesis.BctContractAddress;

                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", bcpAssetId, addressHash);
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", bcpAssetId);

                    var info  = ZoroHelper.InvokeScript(RpcUrl, sb.ToArray(), "");
                    var value = GetBalanceFromJson(info);

                    lblBcpBalance.Text = value;
                }

                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", bctAssetId, addressHash);
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", bctAssetId);

                    var info  = ZoroHelper.InvokeScript(RpcUrl, sb.ToArray(), "");
                    var value = GetBalanceFromJson(info);

                    lblBctBalance.Text = value;
                }

                //using (ScriptBuilder sb = new ScriptBuilder())
                //{
                //    sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", bcsAssetId, addressHash);
                //    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", bcsAssetId);

                //    var info = ZoroHelper.InvokeScript(RpcUrl, sb.ToArray(), "");
                //    var value = GetBalanceFromJson(info);

                //    lblBcsBalance.Text = value;

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取余额出错!" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #5
0
        private void btnCallInvoke_Click(object sender, EventArgs e)
        {
            string api = otherCallAccountFrm.RpcUrl;

            if (string.IsNullOrEmpty(otherCallAccountFrm.wif))
            {
                MessageBox.Show("请输入钱包 wif !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(tbxCallInterface.Text))
            {
                MessageBox.Show("调用接口不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            if (!string.IsNullOrEmpty(rtbxCallParams.Text))
            {
                try
                {
                    List <dynamic> paraList = GetParameterArray(rtbxCallParams.Text);
                    sb.EmitSysCall(tbxCallInterface.Text, paraList.ToArray());
                }
                catch
                {
                    MessageBox.Show("参数格式错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            try
            {
                var info = ZoroHelper.InvokeScript(api, sb.ToArray(), "");
                rtbxCallResult.Text = info;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #6
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;
            }
        }
예제 #7
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;
            }
        }