diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml index c02101f..24c15e6 100644 --- a/.github/workflows/nuget-publish.yml +++ b/.github/workflows/nuget-publish.yml @@ -46,3 +46,13 @@ jobs: # Flag to toggle pushing symbols along with nuget package to the server, disabled by default # INCLUDE_SYMBOLS: false + + - name: publish CES on version change + id: publish_ces_nuget + uses: rohith/publish-nuget@v2 + with: + PROJECT_FILE_PATH: Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj + PACKAGE_NAME: Casper.Network.SDK.CES + VERSION_REGEX: ^\s*(.*)<\/PackageVersion>\s*$ + TAG_FORMAT: v* + NUGET_KEY: ${{secrets.NUGET_API_KEY}} diff --git a/.gitignore b/.gitignore index 1be8a0c..22dc597 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ obj/ riderModule.iml /_ReSharper.Caches/ /.vs +*.DotSettings.user diff --git a/CHANGELOG.md b/CHANGELOG.md index 0289c25..c4e50ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,29 @@ All notable changes to this project will be documented in this file. The format [comment]: <> (Security: in case of vulnerabilities) +## [3.3.0] + +### Added + +* Added Casper Event Standard (CES) schema loading, event decoding, and extraction of contract events from execution results through `CESContractSchema`, `CESEvent`, and `CESParser`. These types are provided by the separate `Casper.Network.SDK.CES` NuGet package, which depends on the core SDK and supports .NET 8 and .NET Standard 2.0. Import the `Casper.Network.SDK.CES` namespace to use them. [PR#111](https://github.com/make-software/casper-net-sdk/pull/111). +* Added binary deserialization of `CLValue` and `NamedArg` values through `FromBytes()` and `FromReader()` methods on their byte serializers, and of named argument lists through `NamedArg.ListFromBytes()` and `NamedArg.ListFromReader()`. [PR#110](https://github.com/make-software/casper-net-sdk/pull/110). +* Added `CLValueDictionary.Parse()` to decode dictionary entries into their value bytes, seed URef, and item key, and `CLValueReader` to read values from a binary stream using a known `CLTypeInfo`. [PR#110](https://github.com/make-software/casper-net-sdk/pull/110) and [PR#111](https://github.com/make-software/casper-net-sdk/pull/111). +* Added a `ServerEventsClient(string sseUrl)` constructor for Casper 2.x nodes that accepts a full HTTP or HTTPS event stream URL, including a custom path and query parameters. [PR#113](https://github.com/make-software/casper-net-sdk/pull/113). +* Added `KeyPair.Create()`, `KeyPair.FromBytes()`, and `KeyPair.RawBytes` for key generation and raw private-key import/export. Raw keys must contain 32 bytes: an ED25519 seed or a SECP256K1 unsigned scalar in big-endian order. [PR#117](https://github.com/make-software/casper-net-sdk/pull/117). +* Added Casper 2.0 guides for `TransactionV1`, balance queries, and addressable entities, and refreshed the existing articles and tutorials. [PR#115](https://github.com/make-software/casper-net-sdk/pull/115). + +### Fixed + +* Fixed incorrect deserialization of `Version2` block headers. [PR#119](https://github.com/make-software/casper-net-sdk/pull/119). +* Renamed `Message.HashAddr` to `Message.EntityAddr` and changed its JSON field from `hash_addr` to `entity_addr` to match Casper 2.0 responses. Applications using `HashAddr` must update their references. [PR#120](https://github.com/make-software/casper-net-sdk/pull/120). +* Fixed speculative execution response parsing for Casper 2.x nodes while preserving support for Casper 1.x responses. [PR#120](https://github.com/make-software/casper-net-sdk/pull/120). +* Corrected the return type of `SpeceulativeExecutionWithBlockHash()` in `ICasperClient` and `NetCasperClient` from `RpcResponse` to `RpcResponse`. Callers and interface implementations must use the corrected type. [PR#120](https://github.com/make-software/casper-net-sdk/pull/120). +* Fixed intermittent invalid SECP256K1 signatures by normalizing the signature's `s` component instead of retrying with the same signer. [PR#117](https://github.com/make-software/casper-net-sdk/pull/117). + +### Deprecated + +* `KeyPair.CreateNew()` is marked as obsolete. Use `KeyPair.Create()` instead. The old method remains available as a compatibility wrapper. [PR#117](https://github.com/make-software/casper-net-sdk/pull/117). + ## [3.2.0] ### Fixed @@ -207,6 +230,8 @@ This new type permits to parse correctly the value `"00"` used for system blocks ### Added * Initial release of Casper .NET SDK. +[3.3.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v3.3.0 +[3.2.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v3.2.0 [3.0.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v3.0.0 [3.0.0-beta4]: https://github.com/make-software/casper-net-sdk/releases/tag/v3.0.0-beta4 [3.0.0-beta3]: https://github.com/make-software/casper-net-sdk/releases/tag/v3.0.0-beta3 diff --git a/Casper.Network.SDK.Test/CESJsonSerializerTest.cs b/Casper.Network.SDK.CES.Test/CESJsonSerializerTest.cs similarity index 99% rename from Casper.Network.SDK.Test/CESJsonSerializerTest.cs rename to Casper.Network.SDK.CES.Test/CESJsonSerializerTest.cs index 7268ea3..b881308 100644 --- a/Casper.Network.SDK.Test/CESJsonSerializerTest.cs +++ b/Casper.Network.SDK.CES.Test/CESJsonSerializerTest.cs @@ -5,7 +5,7 @@ using NUnit.Framework; using Org.BouncyCastle.Utilities.Encoders; -namespace NetCasperTest +namespace Casper.Network.SDK.CES.Test { /// /// Verifies that and round-trip diff --git a/Casper.Network.SDK.Test/CESParserGetEventsTest.cs b/Casper.Network.SDK.CES.Test/CESParserGetEventsTest.cs similarity index 99% rename from Casper.Network.SDK.Test/CESParserGetEventsTest.cs rename to Casper.Network.SDK.CES.Test/CESParserGetEventsTest.cs index 1d62e00..cdc36ff 100644 --- a/Casper.Network.SDK.Test/CESParserGetEventsTest.cs +++ b/Casper.Network.SDK.CES.Test/CESParserGetEventsTest.cs @@ -8,7 +8,7 @@ using NUnit.Framework; using Org.BouncyCastle.Utilities.Encoders; -namespace NetCasperTest +namespace Casper.Network.SDK.CES.Test { [TestFixture] public class CESParserGetEventsTest diff --git a/Casper.Network.SDK.Test/CESParserTest.cs b/Casper.Network.SDK.CES.Test/CESParserTest.cs similarity index 99% rename from Casper.Network.SDK.Test/CESParserTest.cs rename to Casper.Network.SDK.CES.Test/CESParserTest.cs index a2605a7..e5e0654 100644 --- a/Casper.Network.SDK.Test/CESParserTest.cs +++ b/Casper.Network.SDK.CES.Test/CESParserTest.cs @@ -7,7 +7,7 @@ using NUnit.Framework; using Org.BouncyCastle.Utilities.Encoders; -namespace NetCasperTest +namespace Casper.Network.SDK.CES.Test { [TestFixture] public class CESParserTest diff --git a/Casper.Network.SDK.CES.Test/Casper.Network.SDK.CES.Test.csproj b/Casper.Network.SDK.CES.Test/Casper.Network.SDK.CES.Test.csproj new file mode 100644 index 0000000..17bafe6 --- /dev/null +++ b/Casper.Network.SDK.CES.Test/Casper.Network.SDK.CES.Test.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + 9.0 + false + Casper.Network.SDK.CES.Test + + + + + + + + + + + $(TEST_FRAMEWORK) + net8.0 + + + + + + + + + + diff --git a/Casper.Network.SDK/CES/CESEvent.cs b/Casper.Network.SDK.CES/CESEvent.cs similarity index 100% rename from Casper.Network.SDK/CES/CESEvent.cs rename to Casper.Network.SDK.CES/CESEvent.cs diff --git a/Casper.Network.SDK/CES/CESParser.cs b/Casper.Network.SDK.CES/CESParser.cs similarity index 100% rename from Casper.Network.SDK/CES/CESParser.cs rename to Casper.Network.SDK.CES/CESParser.cs diff --git a/Casper.Network.SDK/CES/CESSchema.cs b/Casper.Network.SDK.CES/CESSchema.cs similarity index 100% rename from Casper.Network.SDK/CES/CESSchema.cs rename to Casper.Network.SDK.CES/CESSchema.cs diff --git a/Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj b/Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj new file mode 100644 index 0000000..47b0155 --- /dev/null +++ b/Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj @@ -0,0 +1,34 @@ + + + + net8.0;netstandard2.0 + 9.0 + CS1591 + 3.3.0.0 + 3.3.0 + 3.3.0 + Casper.Network.SDK.CES + Casper.Network.SDK.CES + make-software + https://github.com/make-software/casper-net-sdk + https://github.com/make-software/casper-net-sdk + git + Casper NetCasperSDK CES + README_nuget.md + LICENSE + Casper Event Standard (CES) schema and event parsing for the Casper .NET SDK. + Casper.Network.SDK.CES + true + + + + + + + + + + + + + diff --git a/Casper.Network.SDK.CES/README_nuget.md b/Casper.Network.SDK.CES/README_nuget.md new file mode 100644 index 0000000..ca34a31 --- /dev/null +++ b/Casper.Network.SDK.CES/README_nuget.md @@ -0,0 +1,28 @@ +# Casper Event Standard (CES) for .NET + +`Casper.Network.SDK.CES` parses typed events emitted by Casper smart contracts that follow the Casper Event Standard. It supports .NET 8 and .NET Standard 2.0 and depends on `Casper.Network.SDK`. + +## Installation + +```bash +dotnet add package Casper.Network.SDK.CES +``` + +## Usage + +```csharp +using System; +using Casper.Network.SDK; +using Casper.Network.SDK.CES; + +var client = new NetCasperClient("http://127.0.0.1:11101/rpc"); +var schema = await CESContractSchema.LoadAsync(client, contractPackageHash); + +var events = CESParser.GetEvents(executionResult.Effect, new[] { schema }); +foreach (var evt in events) + Console.WriteLine(evt.Name); +``` + +`contractPackageHash` is the hash of the contract package to watch, and `executionResult` is the execution result of a processed transaction. + +See the [CES documentation](https://make-software.github.io/casper-net-sdk/Articles/CasperEventStandard.html) and the [SSE example](https://github.com/make-software/casper-net-sdk/tree/master/Docs/Examples/CESParser) for more details. diff --git a/Casper.Network.SDK.sln b/Casper.Network.SDK.sln index d67a12a..ebdd1df 100644 --- a/Casper.Network.SDK.sln +++ b/Casper.Network.SDK.sln @@ -4,6 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Casper.Network.SDK", "Caspe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Casper.Network.SDK.Test", "Casper.Network.SDK.Test\Casper.Network.SDK.Test.csproj", "{F0C55C8D-6C59-4066-A6CF-82F2710A1DC1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Casper.Network.SDK.CES", "Casper.Network.SDK.CES\Casper.Network.SDK.CES.csproj", "{46B8D7E6-8764-4CD5-9246-0DB9B328B020}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Casper.Network.SDK.CES.Test", "Casper.Network.SDK.CES.Test\Casper.Network.SDK.CES.Test.csproj", "{B47F84D8-CE31-4C16-A784-55FCA082C29F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +22,13 @@ Global {F0C55C8D-6C59-4066-A6CF-82F2710A1DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU {F0C55C8D-6C59-4066-A6CF-82F2710A1DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU {F0C55C8D-6C59-4066-A6CF-82F2710A1DC1}.Release|Any CPU.Build.0 = Release|Any CPU + {46B8D7E6-8764-4CD5-9246-0DB9B328B020}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46B8D7E6-8764-4CD5-9246-0DB9B328B020}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46B8D7E6-8764-4CD5-9246-0DB9B328B020}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46B8D7E6-8764-4CD5-9246-0DB9B328B020}.Release|Any CPU.Build.0 = Release|Any CPU + {B47F84D8-CE31-4C16-A784-55FCA082C29F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B47F84D8-CE31-4C16-A784-55FCA082C29F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B47F84D8-CE31-4C16-A784-55FCA082C29F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B47F84D8-CE31-4C16-A784-55FCA082C29F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Casper.Network.SDK.sln.DotSettings.user b/Casper.Network.SDK.sln.DotSettings.user deleted file mode 100644 index 2c5113e..0000000 --- a/Casper.Network.SDK.sln.DotSettings.user +++ /dev/null @@ -1,4 +0,0 @@ - - <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> \ No newline at end of file diff --git a/Casper.Network.SDK/Casper.Network.SDK.csproj b/Casper.Network.SDK/Casper.Network.SDK.csproj index 82a601f..4f795c0 100644 --- a/Casper.Network.SDK/Casper.Network.SDK.csproj +++ b/Casper.Network.SDK/Casper.Network.SDK.csproj @@ -4,9 +4,9 @@ net8.0;netstandard2.0 9.0 CS1591 - 3.2.0.0 - 3.2.0 - 3.2.0 + 3.3.0.0 + 3.3.0 + 3.3.0 Casper.Network.SDK make-software https://github.com/make-software/casper-net-sdk diff --git a/Casper.Network.SDK/README_nuget.md b/Casper.Network.SDK/README_nuget.md index 9f97c7f..c3e102f 100644 --- a/Casper.Network.SDK/README_nuget.md +++ b/Casper.Network.SDK/README_nuget.md @@ -2,6 +2,8 @@ The Casper .NET SDK allows developers to interact with the Casper Network using the .NET languages. The project itself is being developed with C#. +For Casper Event Standard (CES) schema and event parsing, install the separate `Casper.Network.SDK.CES` package and import the `Casper.Network.SDK.CES` namespace. + ## GitHub repository https://github.com/make-software/casper-net-sdk diff --git a/Docs/Articles/CasperEventStandard.md b/Docs/Articles/CasperEventStandard.md index 393d258..18db1d3 100644 --- a/Docs/Articles/CasperEventStandard.md +++ b/Docs/Articles/CasperEventStandard.md @@ -2,7 +2,15 @@ The **Casper Event Standard (CES)** is a convention adopted by contract developers for emitting and consuming typed events from Casper smart contracts. Contracts that follow CES store a self-describing schema alongside their events, making it possible to decode any event without out-of-band knowledge of its structure. -The Casper .NET SDK provides the `Casper.Network.SDK.CES` namespace with three classes: `CESContractSchema` (schema loading and parsing), `CESEvent` (event parsing and field access), and `CESParser` (scanning execution results). +The `Casper.Network.SDK.CES` NuGet package provides the `Casper.Network.SDK.CES` namespace with three main classes: `CESContractSchema` (schema loading and parsing), `CESEvent` (event parsing and field access), and `CESParser` (scanning execution results). + +## Installation + +Add the CES package to your application. It depends on `Casper.Network.SDK`, which NuGet installs automatically: + +```bash +dotnet add package Casper.Network.SDK.CES +``` --- @@ -55,6 +63,7 @@ The simplest way to load a contract's schema is `CESContractSchema.LoadAsync`. I When you pass a contract-package hash, the method resolves the latest active contract version automatically. You can also request a specific version with the optional `version` parameter. ```csharp +using Casper.Network.SDK; using Casper.Network.SDK.CES; var client = new NetCasperClient("https://rpc.testnet.casperlabs.io/rpc"); @@ -247,4 +256,10 @@ Console.WriteLine(json); ## Parsing CES events in the SSE stream -See `Docs/Examples/CESParser/Program.cs` for a runnable sample that connects to the node SSE stream, listens to `TransactionProcessed` events, and pretty-prints parsed CES events. +See [the CES parser example](https://github.com/make-software/casper-net-sdk/tree/master/Docs/Examples/CESParser) for a runnable sample that references the CES library, connects to the node SSE stream, listens to `TransactionProcessed` events, and pretty-prints parsed CES events. + +Run it from the repository root, supplying the contract-package hash to watch: + +```bash +dotnet run --project Docs/Examples/CESParser -- +``` diff --git a/Docs/Articles/GettingStarted.md b/Docs/Articles/GettingStarted.md index 85249e3..5e28bf7 100644 --- a/Docs/Articles/GettingStarted.md +++ b/Docs/Articles/GettingStarted.md @@ -22,6 +22,8 @@ Install-Package Casper.Network.SDK dotnet add package Casper.Network.SDK ``` +For Casper Event Standard schema and event parsing, also install `Casper.Network.SDK.CES` and import `Casper.Network.SDK.CES`. See the [CES guide](./CasperEventStandard.md). + ## Add a reference to the source code Clone the GitHub repository in your solution folder and add a reference in your project to the `Casper.Network.SDK.csproj` file. @@ -32,6 +34,12 @@ cd your-project dotnet add reference ../casper-net-sdk/Casper.Network.SDK/Casper.Network.SDK.csproj ``` +If you need the CES parser, also add a reference to the `Casper.Network.SDK.CES.csproj` project in the same way: + +```bash +dotnet add reference ../casper-net-sdk/Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj +``` + ## Create a minimal console application Create a new console app and add the SDK package: diff --git a/Docs/Examples/CESParser/CESParser.csproj b/Docs/Examples/CESParser/CESParser.csproj index 1dfa19e..b245428 100644 --- a/Docs/Examples/CESParser/CESParser.csproj +++ b/Docs/Examples/CESParser/CESParser.csproj @@ -6,7 +6,7 @@ - + diff --git a/Docs/docfx.json b/Docs/docfx.json index d5b6c29..adaee30 100644 --- a/Docs/docfx.json +++ b/Docs/docfx.json @@ -3,8 +3,10 @@ { "src": [ { + "src": "..", "files": [ - "Casper.Network.SDK/**.csproj" + "Casper.Network.SDK/Casper.Network.SDK.csproj", + "Casper.Network.SDK.CES/Casper.Network.SDK.CES.csproj" ] } ], diff --git a/Docs/index.md b/Docs/index.md index 6b52bcb..4acd29e 100644 --- a/Docs/index.md +++ b/Docs/index.md @@ -21,7 +21,7 @@ The Casper .NET SDK allows developers to interact with the Casper Network using * [Working with AddressableEntity](./Articles/WorkingWithAddressableEntity.md) — Query entities (accounts, contracts, and system contracts) on Casper 2.0. * [Key management](./Articles/KeyManagement.md) — Create, load, and save public/private key pairs. * [Working with Server-Sent Events (SSE)](./Articles/WorkingWithSSE.md) — Listen to real-time events from a Casper node. -* [Casper Event Standard (CES)](./Articles/CasperEventStandard.md) — Decode typed events emitted by smart contracts. +* [Casper Event Standard (CES)](./Articles/CasperEventStandard.md) — Decode typed events emitted by smart contracts with the separate `Casper.Network.SDK.CES` package. * [Running a local Casper network with NCTL](./Articles/RunningNctlLocally.md) — Set up a local test network using Docker. * [Migration from v2.x to v3.0](./Articles/Casper20MigrationGuide.md) — Upgrade your application for Casper 2.0 compatibility. @@ -43,3 +43,4 @@ See the complete list of examples [here](./Examples/index.md). * [GitHub repository](https://github.com/make-software/casper-net-sdk) * [NuGet package](https://www.nuget.org/packages/Casper.Network.SDK/) +* [CES NuGet package](https://www.nuget.org/packages/Casper.Network.SDK.CES/) diff --git a/README.md b/README.md index c980519..822344a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,16 @@ Install-Package Casper.Network.SDK dotnet add package Casper.Network.SDK ``` +### Casper Event Standard (CES) + +CES schema and event parsing is provided by the separate `Casper.Network.SDK.CES` package, which depends on the core SDK: + +```bash +dotnet add package Casper.Network.SDK.CES +``` + +Import `Casper.Network.SDK.CES` to use `CESContractSchema`, `CESEvent`, and `CESParser`. See the [CES documentation](Docs/Articles/CasperEventStandard.md) and [SSE example](Docs/Examples/CESParser/Program.cs). + ## Run a Casper node locally with NCTL [NCTL](https://github.com/casper-network/casper-node/tree/release-1.4.3/utils/nctl) is a CLI application to control one or multiple Casper networks locally. Many developers wish to spin up relatively small test networks to localize their testing before deploying to the blockchain.