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

Tx input as output #161

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/crosscut/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ pub fn eval_predicate(
mod tests {
use pallas::ledger::traverse::MultiEraBlock;

use crate::{crosscut::policies::{ErrorAction, RuntimePolicy}, framework::model::BlockContext};
use crate::{
crosscut::policies::{ErrorAction, RuntimePolicy},
framework::model::BlockContext,
};

use super::{eval_predicate, AddressPattern, Predicate};

Expand Down
25 changes: 21 additions & 4 deletions src/reducers/deno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use deno_runtime::deno_core::{self, op2, ModuleSpecifier, OpState};
use deno_runtime::permissions::PermissionsContainer;
use deno_runtime::worker::{MainWorker as DenoWorker, WorkerOptions};
use gasket::framework::*;
use pallas::interop::utxorpc::map_block;
use pallas::ledger::traverse::MultiEraBlock;
use pallas::interop::utxorpc::{map_block, map_tx_output};
use pallas::ledger::traverse::{MultiEraBlock, OutputRef};
use serde::Deserialize;
use serde_json::json;
use tracing::trace;
Expand Down Expand Up @@ -133,11 +133,28 @@ impl gasket::framework::Worker<Stage> for Worker {
let record = record.unwrap();

match record {
Record::EnrichedBlockPayload(block, _) => {
Record::EnrichedBlockPayload(block, ctx) => {
let block = MultiEraBlock::decode(block)
.map_err(Error::cbor)
.or_panic()?;
let block = map_block(&block);
let mut block = map_block(&block);

for tx in block.body.as_mut().unwrap().tx.iter_mut() {
for input in tx.inputs.iter_mut() {
if input.tx_hash.len() == 32 {
let mut hash_bytes = [0u8; 32];
hash_bytes.copy_from_slice(&input.tx_hash);

let tx_hash = pallas::crypto::hash::Hash::from(hash_bytes);
let output_index = input.output_index as u64;
let output_ref = OutputRef::new(tx_hash, output_index);

if let Ok(output) = ctx.find_utxo(&output_ref) {
input.as_output = Some(map_tx_output(&output));
}
}
}
}

let deno = &mut self.runtime;

Expand Down
3 changes: 1 addition & 2 deletions src/storage/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub struct Worker {
#[async_trait::async_trait(?Send)]
impl gasket::framework::Worker<Stage> for Worker {
async fn bootstrap(stage: &Stage) -> Result<Self, WorkerError> {
let manager =
RedisConnectionManager::new(stage.config.url.clone()).or_panic()?;
let manager = RedisConnectionManager::new(stage.config.url.clone()).or_panic()?;
let pool = r2d2::Pool::builder().build(manager).or_panic()?;

Ok(Self { pool })
Expand Down