Skip to content

Commit

Permalink
WithdrawalRecord (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas authored Jul 23, 2022
1 parent a559934 commit 44cacbe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl EventWriter {
.collect_plutus_datum_records(&witnesses.plutus_data)?
.into();
}

if let Some(withdrawals) = &body.withdrawals {
record.withdrawals = self.collect_withdrawal_records(withdrawals).into();
}
}

Ok(record)
Expand Down
21 changes: 17 additions & 4 deletions src/mapper/collect.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use pallas::{
codec::utils::MaybeIndefArray,
codec::utils::{KeyValuePairs, MaybeIndefArray},
ledger::primitives::{
alonzo::{
AuxiliaryData, MintedBlock, Multiasset, NativeScript, PlutusData, PlutusScript,
Redeemer, TransactionInput, VKeyWitness, Value,
AuxiliaryData, Coin, MintedBlock, Multiasset, NativeScript, PlutusData, PlutusScript,
Redeemer, RewardAccount, TransactionInput, VKeyWitness, Value,
},
babbage::{
LegacyTransacionOutput, PlutusV2Script, PostAlonzoTransactionOutput, TransactionOutput,
Expand All @@ -16,7 +16,7 @@ use crate::{
model::{
MetadataRecord, MintRecord, NativeWitnessRecord, OutputAssetRecord, PlutusDatumRecord,
PlutusRedeemerRecord, PlutusWitnessRecord, TransactionRecord, TxInputRecord,
TxOutputRecord, VKeyWitnessRecord,
TxOutputRecord, VKeyWitnessRecord, WithdrawalRecord,
},
Error,
};
Expand Down Expand Up @@ -88,6 +88,19 @@ impl EventWriter {
.collect()
}

pub fn collect_withdrawal_records(
&self,
withdrawls: &KeyValuePairs<RewardAccount, Coin>,
) -> Vec<WithdrawalRecord> {
withdrawls
.iter()
.map(|(reward_account, coin)| WithdrawalRecord {
reward_account: reward_account.to_hex(),
coin: coin.into(),
})
.collect()
}

pub fn collect_metadata_records(
&self,
aux_data: &AuxiliaryData,
Expand Down
4 changes: 4 additions & 0 deletions src/mapper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ impl EventWriter {
.collect_plutus_datum_records(&witnesses.plutus_data)?
.into();
}

if let Some(withdrawals) = &body.withdrawals {
record.withdrawals = self.collect_withdrawal_records(withdrawals).into();
}
}

Ok(record)
Expand Down
7 changes: 7 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ impl From<MintRecord> for EventData {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct WithdrawalRecord {
pub reward_account: String,
pub coin: u64,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)]
pub struct TransactionRecord {
pub hash: String,
Expand All @@ -168,6 +174,7 @@ pub struct TransactionRecord {
pub plutus_witnesses: Option<Vec<PlutusWitnessRecord>>,
pub plutus_redeemers: Option<Vec<PlutusRedeemerRecord>>,
pub plutus_data: Option<Vec<PlutusDatumRecord>>,
pub withdrawals: Option<Vec<WithdrawalRecord>>,
}

impl From<TransactionRecord> for EventData {
Expand Down

0 comments on commit 44cacbe

Please sign in to comment.