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

WithdrawalRecord #349

Merged
merged 3 commits into from
Jul 23, 2022
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
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