diff --git a/CHANGELOG.md b/CHANGELOG.md index b73a860..6b3e271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file. The format [comment]: <> (Fixed: any bug fixes) [comment]: <> (Security: in case of vulnerabilities) +## [2.1.0] + +### Fixed +* Breaking change! the type for the `Proposer` property in the body block has changed from `PublicKey` to `Proposer`. +This new type permits to parse correctly the value `"00"` used for system blocks in Casper network starting from v1.5. + ## [2.0.0] ### Added @@ -56,6 +62,7 @@ All notable changes to this project will be documented in this file. The format ### Added * Initial release of Casper .NET SDK. +[2.1.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v2.1.0 [2.0.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v2.0.0 [1.1.2]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.2 [1.1.1]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.1 diff --git a/Casper.Network.SDK.Test/NctlGetXTest.cs b/Casper.Network.SDK.Test/NctlGetXTest.cs index 44ba2ba..45e3213 100644 --- a/Casper.Network.SDK.Test/NctlGetXTest.cs +++ b/Casper.Network.SDK.Test/NctlGetXTest.cs @@ -186,6 +186,25 @@ public async Task GetBlockTest() } } + [Test] + public async Task GetSystemBlockProposerTest() + { + try + { + var response = await _client.GetBlock(0); + var result = response.Parse(); + Assert.IsNotNull(result.Block.Hash); + Assert.IsTrue(result.Block.Body.Proposer.isSystem); + } + catch (RpcClientException e) + { + Assert.IsNotNull(e.RpcError); + Assert.IsNotNull(e.RpcError.Message); + Assert.AreNotEqual(0, e.RpcError.Code); + Assert.IsNotNull(e.RpcError.Data); + } + } + [Test] public async Task GetAuctionInfoTest() { diff --git a/Casper.Network.SDK/Casper.Network.SDK.csproj b/Casper.Network.SDK/Casper.Network.SDK.csproj index ce4c526..04da2fb 100644 --- a/Casper.Network.SDK/Casper.Network.SDK.csproj +++ b/Casper.Network.SDK/Casper.Network.SDK.csproj @@ -2,9 +2,9 @@ net7.0 - 2.0.0.0 - 2.0.0 - 2.0.0 + 2.1.0.0 + 2.1.0 + 2.1.0 Casper.Network.SDK make-software https://github.com/make-software/casper-net-sdk diff --git a/Casper.Network.SDK/Types/Block.cs b/Casper.Network.SDK/Types/Block.cs index a8339c3..f9f7f32 100644 --- a/Casper.Network.SDK/Types/Block.cs +++ b/Casper.Network.SDK/Types/Block.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; namespace Casper.Network.SDK.Types @@ -69,6 +71,61 @@ public class BlockHeader public string Timestamp { get; init; } } + /// + /// Validator that proposed the block + /// + public class Proposer + { + /// + /// The block was proposed by the system, not a validator + /// + public bool isSystem { get; set; } + + /// + /// Validator's public key + /// + public PublicKey PublicKey { get; set; } + + /// + /// Json converter class to serialize/deserialize a Proposer to/from Json + /// + public class ProposerConverter : JsonConverter + { + public override Proposer Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options) + { + try + { + var pkhex = reader.GetString(); + if (pkhex == "00") + return new Proposer() + { + isSystem = true, + }; + return new Proposer() + { + isSystem = false, + PublicKey = PublicKey.FromHexString(pkhex), + }; + } + catch (Exception e) + { + throw new JsonException(e.Message); + } + } + + public override void Write( + Utf8JsonWriter writer, + Proposer proposer, + JsonSerializerOptions options) + { + writer.WriteStringValue(proposer.isSystem ? "00" : proposer.PublicKey.ToAccountHex()); + } + } + } + /// /// A block body /// @@ -84,8 +141,8 @@ public class BlockBody /// Public key of the validator that proposed the block /// [JsonPropertyName("proposer")] - [JsonConverter(typeof(PublicKey.PublicKeyConverter))] - public PublicKey Proposer { get; init; } + [JsonConverter(typeof(Proposer.ProposerConverter))] + public Proposer Proposer { get; init; } /// /// List of Transfer hashes included in the block @@ -143,4 +200,4 @@ public class Block [JsonPropertyName("proofs")] public List Proofs { get; init; } } -} \ No newline at end of file +}