-
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 #80 from Concordium/get-block-items
Get block items
- Loading branch information
Showing
33 changed files
with
1,241 additions
and
86 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
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,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 GetBlockItems; | ||
|
||
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; } | ||
[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.GetBlockItems"/> | ||
/// </summary> | ||
public static async Task Main(string[] args) => | ||
await Parser.Default | ||
.ParseArguments<GetBlocksOptions>(args) | ||
.WithParsedAsync(Run); | ||
|
||
private static async Task Run(GetBlocksOptions 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 blockItems = await client.GetBlockItems(bi); | ||
|
||
Console.WriteLine($"All block items in block {blockItems.BlockHash}: ["); | ||
await foreach (var item in blockItems.Response) | ||
{ | ||
Console.WriteLine($"{item},"); | ||
} | ||
Console.WriteLine("]"); | ||
} | ||
} | ||
|
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,23 @@ | ||
namespace Concordium.Sdk.Exceptions; | ||
|
||
/// <summary> | ||
/// Thrown when deserialization fails and is explicitly meant not to. | ||
/// </summary> | ||
public class DeserialException : Exception | ||
{ | ||
internal DeserialException(string errorMessage) : | ||
base($"Deserialization error: {errorMessage}") | ||
{ } | ||
} | ||
|
||
/// <summary> | ||
/// Thrown when deserialization fails but no error message is present. This | ||
/// should, by construction, be impossible. | ||
/// </summary> | ||
public sealed class DeserialNullException : DeserialException | ||
{ | ||
internal DeserialNullException() : | ||
base($"Deserialization error: The parsed output is null, but no error was found. This should not be possible.") | ||
{ } | ||
} | ||
|
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,11 @@ | ||
namespace Concordium.Sdk.Exceptions; | ||
|
||
/// <summary> | ||
/// Thrown if the node sends an invalid response. | ||
/// </summary> | ||
public class UnexpectedNodeResponseException : Exception | ||
{ | ||
internal UnexpectedNodeResponseException() : | ||
base($"Unexpected node response received.") | ||
{ } | ||
} |
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
Oops, something went wrong.