Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(spec): Update BlockHeader and Tx to conform to specification #34

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cardano/gen/docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Contains the header information for a block.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| slot | [uint64](#uint64) | | Slot number. |
| height | [uint64](#uint64) | | Block height. |
| hash | [bytes](#bytes) | | Block hash. |


Expand Down Expand Up @@ -697,6 +698,7 @@ Represents a transaction in the Cardano blockchain.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| hash | [bytes](#bytes) | | Hash of the transaction |
| inputs | [TxInput](#utxorpc-cardano-v1-TxInput) | repeated | List of transaction inputs |
| outputs | [TxOutput](#utxorpc-cardano-v1-TxOutput) | repeated | List of transaction outputs |
| certificates | [Certificate](#utxorpc-cardano-v1-Certificate) | repeated | List of certificates |
Expand Down
718 changes: 372 additions & 346 deletions cardano/gen/go/utxorpc/cardano/v1/cardano.pb.go

Large diffs are not rendered by default.

1,563 changes: 836 additions & 727 deletions cardano/gen/haskell/Proto/Utxorpc/Cardano/V1/Cardano.hs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ header ::
(Prelude.Functor f, Data.ProtoLens.Field.HasField s "header" a) =>
Lens.Family2.LensLike' f s a
header = Data.ProtoLens.Field.field @"header"
height ::
forall f s a.
(Prelude.Functor f, Data.ProtoLens.Field.HasField s "height" a) =>
Lens.Family2.LensLike' f s a
height = Data.ProtoLens.Field.field @"height"
inputs ::
forall f s a.
(Prelude.Functor f, Data.ProtoLens.Field.HasField s "inputs" a) =>
Expand Down
2,673 changes: 1,346 additions & 1,327 deletions cardano/gen/rust/src/utxorpc.cardano.v1.rs

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions cardano/gen/rust/src/utxorpc.cardano.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,19 @@ impl serde::Serialize for BlockHeader {
if self.slot != 0 {
len += 1;
}
if self.height != 0 {
len += 1;
}
if !self.hash.is_empty() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("utxorpc.cardano.v1.BlockHeader", len)?;
if self.slot != 0 {
struct_ser.serialize_field("slot", ToString::to_string(&self.slot).as_str())?;
}
if self.height != 0 {
struct_ser.serialize_field("height", ToString::to_string(&self.height).as_str())?;
}
if !self.hash.is_empty() {
struct_ser.serialize_field("hash", pbjson::private::base64::encode(&self.hash).as_str())?;
}
Expand All @@ -833,12 +839,14 @@ impl<'de> serde::Deserialize<'de> for BlockHeader {
{
const FIELDS: &[&str] = &[
"slot",
"height",
"hash",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Slot,
Height,
Hash,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -862,6 +870,7 @@ impl<'de> serde::Deserialize<'de> for BlockHeader {
{
match value {
"slot" => Ok(GeneratedField::Slot),
"height" => Ok(GeneratedField::Height),
"hash" => Ok(GeneratedField::Hash),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
Expand All @@ -883,6 +892,7 @@ impl<'de> serde::Deserialize<'de> for BlockHeader {
V: serde::de::MapAccess<'de>,
{
let mut slot__ = None;
let mut height__ = None;
let mut hash__ = None;
while let Some(k) = map.next_key()? {
match k {
Expand All @@ -894,6 +904,14 @@ impl<'de> serde::Deserialize<'de> for BlockHeader {
Some(map.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::Height => {
if height__.is_some() {
return Err(serde::de::Error::duplicate_field("height"));
}
height__ =
Some(map.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::Hash => {
if hash__.is_some() {
return Err(serde::de::Error::duplicate_field("hash"));
Expand All @@ -906,6 +924,7 @@ impl<'de> serde::Deserialize<'de> for BlockHeader {
}
Ok(BlockHeader {
slot: slot__.unwrap_or_default(),
height: height__.unwrap_or_default(),
hash: hash__.unwrap_or_default(),
})
}
Expand Down Expand Up @@ -4680,6 +4699,9 @@ impl serde::Serialize for Tx {
{
use serde::ser::SerializeStruct;
let mut len = 0;
if !self.hash.is_empty() {
len += 1;
}
if !self.inputs.is_empty() {
len += 1;
}
Expand Down Expand Up @@ -4717,6 +4739,9 @@ impl serde::Serialize for Tx {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("utxorpc.cardano.v1.Tx", len)?;
if !self.hash.is_empty() {
struct_ser.serialize_field("hash", pbjson::private::base64::encode(&self.hash).as_str())?;
}
if !self.inputs.is_empty() {
struct_ser.serialize_field("inputs", &self.inputs)?;
}
Expand Down Expand Up @@ -4763,6 +4788,7 @@ impl<'de> serde::Deserialize<'de> for Tx {
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"hash",
"inputs",
"outputs",
"certificates",
Expand All @@ -4780,6 +4806,7 @@ impl<'de> serde::Deserialize<'de> for Tx {

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
Hash,
Inputs,
Outputs,
Certificates,
Expand Down Expand Up @@ -4813,6 +4840,7 @@ impl<'de> serde::Deserialize<'de> for Tx {
E: serde::de::Error,
{
match value {
"hash" => Ok(GeneratedField::Hash),
"inputs" => Ok(GeneratedField::Inputs),
"outputs" => Ok(GeneratedField::Outputs),
"certificates" => Ok(GeneratedField::Certificates),
Expand Down Expand Up @@ -4844,6 +4872,7 @@ impl<'de> serde::Deserialize<'de> for Tx {
where
V: serde::de::MapAccess<'de>,
{
let mut hash__ = None;
let mut inputs__ = None;
let mut outputs__ = None;
let mut certificates__ = None;
Expand All @@ -4858,6 +4887,14 @@ impl<'de> serde::Deserialize<'de> for Tx {
let mut auxiliary__ = None;
while let Some(k) = map.next_key()? {
match k {
GeneratedField::Hash => {
if hash__.is_some() {
return Err(serde::de::Error::duplicate_field("hash"));
}
hash__ =
Some(map.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
;
}
GeneratedField::Inputs => {
if inputs__.is_some() {
return Err(serde::de::Error::duplicate_field("inputs"));
Expand Down Expand Up @@ -4935,6 +4972,7 @@ impl<'de> serde::Deserialize<'de> for Tx {
}
}
Ok(Tx {
hash: hash__.unwrap_or_default(),
inputs: inputs__.unwrap_or_default(),
outputs: outputs__.unwrap_or_default(),
certificates: certificates__.unwrap_or_default(),
Expand Down
70 changes: 43 additions & 27 deletions cardano/gen/web/src/utxorpc/cardano/v1/cardano_pb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-es v1.2.1 with parameter "target=ts,import_extension=.ts"
// @generated by protoc-gen-es v1.6.0 with parameter "target=ts,import_extension=.ts"
// @generated from file utxorpc/cardano/v1/cardano.proto (package utxorpc.cardano.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down Expand Up @@ -640,87 +640,94 @@ export class AuxData extends Message<AuxData> {
* @generated from message utxorpc.cardano.v1.Tx
*/
export class Tx extends Message<Tx> {
/**
* Hash of the transaction
*
* @generated from field: bytes hash = 1;
*/
hash = new Uint8Array(0);

/**
* List of transaction inputs
*
* @generated from field: repeated utxorpc.cardano.v1.TxInput inputs = 1;
* @generated from field: repeated utxorpc.cardano.v1.TxInput inputs = 2;
*/
inputs: TxInput[] = [];

/**
* List of transaction outputs
*
* @generated from field: repeated utxorpc.cardano.v1.TxOutput outputs = 2;
* @generated from field: repeated utxorpc.cardano.v1.TxOutput outputs = 3;
*/
outputs: TxOutput[] = [];

/**
* List of certificates
*
* @generated from field: repeated utxorpc.cardano.v1.Certificate certificates = 3;
* @generated from field: repeated utxorpc.cardano.v1.Certificate certificates = 4;
*/
certificates: Certificate[] = [];

/**
* List of withdrawals
*
* @generated from field: repeated utxorpc.cardano.v1.Withdrawal withdrawals = 4;
* @generated from field: repeated utxorpc.cardano.v1.Withdrawal withdrawals = 5;
*/
withdrawals: Withdrawal[] = [];

/**
* List of minted custom assets
*
* @generated from field: repeated utxorpc.cardano.v1.Multiasset mint = 5;
* @generated from field: repeated utxorpc.cardano.v1.Multiasset mint = 6;
*/
mint: Multiasset[] = [];

/**
* List of reference inputs
*
* @generated from field: repeated utxorpc.cardano.v1.TxInput reference_inputs = 6;
* @generated from field: repeated utxorpc.cardano.v1.TxInput reference_inputs = 7;
*/
referenceInputs: TxInput[] = [];

/**
* Witnesses that validte the transaction
*
* @generated from field: utxorpc.cardano.v1.WitnessSet witnesses = 7;
* @generated from field: utxorpc.cardano.v1.WitnessSet witnesses = 8;
*/
witnesses?: WitnessSet;

/**
* Collateral details in case of failed transaction
*
* @generated from field: utxorpc.cardano.v1.Collateral collateral = 8;
* @generated from field: utxorpc.cardano.v1.Collateral collateral = 9;
*/
collateral?: Collateral;

/**
* Transaction fee in ADA
*
* @generated from field: uint64 fee = 9;
* @generated from field: uint64 fee = 10;
*/
fee = protoInt64.zero;

/**
* Validity interval of the transaction
*
* @generated from field: utxorpc.cardano.v1.TxValidity validity = 10;
* @generated from field: utxorpc.cardano.v1.TxValidity validity = 11;
*/
validity?: TxValidity;

/**
* Flag indicating whether the transaction was successful
*
* @generated from field: bool successful = 11;
* @generated from field: bool successful = 12;
*/
successful = false;

/**
* Auxiliary data not directly tied to the validation process
*
* @generated from field: utxorpc.cardano.v1.AuxData auxiliary = 12;
* @generated from field: utxorpc.cardano.v1.AuxData auxiliary = 13;
*/
auxiliary?: AuxData;

Expand All @@ -732,18 +739,19 @@ export class Tx extends Message<Tx> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "utxorpc.cardano.v1.Tx";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "inputs", kind: "message", T: TxInput, repeated: true },
{ no: 2, name: "outputs", kind: "message", T: TxOutput, repeated: true },
{ no: 3, name: "certificates", kind: "message", T: Certificate, repeated: true },
{ no: 4, name: "withdrawals", kind: "message", T: Withdrawal, repeated: true },
{ no: 5, name: "mint", kind: "message", T: Multiasset, repeated: true },
{ no: 6, name: "reference_inputs", kind: "message", T: TxInput, repeated: true },
{ no: 7, name: "witnesses", kind: "message", T: WitnessSet },
{ no: 8, name: "collateral", kind: "message", T: Collateral },
{ no: 9, name: "fee", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 10, name: "validity", kind: "message", T: TxValidity },
{ no: 11, name: "successful", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 12, name: "auxiliary", kind: "message", T: AuxData },
{ no: 1, name: "hash", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
{ no: 2, name: "inputs", kind: "message", T: TxInput, repeated: true },
{ no: 3, name: "outputs", kind: "message", T: TxOutput, repeated: true },
{ no: 4, name: "certificates", kind: "message", T: Certificate, repeated: true },
{ no: 5, name: "withdrawals", kind: "message", T: Withdrawal, repeated: true },
{ no: 6, name: "mint", kind: "message", T: Multiasset, repeated: true },
{ no: 7, name: "reference_inputs", kind: "message", T: TxInput, repeated: true },
{ no: 8, name: "witnesses", kind: "message", T: WitnessSet },
{ no: 9, name: "collateral", kind: "message", T: Collateral },
{ no: 10, name: "fee", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 11, name: "validity", kind: "message", T: TxValidity },
{ no: 12, name: "successful", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 13, name: "auxiliary", kind: "message", T: AuxData },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Tx {
Expand Down Expand Up @@ -776,10 +784,17 @@ export class BlockHeader extends Message<BlockHeader> {
*/
slot = protoInt64.zero;

/**
* Block height.
*
* @generated from field: uint64 height = 2;
*/
height = protoInt64.zero;

/**
* Block hash.
*
* @generated from field: bytes hash = 2;
* @generated from field: bytes hash = 3;
*/
hash = new Uint8Array(0);

Expand All @@ -792,7 +807,8 @@ export class BlockHeader extends Message<BlockHeader> {
static readonly typeName = "utxorpc.cardano.v1.BlockHeader";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "slot", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 2, name: "hash", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
{ no: 2, name: "height", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
{ no: 3, name: "hash", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): BlockHeader {
Expand Down
28 changes: 15 additions & 13 deletions cardano/proto/utxorpc/cardano/v1/cardano.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,26 @@ message AuxData {

// Represents a transaction in the Cardano blockchain.
message Tx {
repeated TxInput inputs = 1; // List of transaction inputs
repeated TxOutput outputs = 2; // List of transaction outputs
repeated Certificate certificates = 3; // List of certificates
repeated Withdrawal withdrawals = 4; // List of withdrawals
repeated Multiasset mint = 5; // List of minted custom assets
repeated TxInput reference_inputs = 6; // List of reference inputs
WitnessSet witnesses = 7; // Witnesses that validte the transaction
Collateral collateral = 8; // Collateral details in case of failed transaction
uint64 fee = 9; // Transaction fee in ADA
TxValidity validity = 10; // Validity interval of the transaction
bool successful = 11; // Flag indicating whether the transaction was successful
AuxData auxiliary = 12; // Auxiliary data not directly tied to the validation process
bytes hash = 1; // Hash of the transaction
repeated TxInput inputs = 2; // List of transaction inputs
repeated TxOutput outputs = 3; // List of transaction outputs
repeated Certificate certificates = 4; // List of certificates
repeated Withdrawal withdrawals = 5; // List of withdrawals
repeated Multiasset mint = 6; // List of minted custom assets
repeated TxInput reference_inputs = 7; // List of reference inputs
WitnessSet witnesses = 8; // Witnesses that validte the transaction
Collateral collateral = 9; // Collateral details in case of failed transaction
uint64 fee = 10; // Transaction fee in ADA
TxValidity validity = 11; // Validity interval of the transaction
bool successful = 12; // Flag indicating whether the transaction was successful
AuxData auxiliary = 13; // Auxiliary data not directly tied to the validation process
}

// Contains the header information for a block.
message BlockHeader {
uint64 slot = 1; // Slot number.
bytes hash = 2; // Block hash.
uint64 height = 2; // Block height.
bytes hash = 3; // Block hash.
}

// Contains the transaction data for a block.
Expand Down
Loading
Loading