Skip to content

Commit

Permalink
feat: Use era-agnostic address strings (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jul 23, 2022
1 parent d599138 commit d4ede65
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 49 deletions.
33 changes: 16 additions & 17 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 src/enrich/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<_>, crate::Error> = utxo_refs
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/address_by_txo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
11 changes: 4 additions & 7 deletions src/reducers/balance_by_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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(());
}
}
Expand All @@ -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)?;
}

Expand Down
6 changes: 3 additions & 3 deletions src/reducers/total_transactions_count_by_addresses.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)?;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/reducers/transactions_count_by_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/reducers/transactions_count_by_address_by_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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();
Expand Down
9 changes: 3 additions & 6 deletions src/reducers/utxo_by_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)?;
}

Expand Down

0 comments on commit d4ede65

Please sign in to comment.