Skip to content

Commit

Permalink
added basetuple with arguments up to 39 in again
Browse files Browse the repository at this point in the history
added reconenctivity on json rpc disconnect
  • Loading branch information
darkfriend77 committed Sep 14, 2024
1 parent 0ad0b79 commit 08f3985
Show file tree
Hide file tree
Showing 6 changed files with 7,116 additions and 37 deletions.
60 changes: 60 additions & 0 deletions Substrate.NetApi.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Serilog;
using Substrate.NetApi;
using Substrate.NetApi.Model.Extrinsics;

internal class Program
{
private static async Task Main(string[] args)
{
// Configure Serilog for logging
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Debug()
.CreateLogger();

// Set up a cancellation token for graceful shutdown
CancellationTokenSource cts = new CancellationTokenSource();

await MainAsync(cts.Token);

// Keep the application alive to continue monitoring the connection
Console.WriteLine("Press any key to exit...");
Console.ReadKey();

// Cleanup logging resources
await Log.CloseAndFlushAsync();
}

private static async Task MainAsync(CancellationToken token)
{
// Create the client
string substrateNodeUrl = "wss://rpc-parachain.bajun.network";
var client = new SubstrateClient(new Uri(substrateNodeUrl), ChargeTransactionPayment.Default());

while (!token.IsCancellationRequested)
{
// Ensure the client is connected
if (!client.IsConnected)
{
Log.Information("Attempting to connect to the client...");
await client.ConnectAsync(
useMetaData: true,
standardSubstrate: true,
maxRetryAttempts: 5,
delayRetryMilliseconds: 5000,
token: token
);
Log.Information("Client connected successfully.");
}

var currentBlocknumber = await client.State.GetStorageAsync(Utils.HexToByteArray("0x26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac"), (string)null, token);
Log.Information("MainAsync running... block: {blocknumber}", currentBlocknumber.ToString());

// Wait before next call
await Task.Delay(12000);
}

// Gracefully shut down
await client.CloseAsync();
}
}
18 changes: 18 additions & 0 deletions Substrate.NetApi.Console/Substrate.NetApi.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Substrate.NetApi\Substrate.NetApi.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 08f3985

Please sign in to comment.