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

Tuple deserialization fix #626

Merged
merged 7 commits into from
Aug 21, 2023
Merged
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
204 changes: 102 additions & 102 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

/**
*/

Expand Down Expand Up @@ -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
|};

/**
*/

Expand Down Expand Up @@ -408,14 +399,6 @@ declare export var MetadataJsonSchema: {|
+DetailedSchema: 2, // 2
|};

/**
*/

declare export var CborContainerType: {|
+Array: 0, // 0
+Map: 1, // 1
|};

/**
*/

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -11036,5 +11036,5 @@ export interface VkeywitnessJSON {
}
export type VkeywitnessesJSON = VkeywitnessJSON[];
export interface WithdrawalsJSON {
[k: string]: ProtocolParamUpdateJSON;
[k: string]: string;
}
4 changes: 2 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<GenesisHash, ProtocolParamUpdate>::json_schema(gen)
std::collections::BTreeMap::<RewardAddress, Coin>::json_schema(gen)
}
fn is_referenceable() -> bool {
std::collections::BTreeMap::<GenesisHash, ProtocolParamUpdate>::is_referenceable()
std::collections::BTreeMap::<RewardAddress, Coin>::is_referenceable()
}
}

Expand Down
13 changes: 11 additions & 2 deletions rust/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ pub(crate) fn read_bounded_bytes<R: BufRead + Seek>(
.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());
}
Expand Down
Loading