Skip to content

Commit

Permalink
Add new operation types
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed May 15, 2024
1 parent 5bd1512 commit 5539779
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b7e640e3e07beb8dc10a7582ad323c5788258b90186bd730d24e1962e08296617000f0008b45400000000e7bd5159f624e9d3d2ea82108a37653566ef72a3bc428a667769dabba5448ad400
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"branch": "BKoLvj4KKvpYZogKgjARRu6jzcJMqTm8NRUe47dNHKguTYUCmnx",
"contents": [
{
"kind": "attestation_with_dal",
"slot": 15,
"level": 570452,
"round": 0,
"block_payload_hash": "vh3SBb7RHo3Dva947myZ9cdNxpGeVE1RfZU2NGHC7Jn9eyVNwhiW",
"dal_attestation": "0"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12a89577eaecd1668e68196ba5a61854769f1b347183ddfdd2d4a334810f637be600e1640b293ba2b314f58cbb4c9853f68d01ad3382810402990b000aaf8429a7306f137055ee91cbbf0350048fbb9399bdda3f1290f0f2f80d30da4c6fc3fe7e6a9b4d7965f094bf571db596b989e195c8f3d63eea3c5a1b51b32c853b4c09c124d53d8eac621c2d60c00544b4f11b9546f9fc4b8d4d641d097851c7112b7d539e6cfcf61ae5b17de43320f10ee33ee31e8080aca6660426fd40f02ba41a7da8845514d433f583e5d2872d42
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"branch": "BKrVwdc7fD2Sz6BypYQUNE5YvYBRYSM2mLBW39tss916K2e7eCB",
"contents": [
{
"kind": "dal_publish_commitment",
"source": "tz1gBnaS1n7LKqpaRnyBX5MSmamadXXfzNpt",
"fee": "513",
"counter": "2",
"gas_limit": "1433",
"storage_limit": "0",
"slot_header": {
"slot_index": 10,
"commitment": "sh25wJo53VSwWsR3NLHw6s6VhL2kXXb2zXsQgYiWGhVykfYMbFsVgKFXnhd7QrJJNRJz7bAxzT",
"commitment_proof": "b989e195c8f3d63eea3c5a1b51b32c853b4c09c124d53d8eac621c2d60c00544b4f11b9546f9fc4b8d4d641d097851c7112b7d539e6cfcf61ae5b17de43320f10ee33ee31e8080aca6660426fd40f02ba41a7da8845514d433f583e5d2872d42"
}
}
]
}
27 changes: 27 additions & 0 deletions Netezos/Forging/Local/LocalForge.Forgers.Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static byte[] ForgeOperation(OperationContent content)
{
return content switch
{
AttestationWithDalContent op => ForgeAttestationWithDal(op),
EndorsementContent op => ForgeEndorsement(op),
PreendorsementContent op => ForgePreendorsement(op),
BallotContent op => ForgeBallot(op),
Expand Down Expand Up @@ -47,10 +48,22 @@ static byte[] ForgeOperation(OperationContent content)
SrRecoverBondContent op => ForgeSrRecoverBond(op),
SrRefuteContent op => ForgeSrRefute(op),
SrTmieoutContent op => ForgeSrTimeout(op),
DalPublishCommitmentContent op => ForgeDalPublishCommitment(op),
_ => throw new ArgumentException($"Invalid operation content kind {content.Kind}")
};
}

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));
}

static byte[] ForgeEndorsement(EndorsementContent operation)
{
return Bytes.Concat(
Expand Down Expand Up @@ -499,6 +512,20 @@ static byte[] ForgeSrRefute(SrRefuteContent operation)
ForgeRefutation(operation.Refutation));
}

static byte[] ForgeDalPublishCommitment(DalPublishCommitmentContent operation)
{
return Bytes.Concat(
ForgeTag(OperationTag.DalPublishCommitment),
ForgeTzAddress(operation.Source),
ForgeMicheNat(operation.Fee),
ForgeMicheNat(operation.Counter),
ForgeMicheNat(operation.GasLimit),
ForgeMicheNat(operation.StorageLimit),
[operation.SlotHeader.SlotIndex],
Base58.Parse(operation.SlotHeader.Commitment, Prefix.sh),
operation.SlotHeader.CommitmentProof);
}

#region nested
static byte[] ForgeBlockHeader(BlockHeader header)
{
Expand Down
34 changes: 32 additions & 2 deletions Netezos/Forging/Local/LocalForge.Unforgers.Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static OperationContent UnforgeOperation(ForgedReader reader)
{
return (OperationTag)reader.ReadByte() switch
{
OperationTag.AttestationWithDal => UnforgeAttestationWithDal(reader),
OperationTag.Endorsement => UnforgeEndorsement(reader),
OperationTag.Preendorsement => UnforgePreendorsement(reader),
OperationTag.Ballot => UnforgeBallot(reader),
Expand Down Expand Up @@ -46,10 +47,23 @@ static OperationContent UnforgeOperation(ForgedReader reader)
OperationTag.SrPublish => UnforgeSrPublish(reader),
OperationTag.SrRecoverBond => UnforgeSrRecoverBond(reader),
OperationTag.SrRefute => UnforgeSrRefute(reader),
OperationTag.DalPublishCommitment => UnforgeDalPublishCommitment(reader),
var operation => throw new ArgumentException($"Invalid operation: {operation}")
};
}

static AttestationWithDalContent UnforgeAttestationWithDal(ForgedReader reader)
{
return new AttestationWithDalContent
{
Slot = reader.ReadInt32(2),
Level = reader.ReadInt32(),
Round = reader.ReadInt32(),
PayloadHash = reader.ReadBase58(32, Prefix.vh),
DalAttestation = reader.ReadMichelineInt().Value
};
}

static EndorsementContent UnforgeEndorsement(ForgedReader reader)
{
return new EndorsementContent
Expand Down Expand Up @@ -532,8 +546,25 @@ static SrRefuteContent UnforgeSrRefute(ForgedReader reader)
};
}

