예제 #1
0
        private void btnCallSendRaw_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
            {
                bcpFee = ZoroHelper.GetScriptGasConsumed(api, sb.ToArray(), "");
                tbxCallGasLimit.Text = bcpFee.ToString();

                var tx = ZoroHelper.MakeTransaction(sb.ToArray(), otherCallAccountFrm.keypair, Fixed8.FromDecimal(bcpFee), Fixed8.FromDecimal(0.0001m));

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

                rtbxCallResult.Text = result;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #2
0
        private void btnCallEstimateGas_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
            {
                bcpFee = ZoroHelper.GetScriptGasConsumed(api, sb.ToArray(), "");

                tbxCallGasLimit.Text = bcpFee.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
예제 #3
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;
            }
        }
예제 #4
0
        //转账交易
        private void btnSendTransaction_Click(object sender, EventArgs e)
        {
            UInt160 assetId;
            string  api = transAccountFrm.RpcUrl;

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

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

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

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

                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", assetId, transAccountFrm.addressHash, targetscripthash, new BigInteger(value));

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

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

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

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

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

                    rtbxTranResult.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;
            }
        }