From 4ed2b54b7587d4f0724b793a7129c447e6b69cce Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sat, 23 Jul 2022 09:37:41 -0300 Subject: [PATCH] feat: Use era-agnostic address strings --- Cargo.lock | 33 +++++++++---------- src/enrich/sled.rs | 2 +- src/reducers/address_by_txo.rs | 2 +- src/reducers/balance_by_address.rs | 11 +++---- .../total_transactions_count_by_addresses.rs | 6 ++-- src/reducers/transactions_count_by_address.rs | 14 ++++---- .../transactions_count_by_address_by_epoch.rs | 14 ++++---- src/reducers/utxo_by_address.rs | 9 ++--- 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe82b78a..592c1b12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -625,8 +625,8 @@ checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "pallas" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "pallas-addresses", "pallas-codec", @@ -639,30 +639,29 @@ dependencies = [ [[package]] name = "pallas-addresses" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "base58", "bech32 0.8.1", "hex", "pallas-codec", "pallas-crypto", - "pallas-primitives", "thiserror", ] [[package]] name = "pallas-codec" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "minicbor 0.17.1", ] [[package]] name = "pallas-crypto" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "cryptoxide", "hex", @@ -673,8 +672,8 @@ dependencies = [ [[package]] name = "pallas-miniprotocols" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "hex", "itertools", @@ -686,8 +685,8 @@ dependencies = [ [[package]] name = "pallas-multiplexer" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "byteorder", "hex", @@ -699,8 +698,8 @@ dependencies = [ [[package]] name = "pallas-primitives" -version = "0.11.0" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "base58", "bech32 0.9.0", @@ -714,8 +713,8 @@ dependencies = [ [[package]] name = "pallas-traverse" -version = "0.11.1" -source = "git+https://github.com/txpipe/pallas.git#758d6e211995bb612e6bd43e0495210084f5db9e" +version = "0.12.0-alpha.0" +source = "git+https://github.com/txpipe/pallas.git#ebfb6a1d6573339f1ba718a323ed8e790f1c5fee" dependencies = [ "hex", "pallas-addresses", diff --git a/src/enrich/sled.rs b/src/enrich/sled.rs index 2eecd877..ab5c3026 100644 --- a/src/enrich/sled.rs +++ b/src/enrich/sled.rs @@ -174,7 +174,7 @@ impl Worker { let utxo_refs: Vec<_> = txs .iter() .flat_map(|tx| tx.inputs()) - .filter_map(|input| input.output_ref()) + .map(|input| input.output_ref()) .collect(); let matches: Result, crate::Error> = utxo_refs diff --git a/src/reducers/address_by_txo.rs b/src/reducers/address_by_txo.rs index 5dc646d1..a9904f36 100644 --- a/src/reducers/address_by_txo.rs +++ b/src/reducers/address_by_txo.rs @@ -53,7 +53,7 @@ impl Reducer { let tx_hash = tx.hash(); for (output_idx, tx_out) in tx.outputs().iter().enumerate() { - let address = tx_out.to_address().and_then(|x| x.to_bech32()).or_panic()?; + let address = tx_out.address().map(|x| x.to_string()).or_panic()?; self.send_set_add(slot, &address, tx_hash, output_idx, output)?; } diff --git a/src/reducers/balance_by_address.rs b/src/reducers/balance_by_address.rs index f2ef16cf..3453c804 100644 --- a/src/reducers/balance_by_address.rs +++ b/src/reducers/balance_by_address.rs @@ -29,7 +29,7 @@ impl Reducer { None => return Ok(()), }; - let address = utxo.to_address().and_then(|x| x.to_bech32()).or_panic()?; + let address = utxo.address().map(|x| x.to_string()).or_panic()?; if let Some(addresses) = &self.config.filter { if let Err(_) = addresses.binary_search(&address.to_string()) { @@ -54,13 +54,10 @@ impl Reducer { tx_output: &MultiEraOutput, output: &mut super::OutputPort, ) -> Result<(), gasket::error::Error> { - let address = tx_output - .to_address() - .and_then(|x| x.to_bech32()) - .or_panic()?; + let address = tx_output.address().map(|x| x.to_string()).or_panic()?; if let Some(addresses) = &self.config.filter { - if let Err(_) = addresses.binary_search(&address.to_string()) { + if let Err(_) = addresses.binary_search(&address) { return Ok(()); } } @@ -84,7 +81,7 @@ impl Reducer { output: &mut super::OutputPort, ) -> Result<(), gasket::error::Error> { for tx in block.txs().into_iter() { - for input in tx.inputs().iter().filter_map(|i| i.output_ref()) { + for input in tx.inputs().iter().map(|i| i.output_ref()) { self.process_inbound_txo(&ctx, &input, output)?; } diff --git a/src/reducers/total_transactions_count_by_addresses.rs b/src/reducers/total_transactions_count_by_addresses.rs index 4dac2430..f818ac9b 100644 --- a/src/reducers/total_transactions_count_by_addresses.rs +++ b/src/reducers/total_transactions_count_by_addresses.rs @@ -1,7 +1,7 @@ use pallas::ledger::traverse::{Feature, MultiEraBlock}; use serde::Deserialize; -use crate::{crosscut, model}; +use crate::model; #[derive(Deserialize)] pub struct Config { @@ -35,8 +35,8 @@ impl Reducer { ) -> Result<(), gasket::error::Error> { if block.era().has_feature(Feature::SmartContracts) { for tx in block.txs() { - for tx_out in tx.outputs().iter().filter_map(|x| x.as_alonzo()) { - if crosscut::addresses::is_smart_contract(tx_out.address.as_slice()) { + for addr in tx.outputs().iter().filter_map(|x| x.address().ok()) { + if addr.has_script() { self.increment_for_address(output)?; } } diff --git a/src/reducers/transactions_count_by_address.rs b/src/reducers/transactions_count_by_address.rs index 2e162f8c..6eacc9dc 100644 --- a/src/reducers/transactions_count_by_address.rs +++ b/src/reducers/transactions_count_by_address.rs @@ -42,12 +42,12 @@ impl Reducer { let utxo = match utxo { Some(x) => x, None => { - log::error!("Output index not found, index:{}", input.tx_index()); + log::error!("Output index not found, index:{}", input.index()); return Result::Ok(None); } }; - let address = utxo.to_address().and_then(|x| x.to_bech32()).or_panic()?; + let address = utxo.address().map(|x| x.to_string()).or_panic()?; Ok(Some(address)) } @@ -64,7 +64,7 @@ impl Reducer { .inputs() .iter() .filter_map(|multi_era_input| { - let output_ref = multi_era_input.output_ref().unwrap(); + let output_ref = multi_era_input.output_ref(); let maybe_input_address = self.find_address_from_output_ref(ctx, &output_ref); @@ -74,8 +74,8 @@ impl Reducer { Err(x) => { log::error!( "Not found, tx_id:{}, index_at:{}, e:{}", - output_ref.tx_id(), - output_ref.tx_index(), + output_ref.hash(), + output_ref.index(), x ); None @@ -87,8 +87,8 @@ impl Reducer { let output_addresses: Vec<_> = tx .outputs() .iter() - .filter_map(|tx| tx.to_address().ok()) - .filter_map(|addr| addr.to_bech32().ok()) + .filter_map(|tx| tx.address().ok()) + .map(|addr| addr.to_string()) .collect(); let all_addresses = [&input_addresses[..], &output_addresses[..]].concat(); diff --git a/src/reducers/transactions_count_by_address_by_epoch.rs b/src/reducers/transactions_count_by_address_by_epoch.rs index 8f87395e..2583e24d 100644 --- a/src/reducers/transactions_count_by_address_by_epoch.rs +++ b/src/reducers/transactions_count_by_address_by_epoch.rs @@ -44,12 +44,12 @@ impl Reducer { let utxo = match utxo { Some(x) => x, None => { - log::error!("Output index not found, index:{}", input.tx_index()); + log::error!("Output index not found, index:{}", input.index()); return Result::Ok(None); } }; - let address = utxo.to_address().and_then(|x| x.to_bech32()).or_panic()?; + let address = utxo.address().map(|x| x.to_string()).or_panic()?; Ok(Some(address)) } @@ -68,7 +68,7 @@ impl Reducer { .inputs() .iter() .filter_map(|multi_era_input| { - let output_ref = multi_era_input.output_ref().unwrap(); + let output_ref = multi_era_input.output_ref(); let maybe_input_address = self.find_address_from_output_ref(ctx, &output_ref); @@ -78,8 +78,8 @@ impl Reducer { Err(x) => { log::error!( "Not found, tx_id:{}, index_at:{}, e:{}", - output_ref.tx_id(), - output_ref.tx_index(), + output_ref.hash(), + output_ref.index(), x ); None @@ -91,8 +91,8 @@ impl Reducer { let output_addresses: Vec<_> = tx .outputs() .iter() - .filter_map(|x| x.to_address().ok()) - .filter_map(|x| x.to_bech32().ok()) + .filter_map(|x| x.address().ok()) + .map(|x| x.to_string()) .collect(); let all_addresses = [&input_addresses[..], &output_addresses[..]].concat(); diff --git a/src/reducers/utxo_by_address.rs b/src/reducers/utxo_by_address.rs index 280aea8c..8406d3f4 100644 --- a/src/reducers/utxo_by_address.rs +++ b/src/reducers/utxo_by_address.rs @@ -29,7 +29,7 @@ impl Reducer { None => return Ok(()), }; - let address = utxo.to_address().and_then(|x| x.to_bech32()).or_panic()?; + let address = utxo.address().map(|x| x.to_string()).or_panic()?; if let Some(addresses) = &self.config.filter { if let Err(_) = addresses.binary_search(&address) { @@ -54,10 +54,7 @@ impl Reducer { output: &mut super::OutputPort, ) -> Result<(), gasket::error::Error> { let tx_hash = tx.hash(); - let address = tx_output - .to_address() - .and_then(|x| x.to_bech32()) - .or_panic()?; + let address = tx_output.address().map(|x| x.to_string()).or_panic()?; if let Some(addresses) = &self.config.filter { if let Err(_) = addresses.binary_search(&address) { @@ -81,7 +78,7 @@ impl Reducer { output: &mut super::OutputPort, ) -> Result<(), gasket::error::Error> { for tx in block.txs().into_iter() { - for input in tx.inputs().iter().filter_map(|i| i.output_ref()) { + for input in tx.inputs().iter().map(|i| i.output_ref()) { self.process_inbound_txo(&ctx, &input, output)?; }