From d943576cb66d73d38b4698bf4f3cd631a774cd4d Mon Sep 17 00:00:00 2001 From: Maksim Strebkov <257byte@gmail.com> Date: Thu, 23 May 2024 20:09:44 +0300 Subject: [PATCH] Merge attestation and attestation_with_dal contents --- .../_double_attestation_evidence/forged.hex | 1 + .../unsigned.json | 30 +++++++++++++++ .../forged.hex | 1 + .../unsigned.json | 32 ++++++++++++++++ .../Local/LocalForge.Forgers.Operations.cs | 37 ++++++++++--------- .../Local/LocalForge.Unforgers.Operations.cs | 7 ++-- .../Operations/Content/AttestationContent.cs | 9 ++++- .../Content/AttestationWithDalContent.cs | 27 -------------- .../Converters/OperationContentConverter.cs | 2 +- 9 files changed, 95 insertions(+), 51 deletions(-) create mode 100644 Netezos.Tests/Forging/operations/_double_attestation_evidence/forged.hex create mode 100644 Netezos.Tests/Forging/operations/_double_attestation_evidence/unsigned.json create mode 100644 Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/forged.hex create mode 100644 Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/unsigned.json delete mode 100644 Netezos/Forging/Models/Operations/Content/AttestationWithDalContent.cs diff --git a/Netezos.Tests/Forging/operations/_double_attestation_evidence/forged.hex b/Netezos.Tests/Forging/operations/_double_attestation_evidence/forged.hex new file mode 100644 index 00000000..fe98c41c --- /dev/null +++ b/Netezos.Tests/Forging/operations/_double_attestation_evidence/forged.hex @@ -0,0 +1 @@ +0b7e640e3e07beb8dc10a7582ad323c5788258b90186bd730d24e1962e082966020000008b449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e15005300074004000000009c602403e53efcd8c1c6def8dff2dce4e65169bfe3b9dc83c999401ffbf6dc50dc86bd6bcd6cb80de43fc274409a57bb74f3fc863d67619cc94f303afdfa9d48fee1e9ddce6883cbe84642efb8f05831c0c3ebd5acdbf8e28b111cec175d470a0000008b449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e1500530007400400000000126252e0a3e4b4912b08f9eb686b9e31589ef97749e0f2aeefcac9fa385c34faabef4735682bb173152481e3638d33a8dd51456334a1b6bc3c671ff626a95004a77639b29b48da6920f773fe37789574405894de77f467865647a7d076f7ef0b \ No newline at end of file diff --git a/Netezos.Tests/Forging/operations/_double_attestation_evidence/unsigned.json b/Netezos.Tests/Forging/operations/_double_attestation_evidence/unsigned.json new file mode 100644 index 00000000..527c7e0d --- /dev/null +++ b/Netezos.Tests/Forging/operations/_double_attestation_evidence/unsigned.json @@ -0,0 +1,30 @@ +{ + "branch": "BKoLvj4KKvpYZogKgjARRu6jzcJMqTm8NRUe47dNHKguTYUCmnx", + "contents": [ + { + "kind": "double_attestation_evidence", + "op1": { + "branch": "BLEVomdmPi274XtWAu6uVB5S1Dchba5xmJ8YfS7kxaprBPWWMLL", + "operations": { + "kind": "attestation", + "slot": 83, + "level": 475140, + "round": 0, + "block_payload_hash": "vh2rzWxkdUALsamUHcNFi8kybDM7R26xgyFyv1WVZaowW2VWJ2ot" + }, + "signature": "sigrqfEUAcALXvU7cCeiTGzQrRmL9PE7w3pUvA5i8C5V53aUpqkQqvzic5NEwbR7zNG8ndFJTmJusS6CRLk2iBUNYamnLc4V" + }, + "op2": { + "branch": "BLEVomdmPi274XtWAu6uVB5S1Dchba5xmJ8YfS7kxaprBPWWMLL", + "operations": { + "kind": "attestation", + "slot": 83, + "level": 475140, + "round": 0, + "block_payload_hash": "vh1pDiA9BsDjscfR7hBeGnzWUGa1hPqDDwKtECZNcBYPBiB3hvsN" + }, + "signature": "sigkUwi8AKuL9ViT56ktaEBxF7Zb4JsSSqgVewYdMjjQm9S7oY7j4aZZSWX47i9xHsMkTeauPzD47mK5XJn6Q3wzeUeaWZoq" + } + } + ] +} \ No newline at end of file diff --git a/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/forged.hex b/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/forged.hex new file mode 100644 index 00000000..644319a1 --- /dev/null +++ b/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/forged.hex @@ -0,0 +1 @@ +0b7e640e3e07beb8dc10a7582ad323c5788258b90186bd730d24e1962e082966020000008c449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e17005300074004000000009c602403e53efcd8c1c6def8dff2dce4e65169bfe3b9dc83c999401ffbf6dc5000dc86bd6bcd6cb80de43fc274409a57bb74f3fc863d67619cc94f303afdfa9d48fee1e9ddce6883cbe84642efb8f05831c0c3ebd5acdbf8e28b111cec175d470a00000094449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e1700530007400400000000126252e0a3e4b4912b08f9eb686b9e31589ef97749e0f2aeefcac9fa385c34fa83cdaa9680f5b5b503abef4735682bb173152481e3638d33a8dd51456334a1b6bc3c671ff626a95004a77639b29b48da6920f773fe37789574405894de77f467865647a7d076f7ef0b \ No newline at end of file diff --git a/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/unsigned.json b/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/unsigned.json new file mode 100644 index 00000000..8aee8243 --- /dev/null +++ b/Netezos.Tests/Forging/operations/_double_attestation_evidence_with_dal/unsigned.json @@ -0,0 +1,32 @@ +{ + "branch": "BKoLvj4KKvpYZogKgjARRu6jzcJMqTm8NRUe47dNHKguTYUCmnx", + "contents": [ + { + "kind": "double_attestation_evidence", + "op1": { + "branch": "BLEVomdmPi274XtWAu6uVB5S1Dchba5xmJ8YfS7kxaprBPWWMLL", + "operations": { + "kind": "attestation_with_dal", + "slot": 83, + "level": 475140, + "round": 0, + "block_payload_hash": "vh2rzWxkdUALsamUHcNFi8kybDM7R26xgyFyv1WVZaowW2VWJ2ot", + "dal_attestation": "0" + }, + "signature": "sigrqfEUAcALXvU7cCeiTGzQrRmL9PE7w3pUvA5i8C5V53aUpqkQqvzic5NEwbR7zNG8ndFJTmJusS6CRLk2iBUNYamnLc4V" + }, + "op2": { + "branch": "BLEVomdmPi274XtWAu6uVB5S1Dchba5xmJ8YfS7kxaprBPWWMLL", + "operations": { + "kind": "attestation_with_dal", + "slot": 83, + "level": 475140, + "round": 0, + "block_payload_hash": "vh1pDiA9BsDjscfR7hBeGnzWUGa1hPqDDwKtECZNcBYPBiB3hvsN", + "dal_attestation": "123123123123213123" + }, + "signature": "sigkUwi8AKuL9ViT56ktaEBxF7Zb4JsSSqgVewYdMjjQm9S7oY7j4aZZSWX47i9xHsMkTeauPzD47mK5XJn6Q3wzeUeaWZoq" + } + } + ] +} \ No newline at end of file diff --git a/Netezos/Forging/Local/LocalForge.Forgers.Operations.cs b/Netezos/Forging/Local/LocalForge.Forgers.Operations.cs index a9cd5c45..782d2693 100644 --- a/Netezos/Forging/Local/LocalForge.Forgers.Operations.cs +++ b/Netezos/Forging/Local/LocalForge.Forgers.Operations.cs @@ -11,7 +11,6 @@ static byte[] ForgeOperation(OperationContent content) return content switch { AttestationContent op => ForgeAttestation(op), - AttestationWithDalContent op => ForgeAttestationWithDal(op), PreattestationContent op => ForgePreattestation(op), BallotContent op => ForgeBallot(op), ProposalsContent op => ForgeProposals(op), @@ -55,23 +54,25 @@ static byte[] ForgeOperation(OperationContent content) static byte[] ForgeAttestation(AttestationContent operation) { - return Bytes.Concat( - ForgeTag(OperationTag.Attestation), - ForgeInt32(operation.Slot, 2), - ForgeInt32(operation.Level), - ForgeInt32(operation.Round), - Base58.Parse(operation.PayloadHash, Prefix.vh)); - } - - static byte[] ForgeAttestationWithDal(AttestationWithDalContent operation) - { - return Bytes.Concat( - ForgeTag(OperationTag.AttestationWithDal), - ForgeInt32(operation.Slot, 2), - ForgeInt32(operation.Level), - ForgeInt32(operation.Round), - Base58.Parse(operation.PayloadHash, Prefix.vh), - ForgeMicheInt(operation.DalAttestation)); + if (operation.DalAttestation == null) + { + return Bytes.Concat( + ForgeTag(OperationTag.Attestation), + ForgeInt32(operation.Slot, 2), + ForgeInt32(operation.Level), + ForgeInt32(operation.Round), + Base58.Parse(operation.PayloadHash, Prefix.vh)); + } + else + { + return Bytes.Concat( + ForgeTag(OperationTag.AttestationWithDal), + ForgeInt32(operation.Slot, 2), + ForgeInt32(operation.Level), + ForgeInt32(operation.Round), + Base58.Parse(operation.PayloadHash, Prefix.vh), + ForgeMicheInt(operation.DalAttestation.Value)); + } } static byte[] ForgePreattestation(PreattestationContent operation) diff --git a/Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs b/Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs index 2817d823..cf3c47de 100644 --- a/Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs +++ b/Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs @@ -59,13 +59,14 @@ static AttestationContent UnforgeAttestation(ForgedReader reader) Slot = reader.ReadInt32(2), Level = reader.ReadInt32(), Round = reader.ReadInt32(), - PayloadHash = reader.ReadBase58(32, Prefix.vh) + PayloadHash = reader.ReadBase58(32, Prefix.vh), + DalAttestation = null }; } - static AttestationWithDalContent UnforgeAttestationWithDal(ForgedReader reader) + static AttestationContent UnforgeAttestationWithDal(ForgedReader reader) { - return new AttestationWithDalContent + return new AttestationContent { Slot = reader.ReadInt32(2), Level = reader.ReadInt32(), diff --git a/Netezos/Forging/Models/Operations/Content/AttestationContent.cs b/Netezos/Forging/Models/Operations/Content/AttestationContent.cs index 9d84a4d0..acdbfc62 100644 --- a/Netezos/Forging/Models/Operations/Content/AttestationContent.cs +++ b/Netezos/Forging/Models/Operations/Content/AttestationContent.cs @@ -1,11 +1,12 @@ -using System.Text.Json.Serialization; +using System.Numerics; +using System.Text.Json.Serialization; namespace Netezos.Forging.Models { public class AttestationContent : OperationContent { [JsonPropertyName("kind")] - public override string Kind => "attestation"; + public override string Kind => DalAttestation == null ? "attestation" : "attestation_with_dal"; [JsonPropertyName("slot")] public int Slot { get; set; } @@ -18,5 +19,9 @@ public class AttestationContent : OperationContent [JsonPropertyName("block_payload_hash")] public string PayloadHash { get; set; } = null!; + + [JsonPropertyName("dal_attestation")] + [JsonConverter(typeof(BigIntegerNullableStringConverter))] + public BigInteger? DalAttestation { get; set; } } } diff --git a/Netezos/Forging/Models/Operations/Content/AttestationWithDalContent.cs b/Netezos/Forging/Models/Operations/Content/AttestationWithDalContent.cs deleted file mode 100644 index 68ade953..00000000 --- a/Netezos/Forging/Models/Operations/Content/AttestationWithDalContent.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Numerics; -using System.Text.Json.Serialization; - -namespace Netezos.Forging.Models -{ - public class AttestationWithDalContent : OperationContent - { - [JsonPropertyName("kind")] - public override string Kind => "attestation_with_dal"; - - [JsonPropertyName("slot")] - public int Slot { get; set; } - - [JsonPropertyName("level")] - public int Level { get; set; } - - [JsonPropertyName("round")] - public int Round { get; set; } - - [JsonPropertyName("block_payload_hash")] - public string PayloadHash { get; set; } = null!; - - [JsonPropertyName("dal_attestation")] - [JsonConverter(typeof(BigIntegerStringConverter))] - public BigInteger DalAttestation { get; set; } - } -} diff --git a/Netezos/Utils/Converters/OperationContentConverter.cs b/Netezos/Utils/Converters/OperationContentConverter.cs index c949e7e2..145d738b 100644 --- a/Netezos/Utils/Converters/OperationContentConverter.cs +++ b/Netezos/Utils/Converters/OperationContentConverter.cs @@ -20,7 +20,7 @@ class OperationContentConverter : JsonConverter return sideReader.GetString() switch { "attestation" => JsonSerializer.Deserialize(ref reader, options), - "attestation_with_dal" => JsonSerializer.Deserialize(ref reader, options), + "attestation_with_dal" => JsonSerializer.Deserialize(ref reader, options), "preattestation" => JsonSerializer.Deserialize(ref reader, options), "ballot" => JsonSerializer.Deserialize(ref reader, options), "proposals" => JsonSerializer.Deserialize(ref reader, options),