private bool GetAccount() { try { keypair = ZoroHelper.GetKeyPairFromWIF(tbxAccountWif.Text); addressHash = ZoroHelper.GetPublicKeyHash(keypair.PublicKey); tbxAccountAddress.Text = ZoroHelper.GetAddressFromScriptHash(addressHash); wif = tbxAccountWif.Text; address = ZoroHelper.GetAddressFromScriptHash(addressHash); } catch { MessageBox.Show("钱包 Wif 密钥格式错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
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; } }