Skip to content

Commit

Permalink
Merge branch 'main' into testdrive
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Feb 14, 2023
2 parents 903eeea + cfb9ef2 commit 6f3ef5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
19 changes: 8 additions & 11 deletions src/reducers/addresses_by_stake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use pallas::ledger::addresses::{self, Address, StakeAddress};
use pallas::ledger::traverse::MultiEraOutput;
use pallas::ledger::traverse::{MultiEraBlock, MultiEraTx, OutputRef};
use pallas::ledger::addresses::{Address, StakeAddress};
use pallas::ledger::traverse::MultiEraBlock;
use serde::Deserialize;

use crate::{crosscut, model, prelude::*};
Expand Down Expand Up @@ -28,15 +27,12 @@ fn any_address_to_stake_bech32(address: Address) -> Option<String> {
}

impl Reducer {
fn process_produced_txo(
fn process_address(
&mut self,
tx: &MultiEraTx,
tx_output: &MultiEraOutput,
output_idx: usize,
address: Address,
output: &mut super::OutputPort,
) -> Result<(), gasket::error::Error> {
let tx_hash = tx.hash();
let address = tx_output.address().or_panic()?;
let full_address = address.to_bech32().or_panic()?;
let stake_address = any_address_to_stake_bech32(address);

let stake_address = match stake_address {
Expand All @@ -53,7 +49,7 @@ impl Reducer {
let crdt = model::CRDTCommand::set_add(
self.config.key_prefix.as_deref(),
&stake_address,
address.to_bech32()
full_address,
);

output.send(crdt.into())
Expand All @@ -67,7 +63,8 @@ impl Reducer {
) -> Result<(), gasket::error::Error> {
for tx in block.txs().into_iter() {
for (idx, produced) in tx.produces() {
self.process_produced_txo(&tx, &produced, idx, output)?;
let address = produced.address().or_panic()?;
self.process_address(address, output)?;
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/reducers/supply_by_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl Reducer {

fn process_asset(
&mut self,
policy: Hash<28>,
asset: Vec<u8>,
policy: &Hash<28>,
asset: &Vec<u8>,
qty: i64,
output: &mut super::OutputPort,
) -> Result<(), gasket::error::Error> {
Expand Down Expand Up @@ -59,11 +59,9 @@ impl Reducer {
) -> Result<(), gasket::error::Error> {
for tx in block.txs().into_iter() {
if let Some(mints) = tx.mint().as_alonzo() {
for (_, assets) in mints.iter() {
for asset in assets {
if let Asset::NativeAsset(policy, asset, qty) = asset {
self.process_asset(policy, asset, qty as i64, output)?;
}
for (policy, assets) in mints.iter() {
for (name, amount) in assets.iter() {
self.process_asset(policy, name, *amount, output)?;
}
}
}
Expand Down

0 comments on commit 6f3ef5d

Please sign in to comment.