Skip to content

Commit

Permalink
Merge attestation and attestation_with_dal contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed May 23, 2024
1 parent 51553a9 commit d943576
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b7e640e3e07beb8dc10a7582ad323c5788258b90186bd730d24e1962e082966020000008b449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e15005300074004000000009c602403e53efcd8c1c6def8dff2dce4e65169bfe3b9dc83c999401ffbf6dc50dc86bd6bcd6cb80de43fc274409a57bb74f3fc863d67619cc94f303afdfa9d48fee1e9ddce6883cbe84642efb8f05831c0c3ebd5acdbf8e28b111cec175d470a0000008b449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e1500530007400400000000126252e0a3e4b4912b08f9eb686b9e31589ef97749e0f2aeefcac9fa385c34faabef4735682bb173152481e3638d33a8dd51456334a1b6bc3c671ff626a95004a77639b29b48da6920f773fe37789574405894de77f467865647a7d076f7ef0b
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b7e640e3e07beb8dc10a7582ad323c5788258b90186bd730d24e1962e082966020000008c449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e17005300074004000000009c602403e53efcd8c1c6def8dff2dce4e65169bfe3b9dc83c999401ffbf6dc5000dc86bd6bcd6cb80de43fc274409a57bb74f3fc863d67619cc94f303afdfa9d48fee1e9ddce6883cbe84642efb8f05831c0c3ebd5acdbf8e28b111cec175d470a00000094449b5ed2f52b357b3a8df4794643408248e27839fdf7e2d28db64d65135c2e2e1700530007400400000000126252e0a3e4b4912b08f9eb686b9e31589ef97749e0f2aeefcac9fa385c34fa83cdaa9680f5b5b503abef4735682bb173152481e3638d33a8dd51456334a1b6bc3c671ff626a95004a77639b29b48da6920f773fe37789574405894de77f467865647a7d076f7ef0b
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
37 changes: 19 additions & 18 deletions Netezos/Forging/Local/LocalForge.Forgers.Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -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; }
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion Netezos/Utils/Converters/OperationContentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OperationContentConverter : JsonConverter<OperationContent?>
return sideReader.GetString() switch
{
"attestation" => JsonSerializer.Deserialize<AttestationContent>(ref reader, options),
"attestation_with_dal" => JsonSerializer.Deserialize<AttestationWithDalContent>(ref reader, options),
"attestation_with_dal" => JsonSerializer.Deserialize<AttestationContent>(ref reader, options),
"preattestation" => JsonSerializer.Deserialize<PreattestationContent>(ref reader, options),
"ballot" => JsonSerializer.Deserialize<BallotContent>(ref reader, options),
"proposals" => JsonSerializer.Deserialize<ProposalsContent>(ref reader, options),
Expand Down

0 comments on commit d943576

Please sign in to comment.