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 13 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Unreleased changes
- Added
- New GRPC-endpoints: `GetBlocks`, `GetFinalizedBlocks`, `GetBranches`, `GetAncestors`, `GetBlockPendingUpdates`

## 4.1.0
- 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
- 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>
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
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>
45 changes: 45 additions & 0 deletions examples/GetBranches/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 (int 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
Loading