Skip to content

Commit

Permalink
fix: Fix byron address string representation (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jan 29, 2023
1 parent 91532f5 commit 0f149a2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 96 deletions.
8 changes: 3 additions & 5 deletions src/mapper/babbage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ impl EventWriter {
let record = self.to_post_alonzo_output_record(output)?;
self.append(record.into())?;

let address = pallas::ledger::addresses::Address::from_bytes(&output.address)?;

let child = &self.child_writer(EventContext {
output_address: self
.utils
.bech32
.encode_address(output.address.as_slice())?
.into(),
output_address: address.to_string().into(),
..EventContext::default()
});

Expand Down
14 changes: 6 additions & 8 deletions src/mapper/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ impl EventWriter {
&self,
output: &alonzo::TransactionOutput,
) -> Result<TxOutputRecord, Error> {
let address = pallas::ledger::addresses::Address::from_bytes(&output.address)?;

Ok(TxOutputRecord {
address: self
.utils
.bech32
.encode_address(output.address.as_slice())?,
address: address.to_string(),
amount: get_tx_output_coin_value(&output.amount),
assets: self.collect_asset_records(&output.amount).into(),
datum_hash: output.datum_hash.map(|hash| hash.to_string()),
Expand All @@ -183,11 +182,10 @@ impl EventWriter {
&self,
output: &babbage::PostAlonzoTransactionOutput,
) -> Result<TxOutputRecord, Error> {
let address = pallas::ledger::addresses::Address::from_bytes(&output.address)?;

Ok(TxOutputRecord {
address: self
.utils
.bech32
.encode_address(output.address.as_slice())?,
address: address.to_string(),
amount: get_tx_output_coin_value(&output.value),
assets: self.collect_asset_records(&output.value).into(),
datum_hash: match &output.datum_option {
Expand Down
8 changes: 3 additions & 5 deletions src/mapper/shelley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ impl EventWriter {
let record = self.to_legacy_output_record(output)?;
self.append(record.into())?;

let address = pallas::ledger::addresses::Address::from_bytes(&output.address)?;

let child = &self.child_writer(EventContext {
output_address: self
.utils
.bech32
.encode_address(output.address.as_slice())?
.into(),
output_address: address.to_string().into(),
..EventContext::default()
});

Expand Down
68 changes: 0 additions & 68 deletions src/utils/bech32.rs

This file was deleted.

11 changes: 1 addition & 10 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ pub const PREVIEW_MAGIC: u64 = 2;

use serde::{Deserialize, Serialize};

use crate::{
model::Event,
utils::{
bech32::{Bech32Config, Bech32Provider},
time::NaiveProvider as NaiveTime,
},
};
use crate::{model::Event, utils::time::NaiveProvider as NaiveTime};

use crate::Error;

pub mod cursor;
pub mod metrics;
pub mod throttle;

pub(crate) mod bech32;
pub(crate) mod retry;
pub(crate) mod time;

Expand Down Expand Up @@ -174,7 +167,6 @@ impl Default for ChainWellKnownInfo {
pub struct Utils {
pub(crate) well_known: ChainWellKnownInfo,
pub(crate) time: Option<NaiveTime>,
pub(crate) bech32: Bech32Provider,
pub(crate) cursor: Option<cursor::Provider>,
pub(crate) metrics: Option<metrics::Provider>,
}
Expand All @@ -184,7 +176,6 @@ impl Utils {
pub fn new(well_known: ChainWellKnownInfo) -> Self {
Self {
time: NaiveTime::new(well_known.clone()).into(),
bech32: Bech32Provider::new(Bech32Config::from_well_known(&well_known)),
well_known,
cursor: None,
metrics: None,
Expand Down

0 comments on commit 0f149a2

Please sign in to comment.