Skip to content

Commit 7625b2e

Browse files
CardanoSharp.Koios.SDK integration for important query and transaction commands
New commands via Koios integration: - query tip --network <network> - query protocol-parameters --network <network> - query info account --network <network>--stake-address <bech32_stake_address> - query asset account --network <network> --stake-address <bech32_stake_address> - query info address --network <network> --address <bech32_payment_address> - query info transaction --network <network> --tx-id <transaction_hash> - transaction submit --network <network> --cbor-hex <hex_string>
1 parent aecfa61 commit 7625b2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1520
-146
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ jobs:
3737
with:
3838
dotnet-version: ${{ env.DOTNET_VERSION }}
3939

40-
- name: Set release outputs
40+
- name: Set release params
4141
id: release-params
4242
run: |
43-
VERSION_TAG=$(git describe --tags --abbrev=0)
44-
RELEASE_NAME="cscli-$VERSION_TAG-${{ matrix.target }}"
45-
echo "::set-output name=release_name::$RELEASE_NAME"
43+
echo "::set-output name=release_name::cscli-$(git describe --tags --abbrev=0)-${{ matrix.target }}"
4644
4745
- name: Build
4846
shell: bash

README.md

Lines changed: 215 additions & 32 deletions
Large diffs are not rendered by default.

Src/ConsoleTool/BackendGateway.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CardanoSharp.Wallet.Enums;
2+
using Refit;
3+
4+
namespace Cscli.ConsoleTool.Koios
5+
{
6+
public static class BackendGateway
7+
{
8+
public static T GetBackendClient<T>(NetworkType networkType) =>
9+
RestService.For<T>(GetBaseUrlForNetwork(networkType));
10+
11+
private static string GetBaseUrlForNetwork(NetworkType networkType) => networkType switch
12+
{
13+
NetworkType.Mainnet => "https://api.koios.rest/api/v0",
14+
NetworkType.Testnet => "https://testnet.koios.rest/api/v0",
15+
_ => throw new ArgumentException($"{nameof(networkType)} {networkType} is invalid", nameof(networkType))
16+
};
17+
}
18+
}

Src/ConsoleTool/CardanoNodeTypes.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

Src/ConsoleTool/CommandParser.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Cscli.ConsoleTool.Commands;
1+
using Cscli.ConsoleTool.Crypto;
2+
using Cscli.ConsoleTool.Query;
3+
using Cscli.ConsoleTool.Transaction;
4+
using Cscli.ConsoleTool.Wallet;
25
using Microsoft.Extensions.Configuration;
36
using System.Text;
47

@@ -41,9 +44,9 @@ private static ICommand ParseCommands(string intent, string[] args) =>
4144
args[0] switch
4245
{
4346
"wallet" => ParseWalletCommands(intent, args),
44-
//"query" => ParseQueryCommands(intent, args), // TODO: query via Blockfrost/Koios integration
45-
//"tx" => ParseTxCommands(intent, args), // TODO: Easier Tx creation and submission via Blockfrost/Koios integration
46-
"bech32" or "blake2b" => ParseEncodingHashingCommands(intent, args),
47+
"query" => ParseQueryCommands(intent, args),
48+
"transaction" => ParseTransactionCommands(intent, args),
49+
"bech32" or "blake2b" => ParseCryptoCommands(intent, args),
4750
_ => new ShowInvalidArgumentCommand(intent)
4851
};
4952

@@ -60,7 +63,26 @@ private static ICommand ParseWalletCommands(string intent, string[] args) =>
6063
_ => new ShowInvalidArgumentCommand(intent)
6164
};
6265

