diff --git a/package-lock.json b/package-lock.json index 757e3e0f..c3875f14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cardano-serialization-lib", - "version": "12.1.1", + "version": "13.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cardano-serialization-lib", - "version": "12.1.1", + "version": "13.0.0", "hasInstallScript": true, "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index 74066223..d0e7eb16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cardano-serialization-lib", - "version": "12.1.1", + "version": "13.0.0", "description": "(De)serialization functions for the Cardano blockchain along with related utility functions", "scripts": { "rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; cd ..; npm run js:ts-json-gen; cd rust; wasm-pack pack) && npm run js:flowgen", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7512c48c..2800caae 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardano-serialization-lib" -version = "12.1.1" +version = "13.0.0" edition = "2018" authors = ["EMURGO"] license = "MIT" diff --git a/rust/json-gen/Cargo.lock b/rust/json-gen/Cargo.lock index 4f948604..4aa19346 100644 --- a/rust/json-gen/Cargo.lock +++ b/rust/json-gen/Cargo.lock @@ -49,7 +49,7 @@ checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "cardano-serialization-lib" -version = "12.1.1" +version = "13.0.0" dependencies = [ "bech32", "cbor_event", diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 0057ac19..341da9b2 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -5,6 +5,42 @@ * @flow */ +/** + * @param {Address} address + * @param {TransactionUnspentOutputs} utxos + * @param {TransactionBuilderConfig} config + * @returns {TransactionBatchList} + */ +declare export function create_send_all( + address: Address, + utxos: TransactionUnspentOutputs, + config: TransactionBuilderConfig +): TransactionBatchList; + +/** + * @param {string} password + * @param {string} salt + * @param {string} nonce + * @param {string} data + * @returns {string} + */ +declare export function encrypt_with_password( + password: string, + salt: string, + nonce: string, + data: string +): string; + +/** + * @param {string} password + * @param {string} data + * @returns {string} + */ +declare export function decrypt_with_password( + password: string, + data: string +): string; + /** * @param {Transaction} tx * @param {LinearFee} linear_fee @@ -106,42 +142,6 @@ declare export function decode_metadatum_to_json_str( schema: $Values ): string; -/** - * @param {Address} address - * @param {TransactionUnspentOutputs} utxos - * @param {TransactionBuilderConfig} config - * @returns {TransactionBatchList} - */ -declare export function create_send_all( - address: Address, - utxos: TransactionUnspentOutputs, - config: TransactionBuilderConfig -): TransactionBatchList; - -/** - * @param {string} password - * @param {string} salt - * @param {string} nonce - * @param {string} data - * @returns {string} - */ -declare export function encrypt_with_password( - password: string, - salt: string, - nonce: string, - data: string -): string; - -/** - * @param {string} password - * @param {string} data - * @returns {string} - */ -declare export function decrypt_with_password( - password: string, - data: string -): string; - /** * @param {TransactionHash} tx_body_hash * @param {ByronAddress} addr @@ -184,14 +184,6 @@ declare export function hash_auxiliary_data( auxiliary_data: AuxiliaryData ): AuxiliaryDataHash; -/** - * @param {TransactionBody} tx_body - * @returns {TransactionHash} - */ -declare export function hash_transaction( - tx_body: TransactionBody -): TransactionHash; - /** * @param {PlutusData} plutus_data * @returns {DataHash} @@ -268,34 +260,56 @@ declare export function encode_json_str_to_native_script( ): NativeScript; /** + * Returns the state of the transaction sets. + * If all sets have a tag, it returns AllSetsHaveTag. + * If all sets have no tag, it returns AllSetsHaveNoTag. + * If there is a mix of tagged and untagged sets, it returns MixedSets. + * This function is useful for checking if a transaction might be signed by a hardware wallet. + * And for checking which parameter should be used in a hardware wallet api. + * WARNING this function will be deleted after all tags for set types will be mandatory. Approx after next hf + * @param {Uint8Array} tx_bytes + * @returns {$Values< + typeof + TransactionSetsState>} */ +declare export function has_transaction_set_tag( + tx_bytes: Uint8Array +): $Values; -declare export var TransactionMetadatumKind: {| - +MetadataMap: 0, // 0 - +MetadataList: 1, // 1 - +Int: 2, // 2 - +Bytes: 3, // 3 - +Text: 4, // 4 +/** + */ + +declare export var CoinSelectionStrategyCIP2: {| + +LargestFirst: 0, // 0 + +RandomImprove: 1, // 1 + +LargestFirstMultiAsset: 2, // 2 + +RandomImproveMultiAsset: 3, // 3 |}; /** + * JSON <-> PlutusData conversion schemas. + * Follows ScriptDataJsonSchema in cardano-cli defined at: + * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 + * + * All methods here have the following restrictions due to limitations on dependencies: + * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors + * * Hex strings for bytes don't accept odd-length (half-byte) strings. + * cardano-cli seems to support these however but it seems to be different than just 0-padding + * on either side when tested so proceed with caution */ -declare export var MetadataJsonSchema: {| - +NoConversions: 0, // 0 - +BasicConversions: 1, // 1 - +DetailedSchema: 2, // 2 +declare export var PlutusDatumSchema: {| + +BasicConversions: 0, // 0 + +DetailedSchema: 1, // 1 |}; /** */ -declare export var PlutusDataKind: {| - +ConstrPlutusData: 0, // 0 - +Map: 1, // 1 - +List: 2, // 2 - +Integer: 3, // 3 - +Bytes: 4, // 4 +declare export var RelayKind: {| + +SingleHostAddr: 0, // 0 + +SingleHostName: 1, // 1 + +MultiHostName: 2, // 2 |}; /** @@ -310,38 +324,36 @@ declare export var VoteKind: {| /** */ -declare export var VoterKind: {| - +ConstitutionalCommitteeHotKeyHash: 0, // 0 - +ConstitutionalCommitteeHotScriptHash: 1, // 1 - +DRepKeyHash: 2, // 2 - +DRepScriptHash: 3, // 3 - +StakingPoolKeyHash: 4, // 4 +declare export var AddressKind: {| + +Base: 0, // 0 + +Pointer: 1, // 1 + +Enterprise: 2, // 2 + +Reward: 3, // 3 + +Byron: 4, // 4 + +Malformed: 5, // 5 |}; /** - * Used to choosed the schema for a script JSON string + * Each new language uses a different namespace for hashing its script + * This is because you could have a language where the same bytes have different semantics + * So this avoids scripts in different languages mapping to the same hash + * Note that the enum value here is different than the enum value for deciding the cost model of a script */ -declare export var ScriptSchema: {| - +Wallet: 0, // 0 - +Node: 1, // 1 +declare export var ScriptHashNamespace: {| + +NativeScript: 0, // 0 + +PlutusScript: 1, // 1 + +PlutusScriptV2: 2, // 2 + +PlutusScriptV3: 3, // 3 |}; /** - * JSON <-> PlutusData conversion schemas. - * Follows ScriptDataJsonSchema in cardano-cli defined at: - * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 - * - * All methods here have the following restrictions due to limitations on dependencies: - * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors - * * Hex strings for bytes don't accept odd-length (half-byte) strings. - * cardano-cli seems to support these however but it seems to be different than just 0-padding - * on either side when tested so proceed with caution */ -declare export var PlutusDatumSchema: {| - +BasicConversions: 0, // 0 - +DetailedSchema: 1, // 1 +declare export var TransactionSetsState: {| + +AllSetsHaveTag: 0, // 0 + +AllSetsHaveNoTag: 1, // 1 + +MixedSets: 2, // 2 |}; /** @@ -353,31 +365,20 @@ declare export var CredKind: {| |}; /** + * Used to choosed the schema for a script JSON string */ -declare export var NetworkIdKind: {| - +Testnet: 0, // 0 - +Mainnet: 1, // 1 -|}; - -/** - */ - -declare export var MIRKind: {| - +ToOtherPot: 0, // 0 - +ToStakeCredentials: 1, // 1 +declare export var ScriptSchema: {| + +Wallet: 0, // 0 + +Node: 1, // 1 |}; /** */ -declare export var NativeScriptKind: {| - +ScriptPubkey: 0, // 0 - +ScriptAll: 1, // 1 - +ScriptAny: 2, // 2 - +ScriptNOfK: 3, // 3 - +TimelockStart: 4, // 4 - +TimelockExpiry: 5, // 5 +declare export var CborContainerType: {| + +Array: 0, // 0 + +Map: 1, // 1 |}; /** @@ -395,67 +396,82 @@ declare export var RedeemerTagKind: {| /** */ -declare export var AddressKind: {| - +Base: 0, // 0 - +Pointer: 1, // 1 - +Enterprise: 2, // 2 - +Reward: 3, // 3 - +Byron: 4, // 4 - +Malformed: 5, // 5 +declare export var PlutusDataKind: {| + +ConstrPlutusData: 0, // 0 + +Map: 1, // 1 + +List: 2, // 2 + +Integer: 3, // 3 + +Bytes: 4, // 4 |}; /** */ -declare export var CertificateKind: {| - +StakeRegistration: 0, // 0 - +StakeDeregistration: 1, // 1 - +StakeDelegation: 2, // 2 - +PoolRegistration: 3, // 3 - +PoolRetirement: 4, // 4 - +GenesisKeyDelegation: 5, // 5 - +MoveInstantaneousRewardsCert: 6, // 6 - +CommitteeHotAuth: 7, // 7 - +CommitteeColdResign: 8, // 8 - +DRepDeregistration: 9, // 9 - +DRepRegistration: 10, // 10 - +DRepUpdate: 11, // 11 - +StakeAndVoteDelegation: 12, // 12 - +StakeRegistrationAndDelegation: 13, // 13 - +StakeVoteRegistrationAndDelegation: 14, // 14 - +VoteDelegation: 15, // 15 - +VoteRegistrationAndDelegation: 16, // 16 +declare export var DRepKind: {| + +KeyHash: 0, // 0 + +ScriptHash: 1, // 1 + +AlwaysAbstain: 2, // 2 + +AlwaysNoConfidence: 3, // 3 |}; /** - * Each new language uses a different namespace for hashing its script - * This is because you could have a language where the same bytes have different semantics - * So this avoids scripts in different languages mapping to the same hash - * Note that the enum value here is different than the enum value for deciding the cost model of a script */ -declare export var ScriptHashNamespace: {| - +NativeScript: 0, // 0 - +PlutusScript: 1, // 1 - +PlutusScriptV2: 2, // 2 - +PlutusScriptV3: 3, // 3 +declare export var MIRPot: {| + +Reserves: 0, // 0 + +Treasury: 1, // 1 |}; /** */ -declare export var CborContainerType: {| - +Array: 0, // 0 - +Map: 1, // 1 +declare export var LanguageKind: {| + +PlutusV1: 0, // 0 + +PlutusV2: 1, // 1 + +PlutusV3: 2, // 2 |}; /** */ -declare export var RelayKind: {| - +SingleHostAddr: 0, // 0 - +SingleHostName: 1, // 1 - +MultiHostName: 2, // 2 +declare export var VoterKind: {| + +ConstitutionalCommitteeHotKeyHash: 0, // 0 + +ConstitutionalCommitteeHotScriptHash: 1, // 1 + +DRepKeyHash: 2, // 2 + +DRepScriptHash: 3, // 3 + +StakingPoolKeyHash: 4, // 4 +|}; + +/** + */ + +declare export var NetworkIdKind: {| + +Testnet: 0, // 0 + +Mainnet: 1, // 1 +|}; + +/** + */ + +declare export var TransactionMetadatumKind: {| + +MetadataMap: 0, // 0 + +MetadataList: 1, // 1 + +Int: 2, // 2 + +Bytes: 3, // 3 + +Text: 4, // 4 +|}; + +/** + */ + +declare export var GovernanceActionKind: {| + +ParameterChangeAction: 0, // 0 + +HardForkInitiationAction: 1, // 1 + +TreasuryWithdrawalsAction: 2, // 2 + +NoConfidenceAction: 3, // 3 + +UpdateCommitteeAction: 4, // 4 + +NewConstitutionAction: 5, // 5 + +InfoAction: 6, // 6 |}; /** @@ -475,51 +491,61 @@ declare export var BlockEra: {| /** */ -declare export var LanguageKind: {| - +PlutusV1: 0, // 0 - +PlutusV2: 1, // 1 - +PlutusV3: 2, // 2 +declare export var CertificateKind: {| + +StakeRegistration: 0, // 0 + +StakeDeregistration: 1, // 1 + +StakeDelegation: 2, // 2 + +PoolRegistration: 3, // 3 + +PoolRetirement: 4, // 4 + +GenesisKeyDelegation: 5, // 5 + +MoveInstantaneousRewardsCert: 6, // 6 + +CommitteeHotAuth: 7, // 7 + +CommitteeColdResign: 8, // 8 + +DRepDeregistration: 9, // 9 + +DRepRegistration: 10, // 10 + +DRepUpdate: 11, // 11 + +StakeAndVoteDelegation: 12, // 12 + +StakeRegistrationAndDelegation: 13, // 13 + +StakeVoteRegistrationAndDelegation: 14, // 14 + +VoteDelegation: 15, // 15 + +VoteRegistrationAndDelegation: 16, // 16 |}; /** */ -declare export var GovernanceActionKind: {| - +ParameterChangeAction: 0, // 0 - +HardForkInitiationAction: 1, // 1 - +TreasuryWithdrawalsAction: 2, // 2 - +NoConfidenceAction: 3, // 3 - +UpdateCommitteeAction: 4, // 4 - +NewConstitutionAction: 5, // 5 - +InfoAction: 6, // 6 +declare export var MetadataJsonSchema: {| + +NoConversions: 0, // 0 + +BasicConversions: 1, // 1 + +DetailedSchema: 2, // 2 |}; /** */ -declare export var CoinSelectionStrategyCIP2: {| - +LargestFirst: 0, // 0 - +RandomImprove: 1, // 1 - +LargestFirstMultiAsset: 2, // 2 - +RandomImproveMultiAsset: 3, // 3 +declare export var MIRKind: {| + +ToOtherPot: 0, // 0 + +ToStakeCredentials: 1, // 1 |}; /** */ -declare export var MIRPot: {| - +Reserves: 0, // 0 - +Treasury: 1, // 1 +declare export var NativeScriptKind: {| + +ScriptPubkey: 0, // 0 + +ScriptAll: 1, // 1 + +ScriptAny: 2, // 2 + +ScriptNOfK: 3, // 3 + +TimelockStart: 4, // 4 + +TimelockExpiry: 5, // 5 |}; /** */ -declare export var DRepKind: {| - +KeyHash: 0, // 0 - +ScriptHash: 1, // 1 - +AlwaysAbstain: 2, // 2 - +AlwaysNoConfidence: 3, // 3 +declare export var CborSetType: {| + +Tagged: 0, // 0 + +Untagged: 1, // 1 |}; /** @@ -539,9 +565,9 @@ declare export class Address { to_json(): string; /** - * @returns {AddressJSON} + * @returns {any} */ - to_js_value(): AddressJSON; + to_js_value(): any; /** * @param {string} json @@ -632,9 +658,9 @@ declare export class Anchor { to_json(): string; /** - * @returns {AnchorJSON} + * @returns {any} */ - to_js_value(): AnchorJSON; + to_js_value(): any; /** * @param {string} json @@ -731,9 +757,9 @@ declare export class AssetName { to_json(): string; /** - * @returns {AssetNameJSON} + * @returns {any} */ - to_js_value(): AssetNameJSON; + to_js_value(): any; /** * @param {string} json @@ -785,9 +811,9 @@ declare export class AssetNames { to_json(): string; /** - * @returns {AssetNamesJSON} + * @returns {any} */ - to_js_value(): AssetNamesJSON; + to_js_value(): any; /** * @param {string} json @@ -849,9 +875,9 @@ declare export class Assets { to_json(): string; /** - * @returns {AssetsJSON} + * @returns {any} */ - to_js_value(): AssetsJSON; + to_js_value(): any; /** * @param {string} json @@ -920,9 +946,9 @@ declare export class AuxiliaryData { to_json(): string; /** - * @returns {AuxiliaryDataJSON} + * @returns {any} */ - to_js_value(): AuxiliaryDataJSON; + to_js_value(): any; /** * @param {string} json @@ -1123,9 +1149,9 @@ declare export class BigInt { to_json(): string; /** - * @returns {BigIntJSON} + * @returns {any} */ - to_js_value(): BigIntJSON; + to_js_value(): any; /** * @param {string} json @@ -1248,9 +1274,9 @@ declare export class BigNum { to_json(): string; /** - * @returns {BigNumJSON} + * @returns {any} */ - to_js_value(): BigNumJSON; + to_js_value(): any; /** * @param {string} json @@ -1561,9 +1587,9 @@ declare export class Block { to_json(): string; /** - * @returns {BlockJSON} + * @returns {any} */ - to_js_value(): BlockJSON; + to_js_value(): any; /** * @param {string} json @@ -1684,9 +1710,9 @@ declare export class BootstrapWitness { to_json(): string; /** - * @returns {BootstrapWitnessJSON} + * @returns {any} */ - to_js_value(): BootstrapWitnessJSON; + to_js_value(): any; /** * @param {string} json @@ -1761,9 +1787,9 @@ declare export class BootstrapWitnesses { to_json(): string; /** - * @returns {BootstrapWitnessesJSON} + * @returns {any} */ - to_js_value(): BootstrapWitnessesJSON; + to_js_value(): any; /** * @param {string} json @@ -1790,10 +1816,10 @@ declare export class BootstrapWitnesses { /** * Add a new `BootstrapWitness` to the set. * Returns `true` if the element was not already present in the set. - * @param {BootstrapWitness} elem + * @param {BootstrapWitness} witness * @returns {boolean} */ - add(elem: BootstrapWitness): boolean; + add(witness: BootstrapWitness): boolean; } /** */ @@ -1899,9 +1925,9 @@ declare export class Certificate { to_json(): string; /** - * @returns {CertificateJSON} + * @returns {any} */ - to_js_value(): CertificateJSON; + to_js_value(): any; /** * @param {string} json @@ -2201,9 +2227,9 @@ declare export class Certificates { to_json(): string; /** - * @returns {CertificatesJSON} + * @returns {any} */ - to_js_value(): CertificatesJSON; + to_js_value(): any; /** * @param {string} json @@ -2366,9 +2392,9 @@ declare export class Committee { to_json(): string; /** - * @returns {CommitteeJSON} + * @returns {any} */ - to_js_value(): CommitteeJSON; + to_js_value(): any; /** * @param {string} json @@ -2437,9 +2463,9 @@ declare export class CommitteeColdResign { to_json(): string; /** - * @returns {CommitteeColdResignJSON} + * @returns {any} */ - to_js_value(): CommitteeColdResignJSON; + to_js_value(): any; /** * @param {string} json @@ -2511,9 +2537,9 @@ declare export class CommitteeHotAuth { to_json(): string; /** - * @returns {CommitteeHotAuthJSON} + * @returns {any} */ - to_js_value(): CommitteeHotAuthJSON; + to_js_value(): any; /** * @param {string} json @@ -2579,9 +2605,9 @@ declare export class Constitution { to_json(): string; /** - * @returns {ConstitutionJSON} + * @returns {any} */ - to_js_value(): ConstitutionJSON; + to_js_value(): any; /** * @param {string} json @@ -2692,9 +2718,9 @@ declare export class CostModel { to_json(): string; /** - * @returns {CostModelJSON} + * @returns {any} */ - to_js_value(): CostModelJSON; + to_js_value(): any; /** * @param {string} json @@ -2762,9 +2788,9 @@ declare export class Costmdls { to_json(): string; /** - * @returns {CostmdlsJSON} + * @returns {any} */ - to_js_value(): CostmdlsJSON; + to_js_value(): any; /** * @param {string} json @@ -2873,9 +2899,9 @@ declare export class Credential { to_json(): string; /** - * @returns {CredentialJSON} + * @returns {any} */ - to_js_value(): CredentialJSON; + to_js_value(): any; /** * @param {string} json @@ -2916,9 +2942,9 @@ declare export class Credentials { to_json(): string; /** - * @returns {CredentialsJSON} + * @returns {any} */ - to_js_value(): CredentialsJSON; + to_js_value(): any; /** * @param {string} json @@ -2945,10 +2971,10 @@ declare export class Credentials { /** * Add a new `Credential` to the set. * Returns `true` if the element was not already present in the set. - * @param {Credential} elem + * @param {Credential} credential * @returns {boolean} */ - add(elem: Credential): boolean; + add(credential: Credential): boolean; } /** */ @@ -2983,9 +3009,9 @@ declare export class DNSRecordAorAAAA { to_json(): string; /** - * @returns {DNSRecordAorAAAAJSON} + * @returns {any} */ - to_js_value(): DNSRecordAorAAAAJSON; + to_js_value(): any; /** * @param {string} json @@ -3037,9 +3063,9 @@ declare export class DNSRecordSRV { to_json(): string; /** - * @returns {DNSRecordSRVJSON} + * @returns {any} */ - to_js_value(): DNSRecordSRVJSON; + to_js_value(): any; /** * @param {string} json @@ -3091,9 +3117,9 @@ declare export class DRep { to_json(): string; /** - * @returns {DRepJSON} + * @returns {any} */ - to_js_value(): DRepJSON; + to_js_value(): any; /** * @param {string} json @@ -3190,9 +3216,9 @@ declare export class DRepDeregistration { to_json(): string; /** - * @returns {DRepDeregistrationJSON} + * @returns {any} */ - to_js_value(): DRepDeregistrationJSON; + to_js_value(): any; /** * @param {string} json @@ -3255,9 +3281,9 @@ declare export class DRepRegistration { to_json(): string; /** - * @returns {DRepRegistrationJSON} + * @returns {any} */ - to_js_value(): DRepRegistrationJSON; + to_js_value(): any; /** * @param {string} json @@ -3337,9 +3363,9 @@ declare export class DRepUpdate { to_json(): string; /** - * @returns {DRepUpdateJSON} + * @returns {any} */ - to_js_value(): DRepUpdateJSON; + to_js_value(): any; /** * @param {string} json @@ -3411,9 +3437,9 @@ declare export class DRepVotingThresholds { to_json(): string; /** - * @returns {DRepVotingThresholdsJSON} + * @returns {any} */ - to_js_value(): DRepVotingThresholdsJSON; + to_js_value(): any; /** * @param {string} json @@ -3691,9 +3717,9 @@ declare export class Ed25519KeyHashes { to_json(): string; /** - * @returns {Ed25519KeyHashesJSON} + * @returns {any} */ - to_js_value(): Ed25519KeyHashesJSON; + to_js_value(): any; /** * @param {string} json @@ -3720,10 +3746,10 @@ declare export class Ed25519KeyHashes { /** * Add a new `Ed25519KeyHash` to the set. * Returns `true` if the element was not already present in the set. - * @param {Ed25519KeyHash} elem + * @param {Ed25519KeyHash} keyhash * @returns {boolean} */ - add(elem: Ed25519KeyHash): boolean; + add(keyhash: Ed25519KeyHash): boolean; /** * @param {Ed25519KeyHash} elem @@ -3840,9 +3866,9 @@ declare export class ExUnitPrices { to_json(): string; /** - * @returns {ExUnitPricesJSON} + * @returns {any} */ - to_js_value(): ExUnitPricesJSON; + to_js_value(): any; /** * @param {string} json @@ -3900,9 +3926,9 @@ declare export class ExUnits { to_json(): string; /** - * @returns {ExUnitsJSON} + * @returns {any} */ - to_js_value(): ExUnitsJSON; + to_js_value(): any; /** * @param {string} json @@ -4029,6 +4055,12 @@ declare export class FixedTransaction { is_valid: boolean ): FixedTransaction; + /** + * @param {Uint8Array} raw_body + * @returns {FixedTransaction} + */ + static new_from_body_bytes(raw_body: Uint8Array): FixedTransaction; + /** * @returns {TransactionBody} */ @@ -4297,9 +4329,9 @@ declare export class GeneralTransactionMetadata { to_json(): string; /** - * @returns {GeneralTransactionMetadataJSON} + * @returns {any} */ - to_js_value(): GeneralTransactionMetadataJSON; + to_js_value(): any; /** * @param {string} json @@ -4446,9 +4478,9 @@ declare export class GenesisHashes { to_json(): string; /** - * @returns {GenesisHashesJSON} + * @returns {any} */ - to_js_value(): GenesisHashesJSON; + to_js_value(): any; /** * @param {string} json @@ -4510,9 +4542,9 @@ declare export class GenesisKeyDelegation { to_json(): string; /** - * @returns {GenesisKeyDelegationJSON} + * @returns {any} */ - to_js_value(): GenesisKeyDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -4580,9 +4612,9 @@ declare export class GovernanceAction { to_json(): string; /** - * @returns {GovernanceActionJSON} + * @returns {any} */ - to_js_value(): GovernanceActionJSON; + to_js_value(): any; /** * @param {string} json @@ -4719,9 +4751,9 @@ declare export class GovernanceActionId { to_json(): string; /** - * @returns {GovernanceActionIdJSON} + * @returns {any} */ - to_js_value(): GovernanceActionIdJSON; + to_js_value(): any; /** * @param {string} json @@ -4760,9 +4792,9 @@ declare export class GovernanceActionIds { to_json(): string; /** - * @returns {GovernanceActionIdsJSON} + * @returns {any} */ - to_js_value(): GovernanceActionIdsJSON; + to_js_value(): any; /** * @param {string} json @@ -4824,9 +4856,9 @@ declare export class HardForkInitiationAction { to_json(): string; /** - * @returns {HardForkInitiationActionJSON} + * @returns {any} */ - to_js_value(): HardForkInitiationActionJSON; + to_js_value(): any; /** * @param {string} json @@ -4893,9 +4925,9 @@ declare export class Header { to_json(): string; /** - * @returns {HeaderJSON} + * @returns {any} */ - to_js_value(): HeaderJSON; + to_js_value(): any; /** * @param {string} json @@ -4953,9 +4985,9 @@ declare export class HeaderBody { to_json(): string; /** - * @returns {HeaderBodyJSON} + * @returns {any} */ - to_js_value(): HeaderBodyJSON; + to_js_value(): any; /** * @param {string} json @@ -5147,9 +5179,9 @@ declare export class Int { to_json(): string; /** - * @returns {IntJSON} + * @returns {any} */ - to_js_value(): IntJSON; + to_js_value(): any; /** * @param {string} json @@ -5270,9 +5302,9 @@ declare export class Ipv4 { to_json(): string; /** - * @returns {Ipv4JSON} + * @returns {any} */ - to_js_value(): Ipv4JSON; + to_js_value(): any; /** * @param {string} json @@ -5324,9 +5356,9 @@ declare export class Ipv6 { to_json(): string; /** - * @returns {Ipv6JSON} + * @returns {any} */ - to_js_value(): Ipv6JSON; + to_js_value(): any; /** * @param {string} json @@ -5433,9 +5465,9 @@ declare export class Language { to_json(): string; /** - * @returns {LanguageJSON} + * @returns {any} */ - to_js_value(): LanguageJSON; + to_js_value(): any; /** * @param {string} json @@ -5572,9 +5604,9 @@ declare export class MIRToStakeCredentials { to_json(): string; /** - * @returns {MIRToStakeCredentialsJSON} + * @returns {any} */ - to_js_value(): MIRToStakeCredentialsJSON; + to_js_value(): any; /** * @param {string} json @@ -5808,9 +5840,9 @@ declare export class Mint { to_json(): string; /** - * @returns {MintJSON} + * @returns {any} */ - to_js_value(): MintJSON; + to_js_value(): any; /** * @param {string} json @@ -5996,9 +6028,9 @@ declare export class MintsAssets { to_json(): string; /** - * @returns {MintsAssetsJSON} + * @returns {any} */ - to_js_value(): MintsAssetsJSON; + to_js_value(): any; /** * @param {string} json @@ -6060,9 +6092,9 @@ declare export class MoveInstantaneousReward { to_json(): string; /** - * @returns {MoveInstantaneousRewardJSON} + * @returns {any} */ - to_js_value(): MoveInstantaneousRewardJSON; + to_js_value(): any; /** * @param {string} json @@ -6151,9 +6183,9 @@ declare export class MoveInstantaneousRewardsCert { to_json(): string; /** - * @returns {MoveInstantaneousRewardsCertJSON} + * @returns {any} */ - to_js_value(): MoveInstantaneousRewardsCertJSON; + to_js_value(): any; /** * @param {string} json @@ -6207,9 +6239,9 @@ declare export class MultiAsset { to_json(): string; /** - * @returns {MultiAssetJSON} + * @returns {any} */ - to_js_value(): MultiAssetJSON; + to_js_value(): any; /** * @param {string} json @@ -6313,9 +6345,9 @@ declare export class MultiHostName { to_json(): string; /** - * @returns {MultiHostNameJSON} + * @returns {any} */ - to_js_value(): MultiHostNameJSON; + to_js_value(): any; /** * @param {string} json @@ -6367,9 +6399,9 @@ declare export class NativeScript { to_json(): string; /** - * @returns {NativeScriptJSON} + * @returns {any} */ - to_js_value(): NativeScriptJSON; + to_js_value(): any; /** * @param {string} json @@ -6550,9 +6582,9 @@ declare export class NativeScripts { to_json(): string; /** - * @returns {NativeScriptsJSON} + * @returns {any} */ - to_js_value(): NativeScriptsJSON; + to_js_value(): any; /** * @param {string} json @@ -6593,9 +6625,9 @@ declare export class NetworkId { to_json(): string; /** - * @returns {NetworkIdJSON} + * @returns {any} */ - to_js_value(): NetworkIdJSON; + to_js_value(): any; /** * @param {string} json @@ -6690,9 +6722,9 @@ declare export class NewConstitutionAction { to_json(): string; /** - * @returns {NewConstitutionActionJSON} + * @returns {any} */ - to_js_value(): NewConstitutionActionJSON; + to_js_value(): any; /** * @param {string} json @@ -6764,9 +6796,9 @@ declare export class NoConfidenceAction { to_json(): string; /** - * @returns {NoConfidenceActionJSON} + * @returns {any} */ - to_js_value(): NoConfidenceActionJSON; + to_js_value(): any; /** * @param {string} json @@ -6825,9 +6857,9 @@ declare export class Nonce { to_json(): string; /** - * @returns {NonceJSON} + * @returns {any} */ - to_js_value(): NonceJSON; + to_js_value(): any; /** * @param {string} json @@ -6884,9 +6916,9 @@ declare export class OperationalCert { to_json(): string; /** - * @returns {OperationalCertJSON} + * @returns {any} */ - to_js_value(): OperationalCertJSON; + to_js_value(): any; /** * @param {string} json @@ -6988,9 +7020,9 @@ declare export class ParameterChangeAction { to_json(): string; /** - * @returns {ParameterChangeActionJSON} + * @returns {any} */ - to_js_value(): ParameterChangeActionJSON; + to_js_value(): any; /** * @param {string} json @@ -7193,47 +7225,47 @@ declare export class PlutusList { free(): void; /** - * @returns {Uint8Array} + * @returns {PlutusList} */ - to_bytes(): Uint8Array; + static new(): PlutusList; /** - * @param {Uint8Array} bytes - * @returns {PlutusList} + * @returns {number} */ - static from_bytes(bytes: Uint8Array): PlutusList; + len(): number; /** - * @returns {string} + * @param {number} index + * @returns {PlutusData} */ - to_hex(): string; + get(index: number): PlutusData; /** - * @param {string} hex_str - * @returns {PlutusList} + * @param {PlutusData} elem */ - static from_hex(hex_str: string): PlutusList; + add(elem: PlutusData): void; /** - * @returns {PlutusList} + * @returns {Uint8Array} */ - static new(): PlutusList; + to_bytes(): Uint8Array; /** - * @returns {number} + * @param {Uint8Array} bytes + * @returns {PlutusList} */ - len(): number; + static from_bytes(bytes: Uint8Array): PlutusList; /** - * @param {number} index - * @returns {PlutusData} + * @returns {string} */ - get(index: number): PlutusData; + to_hex(): string; /** - * @param {PlutusData} elem + * @param {string} hex_str + * @returns {PlutusList} */ - add(elem: PlutusData): void; + static from_hex(hex_str: string): PlutusList; } /** */ @@ -7509,9 +7541,9 @@ declare export class PlutusScripts { to_json(): string; /** - * @returns {PlutusScriptsJSON} + * @returns {any} */ - to_js_value(): PlutusScriptsJSON; + to_js_value(): any; /** * @param {string} json @@ -7764,9 +7796,9 @@ declare export class PoolMetadata { to_json(): string; /** - * @returns {PoolMetadataJSON} + * @returns {any} */ - to_js_value(): PoolMetadataJSON; + to_js_value(): any; /** * @param {string} json @@ -7863,9 +7895,9 @@ declare export class PoolParams { to_json(): string; /** - * @returns {PoolParamsJSON} + * @returns {any} */ - to_js_value(): PoolParamsJSON; + to_js_value(): any; /** * @param {string} json @@ -7975,9 +8007,9 @@ declare export class PoolRegistration { to_json(): string; /** - * @returns {PoolRegistrationJSON} + * @returns {any} */ - to_js_value(): PoolRegistrationJSON; + to_js_value(): any; /** * @param {string} json @@ -8029,9 +8061,9 @@ declare export class PoolRetirement { to_json(): string; /** - * @returns {PoolRetirementJSON} + * @returns {any} */ - to_js_value(): PoolRetirementJSON; + to_js_value(): any; /** * @param {string} json @@ -8089,9 +8121,9 @@ declare export class PoolVotingThresholds { to_json(): string; /** - * @returns {PoolVotingThresholdsJSON} + * @returns {any} */ - to_js_value(): PoolVotingThresholdsJSON; + to_js_value(): any; /** * @param {string} json @@ -8246,9 +8278,9 @@ declare export class ProposedProtocolParameterUpdates { to_json(): string; /** - * @returns {ProposedProtocolParameterUpdatesJSON} + * @returns {any} */ - to_js_value(): ProposedProtocolParameterUpdatesJSON; + to_js_value(): any; /** * @param {string} json @@ -8320,9 +8352,9 @@ declare export class ProtocolParamUpdate { to_json(): string; /** - * @returns {ProtocolParamUpdateJSON} + * @returns {any} */ - to_js_value(): ProtocolParamUpdateJSON; + to_js_value(): any; /** * @param {string} json @@ -8700,9 +8732,9 @@ declare export class ProtocolVersion { to_json(): string; /** - * @returns {ProtocolVersionJSON} + * @returns {any} */ - to_js_value(): ProtocolVersionJSON; + to_js_value(): any; /** * @param {string} json @@ -8841,9 +8873,9 @@ declare export class Redeemer { to_json(): string; /** - * @returns {RedeemerJSON} + * @returns {any} */ - to_js_value(): RedeemerJSON; + to_js_value(): any; /** * @param {string} json @@ -8918,9 +8950,9 @@ declare export class RedeemerTag { to_json(): string; /** - * @returns {RedeemerTagJSON} + * @returns {any} */ - to_js_value(): RedeemerTagJSON; + to_js_value(): any; /** * @param {string} json @@ -8998,9 +9030,9 @@ declare export class Redeemers { to_json(): string; /** - * @returns {RedeemersJSON} + * @returns {any} */ - to_js_value(): RedeemersJSON; + to_js_value(): any; /** * @param {string} json @@ -9029,6 +9061,14 @@ declare export class Redeemers { */ add(elem: Redeemer): void; + /** + * WARNING: This function will be removed in after next hard fork + * @returns {$Values< + typeof + CborContainerType>} + */ + get_container_type(): $Values; + /** * @returns {ExUnits} */ @@ -9067,9 +9107,9 @@ declare export class Relay { to_json(): string; /** - * @returns {RelayJSON} + * @returns {any} */ - to_js_value(): RelayJSON; + to_js_value(): any; /** * @param {string} json @@ -9150,9 +9190,9 @@ declare export class Relays { to_json(): string; /** - * @returns {RelaysJSON} + * @returns {any} */ - to_js_value(): RelaysJSON; + to_js_value(): any; /** * @param {string} json @@ -9247,9 +9287,9 @@ declare export class RewardAddresses { to_json(): string; /** - * @returns {RewardAddressesJSON} + * @returns {any} */ - to_js_value(): RewardAddressesJSON; + to_js_value(): any; /** * @param {string} json @@ -9311,9 +9351,9 @@ declare export class ScriptAll { to_json(): string; /** - * @returns {ScriptAllJSON} + * @returns {any} */ - to_js_value(): ScriptAllJSON; + to_js_value(): any; /** * @param {string} json @@ -9365,9 +9405,9 @@ declare export class ScriptAny { to_json(): string; /** - * @returns {ScriptAnyJSON} + * @returns {any} */ - to_js_value(): ScriptAnyJSON; + to_js_value(): any; /** * @param {string} json @@ -9497,9 +9537,9 @@ declare export class ScriptHashes { to_json(): string; /** - * @returns {ScriptHashesJSON} + * @returns {any} */ - to_js_value(): ScriptHashesJSON; + to_js_value(): any; /** * @param {string} json @@ -9561,9 +9601,9 @@ declare export class ScriptNOfK { to_json(): string; /** - * @returns {ScriptNOfKJSON} + * @returns {any} */ - to_js_value(): ScriptNOfKJSON; + to_js_value(): any; /** * @param {string} json @@ -9621,9 +9661,9 @@ declare export class ScriptPubkey { to_json(): string; /** - * @returns {ScriptPubkeyJSON} + * @returns {any} */ - to_js_value(): ScriptPubkeyJSON; + to_js_value(): any; /** * @param {string} json @@ -9675,9 +9715,9 @@ declare export class ScriptRef { to_json(): string; /** - * @returns {ScriptRefJSON} + * @returns {any} */ - to_js_value(): ScriptRefJSON; + to_js_value(): any; /** * @param {string} json @@ -9758,9 +9798,9 @@ declare export class SingleHostAddr { to_json(): string; /** - * @returns {SingleHostAddrJSON} + * @returns {any} */ - to_js_value(): SingleHostAddrJSON; + to_js_value(): any; /** * @param {string} json @@ -9824,9 +9864,9 @@ declare export class SingleHostName { to_json(): string; /** - * @returns {SingleHostNameJSON} + * @returns {any} */ - to_js_value(): SingleHostNameJSON; + to_js_value(): any; /** * @param {string} json @@ -9884,9 +9924,9 @@ declare export class StakeAndVoteDelegation { to_json(): string; /** - * @returns {StakeAndVoteDelegationJSON} + * @returns {any} */ - to_js_value(): StakeAndVoteDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -9959,9 +9999,9 @@ declare export class StakeDelegation { to_json(): string; /** - * @returns {StakeDelegationJSON} + * @returns {any} */ - to_js_value(): StakeDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -10027,9 +10067,9 @@ declare export class StakeDeregistration { to_json(): string; /** - * @returns {StakeDeregistrationJSON} + * @returns {any} */ - to_js_value(): StakeDeregistrationJSON; + to_js_value(): any; /** * @param {string} json @@ -10101,9 +10141,9 @@ declare export class StakeRegistration { to_json(): string; /** - * @returns {StakeRegistrationJSON} + * @returns {any} */ - to_js_value(): StakeRegistrationJSON; + to_js_value(): any; /** * @param {string} json @@ -10175,9 +10215,9 @@ declare export class StakeRegistrationAndDelegation { to_json(): string; /** - * @returns {StakeRegistrationAndDelegationJSON} + * @returns {any} */ - to_js_value(): StakeRegistrationAndDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -10250,9 +10290,9 @@ declare export class StakeVoteRegistrationAndDelegation { to_json(): string; /** - * @returns {StakeVoteRegistrationAndDelegationJSON} + * @returns {any} */ - to_js_value(): StakeVoteRegistrationAndDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -10358,9 +10398,9 @@ declare export class TimelockExpiry { to_json(): string; /** - * @returns {TimelockExpiryJSON} + * @returns {any} */ - to_js_value(): TimelockExpiryJSON; + to_js_value(): any; /** * @param {string} json @@ -10426,9 +10466,9 @@ declare export class TimelockStart { to_json(): string; /** - * @returns {TimelockStartJSON} + * @returns {any} */ - to_js_value(): TimelockStartJSON; + to_js_value(): any; /** * @param {string} json @@ -10498,9 +10538,9 @@ declare export class Transaction { to_json(): string; /** - * @returns {TransactionJSON} + * @returns {any} */ - to_js_value(): TransactionJSON; + to_js_value(): any; /** * @param {string} json @@ -10610,9 +10650,9 @@ declare export class TransactionBodies { to_json(): string; /** - * @returns {TransactionBodiesJSON} + * @returns {any} */ - to_js_value(): TransactionBodiesJSON; + to_js_value(): any; /** * @param {string} json @@ -10674,9 +10714,9 @@ declare export class TransactionBody { to_json(): string; /** - * @returns {TransactionBodyJSON} + * @returns {any} */ - to_js_value(): TransactionBodyJSON; + to_js_value(): any; /** * @param {string} json @@ -11736,9 +11776,9 @@ declare export class TransactionInput { to_json(): string; /** - * @returns {TransactionInputJSON} + * @returns {any} */ - to_js_value(): TransactionInputJSON; + to_js_value(): any; /** * @param {string} json @@ -11796,9 +11836,9 @@ declare export class TransactionInputs { to_json(): string; /** - * @returns {TransactionInputsJSON} + * @returns {any} */ - to_js_value(): TransactionInputsJSON; + to_js_value(): any; /** * @param {string} json @@ -11825,11 +11865,10 @@ declare export class TransactionInputs { /** * Add a new `TransactionInput` to the set. * Returns `true` if the element was not already present in the set. - * Note that the `TransactionInput` is added to the set only if it is not already present. - * @param {TransactionInput} elem + * @param {TransactionInput} input * @returns {boolean} */ - add(elem: TransactionInput): boolean; + add(input: TransactionInput): boolean; /** * @returns {TransactionInputs | void} @@ -12006,9 +12045,9 @@ declare export class TransactionOutput { to_json(): string; /** - * @returns {TransactionOutputJSON} + * @returns {any} */ - to_js_value(): TransactionOutputJSON; + to_js_value(): any; /** * @param {string} json @@ -12204,9 +12243,9 @@ declare export class TransactionOutputs { to_json(): string; /** - * @returns {TransactionOutputsJSON} + * @returns {any} */ - to_js_value(): TransactionOutputsJSON; + to_js_value(): any; /** * @param {string} json @@ -12268,9 +12307,9 @@ declare export class TransactionUnspentOutput { to_json(): string; /** - * @returns {TransactionUnspentOutputJSON} + * @returns {any} */ - to_js_value(): TransactionUnspentOutputJSON; + to_js_value(): any; /** * @param {string} json @@ -12309,9 +12348,9 @@ declare export class TransactionUnspentOutputs { to_json(): string; /** - * @returns {TransactionUnspentOutputsJSON} + * @returns {any} */ - to_js_value(): TransactionUnspentOutputsJSON; + to_js_value(): any; /** * @param {string} json @@ -12373,9 +12412,9 @@ declare export class TransactionWitnessSet { to_json(): string; /** - * @returns {TransactionWitnessSetJSON} + * @returns {any} */ - to_js_value(): TransactionWitnessSetJSON; + to_js_value(): any; /** * @param {string} json @@ -12481,9 +12520,9 @@ declare export class TransactionWitnessSets { to_json(): string; /** - * @returns {TransactionWitnessSetsJSON} + * @returns {any} */ - to_js_value(): TransactionWitnessSetsJSON; + to_js_value(): any; /** * @param {string} json @@ -12523,9 +12562,9 @@ declare export class TreasuryWithdrawals { to_json(): string; /** - * @returns {TreasuryWithdrawalsJSON} + * @returns {any} */ - to_js_value(): TreasuryWithdrawalsJSON; + to_js_value(): any; /** * @param {string} json @@ -12593,9 +12632,9 @@ declare export class TreasuryWithdrawalsAction { to_json(): string; /** - * @returns {TreasuryWithdrawalsActionJSON} + * @returns {any} */ - to_js_value(): TreasuryWithdrawalsActionJSON; + to_js_value(): any; /** * @param {string} json @@ -12806,9 +12845,9 @@ declare export class URL { to_json(): string; /** - * @returns {URLJSON} + * @returns {any} */ - to_js_value(): URLJSON; + to_js_value(): any; /** * @param {string} json @@ -12860,9 +12899,9 @@ declare export class UnitInterval { to_json(): string; /** - * @returns {UnitIntervalJSON} + * @returns {any} */ - to_js_value(): UnitIntervalJSON; + to_js_value(): any; /** * @param {string} json @@ -12920,9 +12959,9 @@ declare export class Update { to_json(): string; /** - * @returns {UpdateJSON} + * @returns {any} */ - to_js_value(): UpdateJSON; + to_js_value(): any; /** * @param {string} json @@ -12983,9 +13022,9 @@ declare export class UpdateCommitteeAction { to_json(): string; /** - * @returns {UpdateCommitteeActionJSON} + * @returns {any} */ - to_js_value(): UpdateCommitteeActionJSON; + to_js_value(): any; /** * @param {string} json @@ -13063,9 +13102,9 @@ declare export class VRFCert { to_json(): string; /** - * @returns {VRFCertJSON} + * @returns {any} */ - to_js_value(): VRFCertJSON; + to_js_value(): any; /** * @param {string} json @@ -13201,9 +13240,9 @@ declare export class Value { to_json(): string; /** - * @returns {ValueJSON} + * @returns {any} */ - to_js_value(): ValueJSON; + to_js_value(): any; /** * @param {string} json @@ -13318,9 +13357,9 @@ declare export class VersionedBlock { to_json(): string; /** - * @returns {VersionedBlockJSON} + * @returns {any} */ - to_js_value(): VersionedBlockJSON; + to_js_value(): any; /** * @param {string} json @@ -13380,9 +13419,9 @@ declare export class Vkey { to_json(): string; /** - * @returns {VkeyJSON} + * @returns {any} */ - to_js_value(): VkeyJSON; + to_js_value(): any; /** * @param {string} json @@ -13460,9 +13499,9 @@ declare export class Vkeywitness { to_json(): string; /** - * @returns {VkeywitnessJSON} + * @returns {any} */ - to_js_value(): VkeywitnessJSON; + to_js_value(): any; /** * @param {string} json @@ -13520,9 +13559,9 @@ declare export class Vkeywitnesses { to_json(): string; /** - * @returns {VkeywitnessesJSON} + * @returns {any} */ - to_js_value(): VkeywitnessesJSON; + to_js_value(): any; /** * @param {string} json @@ -13549,10 +13588,10 @@ declare export class Vkeywitnesses { /** * Add a new `Vkeywitness` to the set. * Returns `true` if the element was not already present in the set. - * @param {Vkeywitness} elem + * @param {Vkeywitness} witness * @returns {boolean} */ - add(elem: Vkeywitness): boolean; + add(witness: Vkeywitness): boolean; } /** */ @@ -13587,9 +13626,9 @@ declare export class VoteDelegation { to_json(): string; /** - * @returns {VoteDelegationJSON} + * @returns {any} */ - to_js_value(): VoteDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -13652,9 +13691,9 @@ declare export class VoteRegistrationAndDelegation { to_json(): string; /** - * @returns {VoteRegistrationAndDelegationJSON} + * @returns {any} */ - to_js_value(): VoteRegistrationAndDelegationJSON; + to_js_value(): any; /** * @param {string} json @@ -13727,9 +13766,9 @@ declare export class Voter { to_json(): string; /** - * @returns {VoterJSON} + * @returns {any} */ - to_js_value(): VoterJSON; + to_js_value(): any; /** * @param {string} json @@ -13798,9 +13837,9 @@ declare export class Voters { to_json(): string; /** - * @returns {VotersJSON} + * @returns {any} */ - to_js_value(): VotersJSON; + to_js_value(): any; /** * @param {string} json @@ -13934,9 +13973,9 @@ declare export class VotingProcedure { to_json(): string; /** - * @returns {VotingProcedureJSON} + * @returns {any} */ - to_js_value(): VotingProcedureJSON; + to_js_value(): any; /** * @param {string} json @@ -14009,9 +14048,9 @@ declare export class VotingProcedures { to_json(): string; /** - * @returns {VotingProceduresJSON} + * @returns {any} */ - to_js_value(): VotingProceduresJSON; + to_js_value(): any; /** * @param {string} json @@ -14089,9 +14128,9 @@ declare export class VotingProposal { to_json(): string; /** - * @returns {VotingProposalJSON} + * @returns {any} */ - to_js_value(): VotingProposalJSON; + to_js_value(): any; /** * @param {string} json @@ -14210,9 +14249,9 @@ declare export class VotingProposals { to_json(): string; /** - * @returns {VotingProposalsJSON} + * @returns {any} */ - to_js_value(): VotingProposalsJSON; + to_js_value(): any; /** * @param {string} json @@ -14237,12 +14276,23 @@ declare export class VotingProposals { get(index: number): VotingProposal; /** - * Add a proposal to the set of proposals - * Returns true if the proposal was added, false if it was already present + * Add a new `VotingProposal` to the set. + * Returns `true` if the element was not already present in the set. * @param {VotingProposal} proposal * @returns {boolean} */ add(proposal: VotingProposal): boolean; + + /** + * @param {VotingProposal} elem + * @returns {boolean} + */ + contains(elem: VotingProposal): boolean; + + /** + * @returns {VotingProposals | void} + */ + to_option(): VotingProposals | void; } /** */ @@ -14277,9 +14327,9 @@ declare export class Withdrawals { to_json(): string; /** - * @returns {WithdrawalsJSON} + * @returns {any} */ - to_js_value(): WithdrawalsJSON; + to_js_value(): any; /** * @param {string} json @@ -14383,929 +14433,3 @@ declare export class WithdrawalsBuilder { */ build(): Withdrawals; } -export type AddressJSON = string; -export type URLJSON = string; -export interface AnchorJSON { - anchor_data_hash: string; - anchor_url: URLJSON; -} -export type AnchorDataHashJSON = string; -export type AssetNameJSON = string; -export type AssetNamesJSON = string[]; -export interface AssetsJSON { - [k: string]: string; -} -export type NativeScriptJSON = - | { - ScriptPubkey: ScriptPubkeyJSON, - ... - } - | { - ScriptAll: ScriptAllJSON, - ... - } - | { - ScriptAny: ScriptAnyJSON, - ... - } - | { - ScriptNOfK: ScriptNOfKJSON, - ... - } - | { - TimelockStart: TimelockStartJSON, - ... - } - | { - TimelockExpiry: TimelockExpiryJSON, - ... - }; -export type NativeScriptsJSON = NativeScriptJSON[]; -export type PlutusScriptsJSON = string[]; -export interface AuxiliaryDataJSON { - metadata?: { - [k: string]: string, - } | null; - native_scripts?: NativeScriptsJSON | null; - plutus_scripts?: PlutusScriptsJSON | null; - prefer_alonzo_format: boolean; -} -export interface ScriptPubkeyJSON { - addr_keyhash: string; -} -export interface ScriptAllJSON { - native_scripts: NativeScriptsJSON; -} -export interface ScriptAnyJSON { - native_scripts: NativeScriptsJSON; -} -export interface ScriptNOfKJSON { - n: number; - native_scripts: NativeScriptsJSON; -} -export interface TimelockStartJSON { - slot: string; -} -export interface TimelockExpiryJSON { - slot: string; -} -export type AuxiliaryDataHashJSON = string; -export interface AuxiliaryDataSetJSON { - [k: string]: AuxiliaryDataJSON; -} -export type BigIntJSON = string; -export type BigNumJSON = string; -export type VkeyJSON = string; -export type HeaderLeaderCertEnumJSON = - | { - /** - * @minItems 2 - * @maxItems 2 - */ - NonceAndLeader: [VRFCertJSON, VRFCertJSON], - ... - } - | { - VrfResult: VRFCertJSON, - ... - }; -export type CertificateJSON = - | { - StakeRegistration: StakeRegistrationJSON, - ... - } - | { - StakeDeregistration: StakeDeregistrationJSON, - ... - } - | { - StakeDelegation: StakeDelegationJSON, - ... - } - | { - PoolRegistration: PoolRegistrationJSON, - ... - } - | { - PoolRetirement: PoolRetirementJSON, - ... - } - | { - GenesisKeyDelegation: GenesisKeyDelegationJSON, - ... - } - | { - MoveInstantaneousRewardsCert: MoveInstantaneousRewardsCertJSON, - ... - } - | { - CommitteeHotAuth: CommitteeHotAuthJSON, - ... - } - | { - CommitteeColdResign: CommitteeColdResignJSON, - ... - } - | { - DRepDeregistration: DRepDeregistrationJSON, - ... - } - | { - DRepRegistration: DRepRegistrationJSON, - ... - } - | { - DRepUpdate: DRepUpdateJSON, - ... - } - | { - StakeAndVoteDelegation: StakeAndVoteDelegationJSON, - ... - } - | { - StakeRegistrationAndDelegation: StakeRegistrationAndDelegationJSON, - ... - } - | { - StakeVoteRegistrationAndDelegation: StakeVoteRegistrationAndDelegationJSON, - ... - } - | { - VoteDelegation: VoteDelegationJSON, - ... - } - | { - VoteRegistrationAndDelegation: VoteRegistrationAndDelegationJSON, - ... - }; -export type CredTypeJSON = - | { - Key: string, - ... - } - | { - Script: string, - ... - }; -export type RelayJSON = - | { - SingleHostAddr: SingleHostAddrJSON, - ... - } - | { - SingleHostName: SingleHostNameJSON, - ... - } - | { - MultiHostName: MultiHostNameJSON, - ... - }; -/** - * @minItems 4 - * @maxItems 4 - */ -export type Ipv4JSON = [number, number, number, number]; -/** - * @minItems 16 - * @maxItems 16 - */ -export type Ipv6JSON = [ - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number -]; -export type DNSRecordAorAAAAJSON = string; -export type DNSRecordSRVJSON = string; -export type RelaysJSON = RelayJSON[]; -export type MIRPotJSON = "Reserves" | "Treasury"; -export type MIREnumJSON = - | { - ToOtherPot: string, - ... - } - | { - ToStakeCredentials: StakeToCoinJSON[], - ... - }; -export type DRepJSON = - | ("AlwaysAbstain" | "AlwaysNoConfidence") - | { - KeyHash: string, - ... - } - | { - ScriptHash: string, - ... - }; -export type DataOptionJSON = - | { - DataHash: string, - ... - } - | { - Data: string, - ... - }; -export type ScriptRefJSON = - | { - NativeScript: NativeScriptJSON, - ... - } - | { - PlutusScript: string, - ... - }; -export type MintJSON = [string, MintAssetsJSON][]; -export type NetworkIdJSON = "Testnet" | "Mainnet"; -export type TransactionOutputsJSON = TransactionOutputJSON[]; -export type CostModelJSON = string[]; -export type VoterJSON = - | { - ConstitutionalCommitteeHotCred: CredTypeJSON, - ... - } - | { - DRep: CredTypeJSON, - ... - } - | { - StakingPool: string, - ... - }; -export type VoteKindJSON = "No" | "Yes" | "Abstain"; -export type GovernanceActionJSON = - | { - ParameterChangeAction: ParameterChangeActionJSON, - ... - } - | { - HardForkInitiationAction: HardForkInitiationActionJSON, - ... - } - | { - TreasuryWithdrawalsAction: TreasuryWithdrawalsActionJSON, - ... - } - | { - NoConfidenceAction: NoConfidenceActionJSON, - ... - } - | { - UpdateCommitteeAction: UpdateCommitteeActionJSON, - ... - } - | { - NewConstitutionAction: NewConstitutionActionJSON, - ... - } - | { - InfoAction: InfoActionJSON, - ... - }; -/** - * @minItems 0 - * @maxItems 0 - */ -export type InfoActionJSON = []; -export type TransactionBodiesJSON = TransactionBodyJSON[]; -export type RedeemerTagJSON = - | "Spend" - | "Mint" - | "Cert" - | "Reward" - | "Vote" - | "VotingProposal"; -export type TransactionWitnessSetsJSON = TransactionWitnessSetJSON[]; -export interface BlockJSON { - auxiliary_data_set: { - [k: string]: AuxiliaryDataJSON, - }; - header: HeaderJSON; - invalid_transactions: number[]; - transaction_bodies: TransactionBodiesJSON; - transaction_witness_sets: TransactionWitnessSetsJSON; -} -export interface HeaderJSON { - body_signature: string; - header_body: HeaderBodyJSON; -} -export interface HeaderBodyJSON { - block_body_hash: string; - block_body_size: number; - block_number: number; - issuer_vkey: VkeyJSON; - leader_cert: HeaderLeaderCertEnumJSON; - operational_cert: OperationalCertJSON; - prev_hash?: string | null; - protocol_version: ProtocolVersionJSON; - slot: string; - vrf_vkey: string; -} -export interface VRFCertJSON { - output: number[]; - proof: number[]; -} -export interface OperationalCertJSON { - hot_vkey: string; - kes_period: number; - sequence_number: number; - sigma: string; -} -export interface ProtocolVersionJSON { - major: number; - minor: number; -} -export interface TransactionBodyJSON { - auxiliary_data_hash?: string | null; - certs?: CertificateJSON[] | null; - collateral?: TransactionInputJSON[] | null; - collateral_return?: TransactionOutputJSON | null; - current_treasury_value?: string | null; - donation?: string | null; - fee: string; - inputs: TransactionInputJSON[]; - mint?: MintJSON | null; - network_id?: NetworkIdJSON | null; - outputs: TransactionOutputsJSON; - reference_inputs?: TransactionInputJSON[] | null; - required_signers?: string[] | null; - script_data_hash?: string | null; - total_collateral?: string | null; - ttl?: string | null; - update?: UpdateJSON | null; - validity_start_interval?: string | null; - voting_procedures?: VoterVotesJSON[] | null; - voting_proposals?: VotingProposalJSON[] | null; - withdrawals?: { - [k: string]: string, - } | null; -} -export interface StakeRegistrationJSON { - coin?: string | null; - stake_credential: CredTypeJSON; -} -export interface StakeDeregistrationJSON { - coin?: string | null; - stake_credential: CredTypeJSON; -} -export interface StakeDelegationJSON { - pool_keyhash: string; - stake_credential: CredTypeJSON; -} -export interface PoolRegistrationJSON { - pool_params: PoolParamsJSON; -} -export interface PoolParamsJSON { - cost: string; - margin: UnitIntervalJSON; - operator: string; - pledge: string; - pool_metadata?: PoolMetadataJSON | null; - pool_owners: string[]; - relays: RelaysJSON; - reward_account: string; - vrf_keyhash: string; -} -export interface UnitIntervalJSON { - denominator: string; - numerator: string; -} -export interface PoolMetadataJSON { - pool_metadata_hash: string; - url: URLJSON; -} -export interface SingleHostAddrJSON { - ipv4?: Ipv4JSON | null; - ipv6?: Ipv6JSON | null; - port?: number | null; -} -export interface SingleHostNameJSON { - dns_name: DNSRecordAorAAAAJSON; - port?: number | null; -} -export interface MultiHostNameJSON { - dns_name: DNSRecordSRVJSON; -} -export interface PoolRetirementJSON { - epoch: number; - pool_keyhash: string; -} -export interface GenesisKeyDelegationJSON { - genesis_delegate_hash: string; - genesishash: string; - vrf_keyhash: string; -} -export interface MoveInstantaneousRewardsCertJSON { - move_instantaneous_reward: MoveInstantaneousRewardJSON; -} -export interface MoveInstantaneousRewardJSON { - pot: MIRPotJSON; - variant: MIREnumJSON; -} -export interface StakeToCoinJSON { - amount: string; - stake_cred: CredTypeJSON; -} -export interface CommitteeHotAuthJSON { - committee_cold_credential: CredTypeJSON; - committee_hot_credential: CredTypeJSON; -} -export interface CommitteeColdResignJSON { - anchor?: AnchorJSON | null; - committee_cold_credential: CredTypeJSON; -} -export interface DRepDeregistrationJSON { - coin: string; - voting_credential: CredTypeJSON; -} -export interface DRepRegistrationJSON { - anchor?: AnchorJSON | null; - coin: string; - voting_credential: CredTypeJSON; -} -export interface DRepUpdateJSON { - anchor?: AnchorJSON | null; - voting_credential: CredTypeJSON; -} -export interface StakeAndVoteDelegationJSON { - drep: DRepJSON; - pool_keyhash: string; - stake_credential: CredTypeJSON; -} -export interface StakeRegistrationAndDelegationJSON { - coin: string; - pool_keyhash: string; - stake_credential: CredTypeJSON; -} -export interface StakeVoteRegistrationAndDelegationJSON { - coin: string; - drep: DRepJSON; - pool_keyhash: string; - stake_credential: CredTypeJSON; -} -export interface VoteDelegationJSON { - drep: DRepJSON; - stake_credential: CredTypeJSON; -} -export interface VoteRegistrationAndDelegationJSON { - coin: string; - drep: DRepJSON; - stake_credential: CredTypeJSON; -} -export interface TransactionInputJSON { - index: number; - transaction_id: string; -} -export interface TransactionOutputJSON { - address: string; - amount: ValueJSON; - plutus_data?: DataOptionJSON | null; - script_ref?: ScriptRefJSON | null; -} -export interface ValueJSON { - coin: string; - multiasset?: MultiAssetJSON | null; -} -export interface MultiAssetJSON { - [k: string]: AssetsJSON; -} -export interface MintAssetsJSON { - [k: string]: string; -} -export interface UpdateJSON { - epoch: number; - proposed_protocol_parameter_updates: { - [k: string]: ProtocolParamUpdateJSON, - }; -} -export interface ProtocolParamUpdateJSON { - ada_per_utxo_byte?: string | null; - collateral_percentage?: number | null; - committee_term_limit?: number | null; - cost_models?: CostmdlsJSON | null; - d?: UnitIntervalJSON | null; - drep_deposit?: string | null; - drep_inactivity_period?: number | null; - drep_voting_thresholds?: DRepVotingThresholdsJSON | null; - execution_costs?: ExUnitPricesJSON | null; - expansion_rate?: UnitIntervalJSON | null; - extra_entropy?: NonceJSON | null; - governance_action_deposit?: string | null; - governance_action_validity_period?: number | null; - key_deposit?: string | null; - max_block_body_size?: number | null; - max_block_ex_units?: ExUnitsJSON | null; - max_block_header_size?: number | null; - max_collateral_inputs?: number | null; - max_epoch?: number | null; - max_tx_ex_units?: ExUnitsJSON | null; - max_tx_size?: number | null; - max_value_size?: number | null; - min_committee_size?: number | null; - min_pool_cost?: string | null; - minfee_a?: string | null; - minfee_b?: string | null; - n_opt?: number | null; - pool_deposit?: string | null; - pool_pledge_influence?: UnitIntervalJSON | null; - pool_voting_thresholds?: PoolVotingThresholdsJSON | null; - protocol_version?: ProtocolVersionJSON | null; - ref_script_coins_per_byte?: UnitIntervalJSON | null; - treasury_growth_rate?: UnitIntervalJSON | null; -} -export interface CostmdlsJSON { - [k: string]: CostModelJSON; -} -export interface DRepVotingThresholdsJSON { - committee_no_confidence: UnitIntervalJSON; - committee_normal: UnitIntervalJSON; - hard_fork_initiation: UnitIntervalJSON; - motion_no_confidence: UnitIntervalJSON; - pp_economic_group: UnitIntervalJSON; - pp_governance_group: UnitIntervalJSON; - pp_network_group: UnitIntervalJSON; - pp_technical_group: UnitIntervalJSON; - treasury_withdrawal: UnitIntervalJSON; - update_constitution: UnitIntervalJSON; -} -export interface ExUnitPricesJSON { - mem_price: UnitIntervalJSON; - step_price: UnitIntervalJSON; -} -export interface NonceJSON { - /** - * @minItems 32 - * @maxItems 32 - */ - hash?: - | [ - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number, - number - ] - | null; -} -export interface ExUnitsJSON { - mem: string; - steps: string; -} -export interface PoolVotingThresholdsJSON { - committee_no_confidence: UnitIntervalJSON; - committee_normal: UnitIntervalJSON; - hard_fork_initiation: UnitIntervalJSON; - motion_no_confidence: UnitIntervalJSON; - security_relevant_threshold: UnitIntervalJSON; -} -export interface VoterVotesJSON { - voter: VoterJSON; - votes: VoteJSON[]; -} -export interface VoteJSON { - action_id: GovernanceActionIdJSON; - voting_procedure: VotingProcedureJSON; -} -export interface GovernanceActionIdJSON { - index: number; - transaction_id: string; -} -export interface VotingProcedureJSON { - anchor?: AnchorJSON | null; - vote: VoteKindJSON; -} -export interface VotingProposalJSON { - anchor: AnchorJSON; - deposit: string; - governance_action: GovernanceActionJSON; - reward_account: string; -} -export interface ParameterChangeActionJSON { - gov_action_id?: GovernanceActionIdJSON | null; - policy_hash?: string | null; - protocol_param_updates: ProtocolParamUpdateJSON; -} -export interface HardForkInitiationActionJSON { - gov_action_id?: GovernanceActionIdJSON | null; - protocol_version: ProtocolVersionJSON; -} -export interface TreasuryWithdrawalsActionJSON { - policy_hash?: string | null; - withdrawals: TreasuryWithdrawalsJSON; -} -export interface TreasuryWithdrawalsJSON { - [k: string]: string; -} -export interface NoConfidenceActionJSON { - gov_action_id?: GovernanceActionIdJSON | null; -} -export interface UpdateCommitteeActionJSON { - committee: CommitteeJSON; - gov_action_id?: GovernanceActionIdJSON | null; - members_to_remove: CredTypeJSON[]; -} -export interface CommitteeJSON { - members: CommitteeMemberJSON[]; - quorum_threshold: UnitIntervalJSON; -} -export interface CommitteeMemberJSON { - stake_credential: CredTypeJSON; - term_limit: number; -} -export interface NewConstitutionActionJSON { - constitution: ConstitutionJSON; - gov_action_id?: GovernanceActionIdJSON | null; -} -export interface ConstitutionJSON { - anchor: AnchorJSON; - script_hash?: string | null; -} -export interface TransactionWitnessSetJSON { - bootstraps?: BootstrapWitnessJSON[] | null; - native_scripts?: NativeScriptsJSON | null; - plutus_data?: PlutusListJSON | null; - plutus_scripts?: PlutusScriptsJSON | null; - redeemers?: RedeemerJSON[] | null; - vkeys?: VkeywitnessJSON[] | null; -} -export interface BootstrapWitnessJSON { - attributes: number[]; - chain_code: number[]; - signature: string; - vkey: VkeyJSON; -} -export interface PlutusListJSON { - definite_encoding?: boolean | null; - elems: string[]; -} -export interface RedeemerJSON { - data: string; - ex_units: ExUnitsJSON; - index: string; - tag: RedeemerTagJSON; -} -export interface VkeywitnessJSON { - signature: string; - vkey: VkeyJSON; -} -export type BlockHashJSON = string; -export type BootstrapWitnessesJSON = BootstrapWitnessJSON[]; -export type CertificateEnumJSON = - | { - StakeRegistration: StakeRegistrationJSON, - ... - } - | { - StakeDeregistration: StakeDeregistrationJSON, - ... - } - | { - StakeDelegation: StakeDelegationJSON, - ... - } - | { - PoolRegistration: PoolRegistrationJSON, - ... - } - | { - PoolRetirement: PoolRetirementJSON, - ... - } - | { - GenesisKeyDelegation: GenesisKeyDelegationJSON, - ... - } - | { - MoveInstantaneousRewardsCert: MoveInstantaneousRewardsCertJSON, - ... - } - | { - CommitteeHotAuth: CommitteeHotAuthJSON, - ... - } - | { - CommitteeColdResign: CommitteeColdResignJSON, - ... - } - | { - DRepDeregistration: DRepDeregistrationJSON, - ... - } - | { - DRepRegistration: DRepRegistrationJSON, - ... - } - | { - DRepUpdate: DRepUpdateJSON, - ... - } - | { - StakeAndVoteDelegation: StakeAndVoteDelegationJSON, - ... - } - | { - StakeRegistrationAndDelegation: StakeRegistrationAndDelegationJSON, - ... - } - | { - StakeVoteRegistrationAndDelegation: StakeVoteRegistrationAndDelegationJSON, - ... - } - | { - VoteDelegation: VoteDelegationJSON, - ... - } - | { - VoteRegistrationAndDelegation: VoteRegistrationAndDelegationJSON, - ... - }; -export type CertificatesJSON = CertificateJSON[]; -export type CredentialJSON = CredTypeJSON; -export type CredentialsJSON = CredTypeJSON[]; -export type DRepEnumJSON = - | ("AlwaysAbstain" | "AlwaysNoConfidence") - | { - KeyHash: string, - ... - } - | { - ScriptHash: string, - ... - }; -export type DataHashJSON = string; -export type Ed25519KeyHashJSON = string; -export type Ed25519KeyHashesJSON = string[]; -export type Ed25519SignatureJSON = string; -export interface GeneralTransactionMetadataJSON { - [k: string]: string; -} -export type GenesisDelegateHashJSON = string; -export type GenesisHashJSON = string; -export type GenesisHashesJSON = string[]; -export type GovernanceActionEnumJSON = - | { - ParameterChangeAction: ParameterChangeActionJSON, - ... - } - | { - HardForkInitiationAction: HardForkInitiationActionJSON, - ... - } - | { - TreasuryWithdrawalsAction: TreasuryWithdrawalsActionJSON, - ... - } - | { - NoConfidenceAction: NoConfidenceActionJSON, - ... - } - | { - UpdateCommitteeAction: UpdateCommitteeActionJSON, - ... - } - | { - NewConstitutionAction: NewConstitutionActionJSON, - ... - } - | { - InfoAction: InfoActionJSON, - ... - }; -export type GovernanceActionIdsJSON = GovernanceActionIdJSON[]; -export type IntJSON = string; -/** - * @minItems 4 - * @maxItems 4 - */ -export type KESVKeyJSON = string; -export type LanguageJSON = LanguageKindJSON; -export type LanguageKindJSON = "PlutusV1" | "PlutusV2" | "PlutusV3"; -export type LanguagesJSON = LanguageJSON[]; -export type MIRToStakeCredentialsJSON = StakeToCoinJSON[]; -export type MintsAssetsJSON = MintAssetsJSON[]; -export type NetworkIdKindJSON = "Testnet" | "Mainnet"; -export type PlutusScriptJSON = string; -export type PoolMetadataHashJSON = string; -export interface ProposedProtocolParameterUpdatesJSON { - [k: string]: ProtocolParamUpdateJSON; -} -export type PublicKeyJSON = string; -export type RedeemerTagKindJSON = - | "Spend" - | "Mint" - | "Cert" - | "Reward" - | "Vote" - | "VotingProposal"; -export type RedeemersJSON = RedeemerJSON[]; -export type RelayEnumJSON = - | { - SingleHostAddr: SingleHostAddrJSON, - ... - } - | { - SingleHostName: SingleHostNameJSON, - ... - } - | { - MultiHostName: MultiHostNameJSON, - ... - }; -/** - * @minItems 4 - * @maxItems 4 - */ -export type RewardAddressJSON = string; -export type RewardAddressesJSON = string[]; -export type ScriptDataHashJSON = string; -export type ScriptHashJSON = string; -export type ScriptHashesJSON = string[]; -export type ScriptRefEnumJSON = - | { - NativeScript: NativeScriptJSON, - ... - } - | { - PlutusScript: string, - ... - }; -export interface TransactionJSON { - auxiliary_data?: AuxiliaryDataJSON | null; - body: TransactionBodyJSON; - is_valid: boolean; - witness_set: TransactionWitnessSetJSON; -} -export type TransactionHashJSON = string; -export type TransactionInputsJSON = TransactionInputJSON[]; -export type TransactionMetadatumJSON = string; -export interface TransactionUnspentOutputJSON { - input: TransactionInputJSON; - output: TransactionOutputJSON; -} -export type TransactionUnspentOutputsJSON = TransactionUnspentOutputJSON[]; -export type VRFKeyHashJSON = string; -export type VRFVKeyJSON = string; -export interface VersionedBlockJSON { - block: BlockJSON; - era_code: number; -} -export type VkeywitnessesJSON = VkeywitnessJSON[]; -export type VoterEnumJSON = - | { - ConstitutionalCommitteeHotCred: CredTypeJSON, - ... - } - | { - DRep: CredTypeJSON, - ... - } - | { - StakingPool: string, - ... - }; -export type VotersJSON = VoterJSON[]; -export type VotingProceduresJSON = VoterVotesJSON[]; -export type VotingProposalsJSON = VotingProposalJSON[]; -export interface WithdrawalsJSON { - [k: string]: string; -} diff --git a/rust/src/builders/batch_tools/cbor_calculator.rs b/rust/src/builders/batch_tools/cbor_calculator.rs index fec45147..83ebc1cd 100644 --- a/rust/src/builders/batch_tools/cbor_calculator.rs +++ b/rust/src/builders/batch_tools/cbor_calculator.rs @@ -26,6 +26,17 @@ impl CborCalculator { } } + pub(super) fn get_wrapped_struct_size(items_count: u64) -> usize { + //wrapped struct is a struct of 2 elements, tag and value + let tag_size = CborCalculator::get_tag_size(258); + let value_size = CborCalculator::get_struct_size(items_count); + tag_size + value_size + } + + pub(super) fn get_tag_size(tag: u64) -> usize { + Self::get_struct_size(tag) + } + pub(super) fn get_coin_size(coin: &Coin) -> usize { Self::get_struct_size(coin.clone().into()) } @@ -71,12 +82,35 @@ impl CborCalculator { pub(super) fn get_bare_tx_body_size(body_fields: &HashSet) -> usize { let mut size = CborCalculator::get_struct_size(body_fields.len() as u64); for field in body_fields { - size += CborCalculator::get_struct_size(field.to_u64().unwrap()); + let wrapped = match field { + TxBodyNames::Inputs => true, + TxBodyNames::Outputs => false, + TxBodyNames::Fee => false, + TxBodyNames::Ttl => false, + TxBodyNames::Certs => true, + TxBodyNames::Withdrawals => false, + TxBodyNames::Update => false, + TxBodyNames::AuxiliaryDataHash => false, + TxBodyNames::ValidityStartInterval => false, + TxBodyNames::Mint => false, + TxBodyNames::ScriptDataHash => false, + TxBodyNames::Collateral => true, + TxBodyNames::RequiredSigners => true, + TxBodyNames::NetworkId => false, + TxBodyNames::CollateralReturn => false, + TxBodyNames::TotalCollateral => false, + TxBodyNames::ReferenceInputs => true, + }; + if wrapped { + size += CborCalculator::get_wrapped_struct_size(field.to_u64().unwrap()); + } else { + size += CborCalculator::get_struct_size(field.to_u64().unwrap()); + } } size } - pub(super) fn get_wintnesses_set_struct_size( + pub(super) fn get_witnesses_set_struct_size( witnesses_fields: &HashSet, ) -> usize { let mut size = CborCalculator::get_struct_size(witnesses_fields.len() as u64); diff --git a/rust/src/builders/batch_tools/witnesses_calculator.rs b/rust/src/builders/batch_tools/witnesses_calculator.rs index b0c50614..0d777b1e 100644 --- a/rust/src/builders/batch_tools/witnesses_calculator.rs +++ b/rust/src/builders/batch_tools/witnesses_calculator.rs @@ -2,7 +2,8 @@ use crate::builders::batch_tools::cbor_calculator::CborCalculator; use crate::serialization::map_names::WitnessSetNames; use crate::*; use std::collections::HashSet; -use crate::builders::fakes::{fake_private_key, fake_raw_key_public, fake_raw_key_sig}; +use crate::builders::fakes::{fake_raw_key_public, fake_raw_key_sig}; +use crate::fakes::fake_bootstrap_witness; #[derive(Clone)] pub(super) struct WitnessesCalculator { @@ -97,7 +98,6 @@ impl WitnessesCalculator { } pub(super) fn create_mock_witnesses_set(&self) -> TransactionWitnessSet { - let fake_key_root = fake_private_key(); let fake_sig = fake_raw_key_sig(); // recall: this includes keys for input, certs and withdrawals @@ -118,13 +118,11 @@ impl WitnessesCalculator { 0 => None, _x => { let mut result = BootstrapWitnesses::new(); + let mut number = 0; for boostrap_address in &self.bootsraps { + number += 1; // picking icarus over daedalus for fake witness generation shouldn't matter - result.add(&make_icarus_bootstrap_witness( - &TransactionHash::from([0u8; TransactionHash::BYTE_COUNT]), - boostrap_address, - &fake_key_root, - )); + result.add(&fake_bootstrap_witness(number, boostrap_address)); } Some(result) } @@ -144,18 +142,18 @@ impl WitnessesCalculator { if self.vkeys_count == 0 { if self.used_fields.len() > 0 { self.total_size -= - CborCalculator::get_wintnesses_set_struct_size(&self.used_fields); + CborCalculator::get_witnesses_set_struct_size(&self.used_fields); } self.used_fields.insert(WitnessSetNames::Vkeys); - self.total_size += CborCalculator::get_wintnesses_set_struct_size(&self.used_fields); + self.total_size += CborCalculator::get_witnesses_set_struct_size(&self.used_fields); } if self.vkeys_count != 0 { - self.total_size -= CborCalculator::get_struct_size(self.vkeys_count); + self.total_size -= CborCalculator::get_wrapped_struct_size(self.vkeys_count); } self.vkeys_count += 1; - self.total_size += CborCalculator::get_struct_size(self.vkeys_count); + self.total_size += CborCalculator::get_wrapped_struct_size(self.vkeys_count); self.total_size += CborCalculator::get_fake_vkey_size(); } @@ -164,18 +162,18 @@ impl WitnessesCalculator { if self.boostrap_count == 0 { if self.used_fields.len() > 0 { self.total_size -= - CborCalculator::get_wintnesses_set_struct_size(&self.used_fields); + CborCalculator::get_witnesses_set_struct_size(&self.used_fields); } self.used_fields.insert(WitnessSetNames::Bootstraps); - self.total_size += CborCalculator::get_wintnesses_set_struct_size(&self.used_fields); + self.total_size += CborCalculator::get_witnesses_set_struct_size(&self.used_fields); } if self.boostrap_count != 0 { - self.total_size -= CborCalculator::get_struct_size(self.boostrap_count); + self.total_size -= CborCalculator::get_wrapped_struct_size(self.boostrap_count); } self.boostrap_count += 1; - self.total_size += CborCalculator::get_struct_size(self.boostrap_count); + self.total_size += CborCalculator::get_wrapped_struct_size(self.boostrap_count); self.total_size += CborCalculator::get_boostrap_witness_size(address); } } diff --git a/rust/src/builders/mint_builder.rs b/rust/src/builders/mint_builder.rs index a4da7606..62934326 100644 --- a/rust/src/builders/mint_builder.rs +++ b/rust/src/builders/mint_builder.rs @@ -333,7 +333,7 @@ impl MintBuilder { _ => {} } } - NativeScripts(native_scripts) + NativeScripts::from(native_scripts) } pub fn get_plutus_witnesses(&self) -> PlutusWitnesses { diff --git a/rust/src/builders/tx_builder.rs b/rust/src/builders/tx_builder.rs index 1c2e53d8..f885c195 100644 --- a/rust/src/builders/tx_builder.rs +++ b/rust/src/builders/tx_builder.rs @@ -107,7 +107,7 @@ fn assert_required_mint_scripts( } let mint_scripts = maybe_mint_scripts.unwrap(); let witness_hashes: HashSet = - mint_scripts.0.iter().map(|script| script.hash()).collect(); + mint_scripts.iter().map(|script| script.hash()).collect(); for mint_hash in mint.keys().0.iter() { if !witness_hashes.contains(mint_hash) { return Err(JsError::from_str(&format!( @@ -930,8 +930,7 @@ impl TransactionBuilder { if self .inputs .inputs() - .inputs - .iter() + .into_iter() .all(|used_input| input.input() != *used_input) { unused_inputs.add(input) @@ -1289,7 +1288,7 @@ impl TransactionBuilder { pub fn set_mint(&mut self, mint: &Mint, mint_scripts: &NativeScripts) -> Result<(), JsError> { assert_required_mint_scripts(mint, Some(mint_scripts))?; let mut scripts_policies = HashMap::new(); - for scipt in &mint_scripts.0 { + for scipt in mint_scripts { scripts_policies.insert(scipt.hash(), scipt.clone()); } @@ -1516,9 +1515,9 @@ impl TransactionBuilder { let mut inputs: HashSet = HashSet::new(); let mut add_ref_inputs_set = |ref_inputs: TransactionInputs| { - for input in ref_inputs { + for input in &ref_inputs { if !self.inputs.has_input(&input) { - inputs.insert(input); + inputs.insert(input.clone()); } } }; @@ -2271,24 +2270,23 @@ impl TransactionBuilder { fn get_combined_native_scripts(&self) -> Option { let mut ns = NativeScripts::new(); if let Some(input_scripts) = self.inputs.get_native_input_scripts() { - input_scripts.0.iter().for_each(|s| { + input_scripts.iter().for_each(|s| { ns.add(s); }); } if let Some(input_scripts) = self.collateral.get_native_input_scripts() { - input_scripts.0.iter().for_each(|s| { + input_scripts.iter().for_each(|s| { ns.add(s); }); } if let Some(mint_builder) = &self.mint { - mint_builder.get_native_scripts().0.iter().for_each(|s| { + mint_builder.get_native_scripts().iter().for_each(|s| { ns.add(s); }); } if let Some(certificates_builder) = &self.certs { certificates_builder .get_native_scripts() - .0 .iter() .for_each(|s| { ns.add(s); @@ -2297,14 +2295,13 @@ impl TransactionBuilder { if let Some(withdrawals_builder) = &self.withdrawals { withdrawals_builder .get_native_scripts() - .0 .iter() .for_each(|s| { ns.add(s); }); } if let Some(voting_builder) = &self.voting_procedures { - voting_builder.get_native_scripts().0.iter().for_each(|s| { + voting_builder.get_native_scripts().iter().for_each(|s| { ns.add(s); }); } diff --git a/rust/src/protocol_types/certificates/certificates_collection.rs b/rust/src/protocol_types/certificates/certificates_collection.rs index d316f6e1..d02d907f 100644 --- a/rust/src/protocol_types/certificates/certificates_collection.rs +++ b/rust/src/protocol_types/certificates/certificates_collection.rs @@ -1,12 +1,18 @@ use crate::*; +use std::collections::HashSet; +use std::hash::{Hash, Hasher}; +use std::iter::Map; +use itertools::Itertools; +use std::ops::Deref; +use std::rc::Rc; +use std::slice; #[wasm_bindgen] -#[derive( - Clone, Debug, Eq, Ord, PartialEq, PartialOrd, -)] +#[derive(Clone, Debug)] pub struct Certificates { - pub(crate) certs: Vec, - pub(crate) dedup: BTreeSet + pub(crate) certs: Vec>, + pub(crate) dedup: HashSet>, + pub(crate) cbor_set_type: CborSetType, } impl_to_from!(Certificates); @@ -22,7 +28,8 @@ impl Certificates { pub fn new() -> Self { Self { certs: Vec::new(), - dedup: BTreeSet::new(), + dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, } } @@ -31,14 +38,15 @@ impl Certificates { } pub fn get(&self, index: usize) -> Certificate { - self.certs[index].clone() + self.certs[index].deref().clone() } /// Add a new `Certificate` to the set. /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, elem: &Certificate) -> bool { - if self.dedup.insert(elem.clone()) { - self.certs.push(elem.clone()); + let rc_elem = Rc::new(elem.clone()); + if self.dedup.insert(rc_elem.clone()) { + self.certs.push(rc_elem.clone()); true } else { false @@ -46,12 +54,12 @@ impl Certificates { } pub(crate) fn add_move(&mut self, elem: Certificate) { - if self.dedup.insert(elem.clone()) { - self.certs.push(elem); + let rc_elem = Rc::new(elem); + if self.dedup.insert(rc_elem.clone()) { + self.certs.push(rc_elem.clone()); } } - pub(crate) fn from_vec(certs_vec: Vec) -> Self { let mut certs = Self::new(); for cert in certs_vec { @@ -59,25 +67,73 @@ impl Certificates { } certs } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, set_type: CborSetType) { + self.cbor_set_type = set_type; + } +} + +impl PartialEq for Certificates { + fn eq(&self, other: &Self) -> bool { + self.certs == other.certs + } +} + +impl Eq for Certificates {} + +impl PartialOrd for Certificates { + fn partial_cmp(&self, other: &Self) -> Option { + self.certs.partial_cmp(&other.certs) + } +} + +impl Ord for Certificates { + fn cmp(&self, other: &Self) -> Ordering { + self.certs.cmp(&other.certs) + } +} + +impl Hash for Certificates { + fn hash(&self, state: &mut H) { + self.certs.hash(state); + } +} + +impl<'a> IntoIterator for &'a Certificates { + type Item = &'a Certificate; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a Certificate, + >; + + fn into_iter(self) -> Self::IntoIter { + self.certs.iter().map(|rc| rc.as_ref()) + } } impl serde::Serialize for Certificates { fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, + where + S: serde::Serializer, { - self.certs.serialize(serializer) + self.certs + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } impl<'de> serde::de::Deserialize<'de> for Certificates { fn deserialize(deserializer: D) -> Result - where - D: serde::de::Deserializer<'de>, + where + D: serde::de::Deserializer<'de>, { - let vec = as serde::de::Deserialize>::deserialize( - deserializer, - )?; + let vec = as serde::de::Deserialize>::deserialize(deserializer)?; Ok(Self::from_vec(vec)) } } diff --git a/rust/src/protocol_types/credentials.rs b/rust/src/protocol_types/credentials.rs index 244c76da..8c95cad4 100644 --- a/rust/src/protocol_types/credentials.rs +++ b/rust/src/protocol_types/credentials.rs @@ -1,18 +1,19 @@ +use std::collections::HashSet; +use std::hash::{Hash, Hasher}; +use std::ops::Deref; +use std::rc::Rc; +use itertools::Itertools; use crate::*; #[wasm_bindgen] #[derive( Clone, Debug, - Hash, - Eq, - Ord, - PartialEq, - PartialOrd, )] pub struct Credentials { - pub(crate) credentials: Vec, - pub(crate) dedup: BTreeSet + pub(crate) credentials: Vec>, + pub(crate) dedup: HashSet>, + pub(crate) cbor_set_type: CborSetType, } impl_to_from!(Credentials); @@ -22,7 +23,19 @@ impl Credentials { pub fn new() -> Self { Self { credentials: Vec::new(), - dedup: BTreeSet::new(), + dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, + } + } + + pub(crate) fn new_from_prepared_fields( + credentials: Vec>, + dedup: HashSet>, + ) -> Self { + Self { + credentials, + dedup, + cbor_set_type: CborSetType::Tagged, } } @@ -31,23 +44,25 @@ impl Credentials { } pub fn get(&self, index: usize) -> Credential { - self.credentials[index].clone() + self.credentials[index].deref().clone() } /// Add a new `Credential` to the set. /// Returns `true` if the element was not already present in the set. - pub fn add(&mut self, elem: &Credential) -> bool { - if self.dedup.insert(elem.clone()) { - self.credentials.push(elem.clone()); + pub fn add(&mut self,credential: &Credential) -> bool { + let credential_rc = Rc::new(credential.clone()); + if self.dedup.insert(credential_rc.clone()) { + self.credentials.push(credential_rc); true } else { false } } - pub(crate) fn add_move(&mut self, elem: Credential) { - if self.dedup.insert(elem.clone()) { - self.credentials.push(elem); + pub(crate) fn add_move(&mut self, credential: Credential) { + let credential_rc = Rc::new(credential); + if self.dedup.insert(credential_rc.clone()) { + self.credentials.push(credential_rc); } } @@ -57,45 +72,75 @@ impl Credentials { } pub(crate) fn from_vec(vec: Vec) -> Self { - let mut dedup = BTreeSet::new(); + let mut dedup = HashSet::new(); let mut credentials = Vec::new(); for elem in vec { - if dedup.insert(elem.clone()) { - credentials.push(elem); + let elem_rc = Rc::new(elem); + if dedup.insert(elem_rc.clone()) { + credentials.push(elem_rc); } } - Self { - credentials, - dedup - } + Self::new_from_prepared_fields(credentials, dedup) } pub(crate) fn from_iter(iter: impl IntoIterator) -> Self { - let mut dedup = BTreeSet::new(); + let mut dedup = HashSet::new(); let mut credentials = Vec::new(); for elem in iter { - if dedup.insert(elem.clone()) { - credentials.push(elem); + let elem_rc = Rc::new(elem); + if dedup.insert(elem_rc.clone()) { + credentials.push(elem_rc); } } - Self { - credentials, - dedup - } + Self::new_from_prepared_fields(credentials, dedup) + } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() } - pub(crate) fn to_vec(&self) -> &Vec { - &self.credentials + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; + } + +} + +impl PartialEq for Credentials { + fn eq(&self, other: &Self) -> bool { + self.credentials == other.credentials } } +impl Eq for Credentials {} + +impl PartialOrd for Credentials { + fn partial_cmp(&self, other: &Self) -> Option { + self.credentials.partial_cmp(&other.credentials) + } +} + +impl Ord for Credentials { + fn cmp(&self, other: &Self) -> Ordering { + self.credentials.cmp(&other.credentials) + } +} impl serde::Serialize for Credentials { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { - self.credentials.serialize(serializer) + self.credentials + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) + } +} + +impl Hash for Credentials { + fn hash(&self, state: &mut H) { + self.credentials.hash(state); } } diff --git a/rust/src/protocol_types/ed25519_key_hashes.rs b/rust/src/protocol_types/ed25519_key_hashes.rs index c26083e3..8f5cad5b 100644 --- a/rust/src/protocol_types/ed25519_key_hashes.rs +++ b/rust/src/protocol_types/ed25519_key_hashes.rs @@ -1,3 +1,10 @@ +use std::collections::HashSet; +use std::hash::{Hash, Hasher}; +use std::ops::Deref; +use std::rc::Rc; +use std::slice; +use std::iter::Map; +use itertools::Itertools; pub use crate::*; pub type RequiredSigners = Ed25519KeyHashes; @@ -6,15 +13,11 @@ pub type RequiredSigners = Ed25519KeyHashes; #[derive( Clone, Debug, - Eq, - Ord, - Hash, - PartialEq, - PartialOrd, )] pub struct Ed25519KeyHashes { - keyhashes: Vec, - dedup: BTreeSet, + keyhashes: Vec>, + dedup: HashSet>, + cbor_set_type: CborSetType, } impl_to_from!(Ed25519KeyHashes); @@ -24,7 +27,19 @@ impl Ed25519KeyHashes { pub fn new() -> Self { Self { keyhashes: Vec::new(), - dedup: BTreeSet::new(), + dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, + } + } + + pub(crate) fn new_from_prepared_fields( + keyhashes: Vec>, + dedup: HashSet>, + ) -> Self { + Self { + keyhashes, + dedup, + cbor_set_type: CborSetType::Tagged, } } @@ -33,14 +48,15 @@ impl Ed25519KeyHashes { } pub fn get(&self, index: usize) -> Ed25519KeyHash { - self.keyhashes[index].clone() + self.keyhashes[index].deref().clone() } /// Add a new `Ed25519KeyHash` to the set. /// Returns `true` if the element was not already present in the set. - pub fn add(&mut self, elem: &Ed25519KeyHash) -> bool { - if self.dedup.insert(elem.clone()) { - self.keyhashes.push(elem.clone()); + pub fn add(&mut self, keyhash: &Ed25519KeyHash) -> bool { + let keyhash_rc = Rc::new(keyhash.clone()); + if self.dedup.insert(keyhash_rc.clone()) { + self.keyhashes.push(keyhash_rc.clone()); true } else { false @@ -59,13 +75,10 @@ impl Ed25519KeyHashes { } } - pub(crate) fn to_vec(&self) -> &Vec { - &self.keyhashes - } - - pub(crate) fn add_move(&mut self, elem: Ed25519KeyHash) { - if self.dedup.insert(elem.clone()) { - self.keyhashes.push(elem); + pub(crate) fn add_move(&mut self, keyhash: Ed25519KeyHash) { + let keyhash_rc = Rc::new(keyhash); + if self.dedup.insert(keyhash_rc.clone()) { + self.keyhashes.push(keyhash_rc); } } @@ -77,20 +90,69 @@ impl Ed25519KeyHashes { pub(crate) fn extend_move(&mut self, other: Ed25519KeyHashes) { for keyhash in other.keyhashes { - self.add_move(keyhash); + if self.dedup.insert(keyhash.clone()) { + self.keyhashes.push(keyhash); + } } } pub(crate) fn from_vec(keyhash_vec: Vec) -> Self { - let mut dedup = BTreeSet::new(); + let mut dedup = HashSet::new(); let mut keyhashes = Vec::new(); for keyhash in keyhash_vec { - if dedup.insert(keyhash.clone()) { - keyhashes.push(keyhash); + let keyhash_rc = Rc::new(keyhash.clone()); + if dedup.insert(keyhash_rc.clone()) { + keyhashes.push(keyhash_rc); } } - Self { keyhashes, dedup } + Self::new_from_prepared_fields(keyhashes, dedup) + } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; + } +} + +impl<'a> IntoIterator for &'a Ed25519KeyHashes { + type Item = &'a Ed25519KeyHash; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a Ed25519KeyHash, + >; + + fn into_iter(self) -> Self::IntoIter { + self.keyhashes.iter().map(|rc| rc.as_ref()) + } +} + +impl PartialEq for Ed25519KeyHashes { + fn eq(&self, other: &Self) -> bool { + self.keyhashes == other.keyhashes + } +} + +impl Eq for Ed25519KeyHashes {} + +impl PartialOrd for Ed25519KeyHashes { + fn partial_cmp(&self, other: &Self) -> Option { + self.keyhashes.partial_cmp(&other.keyhashes) + } +} + +impl Ord for Ed25519KeyHashes { + fn cmp(&self, other: &Self) -> Ordering { + self.keyhashes.cmp(&other.keyhashes) + } +} + +impl Hash for Ed25519KeyHashes { + fn hash(&self, state: &mut H) { + self.keyhashes.hash(state); } } @@ -105,7 +167,11 @@ impl serde::Serialize for Ed25519KeyHashes { where S: serde::Serializer, { - self.keyhashes.serialize(serializer) + self.keyhashes + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } diff --git a/rust/src/protocol_types/fixed_tx.rs b/rust/src/protocol_types/fixed_tx.rs index cad72646..79989a42 100644 --- a/rust/src/protocol_types/fixed_tx.rs +++ b/rust/src/protocol_types/fixed_tx.rs @@ -62,6 +62,21 @@ impl FixedTransaction { }) } + pub fn new_from_body_bytes(raw_body: &[u8]) -> Result { + let body = TransactionBody::from_bytes(raw_body.to_vec())?; + let tx_hash = TransactionHash::from(blake2b256(raw_body)); + + Ok(FixedTransaction { + body, + body_bytes: raw_body.to_vec(), + tx_hash, + witness_set: FixedTxWitnessesSet::new_empty(), + is_valid: true, + auxiliary_data: None, + auxiliary_bytes: None, + }) + } + pub(crate) fn new_with_original_bytes( tx_body: TransactionBody, raw_body: Vec, diff --git a/rust/src/protocol_types/governance/proposals/voting_proposals.rs b/rust/src/protocol_types/governance/proposals/voting_proposals.rs index 15e5413a..9d53efbf 100644 --- a/rust/src/protocol_types/governance/proposals/voting_proposals.rs +++ b/rust/src/protocol_types/governance/proposals/voting_proposals.rs @@ -1,18 +1,23 @@ +use std::hash::{Hash, Hasher}; +use std::ops::Deref; +use std::rc::Rc; +use std::slice; +use std::iter::Map; +use std::collections::HashSet; +use std::cmp::Ordering; +use itertools::Itertools; +use schemars::JsonSchema; use crate::*; +#[wasm_bindgen] #[derive( Clone, Debug, - Hash, - Eq, - Ord, - PartialEq, - PartialOrd, )] -#[wasm_bindgen] pub struct VotingProposals { - pub(crate) proposals: Vec, - pub(crate) dedup: BTreeSet, + proposals: Vec>, + dedup: HashSet>, + cbor_set_type: CborSetType, } impl_to_from!(VotingProposals); @@ -28,7 +33,19 @@ impl VotingProposals { pub fn new() -> Self { Self { proposals: Vec::new(), - dedup: BTreeSet::new(), + dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, + } + } + + pub(crate) fn new_from_prepared_fields( + proposals: Vec>, + dedup: HashSet>, + ) -> Self { + Self { + proposals, + dedup, + cbor_set_type: CborSetType::Tagged, } } @@ -37,46 +54,102 @@ impl VotingProposals { } pub fn get(&self, index: usize) -> VotingProposal { - self.proposals[index].clone() + self.proposals[index].deref().clone() } - /// Add a proposal to the set of proposals - /// Returns true if the proposal was added, false if it was already present + /// Add a new `VotingProposal` to the set. + /// Returns `true` if the element was not already present in the set. pub fn add(&mut self, proposal: &VotingProposal) -> bool { - if self.dedup.insert(proposal.clone()) { - self.proposals.push(proposal.clone()); + let proposal_rc = Rc::new(proposal.clone()); + if self.dedup.insert(proposal_rc.clone()) { + self.proposals.push(proposal_rc.clone()); true } else { false } } - pub(crate) fn add_move(&mut self, proposal: VotingProposal) { - if self.dedup.insert(proposal.clone()) { - self.proposals.push(proposal); + pub fn contains(&self, elem: &VotingProposal) -> bool { + self.dedup.contains(elem) + } + + pub fn to_option(&self) -> Option { + if !self.proposals.is_empty() { + Some(self.clone()) + } else { + None } } - pub(crate) fn from_vec(proposals: Vec) -> Self { - let mut voting_proposals = VotingProposals::new(); - for proposal in proposals { - voting_proposals.add_move(proposal); + pub(crate) fn from_vec(proposal_vec: Vec) -> Self { + let mut dedup = HashSet::new(); + let mut proposals = Vec::new(); + for proposal in proposal_vec { + let proposal_rc = Rc::new(proposal.clone()); + if dedup.insert(proposal_rc.clone()) { + proposals.push(proposal_rc); + } } - voting_proposals + Self::new_from_prepared_fields(proposals, dedup) + } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; } +} - #[allow(dead_code)] - pub(crate) fn contains(&self, proposal: &VotingProposal) -> bool { - self.dedup.contains(proposal) +impl<'a> IntoIterator for &'a VotingProposals { + type Item = &'a VotingProposal; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a VotingProposal, + >; + + fn into_iter(self) -> Self::IntoIter { + self.proposals.iter().map(|rc| rc.as_ref()) + } +} + +impl PartialEq for VotingProposals { + fn eq(&self, other: &Self) -> bool { + self.proposals == other.proposals + } +} + +impl Eq for VotingProposals {} + +impl PartialOrd for VotingProposals { + fn partial_cmp(&self, other: &Self) -> Option { + self.proposals.partial_cmp(&other.proposals) + } +} + +impl Ord for VotingProposals { + fn cmp(&self, other: &Self) -> Ordering { + self.proposals.cmp(&other.proposals) + } +} + +impl Hash for VotingProposals { + fn hash(&self, state: &mut H) { + self.proposals.hash(state); } } impl serde::Serialize for VotingProposals { fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, + where + S: serde::Serializer, { - self.proposals.serialize(serializer) + self.proposals + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } @@ -102,5 +175,4 @@ impl JsonSchema for VotingProposals { fn is_referenceable() -> bool { Vec::::is_referenceable() } -} - +} \ No newline at end of file diff --git a/rust/src/protocol_types/native_scripts.rs b/rust/src/protocol_types/native_scripts.rs index 3e1bf99e..58e8a47a 100644 --- a/rust/src/protocol_types/native_scripts.rs +++ b/rust/src/protocol_types/native_scripts.rs @@ -1,33 +1,41 @@ use crate::*; +use std::vec::IntoIter; +use std::slice::{Iter, IterMut}; #[wasm_bindgen] #[derive( - Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema, + Clone, Debug )] -pub struct NativeScripts(pub(crate) Vec); +pub struct NativeScripts { + pub(crate) scripts: Vec, + pub(crate) cbor_tag_type: Option, +} #[wasm_bindgen] impl NativeScripts { pub fn new() -> Self { - Self(Vec::new()) + Self { + scripts: Vec::new(), + cbor_tag_type: None, + } } pub fn len(&self) -> usize { - self.0.len() + self.scripts.len() } pub fn get(&self, index: usize) -> NativeScript { - self.0[index].clone() + self.scripts[index].clone() } pub fn add(&mut self, elem: &NativeScript) { - self.0.push(elem.clone()); + self.scripts.push(elem.clone()); } pub(crate) fn deduplicated_view(&self) -> Vec<&NativeScript> { let mut dedup = BTreeSet::new(); let mut scripts = Vec::new(); - for elem in &self.0 { + for elem in &self.scripts { if dedup.insert(elem) { scripts.push(elem); } @@ -38,44 +46,80 @@ impl NativeScripts { pub(crate) fn deduplicated_clone(&self) -> NativeScripts { let mut dedup = BTreeSet::new(); let mut scripts = Vec::new(); - for script in &self.0 { + for script in &self.scripts { if dedup.insert(script.clone()) { scripts.push(script.clone()); } } - NativeScripts(scripts) + NativeScripts { + scripts, + cbor_tag_type: self.cbor_tag_type.clone(), + } } #[allow(dead_code)] pub(crate) fn contains(&self, script: &NativeScript) -> bool { - self.0.contains(script) + self.scripts.contains(script) + } + + pub(crate) fn get_set_type(&self) -> Option { + self.cbor_tag_type.clone() + } + + pub(crate) fn iter(&self) -> Iter<'_, NativeScript> { + self.scripts.iter() } } impl_to_from!(NativeScripts); +impl PartialEq for NativeScripts { + fn eq(&self, other: &Self) -> bool { + self.scripts == other.scripts + } +} + +impl Eq for NativeScripts {} + +impl PartialOrd for NativeScripts { + fn partial_cmp(&self, other: &Self) -> Option { + self.scripts.partial_cmp(&other.scripts) + } +} + +impl Ord for NativeScripts { + fn cmp(&self, other: &Self) -> Ordering { + self.scripts.cmp(&other.scripts) + } +} + impl From> for NativeScripts { fn from(scripts: Vec) -> Self { - scripts.iter().fold( - NativeScripts::new(), - |mut scripts, s| { - scripts.add(s); - scripts - }, - ) + Self { + scripts, + cbor_tag_type: None, + } + } +} + +impl From> for NativeScripts { + fn from(scripts: Vec<&NativeScript>) -> Self { + Self { + scripts: scripts.into_iter().cloned().collect(), + cbor_tag_type: None, + } } } impl NoneOrEmpty for NativeScripts { fn is_none_or_empty(&self) -> bool { - self.0.is_empty() + self.scripts.is_empty() } } impl From<&NativeScripts> for Ed25519KeyHashes { fn from(scripts: &NativeScripts) -> Self { scripts - .0 .iter() .fold(Ed25519KeyHashes::new(), |mut set, s| { set.extend_move(Ed25519KeyHashes::from(s)); @@ -83,3 +127,65 @@ impl From<&NativeScripts> for Ed25519KeyHashes { }) } } + +impl IntoIterator for NativeScripts { + type Item = NativeScript; + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.scripts.into_iter() + } +} + +impl<'a> IntoIterator for &'a NativeScripts { + type Item = &'a NativeScript; + type IntoIter = Iter<'a, NativeScript>; + + fn into_iter(self) -> Self::IntoIter { + self.scripts.iter() + } +} + +impl<'a> IntoIterator for &'a mut NativeScripts { + type Item = &'a mut NativeScript; + type IntoIter = IterMut<'a, NativeScript>; + + fn into_iter(self) -> Self::IntoIter { + self.scripts.iter_mut() + } +} + +impl serde::Serialize for NativeScripts { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.scripts.serialize(serializer) + } +} + +impl<'de> serde::de::Deserialize<'de> for NativeScripts { + fn deserialize(deserializer: D) -> Result + where + D: serde::de::Deserializer<'de>, + { + let vec = as serde::de::Deserialize>::deserialize(deserializer)?; + Ok(Self { + scripts: vec, + cbor_tag_type: None, + }) + } +} + +impl JsonSchema for NativeScripts { + fn is_referenceable() -> bool { + Vec::::is_referenceable() + } + fn schema_name() -> String { + String::from("NativeScripts") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + Vec::::json_schema(gen) + } +} + diff --git a/rust/src/protocol_types/plutus/plutus_data.rs b/rust/src/protocol_types/plutus/plutus_data.rs index cd13256c..9dd9b9ea 100644 --- a/rust/src/protocol_types/plutus/plutus_data.rs +++ b/rust/src/protocol_types/plutus/plutus_data.rs @@ -10,6 +10,7 @@ use cbor_event::{ }; use schemars::JsonSchema; +use serde::ser::SerializeStruct; #[wasm_bindgen] #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] @@ -132,6 +133,7 @@ impl PlutusMap { PlutusList { elems: self.0.iter().map(|(k, _v)| k.clone()).collect::>(), definite_encoding: None, + cbor_set_type: None, } } @@ -437,46 +439,23 @@ impl<'de> serde::de::Deserialize<'de> for PlutusData { } #[wasm_bindgen] -#[derive(Clone, Debug, Ord, PartialOrd, Hash, serde::Serialize, serde::Deserialize, JsonSchema)] +#[derive(Clone, Debug)] pub struct PlutusList { pub(crate) elems: Vec, // We should always preserve the original datums when deserialized as this is NOT canonicized // before computing datum hashes. This field will default to cardano-cli behavior if None // and will re-use the provided one if deserialized, unless the list is modified. pub(crate) definite_encoding: Option, + pub(crate) cbor_set_type: Option, } -impl NoneOrEmpty for PlutusList { - fn is_none_or_empty(&self) -> bool { - self.elems.is_empty() - } -} - -impl<'a> IntoIterator for &'a PlutusList { - type Item = &'a PlutusData; - type IntoIter = std::slice::Iter<'a, PlutusData>; - - fn into_iter(self) -> std::slice::Iter<'a, PlutusData> { - self.elems.iter() - } -} - -impl std::cmp::PartialEq for PlutusList { - fn eq(&self, other: &Self) -> bool { - self.elems.eq(&other.elems) - } -} - -impl std::cmp::Eq for PlutusList {} - -to_from_bytes!(PlutusList); - #[wasm_bindgen] impl PlutusList { pub fn new() -> Self { Self { elems: Vec::new(), definite_encoding: None, + cbor_set_type: None, } } @@ -526,19 +505,125 @@ impl PlutusList { Self { elems, definite_encoding: self.definite_encoding, + cbor_set_type: self.cbor_set_type.clone(), } } pub(crate) fn extend(&mut self, other: &PlutusList) { self.elems.extend(other.elems.iter().cloned()); } + + #[allow(dead_code)] + pub(crate) fn set_set_type(&mut self, set_type: CborSetType) { + self.cbor_set_type = Some(set_type); + } + + pub(crate) fn get_set_type(&self) -> Option { + self.cbor_set_type.clone() + } +} + +impl NoneOrEmpty for PlutusList { + fn is_none_or_empty(&self) -> bool { + self.elems.is_empty() + } +} + +impl serde::Serialize for PlutusList { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut state = serializer.serialize_struct("PlutusList", 2)?; + state.serialize_field("elems", &self.elems)?; + state.serialize_field("definite_encoding", &self.definite_encoding)?; + state.end() + } +} + + +#[derive(serde::Deserialize, JsonSchema)] +struct PlutusListFields { + elems: Vec, + definite_encoding: Option, } +impl<'de> serde::de::Deserialize<'de> for PlutusList { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let fields = PlutusListFields::deserialize(deserializer)?; + Ok(Self { + elems: fields.elems, + definite_encoding: fields.definite_encoding, + cbor_set_type: None, + }) + } +} + +impl JsonSchema for PlutusList { + fn schema_name() -> String { + String::from("PlutusList") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + PlutusListFields::json_schema(gen) + } + fn is_referenceable() -> bool { + PlutusListFields::is_referenceable() + } +} + +impl<'a> IntoIterator for &'a PlutusList { + type Item = &'a PlutusData; + type IntoIter = std::slice::Iter<'a, PlutusData>; + + fn into_iter(self) -> std::slice::Iter<'a, PlutusData> { + self.elems.iter() + } +} + +impl PartialOrd for PlutusList { + fn partial_cmp(&self, other: &Self) -> Option { + match self.elems.partial_cmp(&other.elems) { + Some(core::cmp::Ordering::Equal) => self.definite_encoding.partial_cmp(&other.definite_encoding), + non_eq => non_eq, + } + } +} + +impl Hash for PlutusList { + fn hash(&self, state: &mut H) { + self.elems.hash(state); + self.definite_encoding.hash(state); + } +} + +impl Ord for PlutusList { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + match self.elems.cmp(&other.elems) { + core::cmp::Ordering::Equal => self.definite_encoding.cmp(&other.definite_encoding), + non_eq => non_eq, + } + } +} + +impl std::cmp::PartialEq for PlutusList { + fn eq(&self, other: &Self) -> bool { + self.elems.eq(&other.elems) + } +} + +impl std::cmp::Eq for PlutusList {} + +to_from_bytes!(PlutusList); + impl From> for PlutusList { fn from(elems: Vec) -> Self { Self { elems, definite_encoding: None, + cbor_set_type: None, } } } diff --git a/rust/src/protocol_types/plutus/plutus_scripts.rs b/rust/src/protocol_types/plutus/plutus_scripts.rs index 4d6db98a..7e54549c 100644 --- a/rust/src/protocol_types/plutus/plutus_scripts.rs +++ b/rust/src/protocol_types/plutus/plutus_scripts.rs @@ -1,63 +1,93 @@ +use std::collections::HashMap; +use itertools::Itertools; +use std::slice; use crate::*; #[wasm_bindgen] -#[derive( - Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema, -)] -pub struct PlutusScripts(pub(crate) Vec); +#[derive(Clone, Debug)] +pub struct PlutusScripts { + scripts: Vec, + cbor_set_type: Option>, +} impl_to_from!(PlutusScripts); impl NoneOrEmpty for PlutusScripts { fn is_none_or_empty(&self) -> bool { - self.0.is_empty() + self.scripts.is_empty() } } #[wasm_bindgen] impl PlutusScripts { pub fn new() -> Self { - Self(Vec::new()) + Self { + scripts: Vec::new(), + cbor_set_type: None, + } + } + + pub(crate) fn from_vec( + scripts: Vec, + cbor_set_type: Option, + ) -> Self { + Self { + scripts, + cbor_set_type: cbor_set_type.map(|t| { + let mut m = HashMap::new(); + m.insert(Language::new_plutus_v1(), t.clone()); + m.insert(Language::new_plutus_v2(), t.clone()); + m.insert(Language::new_plutus_v3(), t.clone()); + m + }), + } } pub fn len(&self) -> usize { - self.0.len() + self.scripts.len() } pub fn get(&self, index: usize) -> PlutusScript { - self.0[index].clone() + self.scripts[index].clone() } pub fn add(&mut self, elem: &PlutusScript) { - self.0.push(elem.clone()); + self.scripts.push(elem.clone()); } #[allow(dead_code)] pub(crate) fn by_version(&self, language: &Language) -> PlutusScripts { - PlutusScripts( - self.0 + Self::from_vec( + self.scripts .iter() .filter(|s| s.language_version().eq(language)) .map(|s| s.clone()) .collect(), + self.cbor_set_type.as_ref().map(|x| x.get(language).cloned()).flatten(), ) } pub(crate) fn has_version(&self, language: &Language) -> bool { - self.0.iter().any(|s| s.language_version().eq(language)) + self.scripts + .iter() + .any(|s| s.language_version().eq(language)) } - pub(crate) fn merge(&self, other: &PlutusScripts) -> PlutusScripts { + pub(crate) fn merge(&self, other: &PlutusScripts, version: &Language) -> PlutusScripts { let mut res = self.clone(); - for s in &other.0 { + for s in &other.scripts { res.add(s); } + res.set_set_type( + other.get_set_type(version).unwrap_or(CborSetType::Tagged), + version, + ); res } pub(crate) fn view(&self, version: &Language) -> Vec<&PlutusScript> { let mut res = Vec::new(); - for script in &self.0 { + for script in &self.scripts { if !script.language_version().eq(version) { continue; } @@ -69,7 +99,7 @@ impl PlutusScripts { pub(crate) fn deduplicated_view(&self, version: Option<&Language>) -> Vec<&PlutusScript> { let mut dedup = BTreeSet::new(); let mut res = Vec::new(); - for script in &self.0 { + for script in &self.scripts { if let Some(version) = version { if !script.language_version().eq(version) { continue; @@ -85,16 +115,95 @@ impl PlutusScripts { pub(crate) fn deduplicated_clone(&self) -> PlutusScripts { let mut dedup = BTreeSet::new(); let mut scripts = Vec::new(); - for script in &self.0 { + for script in &self.scripts { if dedup.insert(script.clone()) { scripts.push(script.clone()); } } - PlutusScripts(scripts) + Self { + scripts, + cbor_set_type: self.cbor_set_type.clone(), + } } #[allow(dead_code)] pub(crate) fn contains(&self, script: &PlutusScript) -> bool { - self.0.contains(&script) + self.scripts.contains(&script) + } + + pub(crate) fn get_set_type(&self, language: &Language) -> Option { + self.cbor_set_type.as_ref().map(|m| m.get(language).cloned()).flatten() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType, language: &Language) { + if self.cbor_set_type.is_none() { + self.cbor_set_type = Some(HashMap::new()); + } + if let Some(m) = &mut self.cbor_set_type { + m.insert(language.clone(), cbor_set_type); + } + } +} + +impl<'a> IntoIterator for &'a PlutusScripts { + type Item = &'a PlutusScript; + type IntoIter = slice::Iter<'a, PlutusScript>; + + fn into_iter(self) -> Self::IntoIter { + self.scripts.iter() + } +} + +impl PartialEq for PlutusScripts { + fn eq(&self, other: &Self) -> bool { + self.scripts == other.scripts + } +} + +impl Eq for PlutusScripts {} + +impl PartialOrd for PlutusScripts { + fn partial_cmp(&self, other: &Self) -> Option { + self.scripts.partial_cmp(&other.scripts) + } +} + +impl Ord for PlutusScripts { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.scripts.cmp(&other.scripts) + } +} + +impl serde::Serialize for PlutusScripts { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.scripts + .iter() + .collect_vec() + .serialize(serializer) + } +} + +impl<'de> serde::de::Deserialize<'de> for PlutusScripts { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let scripts_vec = as serde::de::Deserialize>::deserialize(deserializer)?; + Ok(Self::from_vec(scripts_vec, None)) + } +} + +impl JsonSchema for PlutusScripts { + fn schema_name() -> String { + String::from("PlutusScripts") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + Vec::::json_schema(gen) + } + fn is_referenceable() -> bool { + Vec::::is_referenceable() } } diff --git a/rust/src/protocol_types/plutus/redeemers.rs b/rust/src/protocol_types/plutus/redeemers.rs index 713f2d98..b0111195 100644 --- a/rust/src/protocol_types/plutus/redeemers.rs +++ b/rust/src/protocol_types/plutus/redeemers.rs @@ -41,6 +41,14 @@ impl Redeemers { self.redeemers.push(elem.clone()); } + /// WARNING: This function will be removed in after next hard fork + pub fn get_container_type(&self) -> CborContainerType { + match &self.serialization_format { + Some(format) => format.clone(), + None => CborContainerType::Map, + } + } + pub fn total_ex_units(&self) -> Result { let mut tot_mem = BigNum::zero(); let mut tot_steps = BigNum::zero(); diff --git a/rust/src/protocol_types/tx_inputs.rs b/rust/src/protocol_types/tx_inputs.rs index 886b7952..97936e3e 100644 --- a/rust/src/protocol_types/tx_inputs.rs +++ b/rust/src/protocol_types/tx_inputs.rs @@ -1,14 +1,17 @@ use crate::*; -use std::slice::Iter; -use std::vec::IntoIter; +use itertools::Itertools; +use std::hash::{Hash, Hasher}; +use std::iter::Map; +use std::ops::Deref; +use std::rc::Rc; +use std::slice; #[wasm_bindgen] -#[derive( - Clone, Debug, Eq, Ord, PartialEq, PartialOrd, -)] +#[derive(Clone, Debug)] pub struct TransactionInputs { - pub(crate) inputs: Vec, - pub(crate) dedup: BTreeSet, + pub(crate) inputs: Vec>, + pub(crate) dedup: BTreeSet>, + pub(crate) cbor_set_type: CborSetType, } impl_to_from!(TransactionInputs); @@ -25,6 +28,18 @@ impl TransactionInputs { Self { inputs: Vec::new(), dedup: BTreeSet::new(), + cbor_set_type: CborSetType::Tagged, + } + } + + pub(crate) fn new_from_prepared_fields( + inputs: Vec>, + dedup: BTreeSet>, + ) -> Self { + Self { + inputs, + dedup, + cbor_set_type: CborSetType::Tagged, } } @@ -33,15 +48,15 @@ impl TransactionInputs { } pub fn get(&self, index: usize) -> TransactionInput { - self.inputs[index].clone() + self.inputs[index].deref().clone() } /// Add a new `TransactionInput` to the set. /// Returns `true` if the element was not already present in the set. - /// Note that the `TransactionInput` is added to the set only if it is not already present. - pub fn add(&mut self, elem: &TransactionInput) -> bool { - if self.dedup.insert(elem.clone()) { - self.inputs.push(elem.clone()); + pub fn add(&mut self, input: &TransactionInput) -> bool { + let input_rc = Rc::new(input.clone()); + if self.dedup.insert(input_rc.clone()) { + self.inputs.push(input_rc.clone()); true } else { false @@ -53,64 +68,93 @@ impl TransactionInputs { self.dedup.contains(elem) } - pub(crate) fn add_move(&mut self, elem: TransactionInput) { - if self.dedup.insert(elem.clone()) { - self.inputs.push(elem); + pub fn to_option(&self) -> Option { + if !self.inputs.is_empty() { + Some(self.clone()) + } else { + None } } pub(crate) fn from_vec(inputs_vec: Vec) -> Self { - let mut inputs = Self::new(); + let mut dedup = BTreeSet::new(); + let mut inputs = Vec::new(); for input in inputs_vec { - inputs.add_move(input); + let input_rc = Rc::new(input.clone()); + if dedup.insert(input_rc.clone()) { + inputs.push(input_rc); + } } - inputs + + Self::new_from_prepared_fields(inputs, dedup) } - pub fn to_option(&self) -> Option { - if self.len() > 0 { - Some(self.clone()) - } else { - None - } + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; } } impl<'a> IntoIterator for &'a TransactionInputs { type Item = &'a TransactionInput; - type IntoIter = Iter<'a, TransactionInput>; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a TransactionInput, + >; fn into_iter(self) -> Self::IntoIter { - self.inputs.iter() + self.inputs.iter().map(|rc| rc.as_ref()) } } -impl IntoIterator for TransactionInputs { - type Item = TransactionInput; - type IntoIter = IntoIter; +impl PartialEq for TransactionInputs { + fn eq(&self, other: &Self) -> bool { + self.inputs == other.inputs + } +} - fn into_iter(self) -> Self::IntoIter { - self.inputs.into_iter() +impl Eq for TransactionInputs {} + +impl PartialOrd for TransactionInputs { + fn partial_cmp(&self, other: &Self) -> Option { + self.inputs.partial_cmp(&other.inputs) + } +} + +impl Ord for TransactionInputs { + fn cmp(&self, other: &Self) -> Ordering { + self.inputs.cmp(&other.inputs) + } +} + +impl Hash for TransactionInputs { + fn hash(&self, state: &mut H) { + self.inputs.hash(state); } } impl serde::Serialize for TransactionInputs { fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, + where + S: serde::Serializer, { - self.inputs.serialize(serializer) + self.inputs + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } impl<'de> serde::de::Deserialize<'de> for TransactionInputs { fn deserialize(deserializer: D) -> Result - where - D: serde::de::Deserializer<'de>, + where + D: serde::de::Deserializer<'de>, { - let vec = as serde::de::Deserialize>::deserialize( - deserializer, - )?; + let vec = as serde::de::Deserialize>::deserialize(deserializer)?; Ok(Self::from_vec(vec)) } } diff --git a/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs b/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs index 9215bb46..fe62574b 100644 --- a/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs +++ b/rust/src/protocol_types/witnesses/bootstrap_witnesses.rs @@ -1,23 +1,50 @@ -use crate::*; +use std::hash::{Hash, Hasher}; +use std::rc::Rc; +use std::ops::Deref; +use std::slice; +use std::iter::Map; use std::collections::HashSet; +use itertools::Itertools; +use schemars::JsonSchema; +use crate::*; #[wasm_bindgen] -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug)] pub struct BootstrapWitnesses { - witnesses: Vec, - - //for deduplication purpose - dedup: HashSet, + witnesses: Vec>, + dedup: HashSet>, + cbor_set_type: CborSetType, + force_original_cbor_set_type: bool, } impl_to_from!(BootstrapWitnesses); +impl NoneOrEmpty for BootstrapWitnesses { + fn is_none_or_empty(&self) -> bool { + self.witnesses.is_empty() + } +} + #[wasm_bindgen] impl BootstrapWitnesses { pub fn new() -> Self { Self { witnesses: Vec::new(), dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, + force_original_cbor_set_type: false, + } + } + + pub(crate) fn new_from_prepared_fields( + witnesses: Vec>, + dedup: HashSet>, + ) -> Self { + Self { + witnesses, + dedup, + cbor_set_type: CborSetType::Tagged, + force_original_cbor_set_type: false, } } @@ -26,48 +53,83 @@ impl BootstrapWitnesses { } pub fn get(&self, index: usize) -> BootstrapWitness { - self.witnesses[index].clone() + self.witnesses[index].deref().clone() } /// Add a new `BootstrapWitness` to the set. /// Returns `true` if the element was not already present in the set. - pub fn add(&mut self, elem: &BootstrapWitness) -> bool { - if self.dedup.insert(elem.clone()) { - self.witnesses.push(elem.clone()); + pub fn add(&mut self, witness: &BootstrapWitness) -> bool { + let witness_rc = Rc::new(witness.clone()); + if self.dedup.insert(witness_rc.clone()) { + self.witnesses.push(witness_rc); true } else { false } } - pub(crate) fn get_vec_wits(&self) -> &Vec { - &self.witnesses - } - - pub(crate) fn from_vec_wits(wits: Vec) -> Self { + pub(crate) fn from_vec(witnesses_vec: Vec) -> Self { let mut dedup = HashSet::new(); let mut witnesses = Vec::new(); - for wit in wits { - if dedup.insert(wit.clone()) { - witnesses.push(wit); + for witness in witnesses_vec { + let witness_rc = Rc::new(witness.clone()); + if dedup.insert(witness_rc.clone()) { + witnesses.push(witness_rc); } } - Self { - witnesses, - dedup, - } + Self::new_from_prepared_fields(witnesses, dedup) + } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; + } + + pub(crate) fn get_vec_wits(&self) -> &Vec> { + &self.witnesses } #[allow(dead_code)] pub (crate) fn contains(&self, elem: &BootstrapWitness) -> bool { self.dedup.contains(elem) } + + pub(crate) fn set_force_original_cbor_set_type(&mut self, force_original_cbor_set_type: bool) { + self.force_original_cbor_set_type = force_original_cbor_set_type; + } + + pub(crate) fn force_original_cbor_set_type(&self) -> bool { + self.force_original_cbor_set_type + } } -impl NoneOrEmpty for BootstrapWitnesses { - fn is_none_or_empty(&self) -> bool { - self.witnesses.is_empty() +impl<'a> IntoIterator for &'a BootstrapWitnesses { + type Item = &'a BootstrapWitness; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a BootstrapWitness, + >; + + fn into_iter(self) -> Self::IntoIter { + self.witnesses.iter().map(|rc| rc.as_ref()) + } +} + +impl PartialEq for BootstrapWitnesses { + fn eq(&self, other: &Self) -> bool { + self.witnesses == other.witnesses + } +} + +impl Eq for BootstrapWitnesses {} + +impl Hash for BootstrapWitnesses { + fn hash(&self, state: &mut H) { + self.witnesses.hash(state); } } @@ -76,30 +138,32 @@ impl serde::Serialize for BootstrapWitnesses { where S: serde::Serializer, { - let wits = self.get_vec_wits(); - wits.serialize(serializer) + self.witnesses + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } impl<'de> serde::de::Deserialize<'de> for BootstrapWitnesses { fn deserialize(deserializer: D) -> Result where - D: serde::de::Deserializer<'de>, + D: serde::Deserializer<'de>, { - let wits = as serde::de::Deserialize>::deserialize(deserializer)?; - - Ok(Self::from_vec_wits(wits)) + let witnesses_vec = as serde::de::Deserialize>::deserialize(deserializer)?; + Ok(Self::from_vec(witnesses_vec)) } } impl JsonSchema for BootstrapWitnesses { - fn is_referenceable() -> bool { - Vec::::is_referenceable() - } fn schema_name() -> String { String::from("BootstrapWitnesses") } fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { Vec::::json_schema(gen) } -} + fn is_referenceable() -> bool { + Vec::::is_referenceable() + } +} \ No newline at end of file diff --git a/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs b/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs index 7e8f0b84..1a3efce3 100644 --- a/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs +++ b/rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs @@ -10,12 +10,33 @@ use crate::*; #[wasm_bindgen] #[derive(Clone, Debug, Eq, PartialEq)] pub struct FixedTxWitnessesSet { - pub(crate) raw_parts: TransactionWitnessSetRaw, - pub(crate) tx_witnesses_set: TransactionWitnessSet, + raw_parts: TransactionWitnessSetRaw, + tx_witnesses_set: TransactionWitnessSet, } #[wasm_bindgen] impl FixedTxWitnessesSet { + + pub(crate) fn new(mut witnesses_set: TransactionWitnessSet, raw_parts: TransactionWitnessSetRaw) -> Self { + if let Some(bootstraps) = &mut witnesses_set.bootstraps { + bootstraps.set_force_original_cbor_set_type(true); + } + if let Some(vkeys) = &mut witnesses_set.vkeys { + vkeys.set_force_original_cbor_set_type(true); + } + Self { + tx_witnesses_set: witnesses_set, + raw_parts, + } + } + + pub(crate) fn new_empty() -> Self { + Self { + tx_witnesses_set: TransactionWitnessSet::new(), + raw_parts: TransactionWitnessSetRaw::new(), + } + } + pub fn tx_witnesses_set(&self) -> TransactionWitnessSet { self.tx_witnesses_set.clone() } @@ -57,4 +78,12 @@ impl FixedTxWitnessesSet { let mut raw = Deserializer::from(std::io::Cursor::new(data)); Ok(Self::deserialize(&mut raw)?) } + + pub(crate) fn tx_witnesses_set_ref(&self) -> &TransactionWitnessSet { + &self.tx_witnesses_set + } + + pub(crate) fn raw_parts_ref(&self) -> &TransactionWitnessSetRaw { + &self.raw_parts + } } \ No newline at end of file diff --git a/rust/src/protocol_types/witnesses/vkeywitnesses.rs b/rust/src/protocol_types/witnesses/vkeywitnesses.rs index 791f0c33..94bce1d1 100644 --- a/rust/src/protocol_types/witnesses/vkeywitnesses.rs +++ b/rust/src/protocol_types/witnesses/vkeywitnesses.rs @@ -1,21 +1,53 @@ -use hashlink::LinkedHashSet; +use std::hash::{Hash, Hasher}; +use std::ops::Deref; +use std::rc::Rc; +use std::slice; +use std::iter::Map; +use std::collections::HashSet; +use itertools::Itertools; +use schemars::JsonSchema; use crate::*; #[wasm_bindgen] -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive( + Clone, + Debug, +)] pub struct Vkeywitnesses { - pub(crate) witnesses: Vec, - pub(crate) dedup: LinkedHashSet, + witnesses: Vec>, + dedup: HashSet>, + cbor_set_type: CborSetType, + force_original_cbor_set_type: bool, } impl_to_from!(Vkeywitnesses); +impl NoneOrEmpty for Vkeywitnesses { + fn is_none_or_empty(&self) -> bool { + self.witnesses.is_empty() + } +} + #[wasm_bindgen] impl Vkeywitnesses { pub fn new() -> Self { Self { witnesses: Vec::new(), - dedup: LinkedHashSet::new(), + dedup: HashSet::new(), + cbor_set_type: CborSetType::Tagged, + force_original_cbor_set_type: false, + } + } + + pub(crate) fn new_from_prepared_fields( + witnesses: Vec>, + dedup: HashSet>, + ) -> Self { + Self { + witnesses, + dedup, + cbor_set_type: CborSetType::Tagged, + force_original_cbor_set_type: false, } } @@ -24,46 +56,85 @@ impl Vkeywitnesses { } pub fn get(&self, index: usize) -> Vkeywitness { - self.witnesses[index].clone() + self.witnesses[index].deref().clone() } /// Add a new `Vkeywitness` to the set. /// Returns `true` if the element was not already present in the set. - pub fn add(&mut self, elem: &Vkeywitness) -> bool { - if self.dedup.insert(elem.clone()) { - self.witnesses.push(elem.clone()); + pub fn add(&mut self, witness: &Vkeywitness) -> bool { + let witness_rc = Rc::new(witness.clone()); + if self.dedup.insert(witness_rc.clone()) { + self.witnesses.push(witness_rc.clone()); true } else { false } } - pub(crate) fn add_move(&mut self, elem: Vkeywitness) { - if self.dedup.insert(elem.clone()) { - self.witnesses.push(elem); + pub(crate) fn add_move(&mut self, witness: Vkeywitness) { + let witness_rc = Rc::new(witness); + if self.dedup.insert(witness_rc.clone()) { + self.witnesses.push(witness_rc); } } pub(crate) fn from_vec(vec: Vec) -> Self { - let mut dedup = LinkedHashSet::new(); + let mut dedup = HashSet::new(); let mut witnesses = Vec::new(); - for elem in vec { - if dedup.insert(elem.clone()) { - witnesses.push(elem); + for witness in vec { + let witness_rc = Rc::new(witness.clone()); + if dedup.insert(witness_rc.clone()) { + witnesses.push(witness_rc); } } - Self { witnesses, dedup } + Self::new_from_prepared_fields(witnesses, dedup) + } + + pub(crate) fn get_set_type(&self) -> CborSetType { + self.cbor_set_type.clone() + } + + pub(crate) fn set_set_type(&mut self, cbor_set_type: CborSetType) { + self.cbor_set_type = cbor_set_type; } #[allow(dead_code)] - pub(crate) fn contains(&self, elem: &Vkeywitness) -> bool { - self.dedup.contains(elem) + pub(crate) fn contains(&self, witness: &Vkeywitness) -> bool { + self.dedup.contains(witness) + } + + pub(crate) fn set_force_original_cbor_set_type(&mut self, force_original_cbor_set_type: bool) { + self.force_original_cbor_set_type = force_original_cbor_set_type; + } + + pub(crate) fn force_original_cbor_set_type(&self) -> bool { + self.force_original_cbor_set_type } } -impl NoneOrEmpty for Vkeywitnesses { - fn is_none_or_empty(&self) -> bool { - self.witnesses.is_empty() +impl<'a> IntoIterator for &'a Vkeywitnesses { + type Item = &'a Vkeywitness; + type IntoIter = Map< + slice::Iter<'a, Rc>, + fn(&'a Rc) -> &'a Vkeywitness, + >; + + fn into_iter(self) -> Self::IntoIter { + self.witnesses.iter().map(|rc| rc.as_ref()) + } +} + +impl PartialEq for Vkeywitnesses { + fn eq(&self, other: &Self) -> bool { + self.witnesses == other.witnesses + } +} + +impl Eq for Vkeywitnesses {} + +impl Hash for Vkeywitnesses { + fn hash(&self, state: &mut H) { + self.witnesses.hash(state); } } @@ -72,16 +143,20 @@ impl serde::Serialize for Vkeywitnesses { where S: serde::Serializer, { - self.witnesses.serialize(serializer) + self.witnesses + .iter() + .map(|x| x.deref()) + .collect_vec() + .serialize(serializer) } } impl<'de> serde::de::Deserialize<'de> for Vkeywitnesses { fn deserialize(deserializer: D) -> Result where - D: serde::de::Deserializer<'de>, + D: serde::Deserializer<'de>, { - let vec = as serde::de::Deserialize>::deserialize(deserializer)?; + let vec = as serde::de::Deserialize>::deserialize(deserializer)?; Ok(Self::from_vec(vec)) } } @@ -96,4 +171,4 @@ impl JsonSchema for Vkeywitnesses { fn is_referenceable() -> bool { Vec::::is_referenceable() } -} +} \ No newline at end of file diff --git a/rust/src/serialization/certificates/certificates_collection.rs b/rust/src/serialization/certificates/certificates_collection.rs index 06b12c7e..ec81f7aa 100644 --- a/rust/src/serialization/certificates/certificates_collection.rs +++ b/rust/src/serialization/certificates/certificates_collection.rs @@ -6,8 +6,7 @@ impl Serialize for Certificates { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; serializer.write_array(Len::Len(self.len() as u64))?; for element in &self.certs { element.serialize(serializer)?; @@ -18,7 +17,7 @@ impl Serialize for Certificates { impl Deserialize for Certificates { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag= skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { let len = raw.array()?; @@ -34,6 +33,12 @@ impl Deserialize for Certificates { Ok(()) })() .map_err(|e| e.annotate("Certificates"))?; - Ok(Self::from_vec(arr)) + let mut certs = Self::from_vec(arr); + if has_set_tag { + certs.set_set_type(CborSetType::Tagged); + } else { + certs.set_set_type(CborSetType::Untagged); + } + Ok(certs) } } diff --git a/rust/src/serialization/credentials.rs b/rust/src/serialization/credentials.rs index a45086fb..3338c890 100644 --- a/rust/src/serialization/credentials.rs +++ b/rust/src/serialization/credentials.rs @@ -6,10 +6,9 @@ impl cbor_event::se::Serialize for Credentials { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; - serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; - for element in self.to_vec() { + serializer.write_tag(258)?; + serializer.write_array(Len::Len(self.len() as u64))?; + for element in &self.credentials { element.serialize(serializer)?; } Ok(serializer) @@ -18,7 +17,7 @@ impl cbor_event::se::Serialize for Credentials { impl Deserialize for Credentials { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut creds = Credentials::new(); let mut counter = 0u64; (|| -> Result<_, DeserializeError> { @@ -36,6 +35,11 @@ impl Deserialize for Credentials { Ok(()) })() .map_err(|e| e.annotate("CredentialsSet"))?; + if has_set_tag { + creds.set_set_type(CborSetType::Tagged); + } else { + creds.set_set_type(CborSetType::Untagged); + } Ok(creds) } } \ No newline at end of file diff --git a/rust/src/serialization/ed25519_key_hashes.rs b/rust/src/serialization/ed25519_key_hashes.rs index 46d6a73e..079932b0 100644 --- a/rust/src/serialization/ed25519_key_hashes.rs +++ b/rust/src/serialization/ed25519_key_hashes.rs @@ -6,10 +6,9 @@ impl Serialize for Ed25519KeyHashes { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; - for element in self.to_vec() { + for element in self { element.serialize(serializer)?; } Ok(serializer) @@ -18,7 +17,7 @@ impl Serialize for Ed25519KeyHashes { impl Deserialize for Ed25519KeyHashes { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut creds = Ed25519KeyHashes::new(); let mut total = 0u64; (|| -> Result<_, DeserializeError> { @@ -36,6 +35,11 @@ impl Deserialize for Ed25519KeyHashes { Ok(()) })() .map_err(|e| e.annotate("Ed25519KeyHashes"))?; + if has_set_tag { + creds.set_set_type(CborSetType::Tagged); + } else { + creds.set_set_type(CborSetType::Untagged); + } Ok(creds) } } \ No newline at end of file diff --git a/rust/src/serialization/governance/proposals/voting_proposals.rs b/rust/src/serialization/governance/proposals/voting_proposals.rs index 64ee941a..b7265c6b 100644 --- a/rust/src/serialization/governance/proposals/voting_proposals.rs +++ b/rust/src/serialization/governance/proposals/voting_proposals.rs @@ -6,10 +6,9 @@ impl cbor_event::se::Serialize for VotingProposals { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; - for element in &self.proposals { + for element in self { element.serialize(serializer)?; } Ok(serializer) @@ -18,7 +17,7 @@ impl cbor_event::se::Serialize for VotingProposals { impl Deserialize for VotingProposals { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { skip_set_tag(raw)?; @@ -35,6 +34,12 @@ impl Deserialize for VotingProposals { Ok(()) })() .map_err(|e| e.annotate("VotingProposals"))?; - Ok(Self::from_vec(arr)) + let mut proposals = Self::from_vec(arr); + if has_set_tag { + proposals.set_set_type(CborSetType::Tagged); + } else { + proposals.set_set_type(CborSetType::Untagged); + } + Ok(proposals) } } diff --git a/rust/src/serialization/metadata.rs b/rust/src/serialization/metadata.rs index 3b73d1e4..58238fa2 100644 --- a/rust/src/serialization/metadata.rs +++ b/rust/src/serialization/metadata.rs @@ -403,9 +403,9 @@ impl Deserialize for AuxiliaryData { } read_len.finish()?; let mut plutus_scripts = None; - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v1); - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v2); - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v3); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v1, &Language::new_plutus_v1()); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v2, &Language::new_plutus_v2()); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v3, &Language::new_plutus_v3()); Ok(Self { metadata, diff --git a/rust/src/serialization/native_scripts.rs b/rust/src/serialization/native_scripts.rs index 8b3f5e7b..d711e613 100644 --- a/rust/src/serialization/native_scripts.rs +++ b/rust/src/serialization/native_scripts.rs @@ -6,8 +6,8 @@ impl cbor_event::se::Serialize for NativeScripts { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; - for element in &self.0 { + serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; + for element in self { element.serialize(serializer)?; } Ok(serializer) @@ -20,17 +20,16 @@ impl NativeScripts { need_deduplication: bool, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; if need_deduplication { let view = self.deduplicated_view(); - serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; + serializer.write_array(cbor_event::Len::Len(self.scripts.len() as u64))?; for element in view { element.serialize(serializer)?; } } else { - serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; - for element in &self.0 { + serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; + for element in self { element.serialize(serializer)?; } } @@ -40,7 +39,7 @@ impl NativeScripts { impl Deserialize for NativeScripts { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { let len = raw.array()?; @@ -56,6 +55,18 @@ impl Deserialize for NativeScripts { Ok(()) })() .map_err(|e| e.annotate("NativeScripts"))?; - Ok(Self(arr)) + + let set_type = if has_tag { + CborSetType::Tagged + } else { + CborSetType::Untagged + }; + + Ok( + Self { + scripts: arr, + cbor_tag_type: Some(set_type), + } + ) } } \ No newline at end of file diff --git a/rust/src/serialization/plutus/plutus_data.rs b/rust/src/serialization/plutus/plutus_data.rs index f3ce5f64..b8246cba 100644 --- a/rust/src/serialization/plutus/plutus_data.rs +++ b/rust/src/serialization/plutus/plutus_data.rs @@ -243,8 +243,7 @@ impl PlutusList { need_deduplication: bool, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; let use_definite_encoding = match self.definite_encoding { Some(definite) => definite, None => self.elems.is_empty(), @@ -272,7 +271,7 @@ impl PlutusList { impl Deserialize for PlutusList { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); let len = (|| -> Result<_, DeserializeError> { let len = raw.array()?; @@ -288,9 +287,17 @@ impl Deserialize for PlutusList { Ok(len) })() .map_err(|e| e.annotate("PlutusList"))?; + + let set_tag = if has_set_tag { + Some(CborSetType::Tagged) + } else { + Some(CborSetType::Untagged) + }; + Ok(Self { elems: arr, definite_encoding: Some(len != cbor_event::Len::Indefinite), + cbor_set_type: set_tag }) } } \ No newline at end of file diff --git a/rust/src/serialization/plutus/plutus_scripts.rs b/rust/src/serialization/plutus/plutus_scripts.rs index 37f30906..7467109b 100644 --- a/rust/src/serialization/plutus/plutus_scripts.rs +++ b/rust/src/serialization/plutus/plutus_scripts.rs @@ -6,8 +6,8 @@ impl cbor_event::se::Serialize for PlutusScripts { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; - for element in &self.0 { + serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; + for element in self { element.serialize(serializer)?; } Ok(serializer) @@ -34,8 +34,7 @@ impl PlutusScripts { version: &Language, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; let view = match need_deduplication { true => self.deduplicated_view(Some(version)), false => self.view(version), @@ -51,10 +50,9 @@ impl PlutusScripts { impl Deserialize for PlutusScripts { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { - skip_set_tag(raw)?; let len = raw.array()?; while match len { cbor_event::Len::Len(n) => arr.len() < n as usize, @@ -68,15 +66,22 @@ impl Deserialize for PlutusScripts { Ok(()) })() .map_err(|e| e.annotate("PlutusScripts"))?; - Ok(Self(arr)) + + let set_tag = if has_set_tag { + Some(CborSetType::Tagged) + } else { + Some(CborSetType::Untagged) + }; + + Ok(Self::from_vec(arr, set_tag)) } } impl PlutusScripts { pub(crate) fn deserialize_with_version(raw: &mut Deserializer, version: &Language) -> Result { let mut arr = Vec::new(); + let has_set_tag = skip_set_tag(raw)?; (|| -> Result<_, DeserializeError> { - skip_set_tag(raw)?; let len = raw.array()?; while match len { cbor_event::Len::Len(n) => arr.len() < n as usize, @@ -90,6 +95,13 @@ impl PlutusScripts { Ok(()) })() .map_err(|e| e.annotate("PlutusScripts"))?; - Ok(Self(arr)) + + let set_tag = if has_set_tag { + Some(CborSetType::Tagged) + } else { + Some(CborSetType::Untagged) + }; + + Ok(Self::from_vec(arr, set_tag)) } } \ No newline at end of file diff --git a/rust/src/serialization/plutus/redeemers.rs b/rust/src/serialization/plutus/redeemers.rs index 1dc73c12..afd871e1 100644 --- a/rust/src/serialization/plutus/redeemers.rs +++ b/rust/src/serialization/plutus/redeemers.rs @@ -1,19 +1,19 @@ use crate::*; use crate::serialization::utils::is_break_tag; -impl cbor_event::se::Serialize for Redeemers { +impl Serialize for Redeemers { fn serialize<'se, W: Write>( &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - match self.serialization_format { - Some(CborContainerType::Map) => { + match self.get_container_type() { + CborContainerType::Map => { serializer.write_map(Len::Len(self.redeemers.len() as u64))?; for element in &self.redeemers { element.serialize_as_map_item(serializer)?; } } - _ => { + CborContainerType::Array => { serializer.write_array(Len::Len(self.redeemers.len() as u64))?; for element in &self.redeemers { element.serialize_as_array_item(serializer)?; diff --git a/rust/src/serialization/ser_info/types.rs b/rust/src/serialization/ser_info/types.rs index 30913ad0..a49c1ef4 100644 --- a/rust/src/serialization/ser_info/types.rs +++ b/rust/src/serialization/ser_info/types.rs @@ -6,3 +6,10 @@ pub enum CborContainerType { Array = 0, Map = 1, } + +#[wasm_bindgen] +#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] +pub enum CborSetType { + Tagged = 0, + Untagged = 1, +} \ No newline at end of file diff --git a/rust/src/serialization/tx_inputs.rs b/rust/src/serialization/tx_inputs.rs index 7fcc683d..4e6de28b 100644 --- a/rust/src/serialization/tx_inputs.rs +++ b/rust/src/serialization/tx_inputs.rs @@ -6,8 +6,7 @@ impl cbor_event::se::Serialize for TransactionInputs { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + serializer.write_tag(258)?; serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; for element in &self.inputs { element.serialize(serializer)?; @@ -18,7 +17,7 @@ impl cbor_event::se::Serialize for TransactionInputs { impl Deserialize for TransactionInputs { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { let len = raw.array()?; @@ -34,6 +33,12 @@ impl Deserialize for TransactionInputs { Ok(()) })() .map_err(|e| e.annotate("TransactionInputs"))?; - Ok(Self::from_vec(arr)) + let mut inputs = TransactionInputs::from_vec(arr); + if has_set_tag { + inputs.set_set_type(CborSetType::Tagged); + } else { + inputs.set_set_type(CborSetType::Untagged); + } + Ok(inputs) } } \ No newline at end of file diff --git a/rust/src/serialization/utils.rs b/rust/src/serialization/utils.rs index 8b9b7015..bc0cc58e 100644 --- a/rust/src/serialization/utils.rs +++ b/rust/src/serialization/utils.rs @@ -99,10 +99,11 @@ pub(super) fn check_len_indefinite( pub(crate) fn merge_option_plutus_list( left: Option, right: Option, + right_version: &Language, ) -> Option { if let Some(left) = left { if let Some(right) = right { - return Some(left.merge(&right)); + return Some(left.merge(&right, right_version)); } else { return Some(left); } @@ -114,7 +115,7 @@ pub(crate) fn merge_option_plutus_list( pub(super) fn skip_tag( raw: &mut Deserializer, tag: u64, -) -> Result<(), DeserializeError> { +) -> Result { if let Ok(extracted_tag) = raw.tag() { if extracted_tag != tag { return Err(DeserializeError::new( @@ -125,14 +126,14 @@ pub(super) fn skip_tag( }, )); } - return Ok(()); + return Ok(true); } - Ok(()) + Ok(false) } pub(super) fn skip_set_tag( raw: &mut Deserializer, -) -> Result<(), DeserializeError> { +) -> Result { skip_tag(raw, 258) } diff --git a/rust/src/serialization/witnesses/bootstrap_witnesses.rs b/rust/src/serialization/witnesses/bootstrap_witnesses.rs index d4d4464c..b46aac7f 100644 --- a/rust/src/serialization/witnesses/bootstrap_witnesses.rs +++ b/rust/src/serialization/witnesses/bootstrap_witnesses.rs @@ -1,7 +1,7 @@ use std::io::{BufRead, Seek, Write}; use cbor_event::de::Deserializer; use cbor_event::se::Serializer; -use crate::{BootstrapWitness, BootstrapWitnesses, DeserializeError}; +use crate::{BootstrapWitness, BootstrapWitnesses, CborSetType, DeserializeError}; use crate::protocol_types::Deserialize; use crate::serialization::utils::skip_set_tag; @@ -10,8 +10,13 @@ impl cbor_event::se::Serialize for BootstrapWitnesses { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; + if self.force_original_cbor_set_type() { + if self.get_set_type() == CborSetType::Tagged { + serializer.write_tag(258)?; + } + } else { + serializer.write_tag(258)?; + } serializer.write_array(cbor_event::Len::Len(self.get_vec_wits().len() as u64))?; for element in self.get_vec_wits() { element.serialize(serializer)?; @@ -22,7 +27,7 @@ impl cbor_event::se::Serialize for BootstrapWitnesses { impl Deserialize for BootstrapWitnesses { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut arr = Vec::new(); (|| -> Result<_, DeserializeError> { let len = raw.array()?; @@ -39,6 +44,14 @@ impl Deserialize for BootstrapWitnesses { Ok(()) })() .map_err(|e| e.annotate("BootstrapWitnesses"))?; - Ok(Self::from_vec_wits(arr)) + + let mut witnesses = Self::from_vec(arr); + if has_set_tag { + witnesses.set_set_type(CborSetType::Tagged); + } else { + witnesses.set_set_type(CborSetType::Untagged); + } + + Ok(witnesses) } } \ No newline at end of file diff --git a/rust/src/serialization/witnesses/fixed_tx_witnesses_set.rs b/rust/src/serialization/witnesses/fixed_tx_witnesses_set.rs index 3df00197..1c53e1eb 100644 --- a/rust/src/serialization/witnesses/fixed_tx_witnesses_set.rs +++ b/rust/src/serialization/witnesses/fixed_tx_witnesses_set.rs @@ -6,7 +6,7 @@ use crate::{DeserializeError}; impl cbor_event::se::Serialize for FixedTxWitnessesSet { fn serialize<'a, W: Write + Sized>(&self, serializer: &'a mut Serializer) -> cbor_event::Result<&'a mut Serializer> { - super::transaction_witnesses_set::serialize(&self.tx_witnesses_set, Some(&self.raw_parts), serializer) + super::transaction_witnesses_set::serialize(self.tx_witnesses_set_ref(), Some(self.raw_parts_ref()), serializer) } } @@ -16,10 +16,7 @@ impl Deserialize for FixedTxWitnessesSet { Self: Sized { let (witness_set, raw_parts) = super::transaction_witnesses_set::deserialize(raw, true)?; - Ok(Self { - tx_witnesses_set: witness_set, - raw_parts - }) + Ok(Self::new(witness_set, raw_parts)) } } diff --git a/rust/src/serialization/witnesses/transaction_witnesses_set.rs b/rust/src/serialization/witnesses/transaction_witnesses_set.rs index c3dde252..77f285c9 100644 --- a/rust/src/serialization/witnesses/transaction_witnesses_set.rs +++ b/rust/src/serialization/witnesses/transaction_witnesses_set.rs @@ -181,9 +181,9 @@ pub(super) fn deserialize(raw: &mut Deserializer, with_raw } read_len.finish()?; let mut plutus_scripts = None; - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v1); - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v2); - plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v3); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v1, &Language::new_plutus_v1()); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v2, &Language::new_plutus_v2()); + plutus_scripts = merge_option_plutus_list(plutus_scripts, plutus_scripts_v3, &Language::new_plutus_v3()); Ok((TransactionWitnessSet { vkeys, diff --git a/rust/src/serialization/witnesses/vkeywitnesses.rs b/rust/src/serialization/witnesses/vkeywitnesses.rs index f3190569..c7c3f0e5 100644 --- a/rust/src/serialization/witnesses/vkeywitnesses.rs +++ b/rust/src/serialization/witnesses/vkeywitnesses.rs @@ -2,7 +2,7 @@ use std::io::{BufRead, Seek, Write}; use cbor_event::de::Deserializer; use cbor_event::se::Serializer; use crate::protocol_types::Deserialize; -use crate::{DeserializeError, Vkeywitness, Vkeywitnesses}; +use crate::{CborSetType, DeserializeError, Vkeywitness, Vkeywitnesses}; use crate::serialization::utils::skip_set_tag; impl cbor_event::se::Serialize for Vkeywitnesses { @@ -10,10 +10,15 @@ impl cbor_event::se::Serialize for Vkeywitnesses { &self, serializer: &'se mut Serializer, ) -> cbor_event::Result<&'se mut Serializer> { - //TODO: uncomment this line when we conway ero will come - //serializer.write_tag(258)?; - serializer.write_array(cbor_event::Len::Len(self.witnesses.len() as u64))?; - for element in &self.witnesses { + if self.force_original_cbor_set_type() { + if self.get_set_type() == CborSetType::Tagged { + serializer.write_tag(258)?; + } + } else { + serializer.write_tag(258)?; + } + serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; + for element in self { element.serialize(serializer)?; } Ok(serializer) @@ -22,7 +27,7 @@ impl cbor_event::se::Serialize for Vkeywitnesses { impl Deserialize for Vkeywitnesses { fn deserialize(raw: &mut Deserializer) -> Result { - skip_set_tag(raw)?; + let has_set_tag = skip_set_tag(raw)?; let mut wits = Vkeywitnesses::new(); let mut total = 0u64; (|| -> Result<_, DeserializeError> { @@ -42,6 +47,12 @@ impl Deserialize for Vkeywitnesses { Ok(()) })() .map_err(|e| e.annotate("Vkeywitnesses"))?; + + if has_set_tag { + wits.set_set_type(CborSetType::Tagged); + } else { + wits.set_set_type(CborSetType::Untagged); + } Ok(wits) } } \ No newline at end of file diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index b713f700..6035c607 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -1,5 +1,5 @@ use crate::tests::helpers::harden; -use crate::tests::fakes::{fake_byron_address, fake_anchor, fake_change_address, fake_default_tx_builder, fake_linear_fee, fake_reallistic_tx_builder, fake_redeemer, fake_redeemer_zero_cost, fake_rich_tx_builder, fake_tx_builder, fake_tx_builder_with_amount, fake_tx_builder_with_fee, fake_tx_builder_with_fee_and_pure_change, fake_tx_builder_with_fee_and_val_size, fake_tx_builder_with_key_deposit, fake_base_address, fake_bytes_32, fake_data_hash, fake_key_hash, fake_plutus_script_and_hash, fake_policy_id, fake_script_hash, fake_tx_hash, fake_tx_input, fake_tx_input2, fake_value, fake_value2, fake_vkey_witness, fake_root_key_15, fake_base_address_with_payment_cred, fake_bootsrap_witness, fake_bootsrap_witness_with_attrs}; +use crate::tests::fakes::{fake_byron_address, fake_anchor, fake_change_address, fake_default_tx_builder, fake_linear_fee, fake_reallistic_tx_builder, fake_redeemer, fake_redeemer_zero_cost, fake_rich_tx_builder, fake_tx_builder, fake_tx_builder_with_amount, fake_tx_builder_with_fee, fake_tx_builder_with_fee_and_pure_change, fake_tx_builder_with_fee_and_val_size, fake_tx_builder_with_key_deposit, fake_base_address, fake_bytes_32, fake_data_hash, fake_key_hash, fake_plutus_script_and_hash, fake_policy_id, fake_script_hash, fake_tx_hash, fake_tx_input, fake_tx_input2, fake_value, fake_value2, fake_vkey_witness, fake_root_key_15, fake_base_address_with_payment_cred, fake_bootsrap_witness_with_attrs}; use crate::*; use crate::builders::fakes::fake_private_key; @@ -98,7 +98,7 @@ fn build_tx_with_change() { .checked_add(&Value::new(&tx_builder.get_fee_if_set().unwrap())) .unwrap() ); - assert_eq!(tx_builder.full_size().unwrap(), 285); + assert_eq!(tx_builder.full_size().unwrap(), 291); assert_eq!(tx_builder.output_sizes(), vec![62, 65]); let _final_tx = tx_builder.build(); // just test that it doesn't throw } @@ -172,7 +172,7 @@ fn build_tx_with_change_with_datum() { .checked_add(&Value::new(&tx_builder.get_fee_if_set().unwrap())) .unwrap() ); - assert_eq!(tx_builder.full_size().unwrap(), 319); + assert_eq!(tx_builder.full_size().unwrap(), 325); assert_eq!(tx_builder.output_sizes(), vec![62, 99]); let _final_tx = tx_builder.build(); // just test that it doesn't throw } @@ -304,8 +304,8 @@ fn build_tx_with_certs() { ) .to_address(); tx_builder.add_change_if_needed(&change_addr).unwrap(); - assert_eq!(tx_builder.min_fee().unwrap().to_str(), "214002"); - assert_eq!(tx_builder.get_fee_if_set().unwrap().to_str(), "214002"); + assert_eq!(tx_builder.min_fee().unwrap().to_str(), "218502"); + assert_eq!(tx_builder.get_fee_if_set().unwrap().to_str(), "218502"); assert_eq!(tx_builder.get_deposit().unwrap().to_str(), "1000000"); assert_eq!(tx_builder.outputs.len(), 1); assert_eq!( @@ -559,7 +559,7 @@ fn build_tx_with_inputs() { ) .unwrap() .to_str(), - "69500" + "71000" ); tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred) @@ -1592,7 +1592,7 @@ fn build_tx_with_native_assets_change_and_no_purification_cuz_not_enough_pure_co ); // The single change output contains more Coin then minimal utxo value // But not enough to cover the additional fee for a separate output - assert_eq!(final_tx.outputs().get(1).amount().coin(), BigNum(499)); + assert_eq!(final_tx.outputs().get(1).amount().coin(), BigNum(493)); } #[test] @@ -2512,7 +2512,7 @@ fn tx_builder_cip2_random_improve_adds_enough_for_fees() { .unwrap(), ) .unwrap(); - assert_eq!(tx_builder.min_fee().unwrap(), BigNum(53)); + assert_eq!(tx_builder.min_fee().unwrap(), BigNum(56)); let mut available_inputs = TransactionUnspentOutputs::new(); available_inputs.add(&make_input(1u8, Value::new(&BigNum(150)))); available_inputs.add(&make_input(2u8, Value::new(&BigNum(150)))); @@ -2520,7 +2520,7 @@ fn tx_builder_cip2_random_improve_adds_enough_for_fees() { let add_inputs_res = tx_builder.add_inputs_from(&available_inputs, CoinSelectionStrategyCIP2::RandomImprove); assert!(add_inputs_res.is_ok(), "{:?}", add_inputs_res.err()); - assert_eq!(tx_builder.min_fee().unwrap(), BigNum(264)); + assert_eq!(tx_builder.min_fee().unwrap(), BigNum(270)); let change_addr = ByronAddress::from_base58("Ae2tdPwUPEZGUEsuMAhvDcy94LKsZxDjCbgaiBBMgYpR8sKf96xJmit7Eho") .unwrap() @@ -2785,8 +2785,9 @@ fn build_tx_multisig_1on1_signed() { let mut witness_set = TransactionWitnessSet::new(); let mut vkw = Vkeywitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a") .unwrap(), @@ -3169,7 +3170,6 @@ fn set_mint_asset_with_existing_mint() { // Only second script is present in the scripts assert_eq!(mint_scripts.len(), 2); let actual_scripts = mint_scripts - .0 .iter() .cloned() .collect::>(); @@ -3228,7 +3228,6 @@ fn add_mint_asset_with_existing_mint() { assert_eq!(mint_scripts.len(), 2); let actual_scripts = mint_scripts - .0 .iter() .cloned() .collect::>(); @@ -3399,7 +3398,6 @@ fn add_mint_asset_and_output() { assert_eq!(mint_scripts.len(), 2); let actual_scripts = mint_scripts - .0 .iter() .cloned() .collect::>(); @@ -3468,7 +3466,6 @@ fn add_mint_asset_and_min_required_coin() { assert_eq!(mint_scripts.len(), 2); let actual_scripts = mint_scripts - .0 .iter() .cloned() .collect::>(); @@ -3529,7 +3526,7 @@ fn add_mint_includes_witnesses_into_fee_estimation() { // Original tx fee now assumes two VKey signatures for two inputs let original_tx_fee = tx_builder.min_fee().unwrap(); - assert_eq!(original_tx_fee, BigNum(168361)); + assert_eq!(original_tx_fee, BigNum(168625)); // Add minting four assets from three different policies tx_builder.add_mint_asset(&mint_script1, &name1, &amount).expect("Failed to add mint asset"); @@ -3555,7 +3552,7 @@ fn add_mint_includes_witnesses_into_fee_estimation() { .unwrap(); assert_eq!(raw_mint_fee, BigNum(5544)); - assert_eq!(raw_mint_script_fee, BigNum(4312)); + assert_eq!(raw_mint_script_fee, BigNum(4444)); let new_tx_fee = tx_builder.min_fee().unwrap(); @@ -4364,10 +4361,10 @@ fn test_ex_unit_costs_are_added_to_the_fees() { tx_builder.get_fee_if_set().unwrap() } - assert_eq!(calc_fee_with_ex_units(0, 0), BigNum(173509)); - assert_eq!(calc_fee_with_ex_units(10000, 0), BigNum(174174)); - assert_eq!(calc_fee_with_ex_units(0, 10000000), BigNum(174406)); - assert_eq!(calc_fee_with_ex_units(10000, 10000000), BigNum(175071)); + assert_eq!(calc_fee_with_ex_units(0, 0), BigNum(174213)); + assert_eq!(calc_fee_with_ex_units(10000, 0), BigNum(174878)); + assert_eq!(calc_fee_with_ex_units(0, 10000000), BigNum(175110)); + assert_eq!(calc_fee_with_ex_units(10000, 10000000), BigNum(175775)); } #[test] @@ -4465,9 +4462,9 @@ fn test_required_signers_are_added_to_the_witness_estimate() { &Value::new(&BigNum(10_000_000)), ).expect("Failed to add input"); - keys.to_vec().iter().for_each(|k| { + for k in keys { tx_builder.add_required_signer(k); - }); + } let tx: Transaction = fake_full_tx(&tx_builder, tx_builder.build().unwrap()).unwrap(); tx.witness_set.vkeys.unwrap().len() diff --git a/rust/src/tests/fees.rs b/rust/src/tests/fees.rs index 04de0d19..9220a3af 100644 --- a/rust/src/tests/fees.rs +++ b/rust/src/tests/fees.rs @@ -40,8 +40,9 @@ fn tx_simple_utxo() { let mut w = TransactionWitnessSet::new(); let mut vkw = Vkeywitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a") .unwrap(), @@ -55,11 +56,11 @@ fn tx_simple_utxo() { let linear_fee = LinearFee::new(&BigNum(500), &BigNum(2)); assert_eq!( hex::encode(signed_tx.to_bytes()), - "84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa10081825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fae5de40c94d759ce13bf9886262159c4f26a289fd192e165995b785259e503f6887bf39dfa23a47cf163784c6eee23f61440e749bc1df3c73975f5231aeda0ff5f6" + "84a400d90102818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa100d9010281825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58406d68d8b7b2ee54f1f46b64e3f61a14f840be2ec125c858ec917f634a1eb898a51660654839226016a2588d39920e6dfe1b66d917027f198b5eb887d20f4ac805f5f6" ); assert_eq!( min_fee(&signed_tx, &linear_fee).unwrap().to_str(), - "94502" // todo: compare to Haskell fee to make sure the diff is not too big + "97502" // todo: compare to Haskell fee to make sure the diff is not too big ); } @@ -95,8 +96,9 @@ fn tx_simple_byron_utxo() { let mut w = TransactionWitnessSet::new(); let mut bootstrap_wits = BootstrapWitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); bootstrap_wits.add(&make_icarus_bootstrap_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &ByronAddress::from_base58("Ae2tdPwUPEZ6r6zbg4ibhFrNnyKHg7SYuPSfDpjKxgvwFX9LquRep7gj7FQ").unwrap(), &Bip32PrivateKey::from_bytes( &hex::decode("d84c65426109a36edda5375ea67f1b738e1dacf8629f2bb5a2b0b20f3cd5075873bf5cdfa7e533482677219ac7d639e30a38e2e645ea9140855f44ff09e60c52c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a3").unwrap() @@ -109,11 +111,11 @@ fn tx_simple_byron_utxo() { let linear_fee = LinearFee::new(&BigNum(500), &BigNum(2)); assert_eq!( hex::encode(signed_tx.to_bytes()), - "84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a0001b582030aa10281845820473811afd4d939b337c9be1a2ceeb2cb2c75108bddf224c5c21c51592a7b204a5840f0b04a852353eb23b9570df80b2aa6a61b723341ab45a2024a05b07cf58be7bdfbf722c09040db6cee61a0d236870d6ad1e1349ac999ec0db28f9471af25fb0c5820c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a341a0f5f6" + "84a400d90102818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a0001b582030aa102d9010281845820473811afd4d939b337c9be1a2ceeb2cb2c75108bddf224c5c21c51592a7b204a58408b4ca7a71340bc6441f0e390122d53aba154b7e2b432ec2927ed8db7395d3d9347989aa1fca4823c991c1ef309570a0bbdf62155e3dba376fae9827cb465f5055820c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a341a0f5f6" ); assert_eq!( min_fee(&signed_tx, &linear_fee).unwrap().to_str(), - "112502" // todo: compare to Haskell fee to make sure the diff is not too big + "115502" // todo: compare to Haskell fee to make sure the diff is not too big ); } @@ -173,8 +175,9 @@ fn tx_multi_utxo() { let mut w = TransactionWitnessSet::new(); let mut vkw = Vkeywitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a") .unwrap(), @@ -182,7 +185,7 @@ fn tx_multi_utxo() { .unwrap(), )); vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("13fe79205e16c09536acb6f0524d04069f380329d13949698c5f22c65c989eb4") .unwrap(), @@ -196,11 +199,11 @@ fn tx_multi_utxo() { let linear_fee = LinearFee::new(&BigNum(500), &BigNum(2)); assert_eq!( hex::encode(signed_tx.to_bytes()), - "84a400828258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7182a82582082839f8200d81858248258203b40265111d8bb3c3c608d95b3a0bf83461ace3207018282581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c19012182581d61bcd18fcffa797c16c007014e2b8553b8b9b1e94c507688726243d6111a3420989c021a0002ccce031903e7a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58401ec3e56008650282ba2e1f8a20e81707810b2d0973c4d42a1b4df65b732bda81567c7824904840b2554d2f33861da5d70588a29d33b2b61042e3c3445301d8008258206872b0a874acfe1cace12b20ea348559a7ecc912f2fc7f674f43481df973d92c5840a0718fb5b37d89ddf926c08e456d3f4c7f749e91f78bb3e370751d5b632cbd20d38d385805291b1ef2541b02543728a235e01911f4b400bfb50e5fce589de907f5f6" + "84a400d90102828258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7182a82582082839f8200d81858248258203b40265111d8bb3c3c608d95b3a0bf83461ace3207018282581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c19012182581d61bcd18fcffa797c16c007014e2b8553b8b9b1e94c507688726243d6111a3420989c021a0002ccce031903e7a100d9010282825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee584082eea9c7848c1136ebcb5fd5774d8dfc330c63b7f44b56a5cc5008887d3923df8785ebab92c230114099cf9b79a6c6c57ead026fa495d526731cc00caa3407088258206872b0a874acfe1cace12b20ea348559a7ecc912f2fc7f674f43481df973d92c5840f8861b68b3f966b6b63cbd3f7abf18efa18620aee9e730dea75d2d1cb0668988486f852f7743f6b5cc841c62d11440073706b52b408c0d776a411e2a0dd0da0af5f6" ); assert_eq!( min_fee(&signed_tx, &linear_fee).unwrap().to_str(), - "184002" // todo: compare to Haskell fee to make sure the diff is not too big + "187002" // todo: compare to Haskell fee to make sure the diff is not too big ); } @@ -283,9 +286,10 @@ fn tx_register_stake() { let mut w = TransactionWitnessSet::new(); let mut vkw = Vkeywitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); // input key witness vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a") .unwrap(), @@ -294,7 +298,7 @@ fn tx_register_stake() { )); // operator key witness vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("2363f3660b9f3b41685665bf10632272e2d03c258e8a5323436f0f3406293505") .unwrap(), @@ -303,7 +307,7 @@ fn tx_register_stake() { )); // owner key witness vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("5ada7f4d92bce1ee1707c0a0e211eb7941287356e6ed0e76843806e307b07c8d") .unwrap(), @@ -317,11 +321,11 @@ fn tx_register_stake() { let linear_fee = LinearFee::new(&BigNum(500), &BigNum(2)); assert_eq!( hex::encode(signed_tx.to_bytes()), - "84a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00040f12030a04818a03581c1c13374874c68016df54b1339b6cacdd801098431e7659b24928efc15820bd0000f498ccacdc917c28274cba51c415f3f21931ff41ca8dc1197499f8e1241a000f42401a000f4240d81e82031864581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7081581c51df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7080f6a10083825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840a7f305d7e46abfe0f7bea6098bdf853ab9ce8e7aa381be5a991a871852f895a718e20614e22be43494c4dc3a8c78c56cd44fd38e0e5fff3e2fbd19f70402fc02825820b24c040e65994bd5b0621a060166d32d356ef4be3cc1f848426a4cf386887089584013c372f82f1523484eab273241d66d92e1402507760e279480912aa5f0d88d656d6f25d41e65257f2f38c65ac5c918a6735297741adfc718394994f20a1cfd0082582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840d326b993dfec21b9b3e1bd2f80adadc2cd673a1d8d033618cc413b0b02bc3b7efbb23d1ff99138abd05c398ce98e7983a641b50dcf0f64ed33f26c6e636b0b0ff5f6" + "84a500d90102818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00040f12030a04d90102818a03581c1c13374874c68016df54b1339b6cacdd801098431e7659b24928efc15820bd0000f498ccacdc917c28274cba51c415f3f21931ff41ca8dc1197499f8e1241a000f42401a000f4240d81e82031864581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af70d9010281581c51df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af7080f6a100d9010283825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee584081e223791960a07f401c378dce048ea658a155510ae6541c6cb692ed41ee45b40b913d1428a94af145885639f8acf99549f7b29af1e34997b9cb8ad05fe6e50a825820b24c040e65994bd5b0621a060166d32d356ef4be3cc1f848426a4cf38688708958401a246b6a4d63e83bd4904ac3b787797ba54238aab8e733b75b5ab2e465c46fce67e4403169a53239e7036f87f0518ec4414a10e45a1aa1788322d2777f59c30182582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840ea9518346e8515aea6c16e7076a1d0a637582f736c0b65abd1f4adccd8920f2da699e8602029cc608da2ba46b6a6e61f41166b12ae17c922114c040facd90b07f5f6" ); assert_eq!( min_fee(&signed_tx, &linear_fee).unwrap().to_str(), - "269502" // todo: compare to Haskell fee to make sure the diff is not too big + "275502" // todo: compare to Haskell fee to make sure the diff is not too big ); } @@ -504,9 +508,10 @@ fn tx_withdrawal() { let mut w = TransactionWitnessSet::new(); let mut vkw = Vkeywitnesses::new(); + let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap(); // input key witness vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a") .unwrap(), @@ -515,7 +520,7 @@ fn tx_withdrawal() { )); // withdrawal key witness vkw.add(&make_vkey_witness( - &hash_transaction(&body), + &fixed_tx.transaction_hash(), &PrivateKey::from_normal_bytes( &hex::decode("5ada7f4d92bce1ee1707c0a0e211eb7941287356e6ed0e76843806e307b07c8d") .unwrap(), @@ -529,11 +534,11 @@ fn tx_withdrawal() { let linear_fee = LinearFee::new(&BigNum(500), &BigNum(2)); assert_eq!( hex::encode(signed_tx.to_bytes()), - "84a500818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00027ac6030a05a1581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af70190539a10082825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fc0493f7121efe385d72830680e735ccdef99c3a31953fe877b89ad3a97fcdb871cc7f2cdd6a8104e52f6963bd9e10d814d4fabdbcdc8475bc63e872dcc94d0a82582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840a051ba927582004aedab736b9f1f9330ff867c260f4751135d480074256e83cd23d2a4bb109f955c43afdcdc5d1841b28d5c1ea2148dfbb6252693590692bb00f5f6" + "84a500d90102818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00027ac6030a05a1581de151df9ba1b74a1c9608a487e114184556801e927d31d96425cb80af70190539a100d9010282825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58406dda4d88a17c7b888d15eb29f0871e85f3c50e1ea4efcc0d7781f4db0ae11dd418abae42f7f62637cc54d21887ccb60dc3ccae545e7a25c7c553b3a91e9e6d0082582054d1a9c5ad69586ceeb839c438400c376c0bd34825fb4c17cc2f58c54e1437f35840a24b4863189d5872fdb98529bbe6feae375031162786bda1244d73c54adafea0ace2f087f23a794af4f232651ba66071246ab5bc1e1b0b9a39044d0531eeac0ef5f6" ); assert_eq!( min_fee(&signed_tx, &linear_fee).unwrap().to_str(), - "163002" // todo: compare to Haskell fee to make sure the diff is not too big + "166002" // todo: compare to Haskell fee to make sure the diff is not too big ); } diff --git a/rust/src/tests/general.rs b/rust/src/tests/general.rs index 781a9661..ce2fca3c 100644 --- a/rust/src/tests/general.rs +++ b/rust/src/tests/general.rs @@ -1,6 +1,6 @@ use crate::*; use crate::tests::helpers::harden; -use crate::tests::fakes::{fake_plutus_script, fake_bootsrap_witness, fake_tx_input, fake_vkey_witness}; +use crate::tests::fakes::{fake_plutus_script, fake_bootsrap_witness, fake_tx_input, fake_vkey_witness, fake_key_hash}; #[test] fn native_script_hash() { @@ -189,27 +189,15 @@ fn mint_to_negative_multiasset_empty() { assert_eq!(n_ass.get(&name1).unwrap(), amount1); } -fn keyhash(x: u8) -> Ed25519KeyHash { - Ed25519KeyHash::from_bytes(vec![ - x, 180, 186, 93, 223, 42, 243, 7, 81, 98, 86, 125, 97, 69, 110, 52, 130, 243, 244, 98, 246, - 13, 33, 212, 128, 168, 136, 40, - ]) - .unwrap() -} - fn pkscript(pk: &Ed25519KeyHash) -> NativeScript { NativeScript::new_script_pubkey(&ScriptPubkey::new(pk)) } -fn scripts_vec(scripts: Vec<&NativeScript>) -> NativeScripts { - NativeScripts(scripts.iter().map(|s| (*s).clone()).collect()) -} - #[test] fn native_scripts_get_pubkeys() { - let keyhash1 = keyhash(1); - let keyhash2 = keyhash(2); - let keyhash3 = keyhash(3); + let keyhash1 = fake_key_hash(1); + let keyhash2 = fake_key_hash(2); + let keyhash3 = fake_key_hash(3); let pks1 = Ed25519KeyHashes::from(&pkscript(&keyhash1)); assert_eq!(pks1.len(), 1); @@ -220,26 +208,26 @@ fn native_scripts_get_pubkeys() { assert_eq!(pks2.len(), 0); let pks3 = Ed25519KeyHashes::from(&NativeScript::new_script_all(&ScriptAll::new( - &scripts_vec(vec![&pkscript(&keyhash1), &pkscript(&keyhash2)]), + &NativeScripts::from(vec![&pkscript(&keyhash1), &pkscript(&keyhash2)]), ))); assert_eq!(pks3.len(), 2); assert!(pks3.contains(&keyhash1)); assert!(pks3.contains(&keyhash2)); let pks4 = Ed25519KeyHashes::from(&NativeScript::new_script_any(&ScriptAny::new( - &scripts_vec(vec![ + &NativeScripts::from(vec![ &NativeScript::new_script_n_of_k(&ScriptNOfK::new( 1, - &scripts_vec(vec![ + &NativeScripts::from(vec![ &NativeScript::new_timelock_start(&TimelockStart::new(132)), &pkscript(&keyhash3), ]), )), - &NativeScript::new_script_all(&ScriptAll::new(&scripts_vec(vec![ + &NativeScript::new_script_all(&ScriptAll::new(&NativeScripts::from(vec![ &NativeScript::new_timelock_expiry(&TimelockExpiry::new(132)), &pkscript(&keyhash1), ]))), - &NativeScript::new_script_any(&ScriptAny::new(&scripts_vec(vec![ + &NativeScript::new_script_any(&ScriptAny::new(&NativeScripts::from(vec![ &pkscript(&keyhash1), &pkscript(&keyhash2), &pkscript(&keyhash3), @@ -448,8 +436,8 @@ fn min_ref_script_fee_test_fail(){ #[test] fn ed25519_key_hashes_dedup() { let mut key_hashes = Ed25519KeyHashes::new(); - let key_hash1 = keyhash(1); - let key_hash2 = keyhash(2); + let key_hash1 = fake_key_hash(1); + let key_hash2 = fake_key_hash(2); assert!(key_hashes.add(&key_hash1)); assert!(key_hashes.add(&key_hash2)); @@ -476,8 +464,8 @@ fn bootstrap_witnesses_dedup() { #[test] fn credential_dedup() { let mut credentials = Credentials::new(); - let credential1 = Credential::from_keyhash(&keyhash(1)); - let credential2 = Credential::from_keyhash(&keyhash(2)); + let credential1 = Credential::from_keyhash(&fake_key_hash(1)); + let credential2 = Credential::from_keyhash(&fake_key_hash(2)); assert!(credentials.add(&credential1)); assert!(credentials.add(&credential2)); @@ -601,7 +589,7 @@ fn plutus_scripts_no_dedup_on_auxdata() { #[test] fn native_scripts_dedup_on_tx_witnesses_set() { - let keyhash1 = keyhash(1); + let keyhash1 = fake_key_hash(1); let native_scripts_1 = NativeScript::new_script_pubkey(&ScriptPubkey::new( &keyhash1, @@ -638,7 +626,7 @@ fn native_scripts_dedup_on_tx_witnesses_set() { #[test] fn native_scripts_no_dedup_on_auxdata() { - let keyhash1 = keyhash(1); + let keyhash1 = fake_key_hash(1); let native_scripts_1 = NativeScript::new_script_pubkey(&ScriptPubkey::new( &keyhash1, diff --git a/rust/src/tests/metadata.rs b/rust/src/tests/metadata.rs index 6bcce071..58546226 100644 --- a/rust/src/tests/metadata.rs +++ b/rust/src/tests/metadata.rs @@ -269,13 +269,13 @@ fn test_auxiliary_data_roundtrip() { let script_v2 = PlutusScript::from_bytes_v2(bytes.clone()).unwrap(); let script_v3 = PlutusScript::from_bytes_v3(bytes.clone()).unwrap(); - auxiliary_data_roundtrip(&PlutusScripts(vec![])); - auxiliary_data_roundtrip(&PlutusScripts(vec![script_v1.clone()])); - auxiliary_data_roundtrip(&PlutusScripts(vec![script_v2.clone()])); - auxiliary_data_roundtrip(&PlutusScripts(vec![script_v3.clone()])); - auxiliary_data_roundtrip(&PlutusScripts(vec![ + auxiliary_data_roundtrip(&PlutusScripts::from_vec(vec![], None)); + auxiliary_data_roundtrip(&PlutusScripts::from_vec(vec![script_v1.clone()], None)); + auxiliary_data_roundtrip(&PlutusScripts::from_vec(vec![script_v2.clone()], None)); + auxiliary_data_roundtrip(&PlutusScripts::from_vec(vec![script_v3.clone()], None)); + auxiliary_data_roundtrip(&PlutusScripts::from_vec(vec![ script_v1.clone(), script_v2.clone(), script_v3.clone(), - ])); + ], None)); } diff --git a/rust/src/tests/plutus.rs b/rust/src/tests/plutus.rs index 05177e63..7539f91a 100644 --- a/rust/src/tests/plutus.rs +++ b/rust/src/tests/plutus.rs @@ -40,13 +40,13 @@ pub fn plutus_list_serialization_cli_compatibility() { // witness_set should have fixed length array let mut witness_set = TransactionWitnessSet::new(); witness_set.set_plutus_data(&list); - assert_eq!("a1049f01ff", hex::encode(witness_set.to_bytes())); + assert_eq!("a104d901029f01ff", hex::encode(witness_set.to_bytes())); list = PlutusList::new(); list.add(&datum); witness_set.set_plutus_data(&list); assert_eq!( - format!("a1049f{}ff", datum_cli), + format!("a104d901029f{}ff", datum_cli), hex::encode(witness_set.to_bytes()) ); } @@ -436,7 +436,7 @@ fn test_known_plutus_data_hash() { let hash = hash_script_data(&redeemers, &retained_cost_models, Some(pdata)); assert_eq!( hex::encode(hash.to_bytes()), - "2fd8b7e248b376314d02989c885c278796ab0e1d6e8aa0cb91f562ff5f7dbd70" + "e77f547d8249947bf0af31c432fcfff9c1872b2502b3f34d8107002255695e07" ); } @@ -478,7 +478,7 @@ fn test_known_plutus_data_hash_with_no_datums() { ); assert_eq!( hex::encode(hash.to_bytes()), - "6b244f15f895fd458a02bef3a8b56f17f24150fddcb06be482f8790a600578a1" + "5b235dbfaa999fb3616da9903d9affd09c7f2121c2d50db7ece0a9fb8587a038" ); } @@ -515,7 +515,7 @@ fn test_known_plutus_data_hash_2() { ); assert_eq!( hex::encode(hash.to_bytes()), - "0a076247a05aacbecf72ea15b94e3d0331b21295a08d9ab7b8675c13840563a6" + "f3ae8e52bff4c7b8d803469ee61eabf37e96e89f8a3bb80115ad068ab5dff598" ); } @@ -589,6 +589,6 @@ fn script_data_hash_no_redeemers() { ); assert_eq!( hex::encode(hash.to_bytes()), - "5f4e4b313590ed119c077f2ef78ff294118e7955c63982e304a791831238baf4" + "fd53a28a846ae6ccf8b221d03d4af122b0b3c442089c05b87e3d86c6792b3ef0" ); } \ No newline at end of file diff --git a/rust/src/tests/serialization/certificates.rs b/rust/src/tests/serialization/certificates.rs index 404afaf9..1fde5401 100644 --- a/rust/src/tests/serialization/certificates.rs +++ b/rust/src/tests/serialization/certificates.rs @@ -462,3 +462,28 @@ fn certificates_collection_ser_round_trip() { assert_eq!(certs, Certificates::from_bytes(cbor).unwrap()); assert_eq!(certs, Certificates::from_hex(&hex_cbor).unwrap()); } + +#[test] +fn certificates_set_always_should_be_with_tag() { + let mut certs = Certificates::new(); + let cert_1 = StakeRegistration::new(&Credential::from_keyhash(&fake_key_hash(1))); + certs.add(&Certificate::new_stake_registration(&cert_1)); + let cert_2 = StakeDeregistration::new(&Credential::from_keyhash(&fake_key_hash(2))); + certs.add(&Certificate::new_stake_deregistration(&cert_2)); + + let cbor = certs.to_bytes(); + let certs_decoded = Certificates::from_bytes(cbor).unwrap(); + + assert_eq!(certs, certs_decoded); + assert_eq!(certs_decoded.get_set_type(), CborSetType::Tagged); + + let untagget_cbor_hex = "8282008200581c01efb5788e8713c844dfd32b2e91de1e309fefffd555f827cc9ee16482018200581c02efb5788e8713c844dfd32b2e91de1e309fefffd555f827cc9ee164"; + let certs_decoded_untagged = Certificates::from_hex(untagget_cbor_hex).unwrap(); + assert_eq!(certs, certs_decoded_untagged); + assert_eq!(certs_decoded_untagged.get_set_type(), CborSetType::Untagged); + + let cbor_2 = certs_decoded_untagged.to_bytes(); + let certs_decoded_2 = Certificates::from_bytes(cbor_2).unwrap(); + assert_eq!(certs, certs_decoded_2); + assert_eq!(certs_decoded_2.get_set_type(), CborSetType::Tagged); +} diff --git a/rust/src/tests/serialization/general.rs b/rust/src/tests/serialization/general.rs index fad31dae..ac8187aa 100644 --- a/rust/src/tests/serialization/general.rs +++ b/rust/src/tests/serialization/general.rs @@ -1,4 +1,4 @@ -use crate::{Address, BigInt, BigNum, Block, BlockHash, CborContainerType, Coin, Credential, DataHash, ExUnits, HeaderBody, HeaderLeaderCertEnum, Int, KESVKey, MIRPot, MIRToStakeCredentials, MoveInstantaneousReward, NativeScript, OperationalCert, PlutusData, PlutusList, PlutusScript, PlutusScripts, ProtocolVersion, Redeemer, RedeemerTag, Redeemers, ScriptHash, ScriptRef, TimelockStart, TransactionBody, TransactionInputs, TransactionOutput, TransactionOutputs, TransactionWitnessSet, VRFCert, VRFVKey, Value, Vkeywitness, Vkeywitnesses, VersionedBlock, BlockEra, to_bytes, BootstrapWitnesses, Credentials, Ed25519KeyHashes}; +use crate::{Address, BigInt, BigNum, Block, BlockHash, CborContainerType, Coin, Credential, DataHash, ExUnits, HeaderBody, HeaderLeaderCertEnum, Int, KESVKey, MIRPot, MIRToStakeCredentials, MoveInstantaneousReward, NativeScript, OperationalCert, PlutusData, PlutusList, PlutusScript, PlutusScripts, ProtocolVersion, Redeemer, RedeemerTag, Redeemers, ScriptHash, ScriptRef, TimelockStart, TransactionBody, TransactionInputs, TransactionOutput, TransactionOutputs, TransactionWitnessSet, VRFCert, VRFVKey, Value, Vkeywitness, Vkeywitnesses, VersionedBlock, BlockEra, to_bytes, BootstrapWitnesses, Credentials, Ed25519KeyHashes, CborSetType, ScriptPubkey, NativeScripts, Language}; use crate::protocol_types::ScriptRefEnum; use crate::tests::fakes::{fake_base_address, fake_bootsrap_witness, fake_bytes_32, fake_data_hash, fake_key_hash, fake_signature, fake_tx_input, fake_tx_output, fake_value, fake_value2, fake_vkey, fake_vkey_witness}; @@ -522,16 +522,16 @@ fn test_witness_set_roundtrip() { let script_v2 = PlutusScript::from_bytes_v2(bytes.clone()).unwrap(); let script_v3 = PlutusScript::from_bytes_v3(bytes.clone()).unwrap(); - witness_set_roundtrip(&PlutusScripts(vec![])); - witness_set_roundtrip(&PlutusScripts(vec![script_v1.clone()])); - witness_set_roundtrip(&PlutusScripts(vec![script_v2.clone()])); - witness_set_roundtrip(&PlutusScripts(vec![script_v3.clone()])); - witness_set_roundtrip(&PlutusScripts(vec![script_v1.clone(), script_v2.clone()])); - witness_set_roundtrip(&PlutusScripts(vec![ + witness_set_roundtrip(&PlutusScripts::from_vec(vec![], None)); + witness_set_roundtrip(&PlutusScripts::from_vec(vec![script_v1.clone()], None)); + witness_set_roundtrip(&PlutusScripts::from_vec(vec![script_v2.clone()], None)); + witness_set_roundtrip(&PlutusScripts::from_vec(vec![script_v3.clone()], None)); + witness_set_roundtrip(&PlutusScripts::from_vec(vec![script_v1.clone(), script_v2.clone()], None)); + witness_set_roundtrip(&PlutusScripts::from_vec(vec![ script_v1.clone(), script_v2.clone(), script_v3.clone(), - ])); + ], None)); } #[test] @@ -675,7 +675,7 @@ fn redeemers_default_array_round_trip() { let bytes = redeemers.to_bytes(); let new_redeemers = Redeemers::from_bytes(bytes.clone()).unwrap(); - assert_eq!(new_redeemers.serialization_format, Some(CborContainerType::Array)); + assert_eq!(new_redeemers.serialization_format, Some(CborContainerType::Map)); assert_eq!(redeemers.serialization_format, None); assert_eq!(redeemers, new_redeemers); assert_eq!(bytes, new_redeemers.to_bytes()) @@ -909,3 +909,174 @@ fn tx_inputs_round_trip() { assert_eq!(bytes, new_inputs.to_bytes()); assert_eq!(json, new_inputs_json.to_json().unwrap()); } + + +#[test] +fn credential_set_always_should_be_with_tag() { + let mut credentials = Credentials::new(); + let credential_1 = Credential::from_keyhash(&fake_key_hash(1)); + let credential_2 = Credential::from_keyhash(&fake_key_hash(2)); + let credential_3 = Credential::from_keyhash(&fake_key_hash(3)); + + credentials.add(&credential_1); + credentials.add(&credential_2); + credentials.add(&credential_3); + + let bytes = credentials.to_bytes(); + let mut new_credentials = Credentials::from_bytes(bytes.clone()).unwrap(); + + assert_eq!(new_credentials.get_set_type(), CborSetType::Tagged); + + new_credentials.set_set_type(CborSetType::Untagged); + assert_eq!(bytes, new_credentials.to_bytes()); +} + +#[test] +fn ed25519keyhashes_set_always_should_be_with_tag() { + let mut credentials = Ed25519KeyHashes::new(); + let keyhash_1 = fake_key_hash(1); + let keyhash_2 = fake_key_hash(2); + let keyhash_3 = fake_key_hash(3); + + credentials.add(&keyhash_1); + credentials.add(&keyhash_2); + credentials.add(&keyhash_3); + + let bytes = credentials.to_bytes(); + let mut new_credentials = Ed25519KeyHashes::from_bytes(bytes.clone()).unwrap(); + + assert_eq!(new_credentials.get_set_type(), CborSetType::Tagged); + + new_credentials.set_set_type(CborSetType::Untagged); + assert_eq!(bytes, new_credentials.to_bytes()); +} + +#[test] +fn transaction_inputs_set_always_should_be_with_tag() { + let mut inputs = TransactionInputs::new(); + let input_1 = fake_tx_input(1); + let input_2 = fake_tx_input(2); + let input_3 = fake_tx_input(3); + + inputs.add(&input_1); + inputs.add(&input_2); + inputs.add(&input_3); + + let bytes = inputs.to_bytes(); + let mut new_inputs = TransactionInputs::from_bytes(bytes.clone()).unwrap(); + + assert_eq!(new_inputs.get_set_type(), CborSetType::Tagged); + + new_inputs.set_set_type(CborSetType::Untagged); + assert_eq!(bytes, new_inputs.to_bytes()); +} + +#[test] +fn vkeywitnesses_set_always_should_be_with_tag() { + let mut witnesses = Vkeywitnesses::new(); + let vkey_witness_1 = fake_vkey_witness(1); + let vkey_witness_2 = fake_vkey_witness(2); + let vkey_witness_3 = fake_vkey_witness(3); + + witnesses.add(&vkey_witness_1); + witnesses.add(&vkey_witness_2); + witnesses.add(&vkey_witness_3); + + let bytes = witnesses.to_bytes(); + let mut new_witnesses = Vkeywitnesses::from_bytes(bytes.clone()).unwrap(); + + assert_eq!(new_witnesses.get_set_type(), CborSetType::Tagged); + + new_witnesses.set_set_type(CborSetType::Untagged); + assert_eq!(bytes, new_witnesses.to_bytes()); +} + +#[test] +fn bootstrap_witnesses_set_always_should_be_with_tag() { + let mut witnesses = BootstrapWitnesses::new(); + let bootstrap_witness_1 = fake_bootsrap_witness(1); + let bootstrap_witness_2 = fake_bootsrap_witness(2); + let bootstrap_witness_3 = fake_bootsrap_witness(3); + + witnesses.add(&bootstrap_witness_1); + witnesses.add(&bootstrap_witness_2); + witnesses.add(&bootstrap_witness_3); + + let bytes = witnesses.to_bytes(); + let mut new_witnesses = BootstrapWitnesses::from_bytes(bytes.clone()).unwrap(); + + assert_eq!(new_witnesses.get_set_type(), CborSetType::Tagged); + + new_witnesses.set_set_type(CborSetType::Untagged); + assert_eq!(bytes, new_witnesses.to_bytes()); +} + +#[test] +fn native_scripts_set_always_should_be_with_tag() { + let native_script = NativeScript::new_script_pubkey(&ScriptPubkey::new(&fake_key_hash(1))); + let native_scripts = NativeScripts::from(vec![&native_script]); + let mut witnesses_set = TransactionWitnessSet::new(); + witnesses_set.set_native_scripts(&native_scripts); + let wit_set_bytes = witnesses_set.to_bytes(); + let wit_set_from_bytes = TransactionWitnessSet::from_bytes(wit_set_bytes).unwrap(); + let native_scripts_from_bytes = wit_set_from_bytes.native_scripts().unwrap(); + assert_eq!(native_scripts, native_scripts_from_bytes); + assert_eq!(native_scripts_from_bytes.get_set_type(), Some(CborSetType::Tagged)); +} + +#[test] +fn plutus_scripts_set_always_should_be_with_tag() { + let plutus_script = PlutusScript::new([61u8; 29].to_vec()); + let plutus_scripts = PlutusScripts::from_vec(vec![plutus_script], None); + let mut witnesses_set = TransactionWitnessSet::new(); + witnesses_set.set_plutus_scripts(&plutus_scripts); + let wit_set_bytes = witnesses_set.to_bytes(); + let wit_set_from_bytes = TransactionWitnessSet::from_bytes(wit_set_bytes).unwrap(); + let plutus_scripts_from_bytes = wit_set_from_bytes.plutus_scripts().unwrap(); + assert_eq!(plutus_scripts, plutus_scripts_from_bytes); + assert_eq!(plutus_scripts_from_bytes.get_set_type(&Language::new_plutus_v1()), Some(CborSetType::Tagged)); +} + +#[test] +fn plutus_list_set_always_should_be_with_tag() { + let plutus_data = PlutusData::new_integer(&BigInt::one()); + let plutus_data_list = PlutusList::from(vec![plutus_data]); + let mut witnesses_set = TransactionWitnessSet::new(); + witnesses_set.set_plutus_data(&plutus_data_list); + let wit_set_bytes = witnesses_set.to_bytes(); + let wit_set_from_bytes = TransactionWitnessSet::from_bytes(wit_set_bytes).unwrap(); + let plutus_data_list_from_bytes = wit_set_from_bytes.plutus_data().unwrap(); + assert_eq!(plutus_data_list, plutus_data_list_from_bytes); + assert_eq!(plutus_data_list_from_bytes.get_set_type(), Some(CborSetType::Tagged)); +} + + +#[test] +fn pure_native_scripts_always_should_be_without_tag() { + let native_script = NativeScript::new_script_pubkey(&ScriptPubkey::new(&fake_key_hash(1))); + let native_scripts = NativeScripts::from(vec![&native_script]); + let native_scripts_bytes = native_scripts.to_bytes(); + let native_scripts_from_bytes = NativeScripts::from_bytes(native_scripts_bytes).unwrap(); + assert_eq!(native_scripts, native_scripts_from_bytes); + assert_eq!(native_scripts_from_bytes.get_set_type(), Some(CborSetType::Untagged)); +} + +#[test] +fn pure_plutus_scripts_always_should_be_without_tag() { + let plutus_script = PlutusScript::new([61u8; 29].to_vec()); + let plutus_scripts = PlutusScripts::from_vec(vec![plutus_script], None); + let plutus_scripts_bytes = plutus_scripts.to_bytes(); + let plutus_scripts_from_bytes = PlutusScripts::from_bytes(plutus_scripts_bytes).unwrap(); + assert_eq!(plutus_scripts, plutus_scripts_from_bytes); + assert_eq!(plutus_scripts_from_bytes.get_set_type(&Language::new_plutus_v1()), Some(CborSetType::Untagged)); +} + +#[test] +fn pure_plutus_list_always_should_be_without_tag() { + let plutus_data = PlutusData::new_integer(&BigInt::one()); + let plutus_data_list = PlutusList::from(vec![plutus_data]); + let plutus_data_list_bytes = plutus_data_list.to_bytes(); + let plutus_data_list_from_bytes = PlutusList::from_bytes(plutus_data_list_bytes).unwrap(); + assert_eq!(plutus_data_list, plutus_data_list_from_bytes); + assert_eq!(plutus_data_list_from_bytes.get_set_type(), Some(CborSetType::Untagged)); +} diff --git a/rust/src/tests/serialization/governance/proposals.rs b/rust/src/tests/serialization/governance/proposals.rs index f8623e5b..a0bd4e8a 100644 --- a/rust/src/tests/serialization/governance/proposals.rs +++ b/rust/src/tests/serialization/governance/proposals.rs @@ -449,4 +449,59 @@ fn tx_with_info_proposal_deser_test() { let info = proposal.governance_action().as_info_action(); assert!(info.is_some()); +} + +#[test] +fn voting_proposals_set_always_should_be_with_tag() { + let mut proposals = VotingProposals::new(); + let mut withdrawals = TreasuryWithdrawals::new(); + let addr1 = RewardAddress::new(1, &Credential::from_keyhash(&fake_key_hash(1))); + let addr2 = RewardAddress::new(2, &Credential::from_keyhash(&fake_key_hash(2))); + withdrawals.insert(&addr1, &Coin::from(1u32)); + withdrawals.insert(&addr2, &Coin::from(2u32)); + + let action1 = GovernanceAction::new_treasury_withdrawals_action( + &TreasuryWithdrawalsAction::new(&withdrawals), + ); + let action2 = GovernanceAction::new_no_confidence_action(&NoConfidenceAction::new()); + let action3 = GovernanceAction::new_info_action(&InfoAction::new()); + + let proposal1 = VotingProposal::new( + &action1, + &fake_anchor(), + &fake_reward_address(1), + &Coin::from(100u32), + ); + let proposal2 = VotingProposal::new( + &action2, + &fake_anchor(), + &fake_reward_address(2), + &Coin::from(200u32), + ); + let proposal3 = VotingProposal::new( + &action3, + &fake_anchor(), + &fake_reward_address(3), + &Coin::from(300u32), + ); + + proposals.add(&proposal1); + proposals.add(&proposal2); + proposals.add(&proposal3); + + let cbor = proposals.to_bytes(); + + let mut proposals_deser = VotingProposals::from_bytes(cbor).unwrap(); + assert_eq!(proposals_deser.get_set_type(), CborSetType::Tagged); + assert_eq!(proposals, proposals_deser); + + proposals_deser.set_set_type(CborSetType::Untagged); + assert_eq!(proposals_deser.get_set_type(), CborSetType::Untagged); + + let cbor = proposals_deser.to_bytes(); + let proposals_deser_2 = VotingProposals::from_bytes(cbor).unwrap(); + assert_eq!(proposals_deser_2.get_set_type(), CborSetType::Tagged); + + assert_eq!(proposals, proposals_deser_2); + } \ No newline at end of file diff --git a/rust/src/tests/utils.rs b/rust/src/tests/utils.rs index c8dabac1..95204318 100644 --- a/rust/src/tests/utils.rs +++ b/rust/src/tests/utils.rs @@ -459,7 +459,7 @@ fn correct_script_data_hash() { assert_eq!( hex::encode(script_data_hash.to_bytes()), - "4415e6667e6d6bbd992af5092d48e3c2ba9825200d0234d2470068f7f0f178b3" + "8452337aed2f75d45838155503407b4241a75f021c3818ec90383c8e0faca5a4" ); } @@ -733,7 +733,7 @@ fn test_vasil_v1_costmodel_hashing() { ); assert_eq!( hex::encode(hash.to_bytes()), - "887e1b6416d750d871c0f5b7136b54f7b8e8b0e293379d090f38f8f821d08a29" + "f173f8e25f385c61c33ab84c1e4a1af36fcd47dc7ab83d89f926828f618630f5" ); } @@ -751,3 +751,24 @@ fn bigint_as_int() { let neg_int = neg.as_int().unwrap(); assert_eq!(neg_int.0, -1024i128); } + +#[test] +fn has_transaction_set_tag_tx_with_only_tag() { + let hex = "84a400d90102818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa100d9010281825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58406d68d8b7b2ee54f1f46b64e3f61a14f840be2ec125c858ec917f634a1eb898a51660654839226016a2588d39920e6dfe1b66d917027f198b5eb887d20f4ac805f5f6"; + let tx_sets = has_transaction_set_tag(hex::decode(hex).unwrap()).unwrap(); + assert_eq!(tx_sets, TransactionSetsState::AllSetsHaveTag); +} + +#[test] +fn has_transaction_set_tag_tx_without_tag() { + let hex = "84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa10081825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee5840fae5de40c94d759ce13bf9886262159c4f26a289fd192e165995b785259e503f6887bf39dfa23a47cf163784c6eee23f61440e749bc1df3c73975f5231aeda0ff5f6"; + let tx_sets = has_transaction_set_tag(hex::decode(hex).unwrap()).unwrap(); + assert_eq!(tx_sets, TransactionSetsState::AllSetsHaveNoTag); +} + +#[test] +fn has_transaction_set_tag_mixed() { + let hex = "84a400818258203b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b700018182581d611c616f1acb460668a9b2f123c80372c2adad3583b9c6cd2b1deeed1c01021a00016f32030aa100d9010281825820f9aa3fccb7fe539e471188ccc9ee65514c5961c070b06ca185962484a4813bee58406d68d8b7b2ee54f1f46b64e3f61a14f840be2ec125c858ec917f634a1eb898a51660654839226016a2588d39920e6dfe1b66d917027f198b5eb887d20f4ac805f5f6"; + let tx_sets = has_transaction_set_tag(hex::decode(hex).unwrap()).unwrap(); + assert_eq!(tx_sets, TransactionSetsState::MixedSets); +} diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 86cbdb55..5c761ad2 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -579,11 +579,6 @@ pub fn hash_auxiliary_data(auxiliary_data: &AuxiliaryData) -> AuxiliaryDataHash AuxiliaryDataHash::from(blake2b256(&auxiliary_data.to_bytes())) } -#[wasm_bindgen] -pub fn hash_transaction(tx_body: &TransactionBody) -> TransactionHash { - TransactionHash::from(crypto::blake2b256(tx_body.to_bytes().as_ref())) -} - #[wasm_bindgen] pub fn hash_plutus_data(plutus_data: &PlutusData) -> DataHash { DataHash::from(blake2b256(&plutus_data.to_bytes())) @@ -1087,4 +1082,140 @@ pub(crate) fn get_input_shortage( } else { Ok(None) } +} + +#[wasm_bindgen] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum TransactionSetsState { + AllSetsHaveTag = 0, + AllSetsHaveNoTag = 1, + MixedSets = 2, +} + +/// Returns the state of the transaction sets. +/// If all sets have a tag, it returns AllSetsHaveTag. +/// If all sets have no tag, it returns AllSetsHaveNoTag. +/// If there is a mix of tagged and untagged sets, it returns MixedSets. +/// This function is useful for checking if a transaction might be signed by a hardware wallet. +/// And for checking which parameter should be used in a hardware wallet api. +/// WARNING this function will be deleted after all tags for set types will be mandatory. Approx after next hf +#[wasm_bindgen] +pub fn has_transaction_set_tag(tx_bytes: Vec) -> Result { + let mut has_tag = false; + let mut has_no_tag = false; + + let tx = Transaction::from_bytes(tx_bytes)?; + tx.witness_set.bootstraps.as_ref().map(|bs| { + match bs.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.witness_set.vkeys.as_ref().map(|vkeys| { + match vkeys.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.witness_set.plutus_data.as_ref().map(|plutus_data| { + match plutus_data.get_set_type() { + Some(CborSetType::Tagged) => has_tag = true, + Some(CborSetType::Untagged) => has_no_tag = true, + None => has_tag = true, + } + }); + tx.witness_set.native_scripts.as_ref().map(|native_scripts| { + match native_scripts.get_set_type() { + Some(CborSetType::Tagged) => has_tag = true, + Some(CborSetType::Untagged) => has_no_tag = true, + None => has_tag = true, + } + }); + tx.witness_set.plutus_scripts.as_ref().map(|plutus_scripts| { + match plutus_scripts.get_set_type(&Language::new_plutus_v1()) { + Some(CborSetType::Tagged) => has_tag = true, + Some(CborSetType::Untagged) => has_no_tag = true, + None => has_tag = true, + } + match plutus_scripts.get_set_type(&Language::new_plutus_v2()) { + Some(CborSetType::Tagged) => has_tag = true, + Some(CborSetType::Untagged) => has_no_tag = true, + None => has_tag = true, + } + match plutus_scripts.get_set_type(&Language::new_plutus_v3()) { + Some(CborSetType::Tagged) => has_tag = true, + Some(CborSetType::Untagged) => has_no_tag = true, + None => has_tag = true, + } + }); + + match tx.body.inputs.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + tx.body.reference_inputs.as_ref().map(|ref_inputs| { + match ref_inputs.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.body.required_signers.as_ref().map(|required_signers| { + match required_signers.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.body.voting_proposals.as_ref().map(|voting_proposals| { + match voting_proposals.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.body.collateral.as_ref().map(|collateral_inputs| { + match collateral_inputs.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + tx.body.certs.as_ref().map(|certs| { + match certs.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + }); + + tx.body.certs.as_ref().map(|certs| { + for cert in certs { + match &cert.0 { + CertificateEnum::PoolRegistration(pool_reg) => { + match pool_reg.pool_params.pool_owners.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + } + _ => {} + } + } + }); + + tx.body.voting_proposals.as_ref().map(|voting_proposals| { + for proposal in voting_proposals { + match &proposal.governance_action.0 { + GovernanceActionEnum::UpdateCommitteeAction(upd_action) => { + match upd_action.members_to_remove.get_set_type() { + CborSetType::Tagged => has_tag = true, + CborSetType::Untagged => has_no_tag = true, + } + } + _ => {} + } + } + }); + + match (has_tag, has_no_tag) { + (true, true) => Ok(TransactionSetsState::MixedSets), + (true, false) => Ok(TransactionSetsState::AllSetsHaveTag), + (false, true) => Ok(TransactionSetsState::AllSetsHaveNoTag), + (false, false) => Err(JsError::from_str("Transaction has invalid state")), + } } \ No newline at end of file