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 static decimal GetZoroBalance(string coinType, string address) { string tokenHash = Config._nep5TokenHashDict[coinType]; UInt160 nep5Hash = UInt160.Parse(tokenHash); var addrHash = ZoroHelper.GetPublicKeyHashFromAddress(address); ScriptBuilder sb = new ScriptBuilder(); if (coinType == "bct" || coinType == "bcp" || coinType == "zoro") { sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", nep5Hash, addrHash); } else { sb.EmitAppCall(nep5Hash, "balanceOf", addrHash); } var info = ZoroHelper.InvokeScript(sb.ToArray(), ""); JObject json = JObject.Parse(info); decimal value = 0; if (json.ContainsKey("result")) { JObject json_result = json["result"] as JObject; JArray stack = json_result["stack"] as JArray; string result = ZoroHelper.GetJsonValue(stack[0] as JObject); value = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, Config._nep5TokenDecimalDict[coinType]), Config._nep5TokenDecimalDict[coinType]); } return(value); }
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; } }
public static async Task <decimal> getDecimalBalanceOfAsync(string chainHash, string assetid, string address) { using (Neo.VM.ScriptBuilder sb = new ScriptBuilder()) { sb.EmitAppCall(ZoroHelper.Parse(assetid), "balanceOf", ZoroHelper.GetPublicKeyHashFromAddress(address)); sb.EmitAppCall(ZoroHelper.Parse(assetid), "decimals"); sb.EmitAppCall(ZoroHelper.Parse(assetid), "symbol"); var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); var value = GetDecimalBalanceFromJson(info); return(value); } }
private static Dictionary <string, decimal> GetZoroBalances(string coinType, JArray addrJArray) { Dictionary <string, decimal> balanceDict = new Dictionary <string, decimal>(); ScriptBuilder sb = new ScriptBuilder(); string tokenHash = Config._nep5TokenHashDict[coinType]; UInt160 nep5Hash = UInt160.Parse(tokenHash); for (int i = 0; i < addrJArray.Count; i++) { var addrHash = ZoroHelper.GetPublicKeyHashFromAddress(addrJArray[i].ToString()); if (coinType == "bct" || coinType == "bcp" || coinType == "zoro") { sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", nep5Hash, addrHash); } else { sb.EmitAppCall(nep5Hash, "balanceOf", addrHash); } } var info = ZoroHelper.InvokeScript(sb.ToArray(), ""); JObject json = JObject.Parse(info); if (json.ContainsKey("result")) { JObject json_result = json["result"] as JObject; JArray stackJArray = json_result["stack"] as JArray; if (addrJArray.Count == stackJArray.Count) { int i = 0; for (int j = 0; j < stackJArray.Count; j++) { string result = ZoroHelper.GetJsonValue(stackJArray[j] as JObject); decimal value = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, Config._nep5TokenDecimalDict[coinType]), Config._nep5TokenDecimalDict[coinType]); balanceDict[addrJArray[i].ToString()] = value; i++; } } } return(balanceDict); }
public static async Task <decimal> getNativeDecimalBalanceOfAsync(string chainHash, string assetid, string address) { using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", UInt160.Parse(assetid), ZoroHelper.GetPublicKeyHashFromAddress(address)); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", UInt160.Parse(assetid)); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", UInt160.Parse(assetid)); var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); var value = GetDecimalBalanceFromJson(info); return(value); } }