/// <summary> /// Catches and processes all notifications triggered in a Neo transaction /// </summary> /// <param name="tx"></param> private void ProcessNotifications(uint height, Transaction tx) { Console.WriteLine($"{height} Processing tx {tx.Hash} notifications..."); // add the transaction to the cache _transactions[tx.Hash] = tx; var notifications = _listenerVM.GetNotifications(tx); if (notifications == null) { return; } foreach (var entry in notifications) { Console.WriteLine($"{entry.Name}\t{JsonConvert.SerializeObject(entry)}"); } }
/// <summary> /// Catches and processes all notifications triggered in a Neo transaction /// </summary> /// <param name="tx"></param> private void ProcessNotifications(uint height, Transaction tx) { Console.WriteLine($"{height} Processing tx {tx.Hash} notifications..."); // add the transaction to the cache _transactions[tx.Hash] = tx; var notifications = _listenerVM.GetNotifications(tx); if (notifications == null) { return; } int index = 0; foreach (Notification entry in notifications) { foreach (object o in entry.Args) { if (o is System.String) { Console.WriteLine($"{index}\t'{entry.Name}'\t'{(string)o}'"); break; } else if (o is System.Byte[]) { Console.WriteLine($"{index}\t'{entry.Name}'\t'{Helpers.ToHex((byte[])o)}'\t{Encoding.ASCII.GetString((byte[])o)}"); break; } else { Console.WriteLine($"{index}\t'{entry.Name}'\t{JsonConvert.SerializeObject(o)}"); break; } } index++; } }
/// <summary> /// Catches and processes all notifications triggered in a Neo transaction /// </summary> /// <param name="tx"></param> private void ProcessNotifications(Transaction tx) { // add the transaction to the cache transactions[tx.Hash] = tx; var notifications = listenerVM.GetNotifications(tx); if (notifications == null) { return; } foreach (var entry in notifications) { switch (entry.Name) { case "blz_create": { if (entry.Args.Length != 3) { throw new Exception($"Swarm.Create expects 3 arguments"); } var uuid = (byte[])entry.Args[0]; var key = (byte[])entry.Args[1]; var value = (byte[])entry.Args[2]; this.swarm.Create(uuid, key, value); break; } case "blz_read": { if (entry.Args.Length != 2) { throw new Exception($"Swarm.Read expects 2 arguments"); } var uuid = (byte[])entry.Args[0]; var key = (byte[])entry.Args[1]; var value = this.swarm.Read(uuid, key); var push_tx = neo_api.CallContract(owner_keys, bluzelle_contract_hash, "api_push", new object[] { uuid, key, value }); neo_api.WaitForTransaction(owner_keys, push_tx); break; } case "blz_update": { if (entry.Args.Length != 3) { throw new Exception($"Swarm.Update expects 3 arguments"); } var uuid = (byte[])entry.Args[0]; var key = (byte[])entry.Args[1]; var value = (byte[])entry.Args[2]; this.swarm.Update(uuid, key, value); // public static event Action<byte[], byte[], byte[]> OnUpdate; break; } case "blz_delete": { if (entry.Args.Length != 2) { throw new Exception($"Swarm.Delete expects 2 arguments"); } var uuid = (byte[])entry.Args[0]; var key = (byte[])entry.Args[1]; this.swarm.Remove(uuid, key); break; } } } }