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

refactor: Switch to Pallas v0.17 (huge change) #527

Merged
merged 3 commits into from
Jan 29, 2023
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
76 changes: 37 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]


[dependencies]
pallas = "0.13.4"
pallas = "0.17.0"
# pallas = { git = "https://github.com/txpipe/pallas" }
# pallas = { path = "../pallas/pallas" }
hex = "0.4.3"
Expand Down
29 changes: 15 additions & 14 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use pallas::codec::utils::KeepRaw;
use pallas::ledger::primitives::ToHash;

use pallas::ledger::primitives::babbage::{
AuxiliaryData, MintedBlock, NetworkId, PostAlonzoTransactionOutput, TransactionBody,
TransactionOutput, TransactionWitnessSet,
AuxiliaryData, MintedBlock, MintedWitnessSet, NetworkId, PostAlonzoTransactionOutput,
TransactionBody, TransactionOutput,
};

use pallas::crypto::hash::Hash;
use pallas::ledger::traverse::OriginalHash;

use crate::model::{BlockRecord, Era, TransactionRecord};
use crate::utils::time::TimeProvider;
Expand All @@ -22,7 +22,7 @@ impl EventWriter {
&self,
body: &KeepRaw<TransactionBody>,
aux_data: Option<&KeepRaw<AuxiliaryData>>,
witness_set: Option<&KeepRaw<TransactionWitnessSet>>,
witness_set: Option<&KeepRaw<MintedWitnessSet>>,
) -> usize {
body.raw_cbor().len()
+ aux_data.map(|ax| ax.raw_cbor().len()).unwrap_or(2)
Expand All @@ -34,7 +34,7 @@ impl EventWriter {
body: &KeepRaw<TransactionBody>,
tx_hash: &str,
aux_data: Option<&KeepRaw<AuxiliaryData>>,
witness_set: Option<&KeepRaw<TransactionWitnessSet>>,
witness_set: Option<&KeepRaw<MintedWitnessSet>>,
) -> Result<TransactionRecord, Error> {
let mut record = TransactionRecord {
hash: tx_hash.to_owned(),
Expand Down Expand Up @@ -85,9 +85,7 @@ impl EventWriter {

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()
}
TransactionOutput::PostAlonzo(x) => self.to_post_alonzo_output_record(x).unwrap(),
});

record.metadata = match aux_data {
Expand Down Expand Up @@ -185,7 +183,7 @@ impl EventWriter {

let witness_set = block.transaction_witness_sets.get(idx);

let tx_hash = tx.to_hash().to_hex();
let tx_hash = tx.original_hash().to_hex();

self.to_babbage_transaction_record(tx, &tx_hash, aux_data, witness_set)
})
Expand Down Expand Up @@ -217,7 +215,10 @@ impl EventWriter {
}
}

fn crawl_babbage_witness_set(&self, witness_set: &TransactionWitnessSet) -> Result<(), Error> {
fn crawl_babbage_witness_set(
&self,
witness_set: &KeepRaw<MintedWitnessSet>,
) -> Result<(), Error> {
if let Some(native) = &witness_set.native_script {
for script in native.iter() {
self.append_from(self.to_native_witness_record(script)?)?;
Expand Down Expand Up @@ -250,7 +251,7 @@ impl EventWriter {
tx: &KeepRaw<TransactionBody>,
tx_hash: &str,
aux_data: Option<&KeepRaw<AuxiliaryData>>,
witness_set: Option<&KeepRaw<TransactionWitnessSet>>,
witness_set: Option<&KeepRaw<MintedWitnessSet>>,
) -> Result<(), Error> {
let record = self.to_babbage_transaction_record(tx, tx_hash, aux_data, witness_set)?;

Expand Down Expand Up @@ -331,7 +332,7 @@ impl EventWriter {

let witness_set = block.transaction_witness_sets.get(idx);

let tx_hash = tx.to_hash().to_hex();
let tx_hash = tx.original_hash().to_hex();

let child = self.child_writer(EventContext {
tx_idx: Some(idx),
Expand Down Expand Up @@ -359,10 +360,10 @@ impl EventWriter {
block: &'b MintedBlock<'b>,
cbor: &'b [u8],
) -> Result<(), Error> {
let hash = block.header.to_hash();
let hash = block.header.original_hash();

let child = self.child_writer(EventContext {
block_hash: Some(hex::encode(&hash)),
block_hash: Some(hex::encode(hash)),
block_number: Some(block.header.header_body.block_number),
slot: Some(block.header.header_body.slot),
timestamp: self.compute_timestamp(block.header.header_body.slot),
Expand Down
Loading