예제 #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 Withdraw(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, ZoroHelper.GetPublicKeyHashFromAddress(tbxWithdrawAddress.Text), (new BigInteger(1)).ToByteArray());

            try
            {
                decimal gasPrice = 0.0001m;
                var     tx       = ZoroHelper.MakeTransaction(sb.ToArray(), accountFrmLock.keypair, Fixed8.Zero, Fixed8.FromDecimal(gasPrice));
                bcpFee = ZoroHelper.EstimateGas(api, tx, "");

                tx = ZoroHelper.MakeTransaction(sb.ToArray(), accountFrmLock.keypair, Fixed8.FromDecimal(bcpFee), Fixed8.FromDecimal(gasPrice));

                var result = ZoroHelper.SendRawTransaction(api, tx, "") + " gas_consumed: " + bcpFee + "\r\n txid: " + tx.Hash;

                rtbxLockReturnResult.Text = result;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #3
0
        private void btnNep5SendTran_Click(object sender, EventArgs e)
        {
            string api = nep5AccountFrm.RpcUrl;

            if (string.IsNullOrEmpty(nep5AccountFrm.wif))
            {
                MessageBox.Show("请输入钱包 wif !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

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

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

            if (string.IsNullOrEmpty(tbxNep5Value.Text))
            {
                MessageBox.Show("转账金额不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(tbxNep5GasPrice.Text))
            {
                MessageBox.Show("Gas Price 不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ScriptBuilder sb = new ScriptBuilder();

            try
            {
                var     toAddressHash = ZoroHelper.GetPublicKeyHashFromAddress(tbxNep5ToAddress.Text);
                decimal value         = Math.Round(decimal.Parse(tbxNep5Value.Text) * (decimal)Math.Pow(10, 8), 0);

                Fixed8 gasPrice = Fixed8.FromDecimal(decimal.Parse(tbxNep5GasPrice.Text));

                sb.EmitAppCall(UInt160.Parse(tbxNep5Hash.Text), "transfer", nep5AccountFrm.addressHash, toAddressHash, new BigInteger(value));

                var tx = ZoroHelper.MakeTransaction(sb.ToArray(), nep5AccountFrm.keypair, Fixed8.Zero, gasPrice);
                bcpFee = ZoroHelper.EstimateGas(api, tx, "");

                tx = ZoroHelper.MakeTransaction(sb.ToArray(), nep5AccountFrm.keypair, Fixed8.FromDecimal(bcpFee), gasPrice);

                var result = ZoroHelper.SendRawTransaction(api, tx, "") + " gas_consumed: " + bcpFee + "\r\n txid: " + tx.Hash;

                rtbxNep5Result.Text = result;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #4
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;
            }
        }
예제 #5
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;
            }
        }
예제 #6
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;
            }
        }
예제 #7
0
        private void BatchSend_Click(object sender, EventArgs e)
        {
            UInt160 assetId;
            string  api = BatchaccountFrm.RpcUrl;

            if (BatchCbxCoinType.Text == "ZORO")
            {
                assetId = Genesis.BcpContractAddress;
            }
            else if (BatchCbxCoinType.Text == "BCT")
            {
                assetId = Genesis.BctContractAddress;
            }
            //else if (BatchCbxCoinType.Text == "BCS")
            //{
            //    assetId = BatchaccountFrm.bcsAssetId;
            //}
            else
            {
                MessageBox.Show("请选择币种!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(BatchaccountFrm.addressHash.ToString()))
            {
                MessageBox.Show("请打开钱包!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(BatchTbxValue.Text))
            {
                MessageBox.Show("请输入金额!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(BatchToAddress.Text))
            {
                MessageBox.Show("请输入接收地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                Decimal value = Decimal.Parse(BatchTbxValue.Text, NumberStyles.Float) * new Decimal(Math.Pow(10, 8));

                ScriptBuilder sb = new ScriptBuilder();

                foreach (var address in BatchToAddress.Lines)
                {
                    UInt160 targetscripthash = ZoroHelper.GetPublicKeyHashFromAddress(address.ToString());

                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", assetId, BatchaccountFrm.addressHash, targetscripthash, new BigInteger(value));
                }

                decimal gasLimit = 1010 * (decimal)BatchToAddress.Lines.Count();

                BatchGasLimit.Text = gasLimit.ToString();

                decimal gasPrice = decimal.Parse(tbxGasPrice.Text);

                var tx = ZoroHelper.MakeTransaction(sb.ToArray(), BatchaccountFrm.keypair, Fixed8.FromDecimal(gasLimit), Fixed8.FromDecimal(gasPrice));

                //var result = ZoroHelper.SendInvocationTransaction(api, sb.ToArray(), transAccountFrm.keypair, "", Fixed8.FromDecimal(1000), Fixed8.FromDecimal(gasPrice));

                BatchResult.Text = ZoroHelper.SendRawTransaction(api, tx, "") + " gas_consumed: " + gasLimit + "\r\n txid: " + tx.Hash;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #8
0
        private void btnMutiSigSendTran_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbxMutiSigRpcUrl.Text))
            {
                MessageBox.Show("RpcUrl 不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(tbxMutiSigValue.Text))
            {
                MessageBox.Show("金额不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(tbxMutiSigRecAddress.Text))
            {
                MessageBox.Show("接收地址不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            UInt160 assetId;
            string  api = tbxMutiSigRpcUrl.Text;

            if (cmbMutiSigCoinType.Text == "ZORO")
            {
                assetId = Genesis.BcpContractAddress;
            }
            else if (cmbMutiSigCoinType.Text == "BCT")
            {
                assetId = Genesis.BctContractAddress;
            }
            else
            {
                MessageBox.Show("请选择币种!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                Decimal value = Decimal.Parse(tbxMutiSigValue.Text, NumberStyles.Float) * new Decimal(Math.Pow(10, 8));

                var       wifArray = rtbxMutiSigWifs.Text.Split(';');
                KeyPair[] keypairs = wifArray.Select(p => ZoroHelper.GetKeyPairFromWIF(p)).ToArray();
                int       m        = keypairs.Length - (keypairs.Length - 1) / 3;

                UInt160 scriptHash = ZoroHelper.GetMultiSigRedeemScriptHash(m, keypairs);

                UInt160 targetscripthash = ZoroHelper.GetPublicKeyHashFromAddress(tbxMutiSigRecAddress.Text);

                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    if (cmbMutiSigCoinType.Text == "ZORO")
                    {
                        sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", assetId, scriptHash, targetscripthash, new BigInteger(value));
                    }
                    if (cmbMutiSigCoinType.Text == "BCT")
                    {
                        sb.EmitSysCall("Zoro.NativeNEP5.Call", "MintToken", assetId, targetscripthash, new BigInteger(value));
                    }

                    decimal gasLimit = ZoroHelper.GetScriptGasConsumed(api, sb.ToArray(), "");

                    gasLimit = Math.Max(decimal.Parse(tbxGasLimit.Text), gasLimit);

                    InvocationTransaction tx = ZoroHelper.MakeMultiSignatureTransaction(sb.ToArray(), m, keypairs, Fixed8.FromDecimal(gasLimit), Fixed8.FromDecimal(0.0001m));

                    rtbxMutiSigResult.Text = ZoroHelper.SendRawTransaction(api, tx, "") + " gas_consumed: " + gasLimit + "\r\n txid: " + tx.Hash;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }