feat: add Babbage phase-1 validations (#405)
This commit is contained in:
parent
7a67453b58
commit
eade9eca82
32 changed files with 4584 additions and 143 deletions
|
|
@ -87,3 +87,42 @@ List of negative unit tests:
|
|||
- **min_lovelace_unreached** takes sucessful_mainnet_tx and submits validation on it with an environment requesting more lovelace on outputs than the amount actually paid by one of the outputs of the transaction.
|
||||
- **max_val_exceeded** takes sucessful_mainnet_tx and submits validation on it with an environment disallowing value sizes as high as the size ofg one of the values in one of the transaction outputs of sucessful_mainnet_tx.
|
||||
- **script_integrity_hash** takes sucessful_mainnet_tx_with_plutus_script and modifies the execution values of one of the redeemers in the witness set of the transaction, in such a way that all checks pass but the integrity hash of script-related data of the transaction is different from the script data hash contained in the body of the transaction.
|
||||
|
||||
### Babbage
|
||||
*pallas-applying/tests/babbage.rs* contains multiple unit tests for validation in the Alonzo era.
|
||||
|
||||
Babbage introduces novel ways to provide Plutus-script-related data, like the introduction of reference scripts and novel ways to provide for collateral.
|
||||
|
||||
List of positive unit tests:
|
||||
- **successful_mainnet_tx** ([here](https://cexplorer.io/tx/b17d685c42e714238c1fb3abcd40e5c6291ebbb420c9c69b641209607bd00c7d) to see on Cardano explorer) is a simple Babbage transaction, with no native, Plutus V1 or Plutus V2 scripts, nor metadata or minting.
|
||||
- **successful_mainnet_tx_with_plutus_v1_script** ([here](https://cexplorer.io/tx/f33d6f7eb877132af7307e385bb24a7d2c12298c8ac0b1460296748810925ccc) to see on Cardano explorer) is a Babbage transaction with a Plutus V1 script.
|
||||
- **successful_mainnet_tx_with_plutus_v2_script** ([here](https://cexplorer.io/tx/ac96a0a2dfdb876b237a8ae674eadab453fd146fb97b221cfd29a1812046fa36) to see on Cardano explorer) is a Babbage transaction with a Plutus V2 script.
|
||||
- **successful_mainnet_tx_with_minting** ([here](https://cexplorer.io/tx/8702b0a5835c16663101f68295e33e3b3868c487f736d3c8a0a4246242675a15) to see on Cardano explorer) is a simple Babbage transaction with minting.
|
||||
- **successful_mainnet_tx_with_metadata** ([here](https://cexplorer.io/tx/7ae8cbe887d5d4cdaa51bce93d296206d4fcc77963e65fad3a64d0e6df672260) to see on Cardano explorer) is a simple Babbage transaction with metadata.
|
||||
|
||||
List of negative unit tests:
|
||||
- **empty_ins** takes successful_mainnet_tx and removes its input.
|
||||
- **unfound_utxo_input** takes successful_mainnet_tx and calls validation on it with an empty UTxO (which causes the input to be unfound).
|
||||
- **validity_interval_lower_bound_unreached** takes sucessful_mainnet_tx and modifies its time interval in such a way that its validity time interval *lower* bound is located exactly one slot after the block slot.
|
||||
- **validity_interval_upper_bound_surpassed** takes sucessful_mainnt_tx and modifies its time interval in such a way that its validity time interval *upper* bound is located exactly one slot before the block slot.
|
||||
- **min_fees_unreached** submits validation on sucessful_mainnet_tx with an environment requesting the minimum fee to be higher than the one that the transaction actually paid.
|
||||
- **no_collateral_inputs** takes successful_mainnet_tx_with_plutus_v1_script and removes its collateral inputs before submitting the transaction for validation.
|
||||
- **too_many_collateral_inputs** takes successful_mainnet_tx_with_plutus_v1_script and submits its for validation with an environment allowing no collateral inputs.
|
||||
- **collateral_is_not_verification_key_locked** takes sucessful_mainnet_tx_with_plutus_v1_script and modifies the address of one of the collateral inputs to become a script-locked output instead of a verification-key-locked one.
|
||||
- **collateral_with_other_assets** takes sucessful_mainnet_tx_with_plutus_v1_script and adds non-lovelace assets to it.
|
||||
- **collateral_without_min_lovelace** takes sucessful_mainnet_tx_with_plutus_v1_script and submits it for validation with an environment requesting a higher lovelace percentage (when compared to the fee paid by the transaction) in collateral inputs than the actual amount paid by the transaction collateral.
|
||||
- **collateral_annotation** takes sucessful_mainnet_tx_with_plutus_v1_script and modifies the collateral annotation to make it wrong.
|
||||
- **preservation_of_value** modifies sucessful_mainnet_tx_with_plutus_v1_script in such a way that the preservation-of-value equality does not hold.
|
||||
- **min_lovelace_unreached** takes sucessful_mainnet_tx and submits validation on it with an environment requesting more lovelace on outputs than the amount actually paid by one of the outputs of the transaction.
|
||||
- **max_val_exceeded** takes sucessful_mainnet_tx and submits validation on it with an environment disallowing value sizes as high as the size ofg one of the values in one of the transaction outputs of sucessful_mainnet_tx.
|
||||
- **output_network_id** takes sucessful_mainnet_tx and modifies the network ID in the address of one of its outputs.
|
||||
- **tx_network_id** takes sucessful_mainnet_tx and modifies its network ID.
|
||||
- **tx_ex_units_exceeded** takes sucessful_mainnet_tx_with_plutus_v1_script and validates it with an environment whose Plutus script execution values are below the needs of the transaction.
|
||||
- **max_tx_size_exceeded** takes sucessful_mainnet_tx and validates it with an environment allowing only transactions whose size is lower than that of sucessful_mainnet_tx.
|
||||
- **minting_lacks_policy** takes sucessful_mainnet_tx_with_minting and removes the native script policy contained in it before submitting it for validation.
|
||||
- **auxiliary_data_removed** takes sucessful_mainnet_tx_with_metadata and removes its auxiliary data (a.k.a. metadata).
|
||||
- **script_input_lacks_script** takes sucessful_mainnet_tx_with_plutus_v1_script and clears the Plutus V1 scripts list in the witness set, making the script required by the transaction inexistent.
|
||||
- **missing_input_datum** takes sucessful_mainnet_tx_with_plutus_v1_script and removes the datum contained in its witness set.
|
||||
- **extra_input_datum** takes sucessful_mainnet_tx_with_plutus_v1_script and adds an unneded datum to its witness set.
|
||||
- **extra_redeemer** takes sucessful_mainnet_tx_with_plutus_v1_script and adds an unneeded redeemer to its witness set.
|
||||
- **script_integrity_hash** takes sucessful_mainnet_tx_with_plutus_v1_script and modifies the execution values of one of the redeemers in the witness set of the transaction, in such a way that all checks pass but the integrity hash of script-related data of the transaction is different from the script data hash contained in the body of the transaction.
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -315,7 +315,7 @@ mod alonzo_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// Same as successful_mainnet_tx, but the validation is called with an empty
|
||||
// Same as successful_mainnet_tx, but validation is called with an empty
|
||||
// UTxO set.
|
||||
fn unfound_utxo_input() {
|
||||
let cbor_bytes: Vec<u8> = cbor_to_bytes(include_str!("../../test_data/alonzo1.tx"));
|
||||
|
|
@ -454,7 +454,7 @@ mod alonzo_tests {
|
|||
#[test]
|
||||
// Same as succesful_mainnet_tx, except that validation is called with an
|
||||
// Environment requesting fees that exceed those paid by the transaction.
|
||||
fn min_fees_unreached() {
|
||||
fn min_fee_unreached() {
|
||||
let cbor_bytes: Vec<u8> = cbor_to_bytes(include_str!("../../test_data/alonzo1.tx"));
|
||||
let mtx: MintedTx = minted_tx_from_cbor(&cbor_bytes);
|
||||
let metx: MultiEraTx = MultiEraTx::from_alonzo_compatible(&mtx, Era::Alonzo);
|
||||
|
|
@ -573,7 +573,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -698,7 +698,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -954,7 +954,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1082,7 +1082,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1122,7 +1122,7 @@ mod alonzo_tests {
|
|||
|
||||
#[test]
|
||||
// Same as succesful_mainnet_tx, except that the fee is reduced by exactly 1,
|
||||
// and so the "preservation of value" property doesn't hold.
|
||||
// and so the "preservation of value" property does not hold.
|
||||
fn preservation_of_value() {
|
||||
let cbor_bytes: Vec<u8> = cbor_to_bytes(include_str!("../../test_data/alonzo1.tx"));
|
||||
let mut mtx: MintedTx = minted_tx_from_cbor(&cbor_bytes);
|
||||
|
|
@ -1162,7 +1162,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Preservation of value doesn't hold"),
|
||||
Ok(()) => panic!("Preservation of value does not hold"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::PreservationOfValue) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -1232,7 +1232,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Transaction network ID should match environment network_id"),
|
||||
Ok(()) => panic!("Output network ID should match environment network ID"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::OutputWrongNetworkID) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -1282,7 +1282,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Transaction network ID should match environment network_id"),
|
||||
Ok(()) => panic!("Transaction network ID should match environment network ID"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::TxWrongNetworkID) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -1292,7 +1292,7 @@ mod alonzo_tests {
|
|||
|
||||
#[test]
|
||||
// Same as successful_mainnet_tx_with_plutus_script, except that the Environment
|
||||
// execution values are below the ones assocaited with the transaction.
|
||||
// execution values are below the ones associated with the transaction.
|
||||
fn tx_ex_units_exceeded() {
|
||||
let cbor_bytes: Vec<u8> = cbor_to_bytes(include_str!("../../test_data/alonzo2.tx"));
|
||||
let mtx: MintedTx = minted_tx_from_cbor(&cbor_bytes);
|
||||
|
|
@ -1369,7 +1369,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1533,7 +1533,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1768,7 +1768,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1891,7 +1891,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -1986,7 +1986,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Minting policy is not supported by native script"),
|
||||
Ok(()) => panic!("Minting policy is not supported by the correponding native script"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::MintingLacksPolicy) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -2072,7 +2072,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -2195,7 +2195,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -2324,7 +2324,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -2454,7 +2454,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
@ -2536,7 +2536,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Unneeded redeemer"),
|
||||
Ok(()) => panic!("Transaction auxiliary data removed"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::MetadataHash) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -2545,7 +2545,7 @@ mod alonzo_tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// Same as successful_mainnet_tx, except that the minimum lovelace in the UTxO
|
||||
// Same as successful_mainnet_tx, except that the minimum lovelace in an output
|
||||
// is unreached.
|
||||
fn min_lovelace_unreached() {
|
||||
let cbor_bytes: Vec<u8> = cbor_to_bytes(include_str!("../../test_data/alonzo1.tx"));
|
||||
|
|
@ -2573,14 +2573,14 @@ mod alonzo_tests {
|
|||
max_val_size: 5000,
|
||||
collateral_percent: 150,
|
||||
max_collateral_inputs: 3,
|
||||
coins_per_utxo_word: 10000000,
|
||||
coins_per_utxo_word: 10000000, // This was 34482 during Alonzo on mainnet.
|
||||
}),
|
||||
prot_magic: 764824073,
|
||||
block_slot: 44237276,
|
||||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Unneeded redeemer"),
|
||||
Ok(()) => panic!("Output minimum lovelace is unreached"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::MinLovelaceUnreached) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -2624,7 +2624,7 @@ mod alonzo_tests {
|
|||
network_id: 1,
|
||||
};
|
||||
match validate(&metx, &utxos, &env) {
|
||||
Ok(()) => panic!("Unneeded redeemer"),
|
||||
Ok(()) => panic!("Max value size exceeded"),
|
||||
Err(err) => match err {
|
||||
Alonzo(AlonzoError::MaxValSizeExceeded) => (),
|
||||
_ => panic!("Unexpected error ({:?})", err),
|
||||
|
|
@ -2712,7 +2712,7 @@ mod alonzo_tests {
|
|||
),
|
||||
],
|
||||
);
|
||||
add_collateral(
|
||||
add_collateral_alonzo(
|
||||
&mtx.transaction_body,
|
||||
&mut utxos,
|
||||
&[(
|
||||
|
|
|
|||
2400
pallas-applying/tests/babbage.rs
Normal file
2400
pallas-applying/tests/babbage.rs
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -2,12 +2,17 @@ use pallas_applying::UTxOs;
|
|||
use pallas_codec::{minicbor::bytes::ByteVec, utils::TagWrap};
|
||||
use pallas_primitives::{
|
||||
alonzo::{MintedTx, TransactionBody, TransactionOutput, Value},
|
||||
babbage::{
|
||||
MintedDatumOption, MintedPostAlonzoTransactionOutput, MintedScriptRef,
|
||||
MintedTransactionBody, MintedTransactionOutput, MintedTx as BabbageMintedTx,
|
||||
PseudoTransactionOutput,
|
||||
},
|
||||
byron::{Address, MintedTxPayload, Tx, TxOut},
|
||||
};
|
||||
use pallas_traverse::{MultiEraInput, MultiEraOutput};
|
||||
use std::{borrow::Cow, iter::zip, vec::Vec};
|
||||
|
||||
use pallas_codec::utils::Bytes;
|
||||
use pallas_codec::utils::{Bytes, CborWrap};
|
||||
use pallas_crypto::hash::Hash;
|
||||
|
||||
pub fn cbor_to_bytes(input: &str) -> Vec<u8> {
|
||||
|
|
@ -18,8 +23,12 @@ pub fn minted_tx_from_cbor(tx_cbor: &[u8]) -> MintedTx<'_> {
|
|||
pallas_codec::minicbor::decode::<MintedTx>(tx_cbor).unwrap()
|
||||
}
|
||||
|
||||
pub fn minted_tx_payload_from_cbor(tx_cbor: &[u8]) -> MintedTxPayload<'_> {
|
||||
pallas_codec::minicbor::decode::<MintedTxPayload>(tx_cbor).unwrap()
|
||||
pub fn babbage_minted_tx_from_cbor(tx_cbor: &[u8]) -> BabbageMintedTx<'_> {
|
||||
pallas_codec::minicbor::decode::<BabbageMintedTx>(&tx_cbor[..]).unwrap()
|
||||
}
|
||||
|
||||
pub fn minted_tx_payload_from_cbor<'a>(tx_cbor: &'a Vec<u8>) -> MintedTxPayload<'a> {
|
||||
pallas_codec::minicbor::decode::<MintedTxPayload>(&tx_cbor[..]).unwrap()
|
||||
}
|
||||
|
||||
pub fn mk_utxo_for_byron_tx<'a>(tx: &Tx, tx_outs_info: &[(String, u64)]) -> UTxOs<'a> {
|
||||
|
|
@ -45,10 +54,16 @@ pub fn mk_utxo_for_byron_tx<'a>(tx: &Tx, tx_outs_info: &[(String, u64)]) -> UTxO
|
|||
|
||||
pub fn mk_utxo_for_alonzo_compatible_tx<'a>(
|
||||
tx_body: &TransactionBody,
|
||||
tx_outs_info: &[(String, Value, Option<Hash<32>>)],
|
||||
tx_outs_info: &[(
|
||||
String, // address in string format
|
||||
Value,
|
||||
Option<Hash<32>>,
|
||||
)],
|
||||
) -> UTxOs<'a> {
|
||||
let mut utxos: UTxOs = UTxOs::new();
|
||||
for (tx_in, (address, amount, datum_hash)) in zip(tx_body.inputs.clone(), tx_outs_info) {
|
||||
let multi_era_in: MultiEraInput =
|
||||
MultiEraInput::AlonzoCompatible(Box::new(Cow::Owned(tx_in)));
|
||||
let address_bytes: Bytes = match hex::decode(address) {
|
||||
Ok(bytes_vec) => Bytes::from(bytes_vec),
|
||||
_ => panic!("Unable to decode input address"),
|
||||
|
|
@ -58,8 +73,6 @@ pub fn mk_utxo_for_alonzo_compatible_tx<'a>(
|
|||
amount: amount.clone(),
|
||||
datum_hash: *datum_hash,
|
||||
};
|
||||
let multi_era_in: MultiEraInput =
|
||||
MultiEraInput::AlonzoCompatible(Box::new(Cow::Owned(tx_in)));
|
||||
let multi_era_out: MultiEraOutput =
|
||||
MultiEraOutput::AlonzoCompatible(Box::new(Cow::Owned(tx_out)));
|
||||
utxos.insert(multi_era_in, multi_era_out);
|
||||
|
|
@ -67,10 +80,44 @@ pub fn mk_utxo_for_alonzo_compatible_tx<'a>(
|
|||
utxos
|
||||
}
|
||||
|
||||
pub fn add_collateral(
|
||||
pub fn mk_utxo_for_babbage_tx<'a>(
|
||||
tx_body: &MintedTransactionBody,
|
||||
tx_outs_info: &'a [(
|
||||
String, // address in string format
|
||||
Value,
|
||||
Option<MintedDatumOption>,
|
||||
Option<CborWrap<MintedScriptRef>>,
|
||||
)],
|
||||
) -> UTxOs<'a> {
|
||||
let mut utxos: UTxOs = UTxOs::new();
|
||||
for (tx_in, (addr, val, datum_opt, script_ref)) in zip(tx_body.inputs.clone(), tx_outs_info) {
|
||||
let multi_era_in: MultiEraInput =
|
||||
MultiEraInput::AlonzoCompatible(Box::new(Cow::Owned(tx_in)));
|
||||
let address_bytes: Bytes = match hex::decode(addr) {
|
||||
Ok(bytes_vec) => Bytes::from(bytes_vec),
|
||||
_ => panic!("Unable to decode input address"),
|
||||
};
|
||||
let tx_out: MintedTransactionOutput =
|
||||
PseudoTransactionOutput::PostAlonzo(MintedPostAlonzoTransactionOutput {
|
||||
address: address_bytes,
|
||||
value: val.clone(),
|
||||
datum_option: datum_opt.clone(),
|
||||
script_ref: script_ref.clone(),
|
||||
});
|
||||
let multi_era_out: MultiEraOutput = MultiEraOutput::Babbage(Box::new(Cow::Owned(tx_out)));
|
||||
utxos.insert(multi_era_in, multi_era_out);
|
||||
}
|
||||
utxos
|
||||
}
|
||||
|
||||
pub fn add_collateral_alonzo<'a>(
|
||||
tx_body: &TransactionBody,
|
||||
utxos: &mut UTxOs<'_>,
|
||||
collateral_info: &[(String, Value, Option<Hash<32>>)],
|
||||
collateral_info: &[(
|
||||
String, // address in string format
|
||||
Value,
|
||||
Option<Hash<32>>,
|
||||
)],
|
||||
) {
|
||||
match &tx_body.collateral {
|
||||
Some(collaterals) => {
|
||||
|
|
@ -94,3 +141,85 @@ pub fn add_collateral(
|
|||
None => panic!("Adding collateral to UTxO failed due to an empty list of collaterals"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_collateral_babbage<'a>(
|
||||
tx_body: &MintedTransactionBody,
|
||||
utxos: &mut UTxOs<'a>,
|
||||
collateral_info: &'a [(
|
||||
String, // address in string format
|
||||
Value,
|
||||
Option<MintedDatumOption>,
|
||||
Option<CborWrap<MintedScriptRef>>,
|
||||
)],
|
||||
) {
|
||||
match &tx_body.collateral {
|
||||
Some(collaterals) => {
|
||||
if collaterals.is_empty() {
|
||||
panic!("UTxO addition error - collateral input missing")
|
||||
} else {
|
||||
for (tx_in, (addr, val, datum_opt, script_ref)) in
|
||||
zip(collaterals.clone(), collateral_info)
|
||||
{
|
||||
let multi_era_in: MultiEraInput =
|
||||
MultiEraInput::AlonzoCompatible(Box::new(Cow::Owned(tx_in)));
|
||||
let address_bytes: Bytes = match hex::decode(addr) {
|
||||
Ok(bytes_vec) => Bytes::from(bytes_vec),
|
||||
_ => panic!("Unable to decode input address"),
|
||||
};
|
||||
let tx_out: MintedTransactionOutput =
|
||||
PseudoTransactionOutput::PostAlonzo(MintedPostAlonzoTransactionOutput {
|
||||
address: address_bytes,
|
||||
value: val.clone(),
|
||||
datum_option: datum_opt.clone(),
|
||||
script_ref: script_ref.clone(),
|
||||
});
|
||||
let multi_era_out: MultiEraOutput =
|
||||
MultiEraOutput::Babbage(Box::new(Cow::Owned(tx_out)));
|
||||
utxos.insert(multi_era_in, multi_era_out);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => panic!("UTxO addition error - collateral input missing"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_ref_input_babbage<'a>(
|
||||
tx_body: &MintedTransactionBody,
|
||||
utxos: &mut UTxOs<'a>,
|
||||
ref_input_info: &'a [(
|
||||
String, // address in string format
|
||||
Value,
|
||||
Option<MintedDatumOption>,
|
||||
Option<CborWrap<MintedScriptRef>>,
|
||||
)],
|
||||
) {
|
||||
match &tx_body.reference_inputs {
|
||||
Some(ref_inputs) => {
|
||||
if ref_inputs.is_empty() {
|
||||
panic!("UTxO addition error - reference input missing")
|
||||
} else {
|
||||
for (tx_in, (addr, val, datum_opt, script_ref)) in
|
||||
zip(ref_inputs.clone(), ref_input_info)
|
||||
{
|
||||
let multi_era_in: MultiEraInput =
|
||||
MultiEraInput::AlonzoCompatible(Box::new(Cow::Owned(tx_in)));
|
||||
let address_bytes: Bytes = match hex::decode(addr) {
|
||||
Ok(bytes_vec) => Bytes::from(bytes_vec),
|
||||
_ => panic!("Unable to decode input address"),
|
||||
};
|
||||
let tx_out: MintedTransactionOutput =
|
||||
PseudoTransactionOutput::PostAlonzo(MintedPostAlonzoTransactionOutput {
|
||||
address: address_bytes,
|
||||
value: val.clone(),
|
||||
datum_option: datum_opt.clone(),
|
||||
script_ref: script_ref.clone(),
|
||||
});
|
||||
let multi_era_out: MultiEraOutput =
|
||||
MultiEraOutput::Babbage(Box::new(Cow::Owned(tx_out)));
|
||||
utxos.insert(multi_era_in, multi_era_out);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => panic!("UTxO addition error - reference input missing"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue