-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Concordium/more-grpc-endpoints
More grpc endpoints
- Loading branch information
Showing
20 changed files
with
654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
examples/GetBlockPendingUpdates/GetBlockPendingUpdates.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.