private static async Task EventDecodeAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); //var eventStr = "0x1802130100020800bc0000007f9267dfabb62a000000000000000000ac9baa9c3eff7f00000000000000000000021006ac9baa9c3eff7f000000000000000000000209006e04000000000000000000005095a20900000000020000010f00087c932416d1f140d6351d3b6b09ff6fee66ff240bdb92976d36c2ef5b13d83c7f0100000000000000490b83057d01d315d27e2b607c31754419bce23df85e39db096abce12716470b010000000000000000"; //var eventStr = "0x08000000000000005095a20900000000020000000100000000000000000000000000020000"; var eventStr = "0x04000000000000005095a20900000000020000"; //var eventRecord = EventRecords.Decode(eventStr, client.MetaData); var eventRecord = new EventRecords(client.MetaData); eventRecord.Create(eventStr); Console.WriteLine(eventRecord.ToString()); }
private static async Task EventhandlingTestAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); Action <string, StorageChangeSet> callBackSubscribeStorage = (subscriptionId, eventObject) => { if (eventObject.Changes == null) { return; } try { Console.WriteLine($"OldEventRecord: {eventObject.Changes[0][1]}"); var eventRecords = new EventRecords(client.MetaData); eventRecords.Create(eventObject.Changes[0][1].ToString()); Console.WriteLine(eventRecords.ToString()); } catch (NotImplementedException e) { Console.WriteLine($"##### {e}"); } }; // GetStorageKeyBytesHash var systemEventsKeys = Utils.Bytes2HexString(RequestGenerator.GetStorageKeyBytesHash("System", "Events")); var jArray = new JArray(systemEventsKeys); Console.WriteLine($"Key: {systemEventsKeys}"); var subscriptionId = await client.State.SubscribeStorageAsync(jArray, callBackSubscribeStorage ); Console.WriteLine("Press any key!"); Console.ReadKey(); //var reqResult = await client.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None); }