/// <summary> /// Connects the asynchronous. /// </summary> /// <param name="webSocketUrl">The web socket URL.</param> private async Task ConnectAsync(string webSocketUrl) { Logger.Info($"Connecting to {webSocketUrl}"); Client = new SubstrateClient(new Uri(webSocketUrl)); //TODO check if that can be made generic as parameter Client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); Client.RegisterTypeConverter(new GenericTypeConverter <MogwaiBios>()); await Client.ConnectAsync(_connectTokenSource.Token); if (!IsConnected) { Logger.Error("Connection couldn't be established!"); return; } var systemName = await Client.System.NameAsync(_connectTokenSource.Token); var systemVersion = await Client.System.VersionAsync(_connectTokenSource.Token); var systemChain = await Client.System.ChainAsync(_connectTokenSource.Token); ChainInfo = new ChainInfo(systemName, systemVersion, systemChain, Client.RuntimeVersion); Logger.Info($"Connection established to {ChainInfo}"); }
private static async Task StorageRuntimeVersionAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiBios>()); await client.ConnectAsync(CancellationToken.None); var reqResult = await client.State.GetRuntimeVersionAsync(); Console.WriteLine(reqResult); }
private static async Task OwnedMogwaisCountSubscriptionAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var reqResult = await client.GetStorageAsync("DotMogModule", "OwnedMogwaisCount", new[] { Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH")) }, null, CancellationToken.None); Console.WriteLine($"DotMogModule.OwnedMogwaisCount = {reqResult}"); Action <string, StorageChangeSet> callBackSubscribeStorage = (subscriptionId, eventObject) => { Console.WriteLine($"Subscription[{subscriptionId}]: {eventObject}"); }; // TODO GetStorageKeyBytesHash var keys = await client.GetStorageKeysAsync("DotMogModule", "OwnedMogwaisCount", CancellationToken.None); //var subscriptionId = await client.SubscribeStorageKeyAsync("DotMogModule", "OwnedMogwaisCount", new string[] { Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH")) }, var subscriptionId = await client.State.SubscribeStorageAsync(keys, callBackSubscribeStorage, CancellationToken.None ); Thread.Sleep(60000); var reqResultUnsubscribe = await client.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None); }
public async Task ConnectAsync(string webSocketUrl) { Logger.Info($"Connecting to {webSocketUrl}"); _client = new SubstrateClient(new Uri(webSocketUrl)); _client.RegisterTypeConverter(new MogwaiStructTypeConverter()); await _client.ConnectAsync(_connectTokenSource.Token); if (!IsConnected) { Logger.Error($"Connection couldn't be established!"); return; } var systemName = await _client.System.NameAsync(_connectTokenSource.Token); var systemVersion = await _client.System.VersionAsync(_connectTokenSource.Token); var systemChain = await _client.System.ChainAsync(_connectTokenSource.Token); ChainInfo = new ChainInfo(systemName, systemVersion, systemChain); Logger.Info($"Connection established to {ChainInfo}"); }
private static async Task GetPairsAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var keys = await client.State.GetPairsAsync( RequestGenerator.GetStorageKeyBytesHash("DotMogModule", "OwnedMogwaisCount"), CancellationToken.None); Console.WriteLine($"Key: {keys}"); }
private static async Task GetKeysPagedAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var keys = await client.State.GetKeysPagedAsync( Utils.HexToByteArray("0x0c97543ac4e96dcb4706b30bdf6e92168b0d930c4954153694987c34a9823bbd"), 3, Utils.HexToByteArray( "0x0c97543ac4e96dcb4706b30bdf6e92168b0d930c4954153694987c34a9823bbd048abc25e90483f36fa94d713b9bf2ea2aff9a42ef458696d3f8e340de66def4692856a8f51e1435f5d5df755a138c51"), CancellationToken.None); Console.WriteLine($"Key: {keys}"); }
private static async Task TestAsync(string[] args) { //Console.WriteLine(Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM").Length); using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var eventStr = "0x14" + "00" + // ******************* EVENT 1 begin "00000000" + // phase {ApplyExtrinsic: 0 u32} "0000" + // event { index: 0x0000 "482d7c0900000000" + // weight: 159,133,000 "02" + // class: Mandatory "00" + // paysFee: Yes "00" + // ******************* EVENT 1 end "00" + // ******************* EVENT 2 begin "01000000" + // phase {ApplyExtrinsic: 1 u32} "0000" + // event { index: 0x0000 "0000000000000000" + // weight: 0, "02" + // class: Mandatory, "00" + // paysFee: Yes "00" + // ******************* EVENT 2 end "00" + // ******************* EVENT 3 begin "02000000" + // phase {ApplyExtrinsic: 1 u32} "2002" + // event { index: 0x2002 "4d2b23d27e1f6e3733d7ebf3dc04f3d5d0010cd18038055f9bbbab48f460b61e" + // public-key "87a1395e8b61d529e7684d80373d52a23dd5de84061ab0a980ecbbcb3364457b" + // mogwai-id "00" + // ******************* EVENT 3 end "00" + // ******************* EVENT 4 begin "02000000" + // phase {ApplyExtrinsic "1106" + // event { index: "2e6bb353c70000000000000000000000" + "00" + // ******************* EVENT 4 end "00" + // ******************* EVENT 5 begin "02000000" + // phase {ApplyExtrinsic "0000" + // event { index: "1008f60500000000" + "00" + // class: Mandatory, "00" + // paysFee: Yes "00"; // ******************* EVENT 4 begin ; var eventRecords = new EventRecords(client.MetaData); eventRecords.Create(eventStr); Console.WriteLine(eventRecords); }
private static async Task GetAllOwnedMogwaisAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var keyBytes = RequestGenerator.GetStorageKeyBytesHash("DotMogModule", "OwnedMogwaisArray"); var keyString = Utils.Bytes2HexString(RequestGenerator.GetStorageKeyBytesHash("DotMogModule", "OwnedMogwaisArray")).ToLower(); var keys = await client.State.GetPairsAsync(keyBytes, CancellationToken.None); foreach (var child in keys.Children()) { Console.WriteLine($"{child[0].ToString()} --> {child[1].ToString()}"); } }
public async Task ConnectAsync(string webSocketUrl = WEBSOCKETURL) { _client = new SubstrateClient(new Uri(webSocketUrl)); _client.RegisterTypeConverter(new MogwaiStructTypeConverter()); await _client.ConnectAsync(_connectTokenSource.Token); var systemName = await _client.System.NameAsync(_connectTokenSource.Token); var systemVersion = await _client.System.VersionAsync(_connectTokenSource.Token); var systemChain = await _client.System.ChainAsync(_connectTokenSource.Token); ChainInfo = new ChainInfo(systemName, systemVersion, systemChain); }
private static async Task GetAllMogwaiHashsAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); // TODO GetStorageKeyBytesHash var keys = await client.GetStorageKeysAsync("DotMogModule", "Mogwais", CancellationToken.None); var keyString = Utils.Bytes2HexString(RequestGenerator.GetStorageKeyBytesHash("DotMogModule", "Mogwais")).ToLower(); Console.WriteLine($"Key: {keyString}"); foreach (var key in keys) { Console.WriteLine(key.ToString().Replace(keyString, "")); } }
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); }
public async Task ParameterizedTest2Async() { var accountZurich = Account.Build( KeyType.Ed25519, Utils.HexToByteArray( "0xf5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e"), Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM")); _substrateClient.RegisterTypeConverter(new GenericTypeConverter <AssetBalance>()); await _substrateClient.ConnectAsync(); var request = await _substrateClient.GetStorageAsync("Assets", "Account", new[] { "0" }, new[] { Utils.Bytes2HexString(accountZurich.Bytes) }); Assert.AreEqual("AssetBalance", request.GetType().Name); Assert.IsTrue(request is AssetBalance); var assetBalance = (AssetBalance)request; Assert.AreEqual(100, assetBalance.Balance.Value); await _substrateClient.CloseAsync(); }
private static async Task RunBlockCallsAsync(CancellationToken cancellationToken) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(cancellationToken); var systemName = await client.System.NameAsync(cancellationToken); var systemVersion = await client.System.VersionAsync(cancellationToken); var systemChain = await client.System.ChainAsync(cancellationToken); Console.WriteLine($"Connected to System: {systemName} Chain: {systemChain} Version: {systemVersion}."); // 544133 CreateMogwai(); for (uint i = 0; i < 10; i++) { var blockNumber = new BlockNumber(); blockNumber.Create(i); Console.WriteLine(blockNumber.Encode()); Console.WriteLine(Utils.Bytes2HexString(blockNumber.Encode())); var blockHash = await client.Chain.GetBlockHashAsync(blockNumber, cancellationToken); //var block = await client.Chain.GetBlockAsync(blockHash, cancellationToken); // Print result //Console.WriteLine($"{i} --> {block.Block.Extrinsics.Length}"); Console.WriteLine($"{i} --> {blockHash.Value}"); } //Console.WriteLine(client.MetaData.Serialize()); Console.ReadKey(); // Close connection await client.CloseAsync(cancellationToken); }
private static async Task ParseEventsAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var dict = new Dictionary <string, string>(); foreach (var module in client.MetaData.Modules) { if (module.Events == null) { continue; } foreach (var singleEvent in module.Events) { if (singleEvent.EventArgs == null) { continue; } foreach (var eventArg in singleEvent.EventArgs) { if (!dict.ContainsKey(eventArg)) { dict.Add(eventArg, $"{module.Name}.{singleEvent.Name}"); } } } } foreach (var keyValue in dict) { Console.WriteLine( $"case \"{keyValue.Key}\":\ndata.Add(({keyValue.Key}){keyValue.Key}.Decode(byteArray, ref p));\nbreak;"); } }
private static async Task AccountSubscriptionAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); Action <string, StorageChangeSet> callBackAccountChange = (subscriptionId, eventObject) => { Console.WriteLine($"Subscription[{subscriptionId}]: {eventObject}"); if (eventObject.Changes != null) { try { var accountInfo = new AccountInfo(); accountInfo.Create(eventObject.Changes[0][1]); Console.WriteLine(accountInfo); } catch (NotImplementedException e) { Console.WriteLine($"##### {e}"); } } }; var subscriptionId = await client.SubscribeStorageKeyAsync("System", "Account", new[] { Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH")) }, callBackAccountChange, CancellationToken.None); Thread.Sleep(60000); var reqResultUnsubscribe = await client.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None); }
private static async Task AllMogwaisCountSubscriptionAsync(string[] args) { using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); await client.ConnectAsync(CancellationToken.None); var subscriptionId = await client.SubscribeStorageKeyAsync("DotMogModule", "AllMogwaisCount", null, (id, storageChangeSet) => { foreach (var change in storageChangeSet.Changes) { var p = 0; var u64 = new U64(); u64.Decode(Utils.HexToByteArray(change[1]), ref p); var result = u64.Value; Console.WriteLine($"AllMogwaisCount = {result}"); } }, CancellationToken.None); Thread.Sleep(60000); var reqResultUnsubscribe = await client.State.UnsubscribeStorageAsync(subscriptionId, CancellationToken.None); }
private static async Task TestClaimShizzleAsync(string[] args) { var accountZurich = Account.Build( KeyType.Ed25519, Utils.HexToByteArray( "0xf5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e"), Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM")); var accountTest = new Account(); using var client = new SubstrateClient(new Uri(Websocketurl)); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiBios>()); client.RegisterTypeConverter(new GenericTypeConverter <GameEvent>()); client.RegisterTypeConverter(new GenericTypeConverter <EnumType <RarityType> >()); client.RegisterTypeConverter(new GenericTypeConverter <EnumType <ClaimState> >()); client.RegisterTypeConverter(new GenericTypeConverter <MogwaicoinAddress>()); await client.ConnectAsync(CancellationToken.None); var hexAddress = Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5E77sDSL4sgAteLAMLjkEyQsHaoiqCMUJTk18XWefeVXC4Bb")); var hexAccount = Utils.Bytes2HexString(Encoding.ASCII.GetBytes("M9XfSaTHgGtwQnkrkG1EWRJpSdVsREU44u")); MogwaicoinAddress reqResult = (MogwaicoinAddress)await client.GetStorageAsync("DotMogBase", "AccountClaim", new [] { hexAddress, hexAccount }, null, CancellationToken.None); //Console.WriteLine(Encoding.Default.GetString(reqResult.Signature.Value.Select(p => p.Bytes[0]).ToArray())); //string mogwaicoinAddress = Encoding.Default.GetString(reqResult.Address.Value.Select(p => p.Bytes[0]).ToArray()); //Console.WriteLine(mogwaicoinAddress); //Console.WriteLine($"RESPONSE: '{reqResult}' [{reqResult?.GetType().Name}]"); var balance = new RawBalance(); //balance.Create("0x03000000000000000000000000000000"); balance.Create(1000000000000000); var update_claim = DotMogCall.UpdateClaim("M9XfSaTHgGtwQnkrkG1EWRJpSdVsREU44u", "5E77sDSL4sgAteLAMLjkEyQsHaoiqCMUJTk18XWefeVXC4Bb", ClaimState.Registred, balance); //var update_claim = DotMogCall.UpdateClaim(reqResult.Address, account, claimState, balance); //UnCheckedExtrinsic extrResult = await client.GetExtrinsicParametersAsync(update_claim, accountTest, 0, 64, true, CancellationToken.None); var extrResult = await client.Author.SubmitExtrinsicAsync(update_claim, accountTest, 0, 64, CancellationToken.None); Console.WriteLine(Utils.Bytes2HexString(extrResult.Encode())); }
public void MultipleConverterTest() { _substrateClient.RegisterTypeConverter(new MogwaiStructTypeConverter()); Assert.Throws <ConverterAlreadyRegisteredException>(() => _substrateClient.RegisterTypeConverter(new MogwaiStructTypeConverter())); }
static async Task MainAsync(CancellationToken cancellationToken) { Account accountAlice = new Account( KeyType.SR25519, Utils.HexToByteArray("0x33A6F3093F158A7109F679410BEF1A0C54168145E0CECB4DF006C1C2FFFB1F09925A225D97AA00682D6A59B95B18780C10D7032336E88F3442B42361F4A66011"), Utils.GetPublicKeyFrom("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")); Account accountZurich = new Account( KeyType.ED25519, Utils.HexToByteArray("0xf5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e"), Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM")); Account accountDMOG_GALxeh = new Account( KeyType.ED25519, Utils.HexToByteArray("0x3f997449154f8aaa134341b07c3710f63d57e73025105ca7e65a151d7fc3e2bf4b94e38b0c2ee21c367d4c9584204ce62edf5b4a6f675f10678cc56b6ea86e71"), Utils.GetPublicKeyFrom("5DmogGALxehCbUmm45XJoADcf9BU71ZK2zmqHDPFJD3VxknC")); using var client = new SubstrateClient(new Uri(WEBSOCKETURL)); client.RegisterTypeConverter(new MogwaiStructTypeConverter()); await client.ConnectAsync(cancellationToken); var systemName = await client.System.NameAsync(cancellationToken); var systemVersion = await client.System.VersionAsync(cancellationToken); var systemChain = await client.System.ChainAsync(cancellationToken); Console.WriteLine($"Connected to System: {systemName} Chain: {systemChain} Version: {systemVersion}."); /*** * Testing storage data ... */ //var reqResult = await client.GetStorageAsync("Sudo", "Key", cancellationToken); // [Plain] Value: u64 //var reqResult = await client.GetStorageAsync("Dmog", "AllMogwaisCount", cancellationToken); // [Map] Key: u64, Hasher: Blake2_128Concat, Value: T::Hash //var reqResult = await client.GetStorageAsync("Dmog", "AllMogwaisArray", "0", cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: Optional<T::AccountId> //var reqResult = await client.GetStorageAsync("Dmog", "MogwaiOwner", "0xAD35415CB5B574819C8521B9192FFFDA772C0770FED9A55494293B2D728F104C", cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: MogwaiStruct<T::Hash, BalanceOf<T>> //var reqResult = await client.GetStorageAsync("Dmog", "Mogwais", "0xAD35415CB5B574819C8521B9192FFFDA772C0770FED9A55494293B2D728F104C", cancellationToken); //var reqResult = await client.GetMethodAsync<JArray>("system_peers", cancellationToken); // [Map] Key: T::AccountId, Hasher: Blake2_128Concat, Value: AccountInfo<T::Index, T::AccountData> //var reqResult = await client.GetStorageAsync("System", "Account", "0xD43593C715FDD31C61141ABD04A99FD6822C8558854CCDE39A5684E7A56DA27D", cancellationToken); //var reqResult = await client.GetStorageAsync("System", "Account", Utils.Bytes2HexString(Utils.HexToByteArray("0xD43593C715FDD31C61141ABD04A99FD6822C8558854CCDE39A5684E7A56DA27D")), cancellationToken); //var reqResult = await client.GetMethodAsync<JArray>("author_pendingExtrinsics", cancellationToken); // *************************** Final Test //var reqResult = await client.SubmitExtrinsicAsync(DmogCall.CreateMogwai(), accountAlice, 0, 64, cancellationToken); //var reqResult = await client.Author.PendingExtrinsicAsync(cancellationToken); //var reqResult = await client.SubmitExtrinsicAsync(ExtrinsicCall.BalanceTransfer("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 100000000), accountDMOG_GALxeh, 0, 64, cancellationToken); // *** subscription test 1 var subscriptionId = await client.Chain .SubscribeAllHeadsAsync( (header) => Console.WriteLine($"CallBack: {header}"), cancellationToken ); Thread.Sleep(30000); var reqResult = await client.Chain.UnsubscribeAllHeadsAsync(subscriptionId, cancellationToken); // *** subscription test 2 //Action<ExtrinsicStatus> actionExtrinsicUpdate = (extrinsicUpdate) => Console.WriteLine($"CallBack: {extrinsicUpdate}"); //var subscriptionId = await client.Author.SubmitAndWatchExtrinsicAsync(actionExtrinsicUpdate, ExtrinsicCall.BalanceTransfer("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 1000), accountDMOG_GALxeh, 0, 64, cancellationToken); //Thread.Sleep(60000); //var reqResult = await client.Author.UnwatchExtrinsicAsync(subscriptionId, cancellationToken); //Hash finalizedHead = await client.Chain.GetFinalizedHeadAsync(cancellationToken); //var reqResult = await client.Chain.GetBlockAsync(finalizedHead, cancellationToken); // Print result Console.WriteLine($"RESPONSE: '{reqResult}' [{reqResult.GetType().Name}]"); Console.ReadKey(); // Close connection await client.CloseAsync(cancellationToken); }
private static async Task MainAsync(CancellationToken cancellationToken) { var accountAlice = Account.Build( KeyType.Sr25519, Utils.HexToByteArray( "0x33A6F3093F158A7109F679410BEF1A0C54168145E0CECB4DF006C1C2FFFB1F09925A225D97AA00682D6A59B95B18780C10D7032336E88F3442B42361F4A66011"), Utils.GetPublicKeyFrom("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")); var accountZurich = Account.Build( KeyType.Ed25519, Utils.HexToByteArray( "0xf5e5767cf153319517630f226876b86c8160cc583bc013744c6bf255f5cc0ee5278117fc144c72340f67d0f2316e8386ceffbf2b2428c9c51fef7c597f1d426e"), Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM")); var accountDMOG_GALxeh = Account.Build( KeyType.Ed25519, Utils.HexToByteArray( "0x3f997449154f8aaa134341b07c3710f63d57e73025105ca7e65a151d7fc3e2bf4b94e38b0c2ee21c367d4c9584204ce62edf5b4a6f675f10678cc56b6ea86e71"), Utils.GetPublicKeyFrom("5DmogGALxehCbUmm45XJoADcf9BU71ZK2zmqHDPFJD3VxknC")); using var client = new SubstrateClient(new Uri(Websocketurl)); // add chain specific types here client.RegisterTypeConverter(new GenericTypeConverter <MogwaiStruct>()); client.RegisterTypeConverter(new GenericTypeConverter <MogwaiBios>()); client.RegisterTypeConverter(new GenericTypeConverter <GameEvent>()); client.RegisterTypeConverter(new GenericTypeConverter <EnumType <RarityType> >()); client.RegisterTypeConverter(new GenericTypeConverter <MogwaicoinAddress>()); await client.ConnectAsync(cancellationToken); /*** * Basic ... */ //var reqResult = await client.System.NameAsync(cancellationToken); //var systemVersion = await client.System.VersionAsync(cancellationToken); //var systemChain = await client.System.ChainAsync(cancellationToken); //var reqResult = await client.State.GetRuntimeVersionAsync(cancellationToken); //Console.WriteLine($"Connected to System: {systemName} Chain: {systemChain} Version: {systemVersion}."); Console.WriteLine( $"Running: {client.RuntimeVersion.SpecName}[{client.RuntimeVersion.SpecVersion}] transaction_version: {client.RuntimeVersion.TransactionVersion}."); // TODO: Implement all rpc standard functions from substrate node //var reqResult = await client.GetMethodAsync<JArray>("system_peers", cancellationToken); /*** * Testing storage data ... */ var address = "5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH"; var mogwaiId = "0x89ab510f57802886c16922685a376edb536f762584dda569cda67381c4e4dec8"; var mogwaiIdGen1 = "0x0b1b9f0f79a9e3971baf6188ed98623284f1c3bb275883602164b7097789523f"; // [Plain] Value: T::AccountId //var reqResult = await client.GetStorageAsync("Sudo", "Key", cancellationToken); //var reqResult = await client.GetStorageAsync("System", "Number", cancellationToken); //var reqResult = await client.GetStorageAsync("Session", "QueuedChanged", cancellationToken); // [Plain] Value: u64 //var reqResult = await client.GetStorageAsync("DotMogModule", "AllMogwaisCount", cancellationToken); // [Plain] Value: u64 //var reqResult = await client.GetStorageAsync("DotMogModule", "OwnedMogwaisCount", new [] {Utils.Bytes2HexString(Utils.GetPublicKeyFrom(address))}, cancellationToken); //var reqResult = await client.GetStorageAsync("DotMogModule", "OwnedMogwaisArray", new [] { Utils.Bytes2HexString(Utils.GetPublicKeyFrom(address)), "1" } , cancellationToken); // [Map] Key: u64, Hasher: BlakeTwo128Concat, Value: T::Hash //var reqResult = await client.GetStorageAsync("DotMogModule", "AllMogwaisArray", new[]{"0"}, cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: Optional<T::AccountId> //var reqResult = await client.GetStorageAsync("DotMogModule", "MogwaiOwner", new string[] { mogwaiId }, cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: MogwaiStruct<T::Hash, T::BlockNumber, BalanceOf<T>> //var reqResult = await client.GetStorageAsync("DotMogModule", "Mogwais", new [] {mogwaiId}, cancellationToken); //var reqResult = await client.GetStorageAsync("DotMogModule", "Mogwais", new[] { "0x9894948a8efd07c896969c39c805e4a92b29270e5d5a873523f9fe7388fa350e" }, cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: MogwaiBios<T::Hash, T::BlockNumber, BalanceOf<T>> //var reqResult = await client.GetStorageAsync("DotMogModule", "MogwaisBios", new [] { mogwaiIdGen1 }, cancellationToken); // [Map] Key: T::AccountId, Hasher: BlakeTwo128Concat, Value: Vec<u8> //var reqResult = await client.GetStorageAsync("DotMogModule", "AccountConfig", // new[] { Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5CxW5DWQDpXi4cpACd62wzbPjbYrx4y67TZEmRXBcvmDTNaM")) }, cancellationToken); // [Map] Key: T::AccountId, Hasher: BlakeTwo128Concat, Value: AccountInfo<T::Index, T::AccountData> //var reqResult = await client.GetStorageAsync("System", "Account", new [] {Utils.Bytes2HexString(Utils.GetPublicKeyFrom(address))}, cancellationToken); // [Map] Key: T::Hash, Hasher: Identity, Value: MogwaiBios<T::Hash, T::BlockNumber, BalanceOf<T>> //var mogwaiIdEgg1 = "0x5129a01b84073771324030bec439dc9218c87a4d73631fbdd828867a8855babf"; //var reqResult = await client.GetStorageAsync("DotMogModule", "GameEventsOfMogwai", new [] { mogwaiIdEgg1 }, cancellationToken); //var gameEventId = "0xb9e4454a9a5c1d4c75dc73c9932515456a4c7542e15b0b6bd57142b1336e562c"; //var reqResult = await client.GetStorageAsync("DotMogModule", "GameEvents", new[] { gameEventId }, cancellationToken); //var hash = new Hash(); //hash.Create("0xC8C6C7693D6D5256B00FA807A0E990D1AFA33034FB2C0F951809F28886A8C108"); //var reqResult = await client.Chain.GetHeaderAsync(hash, cancellationToken); //var hash = new Hash(); //hash.Create("0x55d560dd75e789f955540dc37c6034460b1e5490e4383a83df48b1979de75aa1"); //var reqResult = await client.Chain.GetBlockAsync(hash, cancellationToken); // [Map] Key: (T::AccountId, Vec<u8>), Hasher: BlakeTwo128Concat, Value: MogwaicoinAddress<T::AccountId, ClaimState, BalanceOf<T>> //var reqResult = await client.GetStorageAsync("DotMogBase", "AccountClaim", new [] {Utils.Bytes2HexString(Utils.GetPublicKeyFrom("5E77sDSL4sgAteLAMLjkEyQsHaoiqCMUJTk18XWefeVXC4Bb")), Utils.Bytes2HexString(Encoding.ASCII.GetBytes("M9XfSaTHgGtwQnkrkG1EWRJpSdVsREU44u")) }, cancellationToken); // **************************************************************************************************************************************** // 690,520 // 0x98d7f5fe3efd88cd28d928c418c9ddc8dee254a2e11925a1a78b2ca6c2aac6d5 //var blocknumber = new BlockNumber(); //blocknumber.Create(690520); //var reqResult = await client.Chain.GetBlockHashAsync(blocknumber, cancellationToken); // 486587 // 0x387b43b09e88adc971bfc64fdd8e84dcfd0c4dcfe5f30c6b7444bf3ad3717445 //var reqResult = await client.Chain.GetBlockAsync(new Hash("0x9b1c6c66107ced561edff29ec83d530ffbfb2d21ec326fef0fc8ffe60ee685f9"), cancellationToken); // 792,193 ---> 0x0cf64c1e0e45b2fba6fd524e180737f5e1bb46e0691783d6963b2e26253f8592 Create Mogwai //var reqResult = await client.Chain.GetBlockAsync(new Hash("0x0cf64c1e0e45b2fba6fd524e180737f5e1bb46e0691783d6963b2e26253f8592"), cancellationToken); // 797,188 --> 0x7c0c2cb4f04487f9914e0d910c3a0f3bf1292a39f131ddb44947b3dd04b8c154 Balances Transfer //var reqResult = await client.Chain.GetBlockAsync(new Hash("0x7c0c2cb4f04487f9914e0d910c3a0f3bf1292a39f131ddb44947b3dd04b8c154"), cancellationToken); //var reqResult = await client.Chain.GetBlockAsync(new Hash("0xe7b99ee484e6369dd3c2a66d6306bffde5048ddf2090e990faae83e66f5275f4"), cancellationToken); // 489070 // 0x76d50aa9a8cf86f7c1e5b40c2a02607dc63e3a3fc1077f7172280b443b16252d //var reqResult = await client.Chain.GetBlockAsync(new Hash("0x2a6fa42837069b0b41613855c667daf2fb5418dcdd915db6a0cac68810083296"), cancellationToken); //var reqResult = await client.Chain.GetHeaderAsync(new Hash("0x76d50aa9a8cf86f7c1e5b40c2a02607dc63e3a3fc1077f7172280b443b16252d"), cancellationToken); //var reqResult = await client.GetMethodAsync<JArray>("author_pendingExtrinsics", cancellationToken); // *** test 0 simple extrinsic tests //var reqResult = await client.Author.SubmitExtrinsicAsync(DotMogCall.CreateMogwai(), accountZurich, 0, 64, cancellationToken); //var reqResult = await client.Author.PendingExtrinsicAsync(cancellationToken); //var balanceTransfer = ExtrinsicCall.BalanceTransfer("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH", BigInteger.Parse("100000000000")); //var reqResult = await client.Author.SubmitExtrinsicAsync(balanceTransfer, accountZurich, 0, 64, cancellationToken); //var u8_1 = new U8();u8_1.Create(1);var u8_3 = new U8();u8_3.Create(3); //var reqResult = await client.Author.SubmitExtrinsicAsync(DotMogCall.UpdateConfig(u8_1, u8_3), accountZurich, 0, 64, cancellationToken); // *** test 1 new head subscription //var subscriptionId = await client.Chain // .SubscribeAllHeadsAsync( // (subscriptionId, header) => Console.WriteLine($"CallBack[{subscriptionId}]: {header}"), // cancellationToken //); //Thread.Sleep(30000); //var reqResult = await client.Chain.UnsubscribeAllHeadsAsync(subscriptionId, cancellationToken); // *** test 2 submit extrinsic //Action<string, ExtrinsicStatus> actionExtrinsicUpdate = (subscriptionId, extrinsicUpdate) => Console.WriteLine($"CallBack[{subscriptionId}]: {extrinsicUpdate}"); //var subscriptionId = await client.Author.SubmitAndWatchExtrinsicAsync(actionExtrinsicUpdate, ExtrinsicCall.BalanceTransfer("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH", 100000000000), accountZurich, 0, 64, cancellationToken); //Thread.Sleep(60000); //var reqResult = await client.Author.UnwatchExtrinsicAsync(subscriptionId, cancellationToken); // *** test 2.5 submit extrinsic //Action<string, ExtrinsicStatus> actionExtrinsicUpdate = (subscriptionId, extrinsicUpdate) => Console.WriteLine($"CallBack[{subscriptionId}]: {extrinsicUpdate}"); //var subscriptionId = await client.Author.SubmitAndWatchExtrinsicAsync(actionExtrinsicUpdate, DotMogCall.UpdateClaim("M9XfSaTHgGtwQnkrkG1EWRJpSdVsREU44u", "5E77sDSL4sgAteLAMLjkEyQsHaoiqCMUJTk18XWefeVXC4Bb", ClaimState.Cancelled, new BigInteger(3)), accountZurich, 0, 64, cancellationToken); //Thread.Sleep(60000); //var reqResult = await client.Author.UnwatchExtrinsicAsync(subscriptionId, cancellationToken); // *** test 3 full stoarge test // ??? // *** test 4 event subscription //Action<string, StorageChangeSet> callBackSubscribeStorage = (subscriptionId, eventObject) => Console.WriteLine($"CallBack[{subscriptionId}]: {eventObject}"); //var systemEventsKeys = await client.GetStorageKeysAsync("System", "Events", CancellationToken.None); //var subscriptionId = await client.State.SubscribeStorageAsync(systemEventsKeys, // callBackSubscribeStorage //); //Thread.Sleep(60000); //var reqResult = await client.State.UnsubscribeStorageAsync(subscriptionId, cancellationToken); //Hash finalizedHead = await client.Chain.GetFinalizedHeadAsync(cancellationToken); //var reqResult = await client.Chain.GetBlockAsync(finalizedHead, cancellationToken); // Print result //Console.WriteLine($"RESPONSE: '{reqResult}' [{reqResult?.GetType().Name}]"); Console.WriteLine(client.MetaData.Serialize()); // Close connection await client.CloseAsync(cancellationToken); Console.ReadKey(); }