private void BtnSend_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbxGasLimit.Text)) { MessageBox.Show("Please estimategas first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UInt160 to; Decimal value; try { to = ZoroHelper.GetPublicKeyHashFromAddress(tbxTo.Text); } catch { MessageBox.Show("To address error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { value = Decimal.Parse(tbxValue.Text, NumberStyles.Float) * new Decimal(Math.Pow(10, 8)); } catch { MessageBox.Show("Value error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (ScriptBuilder sb = new ScriptBuilder()) { if (Symbol == "ZORO" || Symbol == "BCT") { sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", AssetId, Account.ScriptHash, to, new BigInteger(value)); } else { sb.EmitAppCall(AssetId, "transfer", Account.ScriptHash, to, new BigInteger(value)); } decimal gasLimit = decimal.Parse(tbxGasLimit.Text); decimal gasPrice = decimal.Parse(tbxGasPrice.Text); var tx = ZoroHelper.MakeTransaction(sb.ToArray(), Account.GetKey(), Fixed8.FromDecimal(gasLimit), Fixed8.FromDecimal(gasPrice)); string txid = tx.Hash.ToString(); var script = sb.ToArray().ToHexString(); Zoro.IO.Json.JArray _params = new Zoro.IO.Json.JArray(); _params.Add(""); _params.Add(tx.ToArray().ToHexString()); var result = Handler.Process("sendrawtransaction", _params); string[] text = new string[] { "Result : " + result.ToString(), "Txid : " + txid }; tbxResult.Lines = text; } }
private void BtnEstimateGas_Click(object sender, EventArgs e) { UInt160 to; Decimal value; try { to = ZoroHelper.GetPublicKeyHashFromAddress(tbxTo.Text); } catch { MessageBox.Show("To address error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { value = Decimal.Parse(tbxValue.Text, NumberStyles.Float) * new Decimal(Math.Pow(10, Decimals)); } catch { MessageBox.Show("Value error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { using (ScriptBuilder sb = new ScriptBuilder()) { if (Symbol == "ZORO" || Symbol == "BCT") { sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", AssetId, Account.ScriptHash, to, new BigInteger(value)); } else { sb.EmitAppCall(AssetId, "transfer", Account.ScriptHash, to, new BigInteger(value)); } var tx = ZoroHelper.MakeTransaction(sb.ToArray(), Account.GetKey(), Fixed8.Zero, Fixed8.FromDecimal(0.0001m)); Zoro.IO.Json.JArray _params = new Zoro.IO.Json.JArray(); _params.Add(""); _params.Add(tx.ToArray().ToHexString()); var info = Program.Handler.Process("estimategas", _params); JObject json_response = JObject.Parse(info.ToString()); string json_gas_consumed = json_response["gas_consumed"].ToString(); tbxGasLimit.Text = json_gas_consumed; } } catch { MessageBox.Show("Transaction!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void BtnPublish_Click(object sender, EventArgs e) { if (contractScript.Length == 0) { MessageBox.Show("Contract file error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 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(), walletAccount.GetKey(), Fixed8.Zero, Fixed8.FromDecimal(0.00001m)); Zoro.IO.Json.JArray _params = new Zoro.IO.Json.JArray(); _params.Add(""); _params.Add(tx.ToArray().ToHexString()); //var info = Program.Handler.Process("estimategas", _params); //JObject json_response = JObject.Parse(info.ToString()); //string json_gas_consumed = json_response["gas_consumed"].ToString(); //lblZoroFee.Text = json_gas_consumed; tx = ZoroHelper.MakeTransaction(sb.ToArray(), walletAccount.GetKey(), Fixed8.FromDecimal(decimal.Parse(lblZoroFee.Text)), Fixed8.FromDecimal(0.0001m)); string txid = tx.Hash.ToString(); var script = sb.ToArray().ToHexString(); Zoro.IO.Json.JArray _paramss = new Zoro.IO.Json.JArray(); _paramss.Add(""); _paramss.Add(tx.ToArray().ToHexString()); var result = Program.Handler.Process("sendrawtransaction", _paramss); string[] text = new string[] { "Result : " + result.ToString(), "Txid : " + txid }; tbxResult.Lines = text; } } catch (Exception ex) { MessageBox.Show("Published error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }