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

Move TransactionContext from js to tracing #183

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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
10 changes: 4 additions & 6 deletions src/tracing/js/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Type bindings for js tracing inspector

use crate::tracing::{
js::{
builtins::{
address_to_byte_array, address_to_byte_array_value, bytes_to_address, bytes_to_hash,
from_buf_value, to_bigint, to_byte_array, to_byte_array_value,
},
TransactionContext,
js::builtins::{
address_to_byte_array, address_to_byte_array_value, bytes_to_address, bytes_to_hash,
from_buf_value, to_bigint, to_byte_array, to_byte_array_value,
},
types::CallKind,
TransactionContext,
};
use alloy_primitives::{Address, Bytes, B256, U256};
use boa_engine::{
Expand Down
41 changes: 2 additions & 39 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::tracing::{
builtins::{register_builtins, to_serde_value, PrecompileList},
},
types::CallKind,
TransactionContext,
};
use alloy_primitives::{Address, Bytes, Log, B256, U256};
use alloy_primitives::{Address, Bytes, Log, U256};
pub use boa_engine::vm::RuntimeLimits;
use boa_engine::{js_string, Context, JsError, JsObject, JsResult, JsValue, Source};
use revm::{
Expand Down Expand Up @@ -572,44 +573,6 @@ where
}
}

/// Contains some contextual infos for a transaction execution that is made available to the JS
/// object.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct TransactionContext {
/// Hash of the block the tx is contained within.
///
/// `None` if this is a call.
pub block_hash: Option<B256>,
/// Index of the transaction within a block.
///
/// `None` if this is a call.
pub tx_index: Option<usize>,
/// Hash of the transaction being traced.
///
/// `None` if this is a call.
pub tx_hash: Option<B256>,
}

impl TransactionContext {
/// Sets the block hash.
pub const fn with_block_hash(mut self, block_hash: B256) -> Self {
self.block_hash = Some(block_hash);
self
}

/// Sets the index of the transaction within a block.
pub const fn with_tx_index(mut self, tx_index: usize) -> Self {
self.tx_index = Some(tx_index);
self
}

/// Sets the hash of the transaction.
pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self {
self.tx_hash = Some(tx_hash);
self
}
}

/// Represents an active call
#[derive(Debug)]
struct CallStackItem {
Expand Down
40 changes: 39 additions & 1 deletion src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
utils::gas_used,
},
};
use alloy_primitives::{Address, Bytes, Log, U256};
use alloy_primitives::{Address, Bytes, Log, B256, U256};
use revm::{
interpreter::{
opcode::{self},
Expand Down Expand Up @@ -678,3 +678,41 @@ struct StackStep {
/// not appear in the steps list.
step_idx: usize,
}

/// Contains some contextual infos for a transaction execution that is made available to the JS
/// object.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct TransactionContext {
/// Hash of the block the tx is contained within.
///
/// `None` if this is a call.
pub block_hash: Option<B256>,
/// Index of the transaction within a block.
///
/// `None` if this is a call.
pub tx_index: Option<usize>,
/// Hash of the transaction being traced.
///
/// `None` if this is a call.
pub tx_hash: Option<B256>,
}

impl TransactionContext {
/// Sets the block hash.
pub const fn with_block_hash(mut self, block_hash: B256) -> Self {
self.block_hash = Some(block_hash);
self
}

/// Sets the index of the transaction within a block.
pub const fn with_tx_index(mut self, tx_index: usize) -> Self {
self.tx_index = Some(tx_index);
self
}

/// Sets the hash of the transaction.
pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self {
self.tx_hash = Some(tx_hash);
self
}
}
Loading