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; } }
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; } }
//发布合约 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; } }
//SendRaw private void btnSendRaw_Click(object sender, EventArgs e) { string api = invokeAccountFrm.RpcUrl; if (string.IsNullOrEmpty(invokeAccountFrm.wif)) { MessageBox.Show("请输入钱包 wif !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(tbxContractScriptHash.Text)) { MessageBox.Show("合约 Hash 不能为空!", "提示", 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 { decimal gasPrice = decimal.Parse(tbxGasPrice.Text); var tx = ZoroHelper.MakeTransaction(sb.ToArray(), invokeAccountFrm.keypair, Fixed8.Zero, Fixed8.FromDecimal(gasPrice)); bcpFee = ZoroHelper.EstimateGas(api, tx, ""); tbxGasLimit.Text = bcpFee.ToString(); tx = ZoroHelper.MakeTransaction(sb.ToArray(), invokeAccountFrm.keypair, Fixed8.FromDecimal(bcpFee), Fixed8.FromDecimal(gasPrice)); var result = ZoroHelper.SendRawTransaction(api, tx, "") + " gas_consumed: " + bcpFee + "\r\n txid: " + tx.Hash; rtbxReturnJson.Text = result; } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void btnEstimateGas_Click(object sender, EventArgs e) { string api = invokeAccountFrm.RpcUrl; if (string.IsNullOrEmpty(tbxContractScriptHash.Text)) { MessageBox.Show("合约 Hash 不能为空!", "提示", 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 tx = ZoroHelper.MakeTransaction(sb.ToArray(), invokeAccountFrm.keypair, Fixed8.Zero, Fixed8.FromDecimal(0.0001m)); bcpFee = ZoroHelper.EstimateGas(api, tx, ""); tbxGasLimit.Text = bcpFee.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }