Skip to content

Commit

Permalink
feat: Expose collateral data (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercurial authored Dec 9, 2022
1 parent 6daf4eb commit b630a57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl EventWriter {
}
}

// Add Collateral Stuff
let collateral_inputs = &body.collateral.as_deref();
record.collateral_input_count = collateral_inputs.iter().count();
record.has_collateral_output = body.collateral_return.is_some();

// TODO
// TransactionBodyComponent::ScriptDataHash(_)
// TransactionBodyComponent::RequiredSigners(_)
Expand All @@ -74,6 +79,17 @@ impl EventWriter {
record.outputs = outputs.into();
record.inputs = inputs.into();

// transaction_details collateral stuff
record.collateral_inputs =
collateral_inputs.map(|inputs| self.collect_input_records(inputs));

record.collateral_output = body.collateral_return.as_ref().map(|output| match output {
TransactionOutput::Legacy(x) => self.to_legacy_output_record(x).unwrap(),
TransactionOutput::PostAlonzo(x) => {
self.to_post_alonzo_output_record(x).unwrap()
}
});

record.metadata = match aux_data {
Some(aux_data) => self.collect_metadata_records(aux_data)?.into(),
None => None,
Expand Down
4 changes: 4 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub struct TransactionRecord {
pub validity_interval_start: Option<u64>,
pub network_id: Option<u32>,
pub input_count: usize,
pub collateral_input_count: usize,
pub has_collateral_output: bool,
pub output_count: usize,
pub mint_count: usize,
pub total_output: u64,
Expand All @@ -168,6 +170,8 @@ pub struct TransactionRecord {
pub metadata: Option<Vec<MetadataRecord>>,
pub inputs: Option<Vec<TxInputRecord>>,
pub outputs: Option<Vec<TxOutputRecord>>,
pub collateral_inputs: Option<Vec<TxInputRecord>>,
pub collateral_output: Option<TxOutputRecord>,
pub mint: Option<Vec<MintRecord>>,
pub vkey_witnesses: Option<Vec<VKeyWitnessRecord>>,
pub native_witnesses: Option<Vec<NativeWitnessRecord>>,
Expand Down

0 comments on commit b630a57

Please sign in to comment.