diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 83827fb1..3d0c61dd 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -5,6 +5,89 @@ * @flow */ +/** + * @param {string} json + * @param {number} schema + * @returns {PlutusData} + */ +declare export function encode_json_str_to_plutus_datum( + json: string, + schema: number +): PlutusData; + +/** + * @param {PlutusData} datum + * @param {number} schema + * @returns {string} + */ +declare export function decode_plutus_datum_to_json_str( + datum: PlutusData, + schema: number +): string; + +/** + * @param {Uint8Array} bytes + * @returns {TransactionMetadatum} + */ +declare export function encode_arbitrary_bytes_as_metadatum( + bytes: Uint8Array +): TransactionMetadatum; + +/** + * @param {TransactionMetadatum} metadata + * @returns {Uint8Array} + */ +declare export function decode_arbitrary_bytes_from_metadatum( + metadata: TransactionMetadatum +): Uint8Array; + +/** + * @param {string} json + * @param {number} schema + * @returns {TransactionMetadatum} + */ +declare export function encode_json_str_to_metadatum( + json: string, + schema: number +): TransactionMetadatum; + +/** + * @param {TransactionMetadatum} metadatum + * @param {number} schema + * @returns {string} + */ +declare export function decode_metadatum_to_json_str( + metadatum: TransactionMetadatum, + schema: number +): string; + +/** + * @param {Transaction} tx + * @param {LinearFee} linear_fee + * @returns {BigNum} + */ +declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum; + +/** + * @param {ExUnits} ex_units + * @param {ExUnitPrices} ex_unit_prices + * @returns {BigNum} + */ +declare export function calculate_ex_units_ceil_cost( + ex_units: ExUnits, + ex_unit_prices: ExUnitPrices +): BigNum; + +/** + * @param {Transaction} tx + * @param {ExUnitPrices} ex_unit_prices + * @returns {BigNum} + */ +declare export function min_script_fee( + tx: Transaction, + ex_unit_prices: ExUnitPrices +): BigNum; + /** * @param {string} password * @param {string} salt @@ -179,89 +262,6 @@ declare export function encode_json_str_to_native_script( schema: number ): NativeScript; -/** - * @param {string} json - * @param {number} schema - * @returns {PlutusData} - */ -declare export function encode_json_str_to_plutus_datum( - json: string, - schema: number -): PlutusData; - -/** - * @param {PlutusData} datum - * @param {number} schema - * @returns {string} - */ -declare export function decode_plutus_datum_to_json_str( - datum: PlutusData, - schema: number -): string; - -/** - * @param {Uint8Array} bytes - * @returns {TransactionMetadatum} - */ -declare export function encode_arbitrary_bytes_as_metadatum( - bytes: Uint8Array -): TransactionMetadatum; - -/** - * @param {TransactionMetadatum} metadata - * @returns {Uint8Array} - */ -declare export function decode_arbitrary_bytes_from_metadatum( - metadata: TransactionMetadatum -): Uint8Array; - -/** - * @param {string} json - * @param {number} schema - * @returns {TransactionMetadatum} - */ -declare export function encode_json_str_to_metadatum( - json: string, - schema: number -): TransactionMetadatum; - -/** - * @param {TransactionMetadatum} metadatum - * @param {number} schema - * @returns {string} - */ -declare export function decode_metadatum_to_json_str( - metadatum: TransactionMetadatum, - schema: number -): string; - -/** - * @param {Transaction} tx - * @param {LinearFee} linear_fee - * @returns {BigNum} - */ -declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum; - -/** - * @param {ExUnits} ex_units - * @param {ExUnitPrices} ex_unit_prices - * @returns {BigNum} - */ -declare export function calculate_ex_units_ceil_cost( - ex_units: ExUnits, - ex_unit_prices: ExUnitPrices -): BigNum; - -/** - * @param {Transaction} tx - * @param {ExUnitPrices} ex_unit_prices - * @returns {BigNum} - */ -declare export function min_script_fee( - tx: Transaction, - ex_unit_prices: ExUnitPrices -): BigNum; - /** */ @@ -333,15 +333,6 @@ declare export var NetworkIdKind: {| +Mainnet: 1, // 1 |}; -/** - * Used to choosed the schema for a script JSON string - */ - -declare export var ScriptSchema: {| - +Wallet: 0, // 0 - +Node: 1, // 1 -|}; - /** */ @@ -408,14 +399,6 @@ declare export var MetadataJsonSchema: {| +DetailedSchema: 2, // 2 |}; -/** - */ - -declare export var CborContainerType: {| - +Array: 0, // 0 - +Map: 1, // 1 -|}; - /** */ @@ -434,6 +417,23 @@ declare export var StakeCredKind: {| +Script: 1, // 1 |}; +/** + * Used to choosed the schema for a script JSON string + */ + +declare export var ScriptSchema: {| + +Wallet: 0, // 0 + +Node: 1, // 1 +|}; + +/** + */ + +declare export var CborContainerType: {| + +Array: 0, // 0 + +Map: 1, // 1 +|}; + /** */ declare export class Address { @@ -10977,7 +10977,7 @@ export interface TransactionBodyJSON { update?: UpdateJSON | null; validity_start_interval?: string | null; withdrawals?: { - [k: string]: ProtocolParamUpdateJSON, + [k: string]: string, } | null; } export type TransactionHashJSON = string; @@ -11036,5 +11036,5 @@ export interface VkeywitnessJSON { } export type VkeywitnessesJSON = VkeywitnessJSON[]; export interface WithdrawalsJSON { - [k: string]: ProtocolParamUpdateJSON; + [k: string]: string; } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 4881f760..747a842f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1797,10 +1797,10 @@ impl JsonSchema for Withdrawals { String::from("Withdrawals") } fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - std::collections::BTreeMap::::json_schema(gen) + std::collections::BTreeMap::::json_schema(gen) } fn is_referenceable() -> bool { - std::collections::BTreeMap::::is_referenceable() + std::collections::BTreeMap::::is_referenceable() } } diff --git a/rust/src/serialization.rs b/rust/src/serialization.rs index 6431741f..cade295b 100644 --- a/rust/src/serialization.rs +++ b/rust/src/serialization.rs @@ -4654,12 +4654,21 @@ impl DeserializeEmbeddedGroup for HeaderBody { let block_body_hash = (|| -> Result<_, DeserializeError> { Ok(BlockHash::deserialize(raw)?) })() .map_err(|e| e.annotate("block_body_hash"))?; + let operational_cert = (|| -> Result<_, DeserializeError> { - Ok(OperationalCert::deserialize_as_embedded_group(raw, len)?) + if raw.cbor_type()? == CBORType::Array { + Ok(OperationalCert::deserialize(raw)?) + } else { + Ok(OperationalCert::deserialize_as_embedded_group(raw, len)?) + } })() .map_err(|e| e.annotate("operational_cert"))?; let protocol_version = (|| -> Result<_, DeserializeError> { - Ok(ProtocolVersion::deserialize_as_embedded_group(raw, len)?) + if raw.cbor_type()? == CBORType::Array { + Ok(ProtocolVersion::deserialize(raw)?) + } else { + Ok(ProtocolVersion::deserialize_as_embedded_group(raw, len)?) + } })() .map_err(|e| e.annotate("protocol_version"))?; Ok(HeaderBody { diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 42fe66be..3dc85bf0 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -855,11 +855,11 @@ pub(crate) fn read_bounded_bytes( .into()); } cbor_event::Len::Len(len) => { - if chunk_len_sz > BOUNDED_BYTES_CHUNK_SIZE { + if len as usize > BOUNDED_BYTES_CHUNK_SIZE { return Err(DeserializeFailure::OutOfRange { min: 0, max: BOUNDED_BYTES_CHUNK_SIZE, - found: chunk_len_sz, + found: len as usize, } .into()); }