63-
private static ICommand ParseEncodingHashingCommands(string intent, string[] args) =>
66+
private static ICommand ParseQueryCommands(string intent, string[] args) =>
67+
intent switch
68+
{
69+
"query tip" => BuildCommand<QueryTipCommand>(args),
70+
"query protocol-parameters" => BuildCommand<QueryProtocolParametersCommand>(args),
71+
"query info account" => BuildCommand<QueryAccountInfoCommand>(args),
72+
"query asset account" => BuildCommand<QueryAccountAssetCommand>(args),
73+
"query info address" => BuildCommand<QueryAddressInfoCommand>(args),
74+
"query info transaction" => BuildCommand<QueryTransactionInfoCommand>(args),
75+
_ => new ShowInvalidArgumentCommand(intent)
76+
};
77+
78+
private static ICommand ParseTransactionCommands(string intent, string[] args) =>
79+
intent switch
80+
{
81+
"transaction submit" => BuildCommand<SubmitTransactionCommand>(args),
82+
_ => new ShowInvalidArgumentCommand(intent)
83+
};
84+
85+
private static ICommand ParseCryptoCommands(string intent, string[] args) =>
6486
intent switch
6587
{
6688
"bech32 encode" => BuildCommand<EncodeBech32Command>(args),
@@ -69,7 +91,6 @@ private static ICommand ParseEncodingHashingCommands(string intent, string[] arg
6991
_ => new ShowInvalidArgumentCommand(intent)
7092
};
7193

72-
7394
private static ICommand BuildCommand<T>(
7495
string[] args)
7596
where T : ICommand

Src/ConsoleTool/Constants.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.Json;
1+
using System.Text.Encodings.Web;
2+
using System.Text.Json;
23

34
namespace Cscli.ConsoleTool;
45

@@ -31,7 +32,8 @@ public static class Constants
3132
public static readonly JsonSerializerOptions SerialiserOptions = new()
3233
{
3334
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
34-
WriteIndented = true
35+
WriteIndented = true,
36+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
3537
};
3638
// Commandline args switch mappings
3739
public static Dictionary<string, string> SwitchMappings => new()
@@ -45,7 +47,9 @@ public static class Constants
4547
{ "--stake-account-index", "stakeAccountIndex" },
4648
{ "--stake-address-index", "stakeAddressIndex" },
4749
{ "--payment-address-type", "paymentAddressType" },
48-
{ "--network-tag", "networkTag" },
50+
{ "--stake-address", "stakeAddress" },
51+
{ "--cbor-hex", "cborHex" },
52+
{ "--tx-id", "txId" },
4953
//{ "--output-format", "outputFormat" },
5054
};
5155
}

Src/ConsoleTool/Commands/DecodeBech32Command.cs renamed to Src/ConsoleTool/Crypto/DecodeBech32Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using CardanoSharp.Wallet.Encoding;
22
using CardanoSharp.Wallet.Extensions;
33

4-
namespace Cscli.ConsoleTool.Commands;
4+
namespace Cscli.ConsoleTool.Crypto;
55

66
public class DecodeBech32Command : ICommand
77
{

Src/ConsoleTool/Commands/EncodeBech32Command.cs renamed to Src/ConsoleTool/Crypto/EncodeBech32Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using CardanoSharp.Wallet.Encoding;
22

3-
namespace Cscli.ConsoleTool.Commands;
3+
namespace Cscli.ConsoleTool.Crypto;
44

55
public class EncodeBech32Command : ICommand
66
{

Src/ConsoleTool/Commands/HashBlake2bCommand.cs renamed to Src/ConsoleTool/Crypto/HashBlake2bCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using CardanoSharp.Wallet.Extensions;
33
using System.Collections.Immutable;
44

5-
namespace Cscli.ConsoleTool.Commands;
5+
namespace Cscli.ConsoleTool.Crypto;
66

77
public class HashBlake2bCommand : ICommand
88
{

Src/ConsoleTool/Cscli.ConsoleTool.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
<None Include="..\..\README.md" Link="README.md" Pack="true" PackagePath="\" />
3232
</ItemGroup>
3333
<ItemGroup>
34-
<PackageReference Include="CardanoSharp.Wallet" Version="2.1.0" />
34+
<PackageReference Include="CardanoSharp.Koios.Sdk" Version="4.2.0" />
35+
<PackageReference Include="CardanoSharp.Wallet" Version="2.2.0" />
3536
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
3637
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
3738
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
3839
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
39-
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.2">
40+
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.3">
4041
<PrivateAssets>all</PrivateAssets>
4142
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4243
</PackageReference>

0 commit comments

Comments
 (0)