stratus/eth/primitives/
transaction_stage.rsuse super::Address;
use super::BlockNumber;
use super::ExecutionResult;
use super::Index;
use crate::alias::AlloyReceipt;
use crate::alias::AlloyTransaction;
use crate::alias::JsonValue;
use crate::eth::primitives::TransactionExecution;
use crate::eth::primitives::TransactionMined;
use crate::ext::to_json_value;
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, derive_new::new)]
pub enum TransactionStage {
Executed(TransactionExecution),
Mined(TransactionMined),
}
impl TransactionStage {
pub fn to_json_rpc_transaction(self) -> JsonValue {
match self {
TransactionStage::Executed(tx) => {
let json_rpc_payload: AlloyTransaction = tx.input.into();
to_json_value(json_rpc_payload)
}
TransactionStage::Mined(tx) => {
let json_rpc_payload: AlloyTransaction = tx.into();
to_json_value(json_rpc_payload)
}
}
}
pub fn to_json_rpc_receipt(self) -> JsonValue {
match self {
TransactionStage::Executed(_) => JsonValue::Null,
TransactionStage::Mined(tx) => {
let json_rpc_format: AlloyReceipt = tx.into();
to_json_value(json_rpc_format)
}
}
}
pub fn deployed_contract_address(&self) -> Option<Address> {
match self {
Self::Executed(tx) => tx.result.execution.deployed_contract_address,
Self::Mined(tx) => tx.execution.deployed_contract_address,
}
}
pub fn result(&self) -> &ExecutionResult {
match self {
Self::Executed(tx) => &tx.result.execution.result,
Self::Mined(tx) => &tx.execution.result,
}
}
pub fn index(&self) -> Option<Index> {
match self {
Self::Mined(tx) => Some(tx.transaction_index),
_ => None,
}
}
pub fn block_number(&self) -> BlockNumber {
match self {
Self::Executed(tx) => tx.evm_input.block_number,
Self::Mined(tx) => tx.block_number,
}
}
pub fn from(&self) -> Address {
match self {
Self::Executed(tx) => tx.evm_input.from,
Self::Mined(tx) => tx.input.signer,
}
}
pub fn to(&self) -> Option<Address> {
match self {
Self::Executed(tx) => tx.evm_input.to,
Self::Mined(tx) => tx.input.to,
}
}
}