public async Task InvokeNep5Async(string chainHash, string WIF, string ContractHash) { UInt160 scriptHash = ZoroHelper.Parse(ContractHash); using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitAppCall(scriptHash, "name"); sb.EmitAppCall(scriptHash, "totalSupply"); sb.EmitAppCall(scriptHash, "symbol"); sb.EmitAppCall(scriptHash, "decimals"); var result = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); //Console.WriteLine(result); MyJson.JsonNode_Object json_result_array = MyJson.Parse(result) as MyJson.JsonNode_Object; MyJson.JsonNode_Object json_result_obj = json_result_array["result"] as MyJson.JsonNode_Object; MyJson.JsonNode_Array stack = json_result_obj["stack"].AsList(); if (stack.Count == 4) { Console.WriteLine("name:" + Helper.GetJsonString(stack[0] as MyJson.JsonNode_Object)); Console.WriteLine("totalSupply:" + Helper.GetJsonBigInteger(stack[1] as MyJson.JsonNode_Object)); Console.WriteLine("symbol:" + Helper.GetJsonString(stack[2] as MyJson.JsonNode_Object)); Console.WriteLine("decimals:" + Helper.GetJsonInteger(stack[3] as MyJson.JsonNode_Object)); } } }
public async Task InvokeNativeNep5Async(string chainHash, string nativeNEP5Hash) { UInt160 nativeNEP5AssetId = ZoroHelper.Parse(nativeNEP5Hash); using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitSysCall("Zoro.NativeNEP5.Call", "Name", nativeNEP5AssetId); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", nativeNEP5AssetId); sb.EmitSysCall("Zoro.NativeNEP5.Call", "TotalSupply", nativeNEP5AssetId); sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", nativeNEP5AssetId); var result = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); //Console.WriteLine(result); MyJson.JsonNode_Object json_result_array = MyJson.Parse(result) as MyJson.JsonNode_Object; MyJson.JsonNode_Object json_result_obj = json_result_array["result"] as MyJson.JsonNode_Object; MyJson.JsonNode_Array stack = json_result_obj["stack"].AsList(); if (stack.Count == 4) { Console.WriteLine("name:" + Helper.GetJsonString(stack[0] as MyJson.JsonNode_Object)); Console.WriteLine("symbol:" + Helper.GetJsonString(stack[1] as MyJson.JsonNode_Object)); Console.WriteLine("totalSupply:" + Helper.GetJsonBigInteger(stack[2] as MyJson.JsonNode_Object)); Console.WriteLine("decimals:" + Helper.GetJsonInteger(stack[3] as MyJson.JsonNode_Object)); } } }
public async Task SendRawTransactionTestAsync(string contractHash, string WIF, UInt160 nativeBcp, int transType) { Console.WriteLine("Transfer Amount:"); string transferValue = Console.ReadLine(); Decimal value = Decimal.Parse(transferValue, NumberStyles.Float) * new Decimal(Math.Pow(10, 8)); string chainHash = Config.getValue("ChainHash"); KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF); UInt160 scriptHash = ZoroHelper.GetPublicKeyHash(keypair.PublicKey); UInt160 targetscripthash = UInt160.Parse(contractHash); using (ScriptBuilder sb = new ScriptBuilder()) { if (transType == 1) { sb.EmitAppCall(ZoroHelper.Parse(contractHash), "transfer", nativeBcp, scriptHash, targetscripthash, (BigInteger)value); } if (transType == 2) { sb.EmitAppCall(ZoroHelper.Parse(contractHash), "transfer_app", nativeBcp, scriptHash, (BigInteger)value); } var result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Config.GasPrice); MyJson.JsonNode_Object resJO = (MyJson.JsonNode_Object)MyJson.Parse(result); Console.WriteLine(resJO.ToString()); } }
public async Task ContractInvokeTestAsync(string contractHash, UInt160 address, UInt160 nativeBcp) { string[] ChainHashList = Config.getStringArray("ChainHashList"); using (ScriptBuilder sb = new ScriptBuilder()) { //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "balanceOf", nativeBcp, address); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "symbol", nativeBcp); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "decimals", nativeBcp); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "totalSupply", nativeBcp); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "test"); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "call"); //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "getheight"); sb.EmitAppCall(ZoroHelper.Parse(contractHash), "getheader", 20); Console.WriteLine($"Contract: {contractHash}"); foreach (var chainHash in ChainHashList) { var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); string chainName = chainHash.Length > 0 ? chainHash : "Root"; Console.WriteLine($"{info}"); } } }
public async Task DeployNEP5Async(string ChainHash, string WIF, string ContractHash) { KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF); using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitAppCall(ZoroHelper.Parse(ContractHash), "deploy", "1"); string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, ChainHash, Config.GasPrice); Console.WriteLine(result); } }
async Task BalanceOfNEP5Contract(string NEP5Contract, UInt160 address, string[] chainHashList) { using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitAppCall(ZoroHelper.Parse(NEP5Contract), "balanceOf", address); sb.EmitAppCall(ZoroHelper.Parse(NEP5Contract), "decimals"); foreach (var chainHash in chainHashList) { var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash); var value = GetBalanceFromJson(info); string chainName = chainHash.Length > 0 ? chainHash : "Root"; Console.WriteLine($"BalanceOf NEP5:{value}, chain:{chainName}"); } } }