#region nested
static DalPublishCommitmentContent UnforgeDalPublishCommitment(ForgedReader reader)
{
return new DalPublishCommitmentContent
{
Source = reader.ReadTzAddress(),
Fee = (long)reader.ReadUBigInt(),
Counter = (int)reader.ReadUBigInt(),
GasLimit = (int)reader.ReadUBigInt(),
StorageLimit = (int)reader.ReadUBigInt(),
SlotHeader = new DalSlotHeader
{
SlotIndex = reader.ReadByte(),
Commitment = reader.ReadBase58(48, Prefix.sh),
CommitmentProof = reader.ReadBytes(96)
}
};
}

#region nested
static BlockHeader UnforgeBlockHeader(ForgedReader reader)
{
return new BlockHeader
Expand Down Expand Up @@ -732,7 +763,6 @@ static RevealProof UnforgeRevealProof(ForgedReader reader)
{
return reader.ReadBool() ? tb() : fb?.Invoke();
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json.Serialization;

namespace Netezos.Forging.Models
{
public class DalPublishCommitmentContent : ManagerOperationContent
{
[JsonPropertyName("kind")]
public override string Kind => "dal_publish_commitment";

[JsonPropertyName("slot_header")]
public DalSlotHeader SlotHeader { get; set; } = null!;
}

public class DalSlotHeader
{
[JsonPropertyName("slot_index")]
public byte SlotIndex { get; set; }

[JsonPropertyName("commitment")]
public string Commitment { get; set; } = null!;

[JsonPropertyName("commitment_proof")]
[JsonConverter(typeof(HexConverter))]
public byte[] CommitmentProof { get; set; } = null!;
}
}
8 changes: 6 additions & 2 deletions Netezos/Forging/Models/Operations/OperationTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public enum OperationTag
DrainDelegate = 9,

FailingNoop = 17,

Preendorsement = 20,
Endorsement = 21,
AttestationWithDal = 23,

Reveal = 107,
Transaction = 108,
Expand All @@ -34,6 +35,7 @@ public enum OperationTag
TxRollupRemoveCommitment = 155,
TxRollupRejection = 156,
TxRollupDispatchTickets = 157,

TransferTicket = 158,

SrOriginate = 200,
Expand All @@ -43,6 +45,8 @@ public enum OperationTag
SrRefute = 204,
SrTimeout = 205,
SrExecute = 206,
SrRecoverBond = 207
SrRecoverBond = 207,

DalPublishCommitment = 230
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ManagerOperationContentConverter : JsonConverter<ManagerOperationContent?>
"smart_rollup_publish" => JsonSerializer.Deserialize<SrPublishContent>(ref reader, options),
"smart_rollup_recover_bond" => JsonSerializer.Deserialize<SrRecoverBondContent>(ref reader, options),
"smart_rollup_refute" => JsonSerializer.Deserialize<SrRefuteContent>(ref reader, options),
"dal_publish_commitment" => JsonSerializer.Deserialize<DalPublishCommitmentContent>(ref reader, options),
_ => throw new JsonException("Invalid operation kind"),
};
}
Expand Down
2 changes: 2 additions & 0 deletions Netezos/Utils/Converters/OperationContentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class OperationContentConverter : JsonConverter<OperationContent?>
sideReader.Read();
return sideReader.GetString() switch
{
"attestation_with_dal" => JsonSerializer.Deserialize<AttestationWithDalContent>(ref reader, options),
"endorsement" => JsonSerializer.Deserialize<EndorsementContent>(ref reader, options),
"preendorsement" => JsonSerializer.Deserialize<PreendorsementContent>(ref reader, options),
"ballot" => JsonSerializer.Deserialize<BallotContent>(ref reader, options),
Expand Down Expand Up @@ -56,6 +57,7 @@ class OperationContentConverter : JsonConverter<OperationContent?>
"smart_rollup_publish" => JsonSerializer.Deserialize<SrPublishContent>(ref reader, options),
"smart_rollup_recover_bond" => JsonSerializer.Deserialize<SrRecoverBondContent>(ref reader, options),
"smart_rollup_refute" => JsonSerializer.Deserialize<SrRefuteContent>(ref reader, options),
"dal_publish_commitment" => JsonSerializer.Deserialize<DalPublishCommitmentContent>(ref reader, options),
_ => throw new JsonException("Invalid operation kind"),
};
}
Expand Down
5 changes: 5 additions & 0 deletions Netezos/Utils/Prefix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,10 @@ static class Prefix
/// Tx Rollup withdraw list hash
/// </summary>
public static readonly byte[] txw = new byte[] { 79, 150, 72 };

/// <summary>
/// DAL slot header
/// </summary>
public static readonly byte[] sh = new byte[] { 2, 116, 180 };
}
}

0 comments on commit 5539779

Please sign in to comment.