Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Send inline datum as new events #539

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pallas::codec::utils::KeepRaw;

use pallas::ledger::primitives::babbage::{
AuxiliaryData, MintedBlock, MintedPostAlonzoTransactionOutput, MintedTransactionBody,
MintedTransactionOutput, MintedWitnessSet, NetworkId,
AuxiliaryData, MintedBlock, MintedDatumOption, MintedPostAlonzoTransactionOutput,
MintedTransactionBody, MintedTransactionOutput, MintedWitnessSet, NetworkId,
};

use pallas::crypto::hash::Hash;
Expand Down Expand Up @@ -113,7 +113,7 @@ impl EventWriter {
.into();

record.plutus_data = self
.collect_plutus_datum_records(&witnesses.plutus_data)?
.collect_witness_plutus_datum_records(&witnesses.plutus_data)?
.into();
}

Expand Down Expand Up @@ -208,6 +208,11 @@ impl EventWriter {

child.crawl_transaction_output_amount(&output.value)?;

if let Some(MintedDatumOption::Data(datum)) = &output.datum_option {
let record = self.to_plutus_datum_record(datum)?;
child.append(record.into())?;
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/mapper/byron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl EventWriter {
amount: source.amount,
assets: None,
datum_hash: None,
inline_datum: None,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/mapper/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl EventWriter {
}
}

pub fn collect_plutus_datum_records(
pub fn collect_witness_plutus_datum_records(
&self,
witness_set: &Option<Vec<KeepRaw<PlutusData>>>,
) -> Result<Vec<PlutusDatumRecord>, Error> {
Expand Down
11 changes: 8 additions & 3 deletions src/mapper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl EventWriter {
amount: get_tx_output_coin_value(&output.amount),
assets: self.collect_asset_records(&output.amount).into(),
datum_hash: output.datum_hash.map(|hash| hash.to_string()),
inline_datum: None,
})
}

Expand All @@ -194,6 +195,10 @@ impl EventWriter {
Some(MintedDatumOption::Data(x)) => Some(x.original_hash().to_hex()),
None => None,
},
inline_datum: match &output.datum_option {
Some(MintedDatumOption::Data(x)) => Some(self.to_plutus_datum_record(x)?),
_ => None,
},
})
}

Expand Down Expand Up @@ -258,10 +263,10 @@ impl EventWriter {

pub fn to_plutus_datum_record(
&self,
datum: &alonzo::PlutusData,
datum: &KeepRaw<'_, alonzo::PlutusData>,
) -> Result<PlutusDatumRecord, crate::Error> {
Ok(PlutusDatumRecord {
datum_hash: datum.compute_hash().to_hex(),
datum_hash: datum.original_hash().to_hex(),
plutus_data: datum.to_json(),
})
}
Expand Down Expand Up @@ -452,7 +457,7 @@ impl EventWriter {
.into();

record.plutus_data = self
.collect_plutus_datum_records(&witnesses.plutus_data)?
.collect_witness_plutus_datum_records(&witnesses.plutus_data)?
.into();
}

Expand Down
3 changes: 2 additions & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ impl From<OutputAssetRecord> for EventData {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct TxOutputRecord {
pub address: String,
pub amount: u64,
pub assets: Option<Vec<OutputAssetRecord>>,
pub datum_hash: Option<String>,
pub inline_datum: Option<PlutusDatumRecord>,
}

impl From<TxOutputRecord> for EventData {
Expand Down