Skip to content

Commit

Permalink
Merge pull request #76 from Concordium/more-grpc-endpoints
Browse files Browse the repository at this point in the history
More grpc endpoints
  • Loading branch information
rasmus-kirk authored Nov 3, 2023
2 parents acc9949 + f2af571 commit cdadc98
Show file tree
Hide file tree
Showing 20 changed files with 654 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased changes
- Added
- New GRPC-endpoints: `GetBlocks`, `GetFinalizedBlocks`, `GetBranches`, `GetAncestors`, `GetBlockPendingUpdates`

## 4.1.0
- Bugfix
Expand Down
35 changes: 35 additions & 0 deletions ConcordiumNetSdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetModuleSource", "examples
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetInstanceInfo", "examples\GetInstanceInfo\GetInstanceInfo.csproj", "{60BB9915-06F0-48FC-ABCD-271B6A361A01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetAncestors", "examples\GetAncestors\GetAncestors.csproj", "{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetBlockPendingUpdates", "examples\GetBlockPendingUpdates\GetBlockPendingUpdates.csproj", "{C5BEBE65-EA24-431D-BB53-DA3673EF7E60}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetBlocks", "examples\GetBlocks\GetBlocks.csproj", "{79E97788-D084-487E-8F34-0BA1911C452A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetBranches", "examples\GetBranches\GetBranches.csproj", "{26417CD7-2897-47BA-BA9B-C4475187331A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetFinalizedBlocks", "examples\GetFinalizedBlocks\GetFinalizedBlocks.csproj", "{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -197,6 +207,26 @@ Global
{60BB9915-06F0-48FC-ABCD-271B6A361A01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60BB9915-06F0-48FC-ABCD-271B6A361A01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60BB9915-06F0-48FC-ABCD-271B6A361A01}.Release|Any CPU.Build.0 = Release|Any CPU
{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A}.Release|Any CPU.Build.0 = Release|Any CPU
{C5BEBE65-EA24-431D-BB53-DA3673EF7E60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5BEBE65-EA24-431D-BB53-DA3673EF7E60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5BEBE65-EA24-431D-BB53-DA3673EF7E60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5BEBE65-EA24-431D-BB53-DA3673EF7E60}.Release|Any CPU.Build.0 = Release|Any CPU
{79E97788-D084-487E-8F34-0BA1911C452A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79E97788-D084-487E-8F34-0BA1911C452A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79E97788-D084-487E-8F34-0BA1911C452A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79E97788-D084-487E-8F34-0BA1911C452A}.Release|Any CPU.Build.0 = Release|Any CPU
{26417CD7-2897-47BA-BA9B-C4475187331A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26417CD7-2897-47BA-BA9B-C4475187331A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26417CD7-2897-47BA-BA9B-C4475187331A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26417CD7-2897-47BA-BA9B-C4475187331A}.Release|Any CPU.Build.0 = Release|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -234,5 +264,10 @@ Global
{E6530630-82A0-4AB2-A600-A86DC619CB88} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{FFF88CB0-DC68-4B00-8632-770A270946F5} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{60BB9915-06F0-48FC-ABCD-271B6A361A01} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{F2A3BBF5-5ACE-443A-BB1C-6A9BDF7CB22A} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{C5BEBE65-EA24-431D-BB53-DA3673EF7E60} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{79E97788-D084-487E-8F34-0BA1911C452A} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{26417CD7-2897-47BA-BA9B-C4475187331A} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
{E2CC6AD7-98CE-41F5-8C66-AE8781F29C77} = {FD2CDD9F-4650-4705-9CA2-98CC81F8891D}
EndGlobalSection
EndGlobal
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>
54 changes: 54 additions & 0 deletions examples/GetAncestors/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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. Defaults to LastFinal."
)]
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 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>
49 changes: 49 additions & 0 deletions examples/GetBlockPendingUpdates/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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. Defaults to LastFinal."
)]
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 client = new ConcordiumClient(new Uri(o.Endpoint), new ConcordiumClientOptions());

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

var updates = await client.GetBlockPendingUpdates(bi);

Console.WriteLine($"Updates:");
await foreach (var update in updates.Response)
{
Console.WriteLine($"Pending update: {update}");

}
}
}
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
{
[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>
47 changes: 47 additions & 0 deletions examples/GetBranches/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 GetBranchesOptions
{
[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<GetBranchesOptions>(args)
.WithParsedAsync(Run);

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

var branch = await client.GetBranchesAsync();

PrintBranchesAsTree(0, branch);
}

private static void PrintBranchesAsTree(uint depth, Branch branch)
{
for (var i = 0; i < depth; i++)
{
Console.Write("--");
}
Console.WriteLine(branch.BlockHash);
branch.Children.ForEach(x => PrintBranchesAsTree(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 GetFinalizedBlocksOptions
{
[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<GetFinalizedBlocksOptions>(args)
.WithParsedAsync(Run);

private static async Task Run(GetFinalizedBlocksOptions 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

0 comments on commit cdadc98

Please sign in to comment.