Пример #1
0
        //发布合约
        private void btnPublish_Click(object sender, EventArgs e)
        {
            string api = publishAccountFrm.RpcUrl;

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

            if (string.IsNullOrEmpty(tbxContractPath.Text))
            {
                MessageBox.Show("请输入合约文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            byte[] parameter__list = ZoroHelper.HexString2Bytes(tbxParameterType.Text);
            byte[] return_type     = ZoroHelper.HexString2Bytes("05");
            int    need_storage    = cbxNeedStorge.Checked == true ? 1 : 0;
            int    need_nep4       = cbxNeedNep4.Checked == true ? 2 : 0;
            int    need_canCharge  = cbxNeedCharge.Checked == true ? 4 : 0;

            try
            {
                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    var ss = need_storage | need_nep4 | need_canCharge;
                    sb.EmitPush(tbxDescri.Text);
                    sb.EmitPush(tbxEmail.Text);
                    sb.EmitPush(tbxAuthor.Text);
                    sb.EmitPush(tbxVersion.Text);
                    sb.EmitPush(tbxContractName.Text);
                    sb.EmitPush(ss);
                    sb.EmitPush(return_type);
                    sb.EmitPush(parameter__list);
                    sb.EmitPush(contractScript);
                    sb.EmitSysCall("Zoro.Contract.Create");

                    var tx = ZoroHelper.MakeTransaction(sb.ToArray(), publishAccountFrm.keypair, Fixed8.Zero, Fixed8.FromDecimal(0.0001m));
                    bcpFee = ZoroHelper.EstimateGas(api, tx, "");

                    lblBcpFee.Text = bcpFee.ToString();

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

                    //var result = ZoroHelper.SendInvocationTransaction(api, sb.ToArray(), publishAccountFrm.keypair, "", Fixed8.FromDecimal(bcpFee), Fixed8.FromDecimal(0.0001m));

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

                    rtbxPublishReturn.Text = result;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Пример #2
0
        public static string GetJsonString(JObject item)
        {
            var type  = item["type"].ToString();
            var value = item["value"];

            if (type == "ByteArray")
            {
                var    bt  = ZoroHelper.HexString2Bytes(value.ToString());
                string str = System.Text.Encoding.ASCII.GetString(bt);
                return(str);
            }
            return("");
        }
Пример #3
0
        public static string GetJsonBigInteger(JObject item)
        {
            var type  = item["type"].ToString();
            var value = item["value"];

            if (type == "ByteArray")
            {
                var bt  = ZoroHelper.HexString2Bytes(value.ToString());
                var num = new BigInteger(bt);
                return(num.ToString());
            }
            else if (type == "Integer")
            {
                return(value.ToString());
            }
            return("");
        }