Release PR: #529
API Changes
Reference inputs support. #514
We introduce DatumSource and PlutusScriptSource types for easily use plutus scripts and datums references. Just create them and put to a new PlutusWitness instance by PlutusWitness::new_with_ref() . See example below.
let datum: PlutusData = get_datum();
let input_with_ref_datum: TransactionInput = get_input_with_ref_datum();
//You can create datum source with a datum or with a ref input
let datum_source = DatumSource::new(&datum);
let datum_ref_source = DatumSource::new_ref_input(&input_with_ref_datum);
let script: PlutusScript = get_script();
let input_with_ref_script: TransactionInput = get_input_with_ref_script();
let script_hash: ScriptHash = get_script_hash();
//You can create script source with a script or with a ref input
let script_source = PlutusScriptSource::new(&script);
let script_ref_source = PlutusScriptSource::new_ref_input(&script_hash, &input_with_ref_script);
//and use script and datum source to create a plutus witness
let plutus_witness = PlutusWitness::new_with_ref(&script_ref_source, &datum_ref_source, &get_redeemer());
//also possible to mix ref inputs source and non-ref inputs source or use just non-ref inputs sources
let plutus_witness = PlutusWitness::new_with_ref(&script_source, &datum_ref_source, &get_redeemer());
//and in the and you just add plutus script input as you do it before
let tx_inputs_builder = TxInputsBuilder::new();
tx_inputs_builder.add_plutus_script_input(&plutus_witness, &get_script_input(), &get_amount());Json and hex serialization support for protocol types. #345 #489 #293
Now, most of the protocol types (but not all) in the CSL contains to_json, from_json, to_hex, from_hex functions.
By to_hex and from_hex you can serialize and deserialize a type instance to or from string with CBOR represented in hex format.
By to_json, from_json you can serialize and deserialize a type instance to or from JSON string, that might help to provide more information when you create an issue on CSL GitHub. Or to build or change protocol type instance by your hands.
There is alsoto_js_value that is available only in js API. to_js_value map a type instance to a js type. For example TransactionInput instance maps to a TransactionInputJSON type. All available ***JSON types you can see in js API.
Cardano-cli JSON datum format support. #357
Despite that we have to_json, from_json support for protocol types. Datum JSON in the cardano-cli format can be represented in two ways by BasicConversions (ScriptDataJsonNoSchema in cardano node ) and DetailedSchema(ScriptDataJsonDetailedSchema in cardano node ). For the PlutusDatum type the functions to_json and from_json are implemented with additional parameter of PlutusDatumSchema type. Also there are 'old style' functions encode_json_str_to_plutus_datum and decode_plutus_datum_to_json_str like as for a metadatum.
Additional changes.
- Now error text from
add_change_if_neededcontains information about how much assets or ada not enough to cover all outputs, except a change. #520 - The
min_ada_for_outputfunction now uses only babbage era algorithm, it usually calculates less ada then pre-babbage algorithm. #526 - Fixed the
add_mint_assetfunction. Now it adds mint assets without replacing old value. #513 - Fixed
RandomImproveMultiAssetalgorithm foradd_inputs_fromfunction. Now it take into account previously added assets and ada into a tx builder. #523 DeserializeErrorandJsErrornow implementsstd::error::Error#506
Thank all who took part in this release!
Published:
https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser/v/11.1.0
https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs/v/11.1.0
https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-asmjs/v/11.1.0
https://crates.io/crates/cardano-serialization-lib/11.1.0