Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More grpc endpoints #76

Merged
merged 18 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
- Bugfix
- Documentation was missing when adding library as nuget packages and hovering over methods and classes.
- Added
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
- New GRPC-endpoints:
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
- `GetBlocks`
- `GetFinalizedBlocks`
- `GetBranches`
- `GetAncestors`
- `GetBlockPendingUpdates`
- gRPC queries relevant for smart contracts.
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
- GetModuleListAsync
- GetInstanceListAsync
Expand Down
18 changes: 18 additions & 0 deletions examples/GetAncestors/GetAncestors.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Concordium.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions examples/GetAncestors/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using CommandLine;
using Concordium.Sdk.Client;
using Concordium.Sdk.Types;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

namespace GetAncestors;

internal sealed class GetAncestorsOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option(
'm',
"max-ancestors",
HelpText = "The maximum number of ancestors returned.",
Required = true
)]
public ulong MaxAncestors { get; set; }
[Option(
'b',
"block-hash",
HelpText = "Block hash of the block."
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
)]
public string BlockHash { get; set; }
}

public static class Program
{
/// <summary>
/// Example how to use <see cref="ConcordiumClient.GetAncestors"/>
/// </summary>
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<GetAncestorsOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetAncestorsOptions o)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved

using var client = new ConcordiumClient(new Uri(o.Endpoint), new ConcordiumClientOptions());

IBlockHashInput bi = o.BlockHash != null ? new Given(BlockHash.From(o.BlockHash)) : new LastFinal();

var ancestors = await client.GetAncestors(bi, o.MaxAncestors);

await foreach (var ancestor in ancestors.Response)
{
Console.WriteLine($"Ancestor: {ancestor}");
}
}
}
18 changes: 18 additions & 0 deletions examples/GetBlockPendingUpdates/GetBlockPendingUpdates.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Concordium.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions examples/GetBlockPendingUpdates/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CommandLine;
using Concordium.Sdk.Client;
using Concordium.Sdk.Types;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

namespace GetBlockPendingUpdates;

internal sealed class GetBlockPendingUpdatesOptions
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
[Option(
'b',
"block-hash",
HelpText = "Block hash of the block."
)]
public string BlockHash { get; set; }
}

public static class Program
{
/// <summary>
/// Example how to use <see cref="ConcordiumClient.GetBlockPendingUpdates"/>
/// </summary>
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<GetBlockPendingUpdatesOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetBlockPendingUpdatesOptions o)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved

using var client = new ConcordiumClient(new Uri(o.Endpoint), new ConcordiumClientOptions());

IBlockHashInput bi = o.BlockHash != null ? new Given(BlockHash.From(o.BlockHash)) : new LastFinal();

var blocks = await client.GetBlockPendingUpdates(bi);

Console.WriteLine($"Updates:");
await foreach (var block in blocks.Response)
{
Console.WriteLine($"Block arrived: {block}");
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
18 changes: 18 additions & 0 deletions examples/GetBlocks/GetBlocks.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Concordium.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions examples/GetBlocks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CommandLine;
using Concordium.Sdk.Client;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

namespace GetBlocks;

internal sealed class GetBlocksOptions
This conversation was marked as resolved.
Show resolved Hide resolved
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

public static class Program
{
/// <summary>
/// Example how to use <see cref="ConcordiumClient.GetBlocks"/>
/// </summary>
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<GetBlocksOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetBlocksOptions options)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));

using var client = new ConcordiumClient(new Uri(options.Endpoint), new ConcordiumClientOptions());

var blocks = client.GetBlocks();

await foreach (var block in blocks)
{
Console.WriteLine($"Block arrived: {block}");
}
}
}
19 changes: 19 additions & 0 deletions examples/GetBranches/GetBranches.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>GetNodeInfo</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Concordium.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions examples/GetBranches/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using CommandLine;
using Concordium.Sdk.Client;
using Branch = Concordium.Sdk.Types.Branch;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

namespace GetBranches;

internal sealed class GetNodeInfoOptions
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}


public static class Program
{
/// <summary>
/// Example how to use <see cref="ConcordiumClient.GetBranches"/>
/// </summary>s
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<GetNodeInfoOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetNodeInfoOptions options)
{
using var client = new ConcordiumClient(new Uri(options.Endpoint), new ConcordiumClientOptions());

var branch = await client.GetBranchesAsync();

// Prints branches as a tree
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
printer(0, branch);
}

private static void printer(uint depth, Branch branch) {
for (int i = 0; i < depth; i++) {
Console.Write("--");
}
Console.WriteLine(branch.BlockHash);
branch.Children.ForEach(x => printer(depth+1, x));
}
}
18 changes: 18 additions & 0 deletions examples/GetFinalizedBlocks/GetFinalizedBlocks.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Concordium.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions examples/GetFinalizedBlocks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CommandLine;
using Concordium.Sdk.Client;

// We disable these warnings since CommandLine needs to set properties in options
// but we don't want to give default values.
#pragma warning disable CS8618

namespace GetFinalizedBlocks;

internal sealed class GetBlocksOptions
rasmus-kirk marked this conversation as resolved.
Show resolved Hide resolved
{
[Option(HelpText = "URL representing the endpoint where the gRPC V2 API is served.",
Default = "http://node.testnet.concordium.com:20000/")]
public string Endpoint { get; set; }
}

public static class Program
{
/// <summary>
/// Example how to use <see cref="ConcordiumClient.GetFinalizedBlocks"/>
/// </summary>
public static async Task Main(string[] args) =>
await Parser.Default
.ParseArguments<GetBlocksOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetBlocksOptions options)
{
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));

using var client = new ConcordiumClient(new Uri(options.Endpoint), new ConcordiumClientOptions());

var blocks = client.GetFinalizedBlocks();

await foreach (var block in blocks)
{
Console.WriteLine($"Finalized block arrived: {block}");
}
}
}
Loading
Loading