Skip to content

Commit

Permalink
feat: withdrawal record
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Jul 3, 2022
1 parent add845f commit 8c10f6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mapper/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 8c10f6d

Please sign in to comment.