diff --git a/src/block.rs b/src/block.rs index f4618a59..817b52f2 100644 --- a/src/block.rs +++ b/src/block.rs @@ -11,7 +11,7 @@ use crate::serde_utils::{BytesAsHex, PrefixedBytesAsHex}; use crate::transaction::{Transaction, TransactionHash, TransactionOutput}; /// A block. -#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)] pub struct Block { pub header: BlockHeader, pub body: BlockBody, @@ -34,7 +34,7 @@ pub struct BlockHeader { /// The [transactions](`crate::transaction::Transaction`) and their /// [outputs](`crate::transaction::TransactionOutput`) in a [block](`crate::block::Block`). -#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)] pub struct BlockBody { pub transactions: Vec, pub transaction_outputs: Vec, diff --git a/src/transaction.rs b/src/transaction.rs index f282393f..4bf4fc69 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, HashSet}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Display; use std::sync::Arc; @@ -32,7 +32,7 @@ pub enum Transaction { } /// A transaction output. -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] pub enum TransactionOutput { /// A declare transaction output. Declare(DeclareTransactionOutput), @@ -66,6 +66,16 @@ impl TransactionOutput { TransactionOutput::L1Handler(output) => &output.events, } } + + pub fn execution_resources(&self) -> &ExecutionResources { + match self { + TransactionOutput::Declare(output) => &output.execution_resources, + TransactionOutput::Deploy(output) => &output.execution_resources, + TransactionOutput::DeployAccount(output) => &output.execution_resources, + TransactionOutput::Invoke(output) => &output.execution_resources, + TransactionOutput::L1Handler(output) => &output.execution_resources, + } + } } /// A declare V0 or V1 transaction (same schema but different version). @@ -307,54 +317,59 @@ pub struct L1HandlerTransaction { } /// A declare transaction output. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct DeclareTransactionOutput { pub actual_fee: Fee, pub messages_sent: Vec, pub events: Vec, pub execution_status: TransactionExecutionStatus, + pub execution_resources: ExecutionResources, } /// A deploy-account transaction output. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct DeployAccountTransactionOutput { pub actual_fee: Fee, pub messages_sent: Vec, pub events: Vec, pub contract_address: ContractAddress, pub execution_status: TransactionExecutionStatus, + pub execution_resources: ExecutionResources, } /// A deploy transaction output. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct DeployTransactionOutput { pub actual_fee: Fee, pub messages_sent: Vec, pub events: Vec, pub contract_address: ContractAddress, pub execution_status: TransactionExecutionStatus, + pub execution_resources: ExecutionResources, } /// An invoke transaction output. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct InvokeTransactionOutput { pub actual_fee: Fee, pub messages_sent: Vec, pub events: Vec, pub execution_status: TransactionExecutionStatus, + pub execution_resources: ExecutionResources, } /// An L1 handler transaction output. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct L1HandlerTransactionOutput { pub actual_fee: Fee, pub messages_sent: Vec, pub events: Vec, pub execution_status: TransactionExecutionStatus, + pub execution_resources: ExecutionResources, } /// A transaction receipt. -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] pub struct TransactionReceipt { pub transaction_hash: TransactionHash, pub block_hash: BlockHash, @@ -625,3 +640,29 @@ pub struct PaymasterData(pub Vec); /// its class hash, address salt and constructor calldata. #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] pub struct AccountDeploymentData(pub Vec); + +/// The execution resources used by a transaction. +#[derive(Debug, Default, Deserialize, Serialize, Clone, Eq, PartialEq)] +pub struct ExecutionResources { + pub n_steps: u64, + pub builtin_instance_counter: BuiltinInstanceCounter, + pub n_memory_holes: u64, +} + +/// A mapping from builtin instance names to their usage count. +#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)] +#[serde(untagged)] +pub enum BuiltinInstanceCounter { + NonEmpty(HashMap), + Empty(EmptyBuiltinInstanceCounter), +} + +impl Default for BuiltinInstanceCounter { + fn default() -> Self { + BuiltinInstanceCounter::Empty(EmptyBuiltinInstanceCounter {}) + } +} + +/// An empty builtin instance counter. +#[derive(Debug, Default, Deserialize, Serialize, Clone, Eq, PartialEq)] +pub struct EmptyBuiltinInstanceCounter {}