Skip to content

Commit dc2a079

Browse files
authored
chore: bump Pallas to v0.30.1 (#811)
1 parent e408e06 commit dc2a079

3 files changed

Lines changed: 84 additions & 29 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]
1414
[dependencies]
1515
pallas-multiplexer = "0.18.2"
1616
pallas-miniprotocols = "0.18.2"
17-
pallas-primitives = "0.29.0"
18-
pallas-traverse = "0.29.0"
19-
pallas-addresses = "0.29.0"
20-
pallas-codec = "0.29.0"
21-
pallas-crypto = "0.29.0"
17+
pallas-primitives = "0.30.1"
18+
pallas-traverse = "0.30.1"
19+
pallas-addresses = "0.30.1"
20+
pallas-codec = "0.30.1"
21+
pallas-crypto = "0.30.1"
2222
# pallas = { git = "https://github.com/txpipe/pallas" }
2323
# pallas = { path = "../pallas/pallas" }
2424
hex = "0.4.3"

src/mapper/conway.rs

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
use pallas_codec::utils::{KeepRaw, NonZeroInt};
1+
use pallas_codec::utils::{KeepRaw, NonEmptyKeyValuePairs, NonZeroInt};
22

33
use pallas_primitives::conway::{
4-
AuxiliaryData, Certificate, MintedBlock, MintedDatumOption, MintedPostAlonzoTransactionOutput,
5-
MintedTransactionBody, MintedTransactionOutput, MintedWitnessSet, Multiasset, NetworkId,
6-
RedeemerTag, RedeemersKey, RedeemersValue,
4+
AuxiliaryData, Certificate, Coin, MintedBlock, MintedDatumOption,
5+
MintedPostAlonzoTransactionOutput, MintedTransactionBody, MintedTransactionOutput,
6+
MintedWitnessSet, Multiasset, NetworkId, RedeemerTag, RedeemersKey, RedeemersValue,
7+
RewardAccount, Value,
78
};
89

910
use pallas_crypto::hash::Hash;
1011
use pallas_primitives::ToCanonicalJson as _;
1112
use pallas_traverse::OriginalHash;
1213

1314
use crate::model::{
14-
BlockRecord, Era, MintRecord, PlutusRedeemerRecord, TransactionRecord, TxOutputRecord,
15+
BlockRecord, Era, MintRecord, OutputAssetRecord, PlutusRedeemerRecord, TransactionRecord,
16+
TxOutputRecord, WithdrawalRecord,
1517
};
1618
use crate::utils::time::TimeProvider;
1719
use crate::{
@@ -22,6 +24,27 @@ use crate::{
2224
use super::{map::ToHex, EventWriter};
2325

2426
impl EventWriter {
27+
pub fn collect_conway_coin_value(&self, amount: &Value) -> u64 {
28+
match amount {
29+
Value::Coin(x) => *x,
30+
Value::Multiasset(x, _) => *x,
31+
}
32+
}
33+
34+
pub fn collect_conway_asset_records(&self, amount: &Value) -> Vec<OutputAssetRecord> {
35+
match amount {
36+
Value::Coin(_) => vec![],
37+
Value::Multiasset(_, policies) => policies
38+
.iter()
39+
.flat_map(|(policy, assets)| {
40+
assets.iter().map(|(asset, amount)| {
41+
self.to_transaction_output_asset_record(policy, asset, u64::from(amount))
42+
})
43+
})
44+
.collect(),
45+
}
46+
}
47+
2548
pub fn collect_conway_mint_records(&self, mint: &Multiasset<NonZeroInt>) -> Vec<MintRecord> {
2649
mint.iter()
2750
.flat_map(|(policy, assets)| {
@@ -50,8 +73,8 @@ impl EventWriter {
5073

5174
Ok(TxOutputRecord {
5275
address: address.to_string(),
53-
amount: super::map::get_tx_output_coin_value(&output.value),
54-
assets: self.collect_asset_records(&output.value).into(),
76+
amount: self.collect_conway_coin_value(&output.value),
77+
assets: self.collect_conway_asset_records(&output.value).into(),
5578
datum_hash: match &output.datum_option {
5679
Some(MintedDatumOption::Hash(x)) => Some(x.to_string()),
5780
Some(MintedDatumOption::Data(x)) => Some(x.original_hash().to_hex()),
@@ -98,6 +121,22 @@ impl EventWriter {
98121
.collect()
99122
}
100123

124+
pub fn collect_conway_withdrawal_records(
125+
&self,
126+
withdrawls: &NonEmptyKeyValuePairs<RewardAccount, Coin>,
127+
) -> Vec<WithdrawalRecord> {
128+
withdrawls
129+
.iter()
130+
.map(|(reward_account, coin)| WithdrawalRecord {
131+
reward_account: {
132+
let hex = reward_account.to_hex();
133+
hex.strip_prefix("e1").map(|x| x.to_string()).unwrap_or(hex)
134+
},
135+
coin: *coin,
136+
})
137+
.collect()
138+
}
139+
101140
pub fn to_conway_tx_size(
102141
&self,
103142
body: &KeepRaw<MintedTransactionBody>,
@@ -243,7 +282,7 @@ impl EventWriter {
243282
}
244283

245284
if let Some(withdrawals) = &body.withdrawals {
246-
record.withdrawals = self.collect_withdrawal_records(withdrawals).into();
285+
record.withdrawals = self.collect_conway_withdrawal_records(withdrawals).into();
247286
}
248287
}
249288

@@ -317,6 +356,22 @@ impl EventWriter {
317356
.collect()
318357
}
319358

359+
pub fn crawl_conway_transaction_output_amount(&self, amount: &Value) -> Result<(), Error> {
360+
if let Value::Multiasset(_, policies) = amount {
361+
for (policy, assets) in policies.iter() {
362+
for (asset, amount) in assets.iter() {
363+
self.append_from(self.to_transaction_output_asset_record(
364+
policy,
365+
asset,
366+
u64::from(amount),
367+
))?;
368+
}
369+
}
370+
}
371+
372+
Ok(())
373+
}
374+
320375
fn crawl_conway_output(&self, output: &MintedPostAlonzoTransactionOutput) -> Result<(), Error> {
321376
let record = self.to_conway_output_record(output)?;
322377
self.append(record.into())?;
@@ -328,7 +383,7 @@ impl EventWriter {
328383
..EventContext::default()
329384
});
330385

331-
child.crawl_transaction_output_amount(&output.value)?;
386+
child.crawl_conway_transaction_output_amount(&output.value)?;
332387

333388
if let Some(MintedDatumOption::Data(datum)) = &output.datum_option {
334389
let record = self.to_plutus_datum_record(datum)?;

0 commit comments

Comments
 (0)