diff --git a/crates/starknet-types-rpc/Cargo.toml b/crates/starknet-types-rpc/Cargo.toml index 5598514..38ae114 100644 --- a/crates/starknet-types-rpc/Cargo.toml +++ b/crates/starknet-types-rpc/Cargo.toml @@ -10,4 +10,14 @@ keywords = ["stark", "zkp", "cairo"] description = "Starknet RPC types." readme = "README.md" +[features] +default = ["std"] + +std = ["serde/std", "starknet-types-core/std"] + [dependencies] +starknet-types-core = { path = "../starknet-types-core", default-features = false, features = ["serde"] } +serde = { version = "1", default-features = false, features = ["derive"] } + +[dev-dependencies] +serde_json = "1" \ No newline at end of file diff --git a/crates/starknet-types-rpc/README.md b/crates/starknet-types-rpc/README.md index 59568a9..84be17d 100644 --- a/crates/starknet-types-rpc/README.md +++ b/crates/starknet-types-rpc/README.md @@ -16,7 +16,26 @@ starknet-types-rpc = { version = "0.0.2", git = "https://github.com/starknet-io/ ## Build from source -Clone the repository and navigate to the starknet-types-rpc directory. Then run: +The crate is built in two steps: + +### Generating bindings against the Starknet OpenRPC specification + +The specification is hosted on Starknet's repository ([link](https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json)). + +Bindings are generated using [`openrpc-gen`](https://github.com/nils-mathieu/openrpc-gen). + +After having built `openrpc-gen`, you can use the following command to generate the final generated +Rust files: + +```bash +openrpc-gen --config configs/v0.5.0.toml --document configs/spec_v0.5.0.json --output src/generated/v0.5.0.rs +``` + +*Note that this first step is normally already done for you upon cloning the repository.* + +### Building the generated files + +Once this is done, you can build the crate with: ```bash cargo build --release diff --git a/crates/starknet-types-rpc/src/custom/block_id.rs b/crates/starknet-types-rpc/src/custom/block_id.rs new file mode 100644 index 0000000..4c933a8 --- /dev/null +++ b/crates/starknet-types-rpc/src/custom/block_id.rs @@ -0,0 +1,129 @@ +use serde::{Deserialize, Deserializer, Serialize}; + +use crate::{BlockHash, BlockNumber, BlockTag}; + +/// A hexadecimal number. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum BlockId { + /// The tag of the block. + Tag(BlockTag), + /// The hash of the block. + Hash(BlockHash), + /// The height of the block. + Number(BlockNumber), +} + +#[derive(Serialize, Deserialize)] +struct BlockHashHelper { + block_hash: BlockHash, +} + +#[derive(Serialize, Deserialize)] +struct BlockNumberHelper { + block_number: BlockNumber, +} + +#[derive(Deserialize)] +#[serde(untagged)] +enum BlockIdHelper { + Tag(BlockTag), + Hash(BlockHashHelper), + Number(BlockNumberHelper), +} + +impl serde::Serialize for BlockId { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match *self { + BlockId::Tag(tag) => tag.serialize(serializer), + BlockId::Hash(block_hash) => { + let helper = BlockHashHelper { block_hash }; + helper.serialize(serializer) + } + BlockId::Number(block_number) => { + let helper = BlockNumberHelper { block_number }; + helper.serialize(serializer) + } + } + } +} + +impl<'de> serde::Deserialize<'de> for BlockId { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let helper = BlockIdHelper::deserialize(deserializer)?; + match helper { + BlockIdHelper::Tag(tag) => Ok(BlockId::Tag(tag)), + BlockIdHelper::Hash(helper) => Ok(BlockId::Hash(helper.block_hash)), + BlockIdHelper::Number(helper) => Ok(BlockId::Number(helper.block_number)), + } + } +} + +#[test] +fn block_id_from_hash() { + use crate::Felt; + + let s = "{\"block_hash\":\"0x123\"}"; + let block_id: BlockId = serde_json::from_str(s).unwrap(); + assert_eq!(block_id, BlockId::Hash(Felt::from_hex("0x123").unwrap())); +} + +#[test] +fn block_id_from_number() { + let s = "{\"block_number\":123}"; + let block_id: BlockId = serde_json::from_str(s).unwrap(); + assert_eq!(block_id, BlockId::Number(123)); +} + +#[test] +fn block_id_from_latest() { + let s = "\"latest\""; + let block_id: BlockId = serde_json::from_str(s).unwrap(); + assert_eq!(block_id, BlockId::Tag(BlockTag::Latest)); +} + +#[test] +fn block_id_from_pending() { + let s = "\"pending\""; + let block_id: BlockId = serde_json::from_str(s).unwrap(); + assert_eq!(block_id, BlockId::Tag(BlockTag::Pending)); +} + +#[cfg(test)] +#[test] +fn block_id_to_hash() { + use crate::Felt; + + let block_id = BlockId::Hash(Felt::from_hex("0x123").unwrap()); + let s = serde_json::to_string(&block_id).unwrap(); + assert_eq!(s, "{\"block_hash\":\"0x123\"}"); +} + +#[cfg(test)] +#[test] +fn block_id_to_number() { + let block_id = BlockId::Number(123); + let s = serde_json::to_string(&block_id).unwrap(); + assert_eq!(s, "{\"block_number\":123}"); +} + +#[cfg(test)] +#[test] +fn block_id_to_latest() { + let block_id = BlockId::Tag(BlockTag::Latest); + let s = serde_json::to_string(&block_id).unwrap(); + assert_eq!(s, "\"latest\""); +} + +#[cfg(test)] +#[test] +fn block_id_to_pending() { + let block_id = BlockId::Tag(BlockTag::Pending); + let s = serde_json::to_string(&block_id).unwrap(); + assert_eq!(s, "\"pending\""); +} diff --git a/crates/starknet-types-rpc/src/custom/mod.rs b/crates/starknet-types-rpc/src/custom/mod.rs new file mode 100644 index 0000000..6b8ecbf --- /dev/null +++ b/crates/starknet-types-rpc/src/custom/mod.rs @@ -0,0 +1,7 @@ +mod block_id; +mod query; +mod syncing_status; + +pub use self::block_id::*; +pub use self::query::*; +pub use self::syncing_status::*; diff --git a/crates/starknet-types-rpc/src/custom/query.rs b/crates/starknet-types-rpc/src/custom/query.rs new file mode 100644 index 0000000..bc5576c --- /dev/null +++ b/crates/starknet-types-rpc/src/custom/query.rs @@ -0,0 +1,48 @@ +// query offset: +// 0x0000000000000000000000000000000100000000000000000000000000000000 + +use serde::{Deserialize, Serialize}; + +use crate::{ + BroadcastedDeclareTxnV1, BroadcastedDeclareTxnV2, DeployAccountTxnV1, InvokeTxnV0, InvokeTxnV1, +}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "version")] +pub enum BroadcastedDeclareTxn { + #[serde(rename = "0x1")] + V1(BroadcastedDeclareTxnV1), + #[serde(rename = "0x2")] + V2(BroadcastedDeclareTxnV2), + /// Query-only broadcasted declare transaction. + #[serde(rename = "0x0000000000000000000000000000000100000000000000000000000000000001")] + QueryV1(BroadcastedDeclareTxnV1), + /// Query-only broadcasted declare transaction. + #[serde(rename = "0x0000000000000000000000000000000100000000000000000000000000000002")] + QueryV2(BroadcastedDeclareTxnV2), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "version")] +pub enum BroadcastedDeployAccountTxn { + #[serde(rename = "0x1")] + V1(DeployAccountTxnV1), + /// Query-only broadcasted deploy account transaction. + #[serde(rename = "0x0000000000000000000000000000000100000000000000000000000000000001")] + QueryV1(DeployAccountTxnV1), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "version")] +pub enum BroadcastedInvokeTxn { + #[serde(rename = "0x0")] + V0(InvokeTxnV0), + #[serde(rename = "0x1")] + V1(InvokeTxnV1), + /// Query-only broadcasted invoke transaction. + #[serde(rename = "0x0000000000000000000000000000000100000000000000000000000000000000")] + QueryV0(InvokeTxnV0), + /// Query-only broadcasted invoke transaction. + #[serde(rename = "0x0000000000000000000000000000000100000000000000000000000000000001")] + QueryV1(InvokeTxnV1), +} diff --git a/crates/starknet-types-rpc/src/custom/syncing_status.rs b/crates/starknet-types-rpc/src/custom/syncing_status.rs new file mode 100644 index 0000000..2f23e40 --- /dev/null +++ b/crates/starknet-types-rpc/src/custom/syncing_status.rs @@ -0,0 +1,88 @@ +use serde::de::Visitor; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +use crate::SyncStatus; + +/// The syncing status of a node. +#[derive(Clone, Debug)] +pub enum SyncingStatus { + /// The node is not syncing. + NotSyncing, + /// The node is syncing. + Syncing(SyncStatus), +} + +impl Serialize for SyncingStatus { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + SyncingStatus::NotSyncing => serializer.serialize_bool(false), + SyncingStatus::Syncing(status) => status.serialize(serializer), + } + } +} + +impl<'de> Deserialize<'de> for SyncingStatus { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct SyncingStatusVisitor; + + impl<'de> Visitor<'de> for SyncingStatusVisitor { + type Value = SyncingStatus; + + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { + writeln!(formatter, "a syncing status") + } + + fn visit_bool(self, v: bool) -> Result + where + E: serde::de::Error, + { + if v { + Err(serde::de::Error::custom("expected a syncing status")) + } else { + Ok(SyncingStatus::NotSyncing) + } + } + + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + let status = + SyncStatus::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(SyncingStatus::Syncing(status)) + } + } + + deserializer.deserialize_any(SyncingStatusVisitor) + } +} + +#[cfg(test)] +#[test] +fn syncing_status_from_false() { + let s = "false"; + let syncing_status: SyncingStatus = serde_json::from_str(s).unwrap(); + assert!(matches!(syncing_status, SyncingStatus::NotSyncing)); +} + +#[cfg(test)] +#[test] +fn syncing_status_to_false() { + let syncing_status = SyncingStatus::NotSyncing; + let s = serde_json::to_string(&syncing_status).unwrap(); + assert_eq!(s, "false"); +} + +#[cfg(test)] +#[test] +fn syncing_status_from_true() { + let s = "true"; + assert!(serde_json::from_str::(s).is_err()); +} diff --git a/crates/starknet-types-rpc/src/custom_serde/mod.rs b/crates/starknet-types-rpc/src/custom_serde/mod.rs new file mode 100644 index 0000000..69302c4 --- /dev/null +++ b/crates/starknet-types-rpc/src/custom_serde/mod.rs @@ -0,0 +1,5 @@ +//! Custom serialization and deserialization routines. + +mod num_as_hex; + +pub use self::num_as_hex::NumAsHex; diff --git a/crates/starknet-types-rpc/src/custom_serde/num_as_hex.rs b/crates/starknet-types-rpc/src/custom_serde/num_as_hex.rs new file mode 100644 index 0000000..a3fe274 --- /dev/null +++ b/crates/starknet-types-rpc/src/custom_serde/num_as_hex.rs @@ -0,0 +1,269 @@ +use core::marker::PhantomData; + +/// A trait for types that should be serialized or deserialized as hexadecimal strings. +pub trait NumAsHex<'de>: Sized { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer; + + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>; +} + +impl<'de> NumAsHex<'de> for u64 { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + /// The symbols to be used for the hexadecimal representation. + const HEX_DIGITS: [u8; 16] = *b"0123456789abcdef"; + /// The maximum number of digits in the hexadecimal representation of a `u64`. + const MAX_NUMBER_SIZE: usize = u64::MAX.ilog(16) as usize + 1; + + if *self == 0 { + return serializer.serialize_str("0x0"); + } + + // The following code can be very much optimized simply by making everything + // `unsafe` and using pointers to write to the buffer. + // Let's benchmark it first to ensure that it's actually worth it. + + // The buffer is filled from the end to the beginning. + // We know that it will always have the correct size because we made it have the + // maximum possible size for a base-16 representation of a `u64`. + // + // +-----------------------------------+ + // + 1 2 f a + + // +-----------------------------------+ + // ^ cursor + // + // Once the number has been written to the buffer, we simply add a `0x` prefix + // to the beginning of the buffer. Just like the digits, we know the buffer is + // large enough to hold the prefix. + // + // +-----------------------------------+ + // + 0 x 1 2 f a + + // +-----------------------------------+ + // ^ cursor + // |-----------------------| remaining + // + // The output string is the part of the buffer that has been written. In other + // words, we have to skip all the bytes that *were not* written yet (remaining). + + let mut buffer = [0u8; MAX_NUMBER_SIZE + 2]; // + 2 to account for 0x + let mut cursor = buffer.iter_mut().rev(); + let mut n = *self; + while n != 0 { + *cursor.next().unwrap() = HEX_DIGITS[(n % 16) as usize]; + n /= 16; + } + *cursor.next().unwrap() = b'x'; + *cursor.next().unwrap() = b'0'; + + let remaining = cursor.len(); + + // SAFETY: + // We only wrote ASCII characters to the buffer, ensuring that it is only composed + // of valid UTF-8 code points. This unwrap can never fail. Just like the code above, + // using `from_utf8_unchecked` is safe. + let s = core::str::from_utf8(&buffer[remaining..]).unwrap(); + + serializer.serialize_str(s) + } + + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct NumAsHexVisitor; + + impl<'de> serde::de::Visitor<'de> for NumAsHexVisitor { + type Value = u64; + + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { + formatter.write_str("a hexadecimal string") + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + // Just like the serialization code, this can be further optimized using + // unsafe code and pointers. Though the gain will probably be less interesting. + + // Explicitly avoid being UTF-8 aware. + let mut bytes = v.as_bytes(); + + // If the input string does not start with the `0x` prefix, then it's an + // error. The `NUM_AS_HEX` regex defined in the specification specifies + // this prefix as mandatory. + bytes = bytes + .strip_prefix(b"0x") + .ok_or_else(|| E::custom("expected a hexadecimal string starting with 0x"))?; + + if bytes.is_empty() { + return Err(E::custom("expected a hexadecimal string")); + } + + // Remove the leading zeros from the string, if any. + // We need this in order to optimize the code below with the knowledge of the + // length of the hexadecimal representation of the number. + while let Some(rest) = bytes.strip_prefix(b"0") { + bytes = rest; + } + + // If the string has a size larger than the maximum size of the hexadecimal + // representation of a `u64`, then we're forced to overflow. + if bytes.len() > u64::MAX.ilog(16) as usize + 1 { + return Err(E::custom("integer overflowed 64-bit")); + } + + // Aggregate the digits into `n`, + // Digits from `0` to `9` represent numbers from `0` to `9`. + // Letters from `a` to `f` represent numbers from `10` to `15`. + // + // As specified in the spec, both uppercase and lowercase characters are + // allowed. + // + // Because we already checked the size of the string earlier, we know that + // the following code will never overflow. + let mut n = 0u64; + for &b in bytes.iter() { + let unit = match b { + b'0'..=b'9' => b as u64 - b'0' as u64, + b'a'..=b'f' => b as u64 - b'a' as u64 + 10, + b'A'..=b'F' => b as u64 - b'A' as u64 + 10, + _ => return Err(E::custom("invalid hexadecimal digit")), + }; + + n = n * 16 + unit; + } + + Ok(n) + } + } + + deserializer.deserialize_str(NumAsHexVisitor) + } +} + +impl<'de, T> NumAsHex<'de> for Option +where + T: NumAsHex<'de>, +{ + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match self { + None => serializer.serialize_none(), + Some(v) => v.serialize(serializer), + } + } + + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct OptionVisitor(PhantomData); + + impl<'de, T> serde::de::Visitor<'de> for OptionVisitor + where + T: NumAsHex<'de>, + { + type Value = Option; + + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { + writeln!(formatter, "an optional number as a hexadecimal string") + } + + fn visit_none(self) -> Result + where + E: serde::de::Error, + { + Ok(None) + } + + fn visit_some(self, deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + T::deserialize(deserializer).map(Some) + } + } + + deserializer.deserialize_option(OptionVisitor(PhantomData)) + } +} + +#[cfg(test)] +#[derive(serde::Serialize, serde::Deserialize)] +#[serde(transparent)] +struct Helper { + #[serde(with = "NumAsHex")] + num: u64, +} + +#[cfg(test)] +fn serialize(num: u64) -> serde_json::Result { + let helper = Helper { num }; + serde_json::to_string(&helper) +} + +#[cfg(test)] +fn deserialize(s: &str) -> serde_json::Result { + let helper: Helper = serde_json::from_str(s)?; + Ok(helper.num) +} + +#[test] +#[cfg(test)] +fn serialize_0_hex() { + assert_eq!(serialize(0x0).unwrap(), "\"0x0\""); +} + +#[test] +#[cfg(test)] +fn srialize_hex() { + assert_eq!(serialize(0x1234).unwrap(), "\"0x1234\""); +} + +#[test] +#[cfg(test)] +fn srialize_max() { + assert_eq!(serialize(u64::MAX).unwrap(), "\"0xffffffffffffffff\""); +} + +#[test] +#[cfg(test)] +fn deserialize_zero() { + assert_eq!(deserialize("\"0x0\"").unwrap(), 0); +} + +#[test] +#[cfg(test)] +fn deserialize_zeros() { + assert_eq!(deserialize("\"0x00000\"").unwrap(), 0); +} + +#[test] +#[cfg(test)] +fn deserialize_max() { + assert_eq!(deserialize("\"0xFFFFFFFFFFFFFFFF\"").unwrap(), u64::MAX); +} + +#[test] +#[cfg(test)] +fn deserialize_big_one() { + assert_eq!( + deserialize("\"0x000000000000000000000000000001\"").unwrap(), + 1 + ); +} + +#[test] +#[cfg(test)] +fn deserialize_hex() { + assert_eq!(deserialize("\"0x1234\"").unwrap(), 0x1234); +} diff --git a/crates/starknet-types-rpc/src/lib.rs b/crates/starknet-types-rpc/src/lib.rs index 23072ed..a186326 100644 --- a/crates/starknet-types-rpc/src/lib.rs +++ b/crates/starknet-types-rpc/src/lib.rs @@ -1,2 +1,29 @@ -//! Types used by the StarkNet RPC. -// //! This crate is meant to be used by other crates that need to interact with Starknet RPC. +//! Types used by the [StarkNet RPC API Specification](spec). +//! +//! [spec]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json +//! +//! # Generation +//! +//! Most of the types of this crate are generated directly from the specification using +//! [openrpc-gen](https://github.com/nils-mathieu/openrpc-gen), ensuring that they are always +//! up-to-date. +//! +//! All generated types implement [`Clone`] and [`Debug`], as well as [`serde`]'s [`Serialize`] +//! and [`Deserialize`] to allow for easy serialization and deserialization. +//! +//! [`Serialize`]: serde::Serialize +//! [`Deserialize`]: serde::Deserialize + +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +mod custom; +mod custom_serde; + +// +// Generated files. +// +pub mod v0_5_0; + +pub use self::v0_5_0::*; diff --git a/crates/starknet-types-rpc/src/v0_5_0/mod.rs b/crates/starknet-types-rpc/src/v0_5_0/mod.rs new file mode 100644 index 0000000..7a43d1b --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/mod.rs @@ -0,0 +1,16 @@ +//! v0.5.0 of the API. + +pub use starknet_types_core::felt::Felt; + +pub use crate::custom::{ + BlockId, BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn, + SyncingStatus, +}; + +mod starknet_api_openrpc; +mod starknet_trace_api_openrpc; +mod starknet_write_api; + +pub use self::starknet_api_openrpc::*; +pub use self::starknet_trace_api_openrpc::*; +pub use self::starknet_write_api::*; diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.json b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.json new file mode 100644 index 0000000..da88bf0 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.json @@ -0,0 +1,3704 @@ +{ + "openrpc": "1.0.0-rc1", + "info": { + "version": "0.6.0", + "title": "StarkNet Node API", + "license": {} + }, + "servers": [], + "methods": [ + { + "name": "starknet_specVersion", + "summary": "Returns the version of the Starknet JSON-RPC specification being used", + "params": [], + "result": { + "name": "result", + "description": "Semver of Starknet's JSON-RPC spec being used", + "required": true, + "schema": { + "title": "JSON-RPC spec version", + "type": "string" + } + } + }, + { + "name": "starknet_getBlockWithTxHashes", + "summary": "Get block information with transaction hashes given the block id", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "The resulting block information with transaction hashes", + "schema": { + "title": "Starknet get block hash with tx hashes result", + "oneOf": [ + { + "title": "Block with transaction hashes", + "$ref": "#/components/schemas/BLOCK_WITH_TX_HASHES" + }, + { + "title": "Pending block with transaction hashes", + "$ref": "#/components/schemas/PENDING_BLOCK_WITH_TX_HASHES" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getBlockWithTxs", + "summary": "Get block information with full transactions given the block id", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "The resulting block information with full transactions", + "schema": { + "title": "Starknet get block with txs result", + "oneOf": [ + { + "title": "Block with transactions", + "$ref": "#/components/schemas/BLOCK_WITH_TXS" + }, + { + "title": "Pending block with transactions", + "$ref": "#/components/schemas/PENDING_BLOCK_WITH_TXS" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getStateUpdate", + "summary": "Get the information about the result of executing the requested block", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "The information about the state update of the requested block", + "schema": { + "title": "Starknet get state update result", + "oneOf": [ + { + "title": "State update", + "$ref": "#/components/schemas/STATE_UPDATE" + }, + { + "title": "Pending state update", + "$ref": "#/components/schemas/PENDING_STATE_UPDATE" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getStorageAt", + "summary": "Get the value of the storage at the given address and key", + "params": [ + { + "name": "contract_address", + "description": "The address of the contract to read from", + "summary": "The address of the contract to read from", + "required": true, + "schema": { + "title": "Address", + "$ref": "#/components/schemas/ADDRESS" + } + }, + { + "name": "key", + "description": "The key to the storage value for the given contract", + "summary": "The key to the storage value for the given contract", + "required": true, + "schema": { + "title": "Storage key", + "$ref": "#/components/schemas/STORAGE_KEY" + } + }, + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "The value at the given key for the given contract. 0 if no value is found", + "summary": "The value at the given key for the given contract.", + "schema": { + "title": "Field element", + "$ref": "#/components/schemas/FELT" + } + }, + "errors": [ + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getTransactionStatus", + "summary": "Gets the transaction status (possibly reflecting that the tx is still in the mempool, or dropped from it)", + "paramStructure": "by-name", + "params": [ + { + "name": "transaction_hash", + "summary": "The hash of the requested transaction", + "required": true, + "schema": { + "title": "Transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + } + ], + "result": { + "name": "result", + "schema": { + "title": "Transaction status", + "type": "object", + "properties": { + "finality_status": { + "title": "finality status", + "$ref": "#/components/schemas/TXN_STATUS" + }, + "execution_status": { + "title": "execution status", + "$ref": "#/components/schemas/TXN_EXECUTION_STATUS" + } + }, + "required": [ + "finality_status" + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/TXN_HASH_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getTransactionByHash", + "summary": "Get the details and status of a submitted transaction", + "paramStructure": "by-name", + "params": [ + { + "name": "transaction_hash", + "summary": "The hash of the requested transaction", + "required": true, + "schema": { + "title": "Transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + } + ], + "result": { + "name": "result", + "schema": { + "title": "Transaction", + "allOf": [ + { + "$ref": "#/components/schemas/TXN" + }, + { + "type": "object", + "properties": { + "transaction_hash": { + "title": "transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + }, + "required": [ + "transaction_hash" + ] + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/TXN_HASH_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getTransactionByBlockIdAndIndex", + "summary": "Get the details of a transaction by a given block id and index", + "description": "Get the details of the transaction given by the identified block and index in that block. If no transaction is found, null is returned.", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "index", + "summary": "The index in the block to search for the transaction", + "required": true, + "schema": { + "title": "Index", + "type": "integer", + "minimum": 0 + } + } + ], + "result": { + "name": "transactionResult", + "schema": { + "title": "Transaction", + "allOf": [ + { + "$ref": "#/components/schemas/TXN" + }, + { + "type": "object", + "properties": { + "transaction_hash": { + "title": "transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + }, + "required": [ + "transaction_hash" + ] + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/INVALID_TXN_INDEX" + } + ] + }, + { + "name": "starknet_getTransactionReceipt", + "summary": "Get the transaction receipt by the transaction hash", + "paramStructure": "by-name", + "params": [ + { + "name": "transaction_hash", + "summary": "The hash of the requested transaction", + "required": true, + "schema": { + "title": "Transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + } + ], + "result": { + "name": "result", + "schema": { + "oneOf": [ + { + "title": "Transaction receipt", + "$ref": "#/components/schemas/TXN_RECEIPT" + }, + { + "title": "Pending transaction receipt", + "$ref": "#/components/schemas/PENDING_TXN_RECEIPT" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/TXN_HASH_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getClass", + "summary": "Get the contract class definition in the given block associated with the given hash", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "class_hash", + "description": "The hash of the requested contract class", + "required": true, + "schema": { + "title": "Field element", + "$ref": "#/components/schemas/FELT" + } + } + ], + "result": { + "name": "result", + "description": "The contract class, if found", + "schema": { + "title": "Starknet get class result", + "oneOf": [ + { + "title": "Deprecated contract class", + "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" + }, + { + "title": "Contract class", + "$ref": "#/components/schemas/CONTRACT_CLASS" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CLASS_HASH_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getClassHashAt", + "summary": "Get the contract class hash in the given block for the contract deployed at the given address", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "contract_address", + "description": "The address of the contract whose class hash will be returned", + "required": true, + "schema": { + "title": "Address", + "$ref": "#/components/schemas/ADDRESS" + } + } + ], + "result": { + "name": "result", + "description": "The class hash of the given contract", + "schema": { + "title": "Field element", + "$ref": "#/components/schemas/FELT" + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getClassAt", + "summary": "Get the contract class definition in the given block at the given address", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "contract_address", + "description": "The address of the contract whose class definition will be returned", + "required": true, + "schema": { + "title": "Address", + "$ref": "#/components/schemas/ADDRESS" + } + } + ], + "result": { + "name": "result", + "description": "The contract class", + "schema": { + "title": "Starknet get class at result", + "oneOf": [ + { + "title": "Deprecated contract class", + "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" + }, + { + "title": "Contract class", + "$ref": "#/components/schemas/CONTRACT_CLASS" + } + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + } + ] + }, + { + "name": "starknet_getBlockTransactionCount", + "summary": "Get the number of transactions in a block given a block id", + "description": "Returns the number of transactions in the designated block.", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "The number of transactions in the designated block", + "summary": "The number of transactions in the designated block", + "schema": { + "title": "Block transaction count", + "type": "integer", + "minimum": 0 + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_call", + "summary": "call a starknet function without creating a StarkNet transaction", + "description": "Calls a function in a contract and returns the return value. Using this call will not create a transaction; hence, will not change the state", + "params": [ + { + "name": "request", + "summary": "The details of the function call", + "schema": { + "title": "Function call", + "$ref": "#/components/schemas/FUNCTION_CALL" + }, + "required": true + }, + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "summary": "The function's return value", + "description": "The function's return value, as defined in the Cairo output", + "schema": { + "type": "array", + "title": "Field element", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "errors": [ + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_ERROR" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_estimateFee", + "summary": "estimate the fee for of StarkNet transactions", + "description": "estimates the resources required by transactions when applyed on a given state", + "params": [ + { + "name": "request", + "summary": "The transaction to estimate", + "schema": { + "type": "array", + "description": "a sequence of transactions to estimate, running each transaction on the state resulting from applying all the previous ones", + "title": "Transaction", + "items": { + "$ref": "#/components/schemas/BROADCASTED_TXN" + } + }, + "required": true + }, + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "the fee estimations", + "schema": { + "title": "Estimation", + "type": "array", + "description": "a sequence of fee estimatione where the i'th estimate corresponds to the i'th transaction", + "items": { + "$ref": "#/components/schemas/FEE_ESTIMATE" + } + } + }, + "errors": [ + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_ERROR" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_estimateMessageFee", + "summary": "estimate the L2 fee of a message sent on L1", + "description": "estimates the resources required by the l1_handler transaction induced by the message", + "params": [ + { + "name": "message", + "description": "the message's parameters", + "schema": { + "$ref": "#/components/schemas/MSG_FROM_L1" + }, + "required": true + }, + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "result", + "description": "the fee estimation", + "schema": { + "$ref": "#/components/schemas/FEE_ESTIMATE" + } + }, + "errors": [ + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_ERROR" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_blockNumber", + "summary": "Get the most recent accepted block number", + "params": [], + "result": { + "name": "result", + "description": "The latest block number", + "schema": { + "title": "Block number", + "$ref": "#/components/schemas/BLOCK_NUMBER" + } + }, + "errors": [ + { + "$ref": "#/components/errors/NO_BLOCKS" + } + ] + }, + { + "name": "starknet_blockHashAndNumber", + "summary": "Get the most recent accepted block hash and number", + "params": [], + "result": { + "name": "result", + "description": "The latest block hash and number", + "schema": { + "title": "Starknet block hash and number result", + "type": "object", + "properties": { + "block_hash": { + "title": "Block hash", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "block_number": { + "title": "Block number", + "$ref": "#/components/schemas/BLOCK_NUMBER" + } + }, + "required": [ + "block_hash", + "block_number" + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/NO_BLOCKS" + } + ] + }, + { + "name": "starknet_chainId", + "summary": "Return the currently configured StarkNet chain id", + "params": [], + "result": { + "name": "result", + "description": "The chain id this node is connected to", + "schema": { + "title": "Chain id", + "$ref": "#/components/schemas/CHAIN_ID" + } + } + }, + { + "name": "starknet_syncing", + "summary": "Returns an object about the sync status, or false if the node is not synching", + "params": [], + "result": { + "name": "syncing", + "summary": "The state of the synchronization, or false if the node is not synchronizing", + "description": "The status of the node, if it is currently synchronizing state. FALSE otherwise", + "schema": { + "title": "SyncingStatus", + "oneOf": [ + { + "type": "boolean", + "title": "False", + "description": "only legal value is FALSE here" + }, + { + "title": "Sync status", + "$ref": "#/components/schemas/SYNC_STATUS" + } + ] + } + } + }, + { + "name": "starknet_getEvents", + "summary": "Returns all events matching the given filter", + "description": "Returns all event objects matching the conditions in the provided filter", + "params": [ + { + "name": "filter", + "summary": "The conditions used to filter the returned events", + "required": true, + "schema": { + "title": "Events request", + "allOf": [ + { + "title": "Event filter", + "$ref": "#/components/schemas/EVENT_FILTER" + }, + { + "title": "Result page request", + "$ref": "#/components/schemas/RESULT_PAGE_REQUEST" + } + ] + } + } + ], + "result": { + "name": "events", + "description": "All the event objects matching the filter", + "schema": { + "title": "Events chunk", + "$ref": "#/components/schemas/EVENTS_CHUNK" + } + }, + "errors": [ + { + "$ref": "#/components/errors/PAGE_SIZE_TOO_BIG" + }, + { + "$ref": "#/components/errors/INVALID_CONTINUATION_TOKEN" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/TOO_MANY_KEYS_IN_FILTER" + } + ] + }, + { + "name": "starknet_getNonce", + "summary": "Get the nonce associated with the given address in the given block", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "title": "Block id", + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "contract_address", + "description": "The address of the contract whose nonce we're seeking", + "required": true, + "schema": { + "title": "Address", + "$ref": "#/components/schemas/ADDRESS" + } + } + ], + "result": { + "name": "result", + "description": "The contract's nonce at the requested state", + "schema": { + "title": "Field element", + "$ref": "#/components/schemas/FELT" + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + } + ] + } + ], + "components": { + "contentDescriptors": {}, + "schemas": { + "EVENTS_CHUNK": { + "title": "Events chunk", + "type": "object", + "properties": { + "events": { + "type": "array", + "title": "Matching Events", + "items": { + "$ref": "#/components/schemas/EMITTED_EVENT" + } + }, + "continuation_token": { + "title": "Continuation token", + "description": "Use this token in a subsequent query to obtain the next page. Should not appear if there are no more pages.", + "type": "string" + } + }, + "required": [ + "events" + ] + }, + "RESULT_PAGE_REQUEST": { + "title": "Result page request", + "type": "object", + "properties": { + "continuation_token": { + "title": "Continuation token", + "description": "The token returned from the previous query. If no token is provided the first page is returned.", + "type": "string" + }, + "chunk_size": { + "title": "Chunk size", + "type": "integer", + "minimum": 1 + } + }, + "required": [ + "chunk_size" + ] + }, + "EMITTED_EVENT": { + "title": "Emitted event", + "description": "Event information decorated with metadata on where it was emitted / An event emitted as a result of transaction execution", + "allOf": [ + { + "title": "Event", + "description": "The event information", + "$ref": "#/components/schemas/EVENT" + }, + { + "title": "Event context", + "description": "The event emission information", + "type": "object", + "properties": { + "block_hash": { + "title": "Block hash", + "description": "The hash of the block in which the event was emitted", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "block_number": { + "title": "Block number", + "description": "The number of the block in which the event was emitted", + "$ref": "#/components/schemas/BLOCK_NUMBER" + }, + "transaction_hash": { + "title": "Transaction hash", + "description": "The transaction that emitted the event", + "$ref": "#/components/schemas/TXN_HASH" + } + }, + "required": [ + "transaction_hash" + ] + } + ] + }, + "EVENT": { + "title": "Event", + "description": "A StarkNet event", + "allOf": [ + { + "title": "Event emitter", + "type": "object", + "properties": { + "from_address": { + "title": "From address", + "$ref": "#/components/schemas/ADDRESS" + } + }, + "required": [ + "from_address" + ] + }, + { + "title": "Event content", + "$ref": "#/components/schemas/EVENT_CONTENT" + } + ] + }, + "EVENT_CONTENT": { + "title": "Event content", + "description": "The content of an event", + "type": "object", + "properties": { + "keys": { + "type": "array", + "title": "Keys", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "data": { + "type": "array", + "title": "Data", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": [ + "keys", + "data" + ] + }, + "EVENT_FILTER": { + "title": "Event filter", + "description": "An event filter/query", + "type": "object", + "properties": { + "from_block": { + "title": "from block", + "$ref": "#/components/schemas/BLOCK_ID" + }, + "to_block": { + "title": "to block", + "$ref": "#/components/schemas/BLOCK_ID" + }, + "address": { + "title": "from contract", + "$ref": "#/components/schemas/ADDRESS" + }, + "keys": { + "title": "Keys", + "description": "The values used to filter the events", + "type": "array", + "items": { + "title": "Keys", + "description": "Per key (by position), designate the possible values to be matched for events to be returned. Empty array designates 'any' value", + "type": "array", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + } + }, + "required": [] + }, + "BLOCK_ID": { + "title": "Block id", + "description": "Block hash, number or tag", + "oneOf": [ + { + "title": "Block hash", + "type": "object", + "properties": { + "block_hash": { + "title": "Block hash", + "$ref": "#/components/schemas/BLOCK_HASH" + } + }, + "required": [ + "block_hash" + ] + }, + { + "title": "Block number", + "type": "object", + "properties": { + "block_number": { + "title": "Block number", + "$ref": "#/components/schemas/BLOCK_NUMBER" + } + }, + "required": [ + "block_number" + ] + }, + { + "title": "Block tag", + "$ref": "#/components/schemas/BLOCK_TAG" + } + ] + }, + "BLOCK_TAG": { + "title": "Block tag", + "type": "string", + "description": "A tag specifying a dynamic reference to a block", + "enum": [ + "latest", + "pending" + ] + }, + "SYNC_STATUS": { + "title": "Sync status", + "type": "object", + "description": "An object describing the node synchronization status", + "properties": { + "starting_block_hash": { + "title": "Starting block hash", + "description": "The hash of the block from which the sync started", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "starting_block_num": { + "title": "Starting block number", + "description": "The number (height) of the block from which the sync started", + "$ref": "#/components/schemas/BLOCK_NUMBER" + }, + "current_block_hash": { + "title": "Current block hash", + "description": "The hash of the current block being synchronized", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "current_block_num": { + "title": "Current block number", + "description": "The number (height) of the current block being synchronized", + "$ref": "#/components/schemas/BLOCK_NUMBER" + }, + "highest_block_hash": { + "title": "Highest block hash", + "description": "The hash of the estimated highest block to be synchronized", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "highest_block_num": { + "title": "Highest block number", + "description": "The number (height) of the estimated highest block to be synchronized", + "$ref": "#/components/schemas/BLOCK_NUMBER" + } + }, + "required": [ + "starting_block_hash", + "starting_block_num", + "current_block_hash", + "current_block_num", + "highest_block_hash", + "highest_block_num" + ] + }, + "NUM_AS_HEX": { + "title": "Number as hex", + "description": "An integer number in hex format (0x...)", + "type": "string", + "pattern": "^0x[a-fA-F0-9]+$" + }, + "CHAIN_ID": { + "title": "Chain id", + "description": "StarkNet chain id, given in hex representation.", + "type": "string", + "pattern": "^0x[a-fA-F0-9]+$" + }, + "STATE_DIFF": { + "description": "The change in state applied in this block, given as a mapping of addresses to the new values and/or new contracts", + "type": "object", + "properties": { + "storage_diffs": { + "title": "Storage diffs", + "type": "array", + "items": { + "description": "The changes in the storage per contract address", + "$ref": "#/components/schemas/CONTRACT_STORAGE_DIFF_ITEM" + } + }, + "deprecated_declared_classes": { + "title": "Deprecated declared classes", + "type": "array", + "items": { + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + } + }, + "declared_classes": { + "title": "Declared classes", + "type": "array", + "items": { + "title": "New classes", + "type": "object", + "description": "The declared class hash and compiled class hash", + "properties": { + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + }, + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The Cairo assembly hash corresponding to the declared class", + "$ref": "#/components/schemas/FELT" + } + } + } + }, + "deployed_contracts": { + "title": "Deployed contracts", + "type": "array", + "items": { + "description": "A new contract deployed as part of the state update", + "$ref": "#/components/schemas/DEPLOYED_CONTRACT_ITEM" + } + }, + "replaced_classes": { + "title": "Replaced classes", + "type": "array", + "items": { + "description": "The list of contracts whose class was replaced", + "title": "Replaced class", + "type": "object", + "properties": { + "contract_address": { + "title": "Contract address", + "description": "The address of the contract whose class was replaced", + "$ref": "#/components/schemas/ADDRESS" + }, + "class_hash": { + "title": "Class hash", + "description": "The new class hash", + "$ref": "#/components/schemas/FELT" + } + } + } + }, + "nonces": { + "title": "Nonces", + "type": "array", + "items": { + "title": "Nonce update", + "description": "The updated nonce per contract address", + "type": "object", + "properties": { + "contract_address": { + "title": "Contract address", + "description": "The address of the contract", + "$ref": "#/components/schemas/ADDRESS" + }, + "nonce": { + "title": "Nonce", + "description": "The nonce for the given address at the end of the block", + "$ref": "#/components/schemas/FELT" + } + } + } + } + }, + "required": [ + "storage_diffs", + "deprecated_declared_classes", + "declared_classes", + "replaced_classes", + "deployed_contracts", + "nonces" + ] + }, + "PENDING_STATE_UPDATE": { + "title": "Pending state update", + "description": "Pending state update", + "type": "object", + "properties": { + "old_root": { + "title": "Old root", + "description": "The previous global state root", + "$ref": "#/components/schemas/FELT" + }, + "state_diff": { + "title": "State diff", + "$ref": "#/components/schemas/STATE_DIFF" + } + }, + "required": [ + "old_root", + "state_diff" + ], + "additionalProperties": false + }, + "STATE_UPDATE": { + "title": "State update", + "type": "object", + "properties": { + "block_hash": { + "title": "Block hash", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "old_root": { + "title": "Old root", + "description": "The previous global state root", + "$ref": "#/components/schemas/FELT" + }, + "new_root": { + "title": "New root", + "description": "The new global state root", + "$ref": "#/components/schemas/FELT" + }, + "state_diff": { + "title": "State diff", + "$ref": "#/components/schemas/STATE_DIFF" + } + }, + "required": [ + "state_diff", + "block_hash", + "old_root", + "new_root" + ] + }, + "ADDRESS": { + "title": "Address", + "$ref": "#/components/schemas/FELT" + }, + "STORAGE_KEY": { + "type": "string", + "title": "Storage key", + "$comment": "A storage key, represented as a string of hex digits", + "description": "A storage key. Represented as up to 62 hex digits, 3 bits, and 5 leading zeroes.", + "pattern": "^0x0[0-7]{1}[a-fA-F0-9]{0,62}$" + }, + "ETH_ADDRESS": { + "title": "Ethereum address", + "type": "string", + "$comment": "An ethereum address", + "description": "an ethereum address represented as 40 hex digits", + "pattern": "^0x[a-fA-F0-9]{40}$" + }, + "TXN_HASH": { + "$ref": "#/components/schemas/FELT", + "description": "The transaction hash, as assigned in StarkNet", + "title": "Transaction hash" + }, + "FELT": { + "type": "string", + "title": "Field element", + "description": "A field element. represented by at most 63 hex digits", + "pattern": "^0x(0|[a-fA-F1-9]{1}[a-fA-F0-9]{0,62})$" + }, + "BLOCK_NUMBER": { + "title": "Block number", + "description": "The block's number (its height)", + "type": "integer", + "minimum": 0 + }, + "BLOCK_HASH": { + "title": "Block hash", + "$ref": "#/components/schemas/FELT" + }, + "BLOCK_BODY_WITH_TX_HASHES": { + "title": "Block body with transaction hashes", + "type": "object", + "properties": { + "transactions": { + "title": "Transaction hashes", + "description": "The hashes of the transactions included in this block", + "type": "array", + "items": { + "description": "The hash of a single transaction", + "$ref": "#/components/schemas/TXN_HASH" + } + } + }, + "required": [ + "transactions" + ] + }, + "BLOCK_BODY_WITH_TXS": { + "title": "Block body with transactions", + "type": "object", + "properties": { + "transactions": { + "title": "Transactions", + "description": "The transactions in this block", + "type": "array", + "items": { + "title": "transactions in block", + "type": "object", + "allOf": [ + { + "title": "transaction", + "$ref": "#/components/schemas/TXN" + }, + { + "type": "object", + "properties": { + "transaction_hash": { + "title": "transaction hash", + "$ref": "#/components/schemas/TXN_HASH" + } + }, + "required": [ + "transaction_hash" + ] + } + ] + } + } + }, + "required": [ + "transactions" + ] + }, + "BLOCK_HEADER": { + "title": "Block header", + "type": "object", + "properties": { + "block_hash": { + "title": "Block hash", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "parent_hash": { + "title": "Parent hash", + "description": "The hash of this block's parent", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "block_number": { + "title": "Block number", + "description": "The block number (its height)", + "$ref": "#/components/schemas/BLOCK_NUMBER" + }, + "new_root": { + "title": "New root", + "description": "The new global state root", + "$ref": "#/components/schemas/FELT" + }, + "timestamp": { + "title": "Timestamp", + "description": "The time in which the block was created, encoded in Unix time", + "type": "integer", + "minimum": 0 + }, + "sequencer_address": { + "title": "Sequencer address", + "description": "The StarkNet identity of the sequencer submitting this block", + "$ref": "#/components/schemas/FELT" + }, + "l1_gas_price": { + "title": "L1 gas price", + "descritpion": "The price of l1 gas in the block", + "$ref": "#/components/schemas/RESOURCE_PRICE" + }, + "starknet_version": { + "title": "Starknet version", + "description": "Semver of the current Starknet protocol", + "type": "string" + } + }, + "required": [ + "block_hash", + "parent_hash", + "block_number", + "new_root", + "timestamp", + "sequencer_address", + "l1_gas_price", + "starknet_version" + ] + }, + "PENDING_BLOCK_HEADER": { + "title": "Pending block header", + "type": "object", + "properties": { + "parent_hash": { + "title": "Parent hash", + "description": "The hash of this block's parent", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "timestamp": { + "title": "Timestamp", + "description": "The time in which the block was created, encoded in Unix time", + "type": "integer", + "minimum": 0 + }, + "sequencer_address": { + "title": "Sequencer address", + "description": "The StarkNet identity of the sequencer submitting this block", + "$ref": "#/components/schemas/FELT" + }, + "l1_gas_price": { + "title": "L1 gas price", + "descritpion": "The price of l1 gas in the block", + "$ref": "#/components/schemas/RESOURCE_PRICE" + }, + "starknet_version": { + "title": "Starknet version", + "description": "Semver of the current Starknet protocol", + "type": "string" + } + }, + "required": [ + "parent_hash", + "timestamp", + "sequencer_address", + "l1_gas_price", + "starknet_version" + ], + "not": { + "required": [ + "block_hash", + "block_number", + "new_root" + ] + } + }, + "BLOCK_WITH_TX_HASHES": { + "title": "Block with transaction hashes", + "description": "The block object", + "allOf": [ + { + "title": "Block status", + "type": "object", + "properties": { + "status": { + "title": "Status", + "$ref": "#/components/schemas/BLOCK_STATUS" + } + }, + "required": [ + "status" + ] + }, + { + "title": "Block header", + "$ref": "#/components/schemas/BLOCK_HEADER" + }, + { + "title": "Block body with transaction hashes", + "$ref": "#/components/schemas/BLOCK_BODY_WITH_TX_HASHES" + } + ] + }, + "BLOCK_WITH_TXS": { + "title": "Block with transactions", + "description": "The block object", + "allOf": [ + { + "title": "block with txs", + "type": "object", + "properties": { + "status": { + "title": "Status", + "$ref": "#/components/schemas/BLOCK_STATUS" + } + }, + "required": [ + "status" + ] + }, + { + "title": "Block header", + "$ref": "#/components/schemas/BLOCK_HEADER" + }, + { + "title": "Block body with transactions", + "$ref": "#/components/schemas/BLOCK_BODY_WITH_TXS" + } + ] + }, + "PENDING_BLOCK_WITH_TX_HASHES": { + "title": "Pending block with transaction hashes", + "description": "The dynamic block being constructed by the sequencer. Note that this object will be deprecated upon decentralization.", + "allOf": [ + { + "title": "Block body with transactions hashes", + "$ref": "#/components/schemas/BLOCK_BODY_WITH_TX_HASHES" + }, + { + "title": "Pending block header", + "$ref": "#/components/schemas/PENDING_BLOCK_HEADER" + } + ] + }, + "PENDING_BLOCK_WITH_TXS": { + "title": "Pending block with transactions", + "description": "The dynamic block being constructed by the sequencer. Note that this object will be deprecated upon decentralization.", + "allOf": [ + { + "title": "Block body with transactions", + "$ref": "#/components/schemas/BLOCK_BODY_WITH_TXS" + }, + { + "title": "Pending block header", + "$ref": "#/components/schemas/PENDING_BLOCK_HEADER" + } + ] + }, + "DEPLOYED_CONTRACT_ITEM": { + "title": "Deployed contract item", + "type": "object", + "properties": { + "address": { + "title": "Address", + "description": "The address of the contract", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the contract code", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "address", + "class_hash" + ] + }, + "CONTRACT_STORAGE_DIFF_ITEM": { + "title": "Contract storage diff item", + "type": "object", + "properties": { + "address": { + "title": "Address", + "description": "The contract address for which the storage changed", + "$ref": "#/components/schemas/FELT" + }, + "storage_entries": { + "title": "Storage entries", + "description": "The changes in the storage of the contract", + "type": "array", + "items": { + "title": "Storage diff item", + "type": "object", + "properties": { + "key": { + "title": "Key", + "description": "The key of the changed value", + "$ref": "#/components/schemas/FELT" + }, + "value": { + "title": "Value", + "description": "The new value applied to the given address", + "$ref": "#/components/schemas/FELT" + } + } + } + } + }, + "required": [ + "address", + "storage_entries" + ] + }, + "TXN": { + "title": "Transaction", + "description": "The transaction schema, as it appears inside a block", + "oneOf": [ + { + "title": "Invoke transaction", + "$ref": "#/components/schemas/INVOKE_TXN" + }, + { + "title": "L1 handler transaction", + "$ref": "#/components/schemas/L1_HANDLER_TXN" + }, + { + "title": "Declare transaction", + "$ref": "#/components/schemas/DECLARE_TXN" + }, + { + "title": "Deploy transaction", + "$ref": "#/components/schemas/DEPLOY_TXN" + }, + { + "title": "Deploy account transaction", + "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN" + } + ] + }, + "SIGNATURE": { + "title": "Signature", + "description": "A transaction signature", + "type": "array", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "DECLARE_TXN": { + "title": "Declare transaction", + "oneOf": [ + { + "title": "Declare transaction V0", + "$ref": "#/components/schemas/DECLARE_TXN_V0" + }, + { + "title": "Declare transaction V1", + "$ref": "#/components/schemas/DECLARE_TXN_V1" + }, + { + "title": "Declare transaction V2", + "$ref": "#/components/schemas/DECLARE_TXN_V2" + }, + { + "title": "Declare transaction V3", + "$ref": "#/components/schemas/DECLARE_TXN_V3" + } + ] + }, + "DECLARE_TXN_V0": { + "title": "Declare Contract Transaction V0", + "description": "Declare Contract Transaction V0", + "allOf": [ + { + "type": "object", + "title": "Declare txn v0", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x0", + "0x100000000000000000000000000000000" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "sender_address", + "max_fee", + "version", + "signature", + "class_hash" + ] + } + ] + }, + "DECLARE_TXN_V1": { + "title": "Declare Contract Transaction V1", + "description": "Declare Contract Transaction V1", + "allOf": [ + { + "type": "object", + "title": "Declare txn v1", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x0", + "0x100000000000000000000000000000001" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "sender_address", + "max_fee", + "version", + "signature", + "nonce", + "class_hash" + ] + } + ] + }, + "DECLARE_TXN_V2": { + "title": "Declare Transaction V2", + "description": "Declare Contract Transaction V2", + "allOf": [ + { + "type": "object", + "title": "Declare txn v2", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The hash of the Cairo assembly resulting from the Sierra compilation", + "$ref": "#/components/schemas/FELT" + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x2", + "0x100000000000000000000000000000002" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "sender_address", + "compiled_class_hash", + "max_fee", + "version", + "signature", + "nonce", + "class_hash" + ] + } + ] + }, + "DECLARE_TXN_V3": { + "title": "Declare Transaction V3", + "description": "Declare Contract Transaction V3", + "allOf": [ + { + "type": "object", + "title": "Declare txn v3", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The hash of the Cairo assembly resulting from the Sierra compilation", + "$ref": "#/components/schemas/FELT" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x3", + "0x100000000000000000000000000000003" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + }, + "l1_gas": { + "title": "L1 Gas", + "description": "The max amount and max price per unit of L1 gas used in this tx", + "$ref": "#/components/schemas/RESOURCE_LIMITS" + } + }, + "required": [ + "type", + "sender_address", + "compiled_class_hash", + "version", + "signature", + "nonce", + "class_hash", + "l1_gas" + ] + } + ] + }, + "BROADCASTED_TXN": { + "oneOf": [ + { + "$ref": "#/components/schemas/BROADCASTED_INVOKE_TXN" + }, + { + "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN" + }, + { + "$ref": "#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" + } + ] + }, + "BROADCASTED_INVOKE_TXN": { + "title": "Broadcasted invoke transaction", + "$ref": "#/components/schemas/INVOKE_TXN" + }, + "BROADCASTED_DEPLOY_ACCOUNT_TXN": { + "title": "Broadcasted deploy account transaction", + "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN" + }, + "BROADCASTED_DECLARE_TXN": { + "title": "Broadcasted declare transaction", + "oneOf": [ + { + "title": "Broadcasted declare transaction V1", + "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN_V1" + }, + { + "title": "Broadcasted declare transaction V2", + "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN_V2" + }, + { + "title": "Broadcasted declare transaction V3", + "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN_V3" + } + ] + }, + "BROADCASTED_DECLARE_TXN_V1": { + "title": "Broadcasted declare contract transaction V1", + "allOf": [ + { + "type": "object", + "title": "Declare txn v1", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x1", + "0x100000000000000000000000000000001" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "contract_class": { + "title": "Contract class", + "description": "The class to be declared", + "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" + } + }, + "required": [ + "type", + "sender_address", + "max_fee", + "version", + "signature", + "nonce", + "contract_class" + ] + } + ] + }, + "BROADCASTED_DECLARE_TXN_V2": { + "title": "Broadcasted declare Transaction V2", + "description": "Broadcasted declare Contract Transaction V2", + "allOf": [ + { + "type": "object", + "title": "Declare txn v2", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The hash of the Cairo assembly resulting from the Sierra compilation", + "$ref": "#/components/schemas/FELT" + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x2", + "0x100000000000000000000000000000002" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "contract_class": { + "title": "Contract class", + "description": "The class to be declared", + "$ref": "#/components/schemas/CONTRACT_CLASS" + } + }, + "required": [ + "type", + "sender_address", + "compiled_class_hash", + "max_fee", + "version", + "signature", + "nonce", + "contract_class" + ] + } + ] + }, + "BROADCASTED_DECLARE_TXN_V3": { + "title": "Broadcasted declare Transaction V3", + "description": "Broadcasted declare Contract Transaction V3", + "allOf": [ + { + "type": "object", + "title": "Declare txn v3", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, + "sender_address": { + "title": "Sender address", + "description": "The address of the account contract sending the declaration transaction", + "$ref": "#/components/schemas/ADDRESS" + }, + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The hash of the Cairo assembly resulting from the Sierra compilation", + "$ref": "#/components/schemas/FELT" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x3", + "0x100000000000000000000000000000003" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "contract_class": { + "title": "Contract class", + "description": "The class to be declared", + "$ref": "#/components/schemas/CONTRACT_CLASS" + }, + "l1_gas": { + "title": "L1 Gas", + "description": "The max amount and max price per unit of L1 gas used in this tx", + "$ref": "#/components/schemas/RESOURCE_LIMITS" + } + }, + "required": [ + "type", + "sender_address", + "compiled_class_hash", + "version", + "signature", + "nonce", + "contract_class", + "l1_gas" + ] + } + ] + }, + "DEPLOY_ACCOUNT_TXN": { + "title": "Deploy account transaction", + "description": "deploys a new account contract", + "oneOf": [ + { + "title": "Deploy account V1", + "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN_V1" + }, + { + "title": "Deploy account V3", + "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN_V3" + } + ] + }, + "DEPLOY_ACCOUNT_TXN_V1": { + "title": "Deploy account transaction", + "description": "Deploys an account contract, charges fee from the pre-funded account addresses", + "type": "object", + "properties": { + "type": { + "title": "Deploy account", + "type": "string", + "enum": [ + "DEPLOY_ACCOUNT" + ] + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x1", + "0x100000000000000000000000000000001" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "contract_address_salt": { + "title": "Contract address salt", + "description": "The salt for the address of the deployed contract", + "$ref": "#/components/schemas/FELT" + }, + "constructor_calldata": { + "type": "array", + "description": "The parameters passed to the constructor", + "title": "Constructor calldata", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the deployed contract's class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "max_fee", + "version", + "signature", + "nonce", + "type", + "contract_address_salt", + "constructor_calldata", + "class_hash" + ] + }, + "DEPLOY_ACCOUNT_TXN_V3": { + "title": "Deploy account transaction", + "description": "Deploys an account contract, charges fee from the pre-funded account addresses", + "type": "object", + "properties": { + "type": { + "title": "Deploy account", + "type": "string", + "enum": [ + "DEPLOY_ACCOUNT" + ] + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x3", + "0x100000000000000000000000000000003" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "contract_address_salt": { + "title": "Contract address salt", + "description": "The salt for the address of the deployed contract", + "$ref": "#/components/schemas/FELT" + }, + "constructor_calldata": { + "type": "array", + "description": "The parameters passed to the constructor", + "title": "Constructor calldata", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the deployed contract's class", + "$ref": "#/components/schemas/FELT" + }, + "l1_gas": { + "title": "L1 Gas", + "description": "The max amount and max price per unit of L1 gas used in this tx", + "$ref": "#/components/schemas/RESOURCE_LIMITS" + } + }, + "required": [ + "version", + "signature", + "nonce", + "type", + "contract_address_salt", + "constructor_calldata", + "class_hash", + "l1_gas" + ] + }, + "DEPLOY_TXN": { + "title": "Deploy Contract Transaction", + "description": "The structure of a deploy transaction. Note that this transaction type is deprecated and will no longer be supported in future versions", + "allOf": [ + { + "type": "object", + "title": "Deploy txn", + "properties": { + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "type": { + "title": "Deploy", + "type": "string", + "enum": [ + "DEPLOY" + ] + }, + "contract_address_salt": { + "description": "The salt for the address of the deployed contract", + "title": "Contract address salt", + "$ref": "#/components/schemas/FELT" + }, + "constructor_calldata": { + "type": "array", + "title": "Constructor calldata", + "description": "The parameters passed to the constructor", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the deployed contract's class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "version", + "type", + "constructor_calldata", + "contract_address_salt", + "class_hash" + ] + } + ] + }, + "INVOKE_TXN_V0": { + "title": "Invoke transaction V0", + "description": "invokes a specific function in the desired contract (not necessarily an account)", + "type": "object", + "properties": { + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x0", + "0x100000000000000000000000000000000" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "contract_address": { + "title": "Contract address", + "$ref": "#/components/schemas/ADDRESS" + }, + "entry_point_selector": { + "title": "Entry point selector", + "$ref": "#/components/schemas/FELT" + }, + "calldata": { + "title": "Calldata", + "type": "array", + "description": "The parameters passed to the function", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": [ + "type", + "contract_address", + "entry_point_selector", + "calldata", + "max_fee", + "version", + "signature" + ] + }, + "INVOKE_TXN_V1": { + "title": "Invoke transaction V1", + "description": "initiates a transaction from a given account", + "allOf": [ + { + "type": "object", + "properties": { + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + }, + "sender_address": { + "title": "sender address", + "$ref": "#/components/schemas/ADDRESS" + }, + "calldata": { + "type": "array", + "title": "calldata", + "description": "The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector)", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "max_fee": { + "title": "Max fee", + "$ref": "#/components/schemas/FELT", + "description": "The maximal fee that can be charged for including the transaction" + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x1", + "0x100000000000000000000000000000001" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "sender_address", + "calldata", + "max_fee", + "version", + "signature", + "nonce" + ] + } + ] + }, + "INVOKE_TXN_V3": { + "title": "Invoke transaction V3", + "description": "initiates a transaction from a given account", + "allOf": [ + { + "type": "object", + "properties": { + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + }, + "sender_address": { + "title": "sender address", + "$ref": "#/components/schemas/ADDRESS" + }, + "calldata": { + "type": "array", + "title": "calldata", + "description": "The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector)", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "type": "string", + "enum": [ + "0x3", + "0x100000000000000000000000000000003" + ] + }, + "signature": { + "title": "Signature", + "$ref": "#/components/schemas/SIGNATURE" + }, + "nonce": { + "title": "Nonce", + "$ref": "#/components/schemas/FELT" + }, + "l1_gas": { + "title": "L1 Gas", + "description": "The max amount and max price per unit of L1 gas used in this tx", + "$ref": "#/components/schemas/RESOURCE_LIMITS" + } + }, + "required": [ + "type", + "sender_address", + "calldata", + "version", + "signature", + "nonce", + "l1_gas" + ] + } + ] + }, + "INVOKE_TXN": { + "title": "Invoke transaction", + "description": "Initiate a transaction from an account", + "oneOf": [ + { + "title": "Invoke transaction V0", + "$ref": "#/components/schemas/INVOKE_TXN_V0" + }, + { + "title": "Invoke transaction V1", + "$ref": "#/components/schemas/INVOKE_TXN_V1" + }, + { + "title": "Invoke transaction V3", + "$ref": "#/components/schemas/INVOKE_TXN_V3" + } + ] + }, + "L1_HANDLER_TXN": { + "title": "L1 Handler transaction", + "allOf": [ + { + "type": "object", + "title": "L1 handler transaction", + "description": "a call to an l1_handler on an L2 contract induced by a message from L1", + "properties": { + "version": { + "title": "Version", + "description": "Version of the transaction scheme", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "type": { + "title": "type", + "type": "string", + "enum": [ + "L1_HANDLER" + ] + }, + "nonce": { + "title": "Nonce", + "description": "The L1->L2 message nonce field of the SN Core L1 contract at the time the transaction was sent", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "version", + "type", + "nonce" + ] + }, + { + "title": "Function call", + "$ref": "#/components/schemas/FUNCTION_CALL" + } + ] + }, + "COMMON_RECEIPT_PROPERTIES": { + "title": "Common receipt properties", + "description": "Common properties for a transaction receipt", + "type": "object", + "properties": { + "transaction_hash": { + "title": "Transaction hash", + "$ref": "#/components/schemas/TXN_HASH", + "description": "The hash identifying the transaction" + }, + "actual_fee": { + "title": "Actual fee", + "$ref": "#/components/schemas/FEE_PAYMENT", + "description": "The fee that was charged by the sequencer" + }, + "execution_status": { + "title": "Execution status", + "$ref": "#/components/schemas/TXN_EXECUTION_STATUS" + }, + "finality_status": { + "title": "Finality status", + "$ref": "#/components/schemas/TXN_FINALITY_STATUS" + }, + "block_hash": { + "title": "Block hash", + "$ref": "#/components/schemas/BLOCK_HASH" + }, + "block_number": { + "title": "Block number", + "$ref": "#/components/schemas/BLOCK_NUMBER" + }, + "messages_sent": { + "type": "array", + "title": "Messages sent", + "items": { + "$ref": "#/components/schemas/MSG_TO_L1" + } + }, + "revert_reason": { + "title": "Revert reason", + "name": "revert reason", + "description": "the revert reason for the failed execution", + "type": "string" + }, + "events": { + "description": "The events emitted as part of this transaction", + "title": "Events", + "type": "array", + "items": { + "$ref": "#/components/schemas/EVENT" + } + }, + "execution_resources": { + "title": "Execution resources", + "description": "The resources consumed by the transaction", + "$ref": "#/components/schemas/EXECUTION_RESOURCES" + } + }, + "required": [ + "transaction_hash", + "actual_fee", + "finality_status", + "execution_status", + "block_hash", + "block_number", + "messages_sent", + "events", + "execution_resources" + ] + }, + "INVOKE_TXN_RECEIPT": { + "title": "Invoke Transaction Receipt", + "allOf": [ + { + "title": "Type", + "type": "object", + "properties": { + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + } + }, + "required": [ + "type" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "PENDING_INVOKE_TXN_RECEIPT": { + "title": "Invoke Transaction Receipt", + "allOf": [ + { + "title": "Type", + "type": "object", + "properties": { + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + } + }, + "required": [ + "type" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "DECLARE_TXN_RECEIPT": { + "title": "Declare Transaction Receipt", + "allOf": [ + { + "title": "Declare txn receipt", + "type": "object", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + } + }, + "required": [ + "type" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "PENDING_DECLARE_TXN_RECEIPT": { + "title": "Declare Transaction Receipt", + "allOf": [ + { + "title": "Declare txn receipt", + "type": "object", + "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + } + }, + "required": [ + "type" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "DEPLOY_ACCOUNT_TXN_RECEIPT": { + "title": "Deploy Account Transaction Receipt", + "allOf": [ + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" + }, + { + "title": "DeployAccount txn receipt", + "type": "object", + "properties": { + "type": { + "title": "Deploy account", + "type": "string", + "enum": [ + "DEPLOY_ACCOUNT" + ] + }, + "contract_address": { + "title": "Contract address", + "description": "The address of the deployed contract", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "contract_address" + ] + } + ] + }, + "PENDING_DEPLOY_ACCOUNT_TXN_RECEIPT": { + "title": "Deploy Account Transaction Receipt", + "allOf": [ + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" + }, + { + "title": "DeployAccount txn receipt", + "type": "object", + "properties": { + "type": { + "title": "Deploy account", + "type": "string", + "enum": [ + "DEPLOY_ACCOUNT" + ] + }, + "contract_address": { + "title": "Contract address", + "description": "The address of the deployed contract", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "contract_address" + ] + } + ] + }, + "DEPLOY_TXN_RECEIPT": { + "title": "Deploy Transaction Receipt", + "allOf": [ + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" + }, + { + "title": "Deploy txn receipt", + "type": "object", + "properties": { + "type": { + "title": "Deploy", + "type": "string", + "enum": [ + "DEPLOY" + ] + }, + "contract_address": { + "title": "Contract address", + "description": "The address of the deployed contract", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "type", + "contract_address" + ] + } + ] + }, + "L1_HANDLER_TXN_RECEIPT": { + "title": "L1 Handler Transaction Receipt", + "description": "receipt for l1 handler transaction", + "allOf": [ + { + "title": "Transaction type", + "type": "object", + "properties": { + "type": { + "title": "type", + "type": "string", + "enum": [ + "L1_HANDLER" + ] + }, + "message_hash": { + "title": "Message hash", + "description": "The message hash as it appears on the L1 core contract", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "type", + "message_hash" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "PENDING_L1_HANDLER_TXN_RECEIPT": { + "title": "L1 Handler Transaction Receipt", + "description": "receipt for l1 handler transaction", + "allOf": [ + { + "title": "Transaction type", + "type": "object", + "properties": { + "type": { + "title": "type", + "type": "string", + "enum": [ + "L1_HANDLER" + ] + }, + "message_hash": { + "title": "Message hash", + "description": "The message hash as it appears on the L1 core contract", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "type", + "message_hash" + ] + }, + { + "title": "Common receipt properties", + "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" + } + ] + }, + "TXN_RECEIPT": { + "title": "Transaction Receipt", + "oneOf": [ + { + "title": "Invoke transaction receipt", + "$ref": "#/components/schemas/INVOKE_TXN_RECEIPT" + }, + { + "title": "L1 handler transaction receipt", + "$ref": "#/components/schemas/L1_HANDLER_TXN_RECEIPT" + }, + { + "title": "Declare transaction receipt", + "$ref": "#/components/schemas/DECLARE_TXN_RECEIPT" + }, + { + "title": "Deploy transaction receipt", + "$ref": "#/components/schemas/DEPLOY_TXN_RECEIPT" + }, + { + "title": "Deploy account transaction receipt", + "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN_RECEIPT" + } + ] + }, + "PENDING_TXN_RECEIPT": { + "title": "Transaction Receipt", + "oneOf": [ + { + "title": "Pending Invoke transaction receipt", + "$ref": "#/components/schemas/PENDING_INVOKE_TXN_RECEIPT" + }, + { + "title": "Pending L1 handler transaction receipt", + "$ref": "#/components/schemas/PENDING_L1_HANDLER_TXN_RECEIPT" + }, + { + "title": "Pending Declare transaction receipt", + "$ref": "#/components/schemas/PENDING_DECLARE_TXN_RECEIPT" + }, + { + "title": "Pending Deploy account transaction receipt", + "$ref": "#/components/schemas/PENDING_DEPLOY_ACCOUNT_TXN_RECEIPT" + } + ] + }, + "PENDING_COMMON_RECEIPT_PROPERTIES": { + "title": "Pending common receipt properties", + "description": "Common properties for a pending transaction receipt", + "type": "object", + "properties": { + "transaction_hash": { + "title": "Transaction hash", + "$ref": "#/components/schemas/TXN_HASH", + "description": "The hash identifying the transaction" + }, + "actual_fee": { + "title": "Actual fee", + "$ref": "#/components/schemas/FEE_PAYMENT", + "description": "The fee that was charged by the sequencer" + }, + "messages_sent": { + "type": "array", + "title": "Messages sent", + "items": { + "$ref": "#/components/schemas/MSG_TO_L1" + } + }, + "events": { + "description": "The events emitted as part of this transaction", + "title": "Events", + "type": "array", + "items": { + "$ref": "#/components/schemas/EVENT" + } + }, + "revert_reason": { + "title": "Revert reason", + "name": "revert reason", + "description": "the revert reason for the failed execution", + "type": "string" + }, + "finality_status": { + "title": "Finality status", + "type": "string", + "enum": [ + "ACCEPTED_ON_L2" + ], + "description": "The finality status of the transaction" + }, + "execution_status": { + "title": "Execution status", + "$ref": "#/components/schemas/TXN_EXECUTION_STATUS" + }, + "execution_resources": { + "title": "Execution resources", + "description": "The resources consumed by the transaction", + "$ref": "#/components/schemas/EXECUTION_RESOURCES" + } + }, + "required": [ + "transaction_hash", + "actual_fee", + "messages_sent", + "events", + "finality_status", + "execution_status", + "execution_resources" + ], + "additionalProperties": false + }, + "MSG_TO_L1": { + "title": "Message to L1", + "type": "object", + "properties": { + "from_address": { + "description": "The address of the L2 contract sending the message", + "$ref": "#/components/schemas/FELT" + }, + "to_address": { + "title": "To address", + "description": "The target L1 address the message is sent to", + "$ref": "#/components/schemas/FELT" + }, + "payload": { + "description": "The payload of the message", + "title": "Payload", + "type": "array", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": [ + "from_address", + "to_address", + "payload" + ] + }, + "MSG_FROM_L1": { + "title": "Message from L1", + "type": "object", + "properties": { + "from_address": { + "description": "The address of the L1 contract sending the message", + "$ref": "#/components/schemas/ETH_ADDRESS" + }, + "to_address": { + "title": "To address", + "description": "The target L2 address the message is sent to", + "$ref": "#/components/schemas/ADDRESS" + }, + "entry_point_selector": { + "title": "Selector", + "description": "The selector of the l1_handler in invoke in the target contract", + "$ref": "#/components/schemas/FELT" + }, + "payload": { + "description": "The payload of the message", + "title": "Payload", + "type": "array", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": [ + "from_address", + "to_address", + "payload", + "entry_point_selector" + ] + }, + "TXN_STATUS": { + "title": "Transaction status", + "type": "string", + "enum": [ + "RECEIVED", + "REJECTED", + "ACCEPTED_ON_L2", + "ACCEPTED_ON_L1" + ], + "description": "The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase" + }, + "TXN_FINALITY_STATUS": { + "title": "Finality status", + "type": "string", + "enum": [ + "ACCEPTED_ON_L2", + "ACCEPTED_ON_L1" + ], + "description": "The finality status of the transaction" + }, + "TXN_EXECUTION_STATUS": { + "title": "Execution status", + "type": "string", + "enum": [ + "SUCCEEDED", + "REVERTED" + ], + "description": "The execution status of the transaction" + }, + "TXN_TYPE": { + "title": "Transaction type", + "type": "string", + "enum": [ + "DECLARE", + "DEPLOY", + "DEPLOY_ACCOUNT", + "INVOKE", + "L1_HANDLER" + ], + "description": "The type of the transaction" + }, + "BLOCK_STATUS": { + "title": "Block status", + "type": "string", + "enum": [ + "PENDING", + "ACCEPTED_ON_L2", + "ACCEPTED_ON_L1", + "REJECTED" + ], + "description": "The status of the block" + }, + "FUNCTION_CALL": { + "title": "Function call", + "type": "object", + "description": "Function call information", + "properties": { + "contract_address": { + "title": "Contract address", + "$ref": "#/components/schemas/ADDRESS" + }, + "entry_point_selector": { + "title": "Entry point selector", + "$ref": "#/components/schemas/FELT" + }, + "calldata": { + "title": "Calldata", + "type": "array", + "description": "The parameters passed to the function", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": [ + "contract_address", + "entry_point_selector", + "calldata" + ] + }, + "CONTRACT_CLASS": { + "title": "Contract class", + "type": "object", + "properties": { + "sierra_program": { + "title": "Sierra program", + "type": "array", + "description": "The list of Sierra instructions of which the program consists", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "contract_class_version": { + "title": "Contract class version", + "type": "string", + "description": "The version of the contract class object. Currently, the Starknet OS supports version 0.1.0" + }, + "entry_points_by_type": { + "title": "Entry points by type", + "type": "object", + "properties": { + "CONSTRUCTOR": { + "type": "array", + "title": "Constructor", + "items": { + "$ref": "#/components/schemas/SIERRA_ENTRY_POINT" + } + }, + "EXTERNAL": { + "title": "External", + "type": "array", + "items": { + "$ref": "#/components/schemas/SIERRA_ENTRY_POINT" + } + }, + "L1_HANDLER": { + "title": "L1 handler", + "type": "array", + "items": { + "$ref": "#/components/schemas/SIERRA_ENTRY_POINT" + } + } + }, + "required": [ + "CONSTRUCTOR", + "EXTERNAL", + "L1_HANDLER" + ] + }, + "abi": { + "title": "ABI", + "type": "string", + "description": "The class ABI, as supplied by the user declaring the class" + } + }, + "required": [ + "sierra_program", + "contract_class_version", + "entry_points_by_type" + ] + }, + "DEPRECATED_CONTRACT_CLASS": { + "title": "Deprecated contract class", + "description": "The definition of a StarkNet contract class", + "type": "object", + "properties": { + "program": { + "type": "string", + "title": "Program", + "description": "A base64 representation of the compressed program code", + "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$" + }, + "entry_points_by_type": { + "type": "object", + "title": "Deprecated entry points by type", + "properties": { + "CONSTRUCTOR": { + "type": "array", + "title": "Deprecated constructor", + "items": { + "$ref": "#/components/schemas/DEPRECATED_CAIRO_ENTRY_POINT" + } + }, + "EXTERNAL": { + "type": "array", + "title": "Deprecated external", + "items": { + "$ref": "#/components/schemas/DEPRECATED_CAIRO_ENTRY_POINT" + } + }, + "L1_HANDLER": { + "type": "array", + "title": "Deprecated L1 handler", + "items": { + "$ref": "#/components/schemas/DEPRECATED_CAIRO_ENTRY_POINT" + } + } + } + }, + "abi": { + "title": "Contract ABI", + "$ref": "#/components/schemas/CONTRACT_ABI" + } + }, + "required": [ + "program", + "entry_points_by_type" + ] + }, + "DEPRECATED_CAIRO_ENTRY_POINT": { + "title": "Deprecated Cairo entry point", + "type": "object", + "properties": { + "offset": { + "title": "Offset", + "description": "The offset of the entry point in the program", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "selector": { + "title": "Selector", + "description": "A unique identifier of the entry point (function) in the program", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "offset", + "selector" + ] + }, + "SIERRA_ENTRY_POINT": { + "title": "Sierra entry point", + "type": "object", + "properties": { + "selector": { + "title": "Selector", + "description": "A unique identifier of the entry point (function) in the program", + "$ref": "#/components/schemas/FELT" + }, + "function_idx": { + "title": "Function index", + "description": "The index of the function in the program", + "type": "integer" + } + }, + "required": [ + "selector", + "function_idx" + ] + }, + "CONTRACT_ABI": { + "title": "Contract ABI", + "type": "array", + "items": { + "$ref": "#/components/schemas/CONTRACT_ABI_ENTRY" + } + }, + "CONTRACT_ABI_ENTRY": { + "title": "Contract ABI entry", + "oneOf": [ + { + "title": "Function ABI entry", + "$ref": "#/components/schemas/FUNCTION_ABI_ENTRY" + }, + { + "title": "Event ABI entry", + "$ref": "#/components/schemas/EVENT_ABI_ENTRY" + }, + { + "title": "Struct ABI entry", + "$ref": "#/components/schemas/STRUCT_ABI_ENTRY" + } + ] + }, + "STRUCT_ABI_TYPE": { + "title": "Struct ABI type", + "type": "string", + "enum": [ + "struct" + ] + }, + "EVENT_ABI_TYPE": { + "title": "Event ABI type", + "type": "string", + "enum": [ + "event" + ] + }, + "FUNCTION_ABI_TYPE": { + "title": "Function ABI type", + "type": "string", + "enum": [ + "function", + "l1_handler", + "constructor" + ] + }, + "STRUCT_ABI_ENTRY": { + "title": "Struct ABI entry", + "type": "object", + "properties": { + "type": { + "title": "Struct ABI type", + "$ref": "#/components/schemas/STRUCT_ABI_TYPE" + }, + "name": { + "title": "Struct name", + "description": "The struct name", + "type": "string" + }, + "size": { + "title": "Size", + "type": "integer", + "minimum": 1 + }, + "members": { + "type": "array", + "title": "Members", + "items": { + "$ref": "#/components/schemas/STRUCT_MEMBER" + } + } + }, + "required": [ + "type", + "name", + "size", + "members" + ] + }, + "STRUCT_MEMBER": { + "title": "Struct member", + "allOf": [ + { + "title": "Typed parameter", + "$ref": "#/components/schemas/TYPED_PARAMETER" + }, + { + "type": "object", + "title": "Offset", + "properties": { + "offset": { + "title": "Offset", + "description": "offset of this property within the struct", + "type": "integer" + } + } + } + ] + }, + "EVENT_ABI_ENTRY": { + "title": "Event ABI entry", + "type": "object", + "properties": { + "type": { + "title": "Event ABI type", + "$ref": "#/components/schemas/EVENT_ABI_TYPE" + }, + "name": { + "title": "Event name", + "description": "The event name", + "type": "string" + }, + "keys": { + "type": "array", + "title": "Typed parameter", + "items": { + "$ref": "#/components/schemas/TYPED_PARAMETER" + } + }, + "data": { + "type": "array", + "title": "Typed parameter", + "items": { + "$ref": "#/components/schemas/TYPED_PARAMETER" + } + } + }, + "required": [ + "type", + "name", + "keys", + "data" + ] + }, + "FUNCTION_STATE_MUTABILITY": { + "title": "Function state mutability type", + "type": "string", + "enum": [ + "view" + ] + }, + "FUNCTION_ABI_ENTRY": { + "title": "Function ABI entry", + "type": "object", + "properties": { + "type": { + "title": "Function ABI type", + "$ref": "#/components/schemas/FUNCTION_ABI_TYPE" + }, + "name": { + "title": "Function name", + "description": "The function name", + "type": "string" + }, + "inputs": { + "type": "array", + "title": "Typed parameter", + "items": { + "$ref": "#/components/schemas/TYPED_PARAMETER" + } + }, + "outputs": { + "type": "array", + "title": "Typed parameter", + "items": { + "$ref": "#/components/schemas/TYPED_PARAMETER" + } + }, + "stateMutability": { + "title": "Function state mutability", + "$ref": "#/components/schemas/FUNCTION_STATE_MUTABILITY" + } + }, + "required": [ + "type", + "name", + "inputs", + "outputs" + ] + }, + "TYPED_PARAMETER": { + "title": "Typed parameter", + "type": "object", + "properties": { + "name": { + "title": "Parameter name", + "description": "The parameter's name", + "type": "string" + }, + "type": { + "title": "Parameter type", + "description": "The parameter's type", + "type": "string" + } + }, + "required": [ + "name", + "type" + ] + }, + "FEE_ESTIMATE": { + "title": "Fee estimation", + "type": "object", + "properties": { + "gas_consumed": { + "title": "Gas consumed", + "description": "The Ethereum gas cost of the transaction (see https://docs.starknet.io/docs/Fees/fee-mechanism for more info)", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "gas_price": { + "title": "Gas price", + "description": "The gas price (in gwei) that was used in the cost estimation", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "overall_fee": { + "title": "Overall fee", + "description": "The estimated fee for the transaction (in gwei), product of gas_consumed and gas_price", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "gas_consumed", + "gas_price", + "overall_fee" + ] + }, + "FEE_PAYMENT": { + "title": "Fee Payment", + "description": "fee payment info as it appears in receipts", + "type": "object", + "properties": { + "amount": { + "title": "Amunt", + "description": "amount paid", + "$ref": "#/components/schemas/FELT" + }, + "unit": { + "title": "fee unit", + "type": "string", + "enum": [ + "WEI", + "STRK" + ] + } + }, + "required": [ + "amount", + "unit" + ] + }, + "DA_MODE": { + "title": "DA mode", + "type": "string", + "description": "Specifies a storage domain in Starknet. Each domain has different gurantess regarding availability", + "enum": [ + "L1", + "L2" + ] + }, + "RESOURCE_LIMITS": { + "type": "object", + "properties": { + "max_amount": { + "title": "max amount", + "description": "the max amount of the resource that can be used in the tx", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "max_price_per_unit": { + "title": "max price", + "description": "the max price per unit of this resource for this tx", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "max_amount", + "max_price_per_unit" + ] + }, + "RESOURCE_PRICE": { + "type": "object", + "properties": { + "price_in_strk": { + "title": "price in strk", + "description": "the price of one unit of the given resource, denominated in strk", + "$ref": "#/components/schemas/NUM_AS_HEX" + }, + "price_in_wei": { + "title": "price in wei", + "description": "the price of one unit of the given resource, denominated in wei", + "$ref": "#/components/schemas/NUM_AS_HEX" + } + }, + "required": [ + "price_in_wei", + "price_in_strk" + ] + }, + "EXECUTION_RESOURCES": { + "title": "Execution resources", + "description": "The resources consumed by the transaction", + "type": "object", + "properties": { + "steps": { + "title": "Steps", + "description": "The number of Cairo steps used", + "type": "integer" + }, + "memory_holes": { + "title": "Memory holes", + "description": "The number of unused memory cells (each cell is roughly equivalent to a step)", + "type": "integer" + }, + "range_check_builtin_applications": { + "title": "Range check applications", + "description": "The number of RANGE_CHECK builtin instances", + "type": "integer" + }, + "pedersen_builtin_applications": { + "title": "Pedersen applications", + "description": "The number of Pedersen builtin instances", + "type": "integer" + }, + "poseidon_builtin_applications": { + "title": "Poseidon applications", + "description": "The number of Poseidon builtin instances", + "type": "integer" + }, + "ec_op_builtin_applications": { + "title": "EC_OP applications", + "description": "the number of EC_OP builtin instances", + "type": "integer" + }, + "ecdsa_builtin_applications": { + "title": "ECDSA applications", + "description": "the number of ECDSA builtin instances", + "type": "integer" + }, + "bitwise_builtin_applications": { + "title": "BITWISE applications", + "description": "the number of BITWISE builtin instances", + "type": "integer" + }, + "keccak_builtin_applications": { + "title": "Keccak applications", + "description": "The number of KECCAK builtin instances", + "type": "integer" + } + }, + "required": [ + "steps", + "range_check_builtin_applications", + "pedersen_builtin_applications", + "poseidon_builtin_applications", + "ec_op_builtin_applications", + "ecdsa_builtin_applications", + "bitwise_builtin_applications", + "keccak_builtin_applications" + ] + } + }, + "errors": { + "FAILED_TO_RECEIVE_TXN": { + "code": 1, + "message": "Failed to write transaction" + }, + "CONTRACT_NOT_FOUND": { + "code": 20, + "message": "Contract not found" + }, + "BLOCK_NOT_FOUND": { + "code": 24, + "message": "Block not found" + }, + "INVALID_TXN_INDEX": { + "code": 27, + "message": "Invalid transaction index in a block" + }, + "CLASS_HASH_NOT_FOUND": { + "code": 28, + "message": "Class hash not found" + }, + "TXN_HASH_NOT_FOUND": { + "code": 29, + "message": "Transaction hash not found" + }, + "PAGE_SIZE_TOO_BIG": { + "code": 31, + "message": "Requested page size is too big" + }, + "NO_BLOCKS": { + "code": 32, + "message": "There are no blocks" + }, + "INVALID_CONTINUATION_TOKEN": { + "code": 33, + "message": "The supplied continuation token is invalid or unknown" + }, + "TOO_MANY_KEYS_IN_FILTER": { + "code": 34, + "message": "Too many keys provided in a filter" + }, + "CONTRACT_ERROR": { + "code": 40, + "message": "Contract error", + "data": { + "type": "object", + "description": "More data about the execution failure", + "properties": { + "revert_error": { + "title": "revert error", + "description": "a string encoding the execution trace up to the point of failure", + "type": "string" + } + }, + "required": "revert_error" + } + } + } + } +} \ No newline at end of file diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.rs b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.rs new file mode 100644 index 0000000..f840fa6 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.rs @@ -0,0 +1,2611 @@ +// +// This file was automatically generated by openrpc-gen. +// +// Do not edit it manually and instead edit either the source OpenRPC document, +// the configuration file, or open an issue or pull request on the openrpc-gen +// GitHub repository. +// +// https://github.com/nils-mathieu/openrpc-gen +// + +use super::{ + BlockId, BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn, Felt, +}; +use crate::custom_serde::NumAsHex; +use alloc::string::String; +use alloc::vec::Vec; +use serde::ser::SerializeMap; +use serde::{Deserialize, Serialize}; + +pub type Address = Felt; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TxnWithHash { + #[serde(flatten)] + pub transaction: Txn, + pub transaction_hash: TxnHash, +} + +pub type BlockHash = Felt; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BlockHeader { + pub block_hash: BlockHash, + /// The block number (its height) + pub block_number: BlockNumber, + pub l1_gas_price: ResourcePrice, + /// The new global state root + pub new_root: Felt, + /// The hash of this block's parent + pub parent_hash: BlockHash, + /// The StarkNet identity of the sequencer submitting this block + pub sequencer_address: Felt, + /// Semver of the current Starknet protocol + pub starknet_version: String, + /// The time in which the block was created, encoded in Unix time + pub timestamp: u64, +} + +/// The block's number (its height) +pub type BlockNumber = u64; + +/// The status of the block +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum BlockStatus { + #[serde(rename = "ACCEPTED_ON_L1")] + AcceptedOnL1, + #[serde(rename = "ACCEPTED_ON_L2")] + AcceptedOnL2, + #[serde(rename = "PENDING")] + Pending, + #[serde(rename = "REJECTED")] + Rejected, +} + +/// A tag specifying a dynamic reference to a block +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum BlockTag { + #[serde(rename = "latest")] + Latest, + #[serde(rename = "pending")] + Pending, +} + +/// The block object +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BlockWithTxs { + /// The transactions in this block + pub transactions: Vec, + pub status: BlockStatus, + #[serde(flatten)] + pub block_header: BlockHeader, +} + +/// The block object +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BlockWithTxHashes { + /// The hashes of the transactions included in this block + pub transactions: Vec, + pub status: BlockStatus, + #[serde(flatten)] + pub block_header: BlockHeader, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BroadcastedDeclareTxnV1 { + /// The class to be declared + pub contract_class: DeprecatedContractClass, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BroadcastedDeclareTxnV2 { + /// The hash of the Cairo assembly resulting from the Sierra compilation + pub compiled_class_hash: Felt, + /// The class to be declared + pub contract_class: ContractClass, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "type")] +pub enum BroadcastedTxn { + #[serde(rename = "INVOKE")] + Invoke(BroadcastedInvokeTxn), + #[serde(rename = "DECLARE")] + Declare(BroadcastedDeclareTxn), + #[serde(rename = "DEPLOY_ACCOUNT")] + DeployAccount(BroadcastedDeployAccountTxn), +} + +/// StarkNet chain id, given in hex representation. +pub type ChainId = u64; + +/// Common properties for a transaction receipt +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CommonReceiptProperties { + /// The fee that was charged by the sequencer + pub actual_fee: FeePayment, + pub block_hash: BlockHash, + pub block_number: BlockNumber, + /// The events emitted as part of this transaction + pub events: Vec, + /// The resources consumed by the transaction + pub execution_resources: ExecutionResources, + pub execution_status: TxnExecutionStatus, + pub finality_status: TxnFinalityStatus, + pub messages_sent: Vec, + /// the revert reason for the failed execution + #[serde(default)] + pub revert_reason: Option, + /// The hash identifying the transaction + pub transaction_hash: TxnHash, +} + +pub type ContractAbi = Vec; + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum ContractAbiEntry { + Function(FunctionAbiEntry), + Event(EventAbiEntry), + Struct(StructAbiEntry), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ContractClass { + /// The class ABI, as supplied by the user declaring the class + #[serde(default)] + pub abi: Option, + /// The version of the contract class object. Currently, the Starknet OS supports version 0.1.0 + pub contract_class_version: String, + pub entry_points_by_type: EntryPointsByType, + /// The list of Sierra instructions of which the program consists + pub sierra_program: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EntryPointsByType { + #[serde(rename = "CONSTRUCTOR")] + pub constructor: Vec, + #[serde(rename = "EXTERNAL")] + pub external: Vec, + #[serde(rename = "L1_HANDLER")] + pub l1_handler: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ContractStorageDiffItem { + /// The contract address for which the storage changed + pub address: Felt, + /// The changes in the storage of the contract + pub storage_entries: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct KeyValuePair { + /// The key of the changed value + #[serde(default)] + pub key: Option, + /// The new value applied to the given address + #[serde(default)] + pub value: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "version")] +pub enum DeclareTxn { + #[serde(rename = "0x0")] + V0(DeclareTxnV0), + #[serde(rename = "0x1")] + V1(DeclareTxnV1), + #[serde(rename = "0x2")] + V2(DeclareTxnV2), + #[serde(rename = "0x3")] + V3(DeclareTxnV3), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: CommonReceiptProperties, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTxnV0 { + /// The hash of the declared class + pub class_hash: Felt, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTxnV1 { + /// The hash of the declared class + pub class_hash: Felt, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTxnV2 { + /// The hash of the declared class + pub class_hash: Felt, + /// The hash of the Cairo assembly resulting from the Sierra compilation + pub compiled_class_hash: Felt, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTxnV3 { + /// The hash of the declared class + pub class_hash: Felt, + /// The hash of the Cairo assembly resulting from the Sierra compilation + pub compiled_class_hash: Felt, + /// The max amount and max price per unit of L1 gas used in this tx + pub l1_gas: ResourceLimits, + pub nonce: Felt, + /// The address of the account contract sending the declaration transaction + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployedContractItem { + /// The address of the contract + pub address: Felt, + /// The hash of the contract code + pub class_hash: Felt, +} + +/// deploys a new account contract +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "version")] +pub enum DeployAccountTxn { + #[serde(rename = "0x1")] + V1(DeployAccountTxnV1), + #[serde(rename = "0x3")] + V3(DeployAccountTxnV3), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployAccountTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: CommonReceiptProperties, + /// The address of the deployed contract + pub contract_address: Felt, +} + +/// Deploys an account contract, charges fee from the pre-funded account addresses +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployAccountTxnV1 { + /// The hash of the deployed contract's class + pub class_hash: Felt, + /// The parameters passed to the constructor + pub constructor_calldata: Vec, + /// The salt for the address of the deployed contract + pub contract_address_salt: Felt, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + pub signature: Signature, +} + +/// Deploys an account contract, charges fee from the pre-funded account addresses +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployAccountTxnV3 { + /// The hash of the deployed contract's class + pub class_hash: Felt, + /// The parameters passed to the constructor + pub constructor_calldata: Vec, + /// The salt for the address of the deployed contract + pub contract_address_salt: Felt, + /// The max amount and max price per unit of L1 gas used in this tx + pub l1_gas: ResourceLimits, + pub nonce: Felt, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployTxn { + /// The hash of the deployed contract's class + pub class_hash: Felt, + /// The parameters passed to the constructor + pub constructor_calldata: Vec, + /// The salt for the address of the deployed contract + pub contract_address_salt: Felt, + /// Version of the transaction scheme + #[serde(with = "NumAsHex")] + pub version: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: CommonReceiptProperties, + /// The address of the deployed contract + pub contract_address: Felt, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeprecatedCairoEntryPoint { + /// The offset of the entry point in the program + #[serde(with = "NumAsHex")] + pub offset: u64, + /// A unique identifier of the entry point (function) in the program + pub selector: Felt, +} + +/// The definition of a StarkNet contract class +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeprecatedContractClass { + #[serde(default)] + pub abi: Option, + pub entry_points_by_type: DeprecatedEntryPointsByType, + /// A base64 representation of the compressed program code + pub program: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeprecatedEntryPointsByType { + #[serde(default)] + #[serde(rename = "CONSTRUCTOR")] + pub constructor: Option>, + #[serde(default)] + #[serde(rename = "EXTERNAL")] + pub external: Option>, + #[serde(default)] + #[serde(rename = "L1_HANDLER")] + pub l1_handler: Option>, +} + +/// Event information decorated with metadata on where it was emitted / An event emitted as a result of transaction execution +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EmittedEvent { + /// The event information + #[serde(flatten)] + pub event: Event, + /// The hash of the block in which the event was emitted + #[serde(default)] + pub block_hash: Option, + /// The number of the block in which the event was emitted + #[serde(default)] + pub block_number: Option, + /// The transaction that emitted the event + pub transaction_hash: TxnHash, +} + +/// an ethereum address represented as 40 hex digits +pub type EthAddress = String; + +/// A StarkNet event +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Event { + pub from_address: Address, + pub data: Vec, + pub keys: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EventsChunk { + /// Use this token in a subsequent query to obtain the next page. Should not appear if there are no more pages. + #[serde(default)] + pub continuation_token: Option, + pub events: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EventAbiEntry { + pub data: Vec, + pub keys: Vec, + /// The event name + pub name: String, + #[serde(rename = "type")] + pub ty: EventAbiType, +} + +pub type EventAbiType = String; + +/// The resources consumed by the transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ExecutionResources { + /// the number of BITWISE builtin instances + pub bitwise_builtin_applications: u64, + /// the number of EC_OP builtin instances + pub ec_op_builtin_applications: u64, + /// the number of ECDSA builtin instances + pub ecdsa_builtin_applications: u64, + /// The number of KECCAK builtin instances + pub keccak_builtin_applications: u64, + /// The number of unused memory cells (each cell is roughly equivalent to a step) + #[serde(default)] + pub memory_holes: Option, + /// The number of Pedersen builtin instances + pub pedersen_builtin_applications: u64, + /// The number of Poseidon builtin instances + pub poseidon_builtin_applications: u64, + /// The number of RANGE_CHECK builtin instances + pub range_check_builtin_applications: u64, + /// The number of Cairo steps used + pub steps: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FeeEstimate { + /// The Ethereum gas cost of the transaction (see https://docs.starknet.io/docs/Fees/fee-mechanism for more info) + #[serde(with = "NumAsHex")] + pub gas_consumed: u64, + /// The gas price (in gwei) that was used in the cost estimation + #[serde(with = "NumAsHex")] + pub gas_price: u64, + /// The estimated fee for the transaction (in gwei), product of gas_consumed and gas_price + #[serde(with = "NumAsHex")] + pub overall_fee: u64, +} + +/// fee payment info as it appears in receipts +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FeePayment { + /// amount paid + pub amount: Felt, + pub unit: FeeUnit, +} + +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum FeeUnit { + #[serde(rename = "STRK")] + Strk, + #[serde(rename = "WEI")] + Wei, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FunctionAbiEntry { + pub inputs: Vec, + /// The function name + pub name: String, + pub outputs: Vec, + #[serde(default)] + #[serde(rename = "stateMutability")] + pub state_mutability: Option, + #[serde(rename = "type")] + pub ty: FunctionAbiType, +} + +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum FunctionAbiType { + #[serde(rename = "constructor")] + Constructor, + #[serde(rename = "function")] + Function, + #[serde(rename = "l1_handler")] + L1Handler, +} + +/// Function call information +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FunctionCall { + /// The parameters passed to the function + pub calldata: Vec, + pub contract_address: Address, + pub entry_point_selector: Felt, +} + +pub type FunctionStateMutability = String; + +/// Initiate a transaction from an account +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "version")] +pub enum InvokeTxn { + #[serde(rename = "0x0")] + V0(InvokeTxnV0), + #[serde(rename = "0x1")] + V1(InvokeTxnV1), + #[serde(rename = "0x3")] + V3(InvokeTxnV3), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InvokeTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: CommonReceiptProperties, +} + +/// invokes a specific function in the desired contract (not necessarily an account) +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InvokeTxnV0 { + /// The parameters passed to the function + pub calldata: Vec, + pub contract_address: Address, + pub entry_point_selector: Felt, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InvokeTxnV1 { + /// The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector) + pub calldata: Vec, + /// The maximal fee that can be charged for including the transaction + pub max_fee: Felt, + pub nonce: Felt, + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InvokeTxnV3 { + /// The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector) + pub calldata: Vec, + /// The max amount and max price per unit of L1 gas used in this tx + pub l1_gas: ResourceLimits, + pub nonce: Felt, + pub sender_address: Address, + pub signature: Signature, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct L1HandlerTxn { + /// The L1->L2 message nonce field of the SN Core L1 contract at the time the transaction was sent + #[serde(with = "NumAsHex")] + pub nonce: u64, + /// Version of the transaction scheme + #[serde(with = "NumAsHex")] + pub version: u64, + #[serde(flatten)] + pub function_call: FunctionCall, +} + +/// receipt for l1 handler transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct L1HandlerTxnReceipt { + /// The message hash as it appears on the L1 core contract + #[serde(with = "NumAsHex")] + pub message_hash: u64, + #[serde(flatten)] + pub common_receipt_properties: CommonReceiptProperties, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MsgFromL1 { + /// The selector of the l1_handler in invoke in the target contract + pub entry_point_selector: Felt, + /// The address of the L1 contract sending the message + pub from_address: EthAddress, + /// The payload of the message + pub payload: Vec, + /// The target L2 address the message is sent to + pub to_address: Address, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MsgToL1 { + /// The address of the L2 contract sending the message + pub from_address: Felt, + /// The payload of the message + pub payload: Vec, + /// The target L1 address the message is sent to + pub to_address: Felt, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingBlockHeader { + pub l1_gas_price: ResourcePrice, + /// The hash of this block's parent + pub parent_hash: BlockHash, + /// The StarkNet identity of the sequencer submitting this block + pub sequencer_address: Felt, + /// Semver of the current Starknet protocol + pub starknet_version: String, + /// The time in which the block was created, encoded in Unix time + pub timestamp: u64, +} + +/// The dynamic block being constructed by the sequencer. Note that this object will be deprecated upon decentralization. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingBlockWithTxs { + /// The transactions in this block + pub transactions: Vec, + #[serde(flatten)] + pub pending_block_header: PendingBlockHeader, +} + +/// The dynamic block being constructed by the sequencer. Note that this object will be deprecated upon decentralization. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingBlockWithTxHashes { + /// The hashes of the transactions included in this block + pub transactions: Vec, + #[serde(flatten)] + pub pending_block_header: PendingBlockHeader, +} + +/// Common properties for a pending transaction receipt +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingCommonReceiptProperties { + /// The fee that was charged by the sequencer + pub actual_fee: FeePayment, + /// The events emitted as part of this transaction + pub events: Vec, + /// The resources consumed by the transaction + pub execution_resources: ExecutionResources, + pub execution_status: TxnExecutionStatus, + /// The finality status of the transaction + pub finality_status: String, /* ACCEPTED_ON_L2 */ + pub messages_sent: Vec, + /// the revert reason for the failed execution + #[serde(default)] + pub revert_reason: Option, + /// The hash identifying the transaction + pub transaction_hash: TxnHash, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingDeclareTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: PendingCommonReceiptProperties, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingDeployAccountTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: PendingCommonReceiptProperties, + /// The address of the deployed contract + pub contract_address: Felt, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingInvokeTxnReceipt { + #[serde(flatten)] + pub common_receipt_properties: PendingCommonReceiptProperties, +} + +/// receipt for l1 handler transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingL1HandlerTxnReceipt { + /// The message hash as it appears on the L1 core contract + #[serde(with = "NumAsHex")] + pub message_hash: u64, + #[serde(flatten)] + pub common_receipt_properties: PendingCommonReceiptProperties, +} + +/// Pending state update +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PendingStateUpdate { + /// The previous global state root + pub old_root: Felt, + pub state_diff: StateDiff, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "type")] +pub enum PendingTxnReceipt { + #[serde(rename = "INVOKE")] + Invoke(PendingInvokeTxnReceipt), + #[serde(rename = "L1_HANDLER")] + L1Handler(PendingL1HandlerTxnReceipt), + #[serde(rename = "DECLARE")] + Declare(PendingDeclareTxnReceipt), + #[serde(rename = "DEPLOY_ACCOUNT")] + DeployAccount(PendingDeployAccountTxnReceipt), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResourceLimits { + /// the max amount of the resource that can be used in the tx + #[serde(with = "NumAsHex")] + pub max_amount: u64, + /// the max price per unit of this resource for this tx + #[serde(with = "NumAsHex")] + pub max_price_per_unit: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResourcePrice { + /// the price of one unit of the given resource, denominated in strk + #[serde(with = "NumAsHex")] + pub price_in_strk: u64, + /// the price of one unit of the given resource, denominated in wei + #[serde(with = "NumAsHex")] + pub price_in_wei: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SierraEntryPoint { + /// The index of the function in the program + pub function_idx: u64, + /// A unique identifier of the entry point (function) in the program + pub selector: Felt, +} + +/// A transaction signature +pub type Signature = Vec; + +/// The change in state applied in this block, given as a mapping of addresses to the new values and/or new contracts +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StateDiff { + pub declared_classes: Vec, + pub deployed_contracts: Vec, + pub deprecated_declared_classes: Vec, + pub nonces: Vec, + pub replaced_classes: Vec, + pub storage_diffs: Vec, +} + +/// The declared class hash and compiled class hash +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct NewClasses { + /// The hash of the declared class + #[serde(default)] + pub class_hash: Option, + /// The Cairo assembly hash corresponding to the declared class + #[serde(default)] + pub compiled_class_hash: Option, +} + +/// The updated nonce per contract address +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct NonceUpdate { + /// The address of the contract + #[serde(default)] + pub contract_address: Option
, + /// The nonce for the given address at the end of the block + #[serde(default)] + pub nonce: Option, +} + +/// The list of contracts whose class was replaced +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ReplacedClass { + /// The new class hash + #[serde(default)] + pub class_hash: Option, + /// The address of the contract whose class was replaced + #[serde(default)] + pub contract_address: Option
, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StateUpdate { + pub block_hash: BlockHash, + /// The new global state root + pub new_root: Felt, + /// The previous global state root + pub old_root: Felt, + pub state_diff: StateDiff, +} + +/// A storage key. Represented as up to 62 hex digits, 3 bits, and 5 leading zeroes. +pub type StorageKey = String; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StructAbiEntry { + pub members: Vec, + /// The struct name + pub name: String, + pub size: u64, + #[serde(rename = "type")] + pub ty: StructAbiType, +} + +pub type StructAbiType = String; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StructMember { + #[serde(flatten)] + pub typed_parameter: TypedParameter, + /// offset of this property within the struct + #[serde(default)] + pub offset: Option, +} + +/// An object describing the node synchronization status +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SyncStatus { + /// The hash of the current block being synchronized + pub current_block_hash: BlockHash, + /// The number (height) of the current block being synchronized + pub current_block_num: BlockNumber, + /// The hash of the estimated highest block to be synchronized + pub highest_block_hash: BlockHash, + /// The number (height) of the estimated highest block to be synchronized + pub highest_block_num: BlockNumber, + /// The hash of the block from which the sync started + pub starting_block_hash: BlockHash, + /// The number (height) of the block from which the sync started + pub starting_block_num: BlockNumber, +} + +/// The transaction schema, as it appears inside a block +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "type")] +pub enum Txn { + #[serde(rename = "INVOKE")] + Invoke(InvokeTxn), + #[serde(rename = "L1_HANDLER")] + L1Handler(L1HandlerTxn), + #[serde(rename = "DECLARE")] + Declare(DeclareTxn), + #[serde(rename = "DEPLOY")] + Deploy(DeployTxn), + #[serde(rename = "DEPLOY_ACCOUNT")] + DeployAccount(DeployAccountTxn), +} + +/// The execution status of the transaction +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum TxnExecutionStatus { + #[serde(rename = "REVERTED")] + Reverted, + #[serde(rename = "SUCCEEDED")] + Succeeded, +} + +/// The finality status of the transaction +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum TxnFinalityStatus { + #[serde(rename = "ACCEPTED_ON_L1")] + L1, + #[serde(rename = "ACCEPTED_ON_L2")] + L2, +} + +/// The transaction hash, as assigned in StarkNet +pub type TxnHash = Felt; + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "type")] +pub enum TxnReceipt { + #[serde(rename = "INVOKE")] + Invoke(InvokeTxnReceipt), + #[serde(rename = "L1_HANDLER")] + L1Handler(L1HandlerTxnReceipt), + #[serde(rename = "DECLARE")] + Declare(DeclareTxnReceipt), + #[serde(rename = "DEPLOY")] + Deploy(DeployTxnReceipt), + #[serde(rename = "DEPLOY_ACCOUNT")] + DeployAccount(DeployAccountTxnReceipt), +} + +/// The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum TxnStatus { + #[serde(rename = "ACCEPTED_ON_L1")] + AcceptedOnL1, + #[serde(rename = "ACCEPTED_ON_L2")] + AcceptedOnL2, + #[serde(rename = "RECEIVED")] + Received, + #[serde(rename = "REJECTED")] + Rejected, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TypedParameter { + /// The parameter's name + pub name: String, + /// The parameter's type + #[serde(rename = "type")] + pub ty: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BlockHashAndNumber { + pub block_hash: BlockHash, + pub block_number: BlockNumber, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum MaybePendingBlockWithTxHashes { + Block(BlockWithTxHashes), + Pending(PendingBlockWithTxHashes), +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum MaybePendingBlockWithTxs { + Block(BlockWithTxs), + Pending(PendingBlockWithTxs), +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum MaybeDeprecatedContractClass { + Deprecated(DeprecatedContractClass), + ContractClass(ContractClass), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EventFilterWithPageRequest { + #[serde(default)] + pub address: Option
, + #[serde(default)] + pub from_block: Option, + /// The values used to filter the events + #[serde(default)] + pub keys: Option>>, + #[serde(default)] + pub to_block: Option, + pub chunk_size: u64, + /// The token returned from the previous query. If no token is provided the first page is returned. + #[serde(default)] + pub continuation_token: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum MaybePendingStateUpdate { + Block(StateUpdate), + Pending(PendingStateUpdate), +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum MaybePendingTxnReceipt { + Receipt(TxnReceipt), + Pending(PendingTxnReceipt), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TxnFinalityAndExecutionStatus { + #[serde(default)] + pub execution_status: Option, + pub finality_status: TxnStatus, +} + +/// Parameters of the `starknet_specVersion` method. +#[derive(Debug, Clone)] +pub struct SpecVersionParams {} + +impl Serialize for SpecVersionParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for SpecVersionParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = SpecVersionParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_specVersion`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 1, + &"expected 0 parameters", + )); + } + + Ok(SpecVersionParams {}) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper {} + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(SpecVersionParams {}) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getBlockWithTxHashes` method. +#[derive(Debug, Clone)] +pub struct GetBlockWithTxHashesParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for GetBlockWithTxHashesParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetBlockWithTxHashesParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetBlockWithTxHashesParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getBlockWithTxHashes`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(GetBlockWithTxHashesParams { block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetBlockWithTxHashesParams { + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getBlockWithTxs` method. +#[derive(Debug, Clone)] +pub struct GetBlockWithTxsParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for GetBlockWithTxsParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetBlockWithTxsParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetBlockWithTxsParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getBlockWithTxs`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(GetBlockWithTxsParams { block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetBlockWithTxsParams { + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getStateUpdate` method. +#[derive(Debug, Clone)] +pub struct GetStateUpdateParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for GetStateUpdateParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetStateUpdateParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetStateUpdateParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getStateUpdate`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(GetStateUpdateParams { block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetStateUpdateParams { + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getStorageAt` method. +#[derive(Debug, Clone)] +pub struct GetStorageAtParams { + /// The address of the contract to read from + pub contract_address: Address, + /// The key to the storage value for the given contract + pub key: StorageKey, + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for GetStorageAtParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("contract_address", &self.contract_address)?; + map.serialize_entry("key", &self.key)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetStorageAtParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetStorageAtParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getStorageAt`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let contract_address: Address = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 3 parameters"))?; + let key: StorageKey = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 3 parameters"))?; + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(3, &"expected 3 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 4, + &"expected 3 parameters", + )); + } + + Ok(GetStorageAtParams { + contract_address, + key, + block_id, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + contract_address: Address, + key: StorageKey, + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetStorageAtParams { + contract_address: helper.contract_address, + key: helper.key, + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getTransactionStatus` method. +#[derive(Debug, Clone)] +pub struct GetTransactionStatusParams { + /// The hash of the requested transaction + pub transaction_hash: TxnHash, +} + +impl Serialize for GetTransactionStatusParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("transaction_hash", &self.transaction_hash)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetTransactionStatusParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetTransactionStatusParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getTransactionStatus`") + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + transaction_hash: TxnHash, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetTransactionStatusParams { + transaction_hash: helper.transaction_hash, + }) + } + } + + deserializer.deserialize_map(Visitor) + } +} + +/// Parameters of the `starknet_getTransactionByHash` method. +#[derive(Debug, Clone)] +pub struct GetTransactionByHashParams { + /// The hash of the requested transaction + pub transaction_hash: TxnHash, +} + +impl Serialize for GetTransactionByHashParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("transaction_hash", &self.transaction_hash)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetTransactionByHashParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetTransactionByHashParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getTransactionByHash`") + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + transaction_hash: TxnHash, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetTransactionByHashParams { + transaction_hash: helper.transaction_hash, + }) + } + } + + deserializer.deserialize_map(Visitor) + } +} + +/// Parameters of the `starknet_getTransactionByBlockIdAndIndex` method. +#[derive(Debug, Clone)] +pub struct GetTransactionByBlockIdAndIndexParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, + /// The index in the block to search for the transaction + pub index: u64, +} + +impl Serialize for GetTransactionByBlockIdAndIndexParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("index", &self.index)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetTransactionByBlockIdAndIndexParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetTransactionByBlockIdAndIndexParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!( + f, + "the parameters for `starknet_getTransactionByBlockIdAndIndex`" + ) + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let index: u64 = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(GetTransactionByBlockIdAndIndexParams { block_id, index }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + index: u64, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetTransactionByBlockIdAndIndexParams { + block_id: helper.block_id, + index: helper.index, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getTransactionReceipt` method. +#[derive(Debug, Clone)] +pub struct GetTransactionReceiptParams { + /// The hash of the requested transaction + pub transaction_hash: TxnHash, +} + +impl Serialize for GetTransactionReceiptParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("transaction_hash", &self.transaction_hash)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetTransactionReceiptParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetTransactionReceiptParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getTransactionReceipt`") + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + transaction_hash: TxnHash, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetTransactionReceiptParams { + transaction_hash: helper.transaction_hash, + }) + } + } + + deserializer.deserialize_map(Visitor) + } +} + +/// Parameters of the `starknet_getClass` method. +#[derive(Debug, Clone)] +pub struct GetClassParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, + /// The hash of the requested contract class + pub class_hash: Felt, +} + +impl Serialize for GetClassParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("class_hash", &self.class_hash)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetClassParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetClassParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getClass`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let class_hash: Felt = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(GetClassParams { + block_id, + class_hash, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + class_hash: Felt, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetClassParams { + block_id: helper.block_id, + class_hash: helper.class_hash, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getClassHashAt` method. +#[derive(Debug, Clone)] +pub struct GetClassHashAtParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, + /// The address of the contract whose class hash will be returned + pub contract_address: Address, +} + +impl Serialize for GetClassHashAtParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("contract_address", &self.contract_address)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetClassHashAtParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetClassHashAtParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getClassHashAt`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let contract_address: Address = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(GetClassHashAtParams { + block_id, + contract_address, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + contract_address: Address, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetClassHashAtParams { + block_id: helper.block_id, + contract_address: helper.contract_address, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getClassAt` method. +#[derive(Debug, Clone)] +pub struct GetClassAtParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, + /// The address of the contract whose class definition will be returned + pub contract_address: Address, +} + +impl Serialize for GetClassAtParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("contract_address", &self.contract_address)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetClassAtParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetClassAtParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getClassAt`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let contract_address: Address = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(GetClassAtParams { + block_id, + contract_address, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + contract_address: Address, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetClassAtParams { + block_id: helper.block_id, + contract_address: helper.contract_address, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getBlockTransactionCount` method. +#[derive(Debug, Clone)] +pub struct GetBlockTransactionCountParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for GetBlockTransactionCountParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetBlockTransactionCountParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetBlockTransactionCountParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getBlockTransactionCount`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(GetBlockTransactionCountParams { block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetBlockTransactionCountParams { + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_call` method. +#[derive(Debug, Clone)] +pub struct CallParams { + /// The details of the function call + pub request: FunctionCall, + /// The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. + pub block_id: BlockId, +} + +impl Serialize for CallParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("request", &self.request)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for CallParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = CallParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_call`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let request: FunctionCall = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(CallParams { request, block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + request: FunctionCall, + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(CallParams { + request: helper.request, + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_estimateFee` method. +#[derive(Debug, Clone)] +pub struct EstimateFeeParams { + /// The transaction to estimate + pub request: Vec, + /// The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. + pub block_id: BlockId, +} + +impl Serialize for EstimateFeeParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("request", &self.request)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for EstimateFeeParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = EstimateFeeParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_estimateFee`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let request: Vec = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(EstimateFeeParams { request, block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + request: Vec, + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(EstimateFeeParams { + request: helper.request, + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_estimateMessageFee` method. +#[derive(Debug, Clone)] +pub struct EstimateMessageFeeParams { + /// the message's parameters + pub message: MsgFromL1, + /// The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. + pub block_id: BlockId, +} + +impl Serialize for EstimateMessageFeeParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("message", &self.message)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for EstimateMessageFeeParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = EstimateMessageFeeParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_estimateMessageFee`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let message: MsgFromL1 = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(EstimateMessageFeeParams { message, block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + message: MsgFromL1, + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(EstimateMessageFeeParams { + message: helper.message, + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_blockNumber` method. +#[derive(Debug, Clone)] +pub struct BlockNumberParams {} + +impl Serialize for BlockNumberParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for BlockNumberParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = BlockNumberParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_blockNumber`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 1, + &"expected 0 parameters", + )); + } + + Ok(BlockNumberParams {}) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper {} + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(BlockNumberParams {}) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_blockHashAndNumber` method. +#[derive(Debug, Clone)] +pub struct BlockHashAndNumberParams {} + +impl Serialize for BlockHashAndNumberParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for BlockHashAndNumberParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = BlockHashAndNumberParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_blockHashAndNumber`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 1, + &"expected 0 parameters", + )); + } + + Ok(BlockHashAndNumberParams {}) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper {} + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(BlockHashAndNumberParams {}) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_chainId` method. +#[derive(Debug, Clone)] +pub struct ChainIdParams {} + +impl Serialize for ChainIdParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for ChainIdParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = ChainIdParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_chainId`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 1, + &"expected 0 parameters", + )); + } + + Ok(ChainIdParams {}) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper {} + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(ChainIdParams {}) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_syncing` method. +#[derive(Debug, Clone)] +pub struct SyncingParams {} + +impl Serialize for SyncingParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for SyncingParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = SyncingParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_syncing`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 1, + &"expected 0 parameters", + )); + } + + Ok(SyncingParams {}) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper {} + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(SyncingParams {}) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getEvents` method. +#[derive(Debug, Clone)] +pub struct GetEventsParams { + /// The conditions used to filter the returned events + pub filter: EventFilterWithPageRequest, +} + +impl Serialize for GetEventsParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("filter", &self.filter)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetEventsParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetEventsParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getEvents`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let filter: EventFilterWithPageRequest = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(GetEventsParams { filter }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + filter: EventFilterWithPageRequest, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetEventsParams { + filter: helper.filter, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_getNonce` method. +#[derive(Debug, Clone)] +pub struct GetNonceParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, + /// The address of the contract whose nonce we're seeking + pub contract_address: Address, +} + +impl Serialize for GetNonceParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("contract_address", &self.contract_address)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for GetNonceParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GetNonceParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_getNonce`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 2 parameters"))?; + let contract_address: Address = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 2 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 3, + &"expected 2 parameters", + )); + } + + Ok(GetNonceParams { + block_id, + contract_address, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + contract_address: Address, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(GetNonceParams { + block_id: helper.block_id, + contract_address: helper.contract_address, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.toml b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.toml new file mode 100644 index 0000000..f78a455 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.toml @@ -0,0 +1,92 @@ +debug-path = false +run-rustfmt = true + +[generation] +additional-imports = [ + "crate::custom_serde::NumAsHex", + "super::{BlockId, Felt, BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn}", + "alloc::vec::Vec", + "alloc::string::String", +] +method-name-prefix = "starknet_" +param-types = true +use-core = true + +[formatters] +num-as-hex = "NumAsHex" + +[fixes] +strip-enum-variants = true +flatten = [ + "#/components/schemas/NUM_AS_HEX", +] +preserve = [ + "#/components/schemas/BLOCK_TAG", + "#/components/schemas/SYNC_STATUS", + "#/components/schemas/BROADCASTED_DECLARE_TXN_V1", + "#/components/schemas/BROADCASTED_DECLARE_TXN_V2", +] + +[fixes.replace] +# Too tricky to automatically fix cleanly +"#/components/schemas/BLOCK_ID" = "BlockId" +"#/methods/starknet_syncing/result/_anon" = "SyncingStatus" +"#/components/schemas/FELT" = "Felt" + +# Query-only types +"#/components/schemas/BROADCASTED_DECLARE_TXN" = "BroadcastedDeclareTxn" +"#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" = "BroadcastedDeployAccountTxn" +"#/components/schemas/BROADCASTED_INVOKE_TXN" = "BroadcastedInvokeTxn" + +# Duplicates +"#/methods/starknet_getClassAt/result/_anon" = "MaybeDeprecatedContractClass" +"#/methods/starknet_getTransactionByBlockIdAndIndex/result/_anon" = "TxnWithHash" +"#/methods/starknet_getTransactionByHash/result/_anon" = "TxnWithHash" + +[fixes.rename] +# Broken Enum Variants +"#/methods/starknet_getBlockWithTxHashes/result/_anon/variant0" = "Block" +"#/methods/starknet_getBlockWithTxs/result/_anon/variant0" = "Block" +"#/methods/starknet_getStateUpdate/result/_anon/variant0" = "Block" +"#/methods/starknet_getTransactionReceipt/result/_anon/variant0" = "Receipt" +"#/methods/starknet_getClass/result/_anon/variant1" = "ContractClass" + +# Anonymous Types +"#/components/schemas/BLOCK_BODY_WITH_TXS/transactions/_anon/_anon" = "TxnWithHash" +"#/components/schemas/CONTRACT_STORAGE_DIFF_ITEM/storage_entries/_anon/_anon" = "KeyValuePair" +"#/methods/starknet_blockHashAndNumber/result/_anon" = "BlockHashAndNumber" +"#/methods/starknet_getBlockWithTxHashes/result/_anon" = "MaybePendingBlockWithTxHashes" +"#/methods/starknet_getBlockWithTxs/result/_anon" = "MaybePendingBlockWithTxs" +"#/methods/starknet_getClass/result/_anon" = "MaybeDeprecatedContractClass" +"#/methods/starknet_getEvents/params/filter/_anon" = "EventFilterWithPageRequest" +"#/methods/starknet_getStateUpdate/result/_anon" = "MaybePendingStateUpdate" +"#/methods/starknet_getTransactionReceipt/result/_anon" = "MaybePendingTxnReceipt" +"#/methods/starknet_getTransactionStatus/result/_anon" = "TxnFinalityAndExecutionStatus" + +# Broken convert_case +"#/components/schemas/FUNCTION_ABI_ENTRY/stateMutability" = "state_mutability" + +[fixes.tagged-enums] +"#/components/schemas/DECLARE_TXN" = "version" +"#/components/schemas/INVOKE_TXN" = "version" +"#/components/schemas/TXN" = "type" +"#/components/schemas/TXN_RECEIPT" = "type" +"#/components/schemas/PENDING_TXN_RECEIPT" = "type" +"#/components/schemas/DEPLOY_ACCOUNT_TXN" = "version" +"#/components/schemas/BROADCASTED_TXN" = "type" + +[fixes.set-tags] +"#/components/schemas/BROADCASTED_DECLARE_TXN_V1/_anon/version" = "0x1" +"#/components/schemas/BROADCASTED_DECLARE_TXN_V2/_anon/version" = "0x2" +"#/components/schemas/INVOKE_TXN_V0/version" = "0x0" +"#/components/schemas/INVOKE_TXN_V1/_anon/version" = "0x1" +"#/components/schemas/INVOKE_TXN_V3/_anon/version" = "0x3" +"#/components/schemas/DECLARE_TXN_V0/_anon/version" = "0x0" +"#/components/schemas/DECLARE_TXN_V1/_anon/version" = "0x1" +"#/components/schemas/DECLARE_TXN_V2/_anon/version" = "0x2" +"#/components/schemas/DECLARE_TXN_V3/_anon/version" = "0x3" +"#/components/schemas/DEPLOY_ACCOUNT_TXN_V1/version" = "0x1" +"#/components/schemas/DEPLOY_ACCOUNT_TXN_V3/version" = "0x3" + +[primitives] +integer = "u64" \ No newline at end of file diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.json b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.json new file mode 100644 index 0000000..9b45605 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.json @@ -0,0 +1,491 @@ +{ + "openrpc": "1.0.0-rc1", + "info": { + "version": "0.5.0", + "title": "StarkNet Trace API", + "license": {} + }, + "servers": [], + "methods": [ + { + "name": "starknet_traceTransaction", + "summary": "For a given executed transaction, return the trace of its execution, including internal calls", + "description": "Returns the execution trace of the transaction designated by the input hash", + "params": [ + { + "name": "transaction_hash", + "summary": "The hash of the transaction to trace", + "required": true, + "schema": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/TXN_HASH" + } + } + ], + "result": { + "name": "trace", + "description": "The function call trace of the transaction designated by the given hash", + "schema": { + "$ref": "#/components/schemas/TRANSACTION_TRACE" + } + }, + "errors": [ + { + "$ref": "#/components/errors/INVALID_TXN_HASH" + }, + { + "$ref": "#/components/errors/NO_TRACE_AVAILABLE" + } + ] + }, + { + "name": "starknet_simulateTransactions", + "summary": "simulate a given sequence of transactions on the requested state, and generate the execution traces. If one of the transactions is reverted, raises CONTRACT_ERROR.", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on.", + "required": true, + "schema": { + "$ref": "#/components/schemas/BLOCK_ID" + } + }, + { + "name": "transactions", + "description": "The transactions to simulate", + "required": true, + "schema": { + "type": "array", + "description": "a sequence of transactions to simulate, running each transaction on the state resulting from applying all the previous ones", + "items": { + "$ref": "#/components/schemas/BROADCASTED_TXN" + } + } + }, + { + "name": "simulation_flags", + "description": "describes what parts of the transaction should be executed", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/SIMULATION_FLAG" + } + } + } + ], + "result": { + "name": "simulated_transactions", + "description": "The execution trace and consuemd resources of the required transactions", + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "transaction_trace": { + "title": "the transaction's trace", + "$ref": "#/components/schemas/TRANSACTION_TRACE" + }, + "fee_estimation": { + "title": "the transaction's resources and fee", + "$ref": "#/components/schemas/FEE_ESTIMATE" + } + } + } + } + }, + "errors": [ + { + "$ref": "#/components/errors/CONTRACT_NOT_FOUND" + }, + { + "$ref": "#/components/errors/CONTRACT_ERROR" + }, + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + }, + { + "name": "starknet_traceBlockTransactions", + "summary": "Retrieve traces for all transactions in the given block", + "description": "Returns the execution traces of all transactions included in the given block", + "params": [ + { + "name": "block_id", + "description": "The hash of the requested block, or number (height) of the requested block, or a block tag", + "required": true, + "schema": { + "$ref": "#/components/schemas/BLOCK_ID" + } + } + ], + "result": { + "name": "traces", + "description": "The traces of all transactions in the block", + "schema": { + "type": "array", + "items": { + "type": "object", + "description": "A single pair of transaction hash and corresponding trace", + "properties": { + "transaction_hash": { + "$ref": "#/components/schemas/FELT" + }, + "trace_root": { + "$ref": "#/components/schemas/TRANSACTION_TRACE" + } + } + } + } + }, + "errors": [ + { + "$ref": "#/components/errors/BLOCK_NOT_FOUND" + } + ] + } + ], + "components": { + "contentDescriptors": {}, + "schemas": { + "TRANSACTION_TRACE": { + "oneOf": [ + { + "name": "INVOKE_TXN_TRACE", + "type": "object", + "description": "the execution trace of an invoke transaction", + "properties": { + "validate_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "execute_invocation": { + "description": "the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)", + "oneOf": [ + { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + { + "type": "object", + "properties": { + "revert_reason": { + "name": "revert reason", + "description": "the revert reason for the failed execution", + "type": "string" + } + } + } + ] + }, + "fee_transfer_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "state_diff": { + "title": "state_diff", + "description": "the state diffs induced by the transaction", + "$ref": "#/components/schemas/STATE_DIFF" + }, + "type": { + "title": "Type", + "type": "string", + "enum": [ + "INVOKE" + ] + } + }, + "required": [ + "validate_invocation", + "execute_invocation", + "fee_transfer_invocation", + "state_diff", + "type" + ] + }, + { + "name": "DECLARE_TXN_TRACE", + "type": "object", + "description": "the execution trace of a declare transaction", + "properties": { + "validate_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "fee_transfer_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "state_diff": { + "title": "state_diff", + "description": "the state diffs induced by the transaction", + "$ref": "#/components/schemas/STATE_DIFF" + }, + "type": { + "title": "Type", + "type": "string", + "enum": [ + "DECLARE" + ] + } + }, + "required": [ + "validate_invocation", + "fee_transfer_invocation", + "state_diff", + "type" + ] + }, + { + "name": "DEPLOY_ACCOUNT_TXN_TRACE", + "type": "object", + "description": "the execution trace of a deploy account transaction", + "properties": { + "validate_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "constructor_invocation": { + "description": "the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)", + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "fee_transfer_invocation": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "state_diff": { + "title": "state_diff", + "description": "the state diffs induced by the transaction", + "$ref": "#/components/schemas/STATE_DIFF" + }, + "type": { + "title": "Type", + "type": "string", + "enum": [ + "DEPLOY_ACCOUNT" + ] + } + }, + "required": [ + "validate_invocation", + "constructor_invocation", + "fee_transfer_invocation", + "state_diff", + "type" + ] + }, + { + "name": "L1_HANDLER_TXN_TRACE", + "type": "object", + "description": "the execution trace of an L1 handler transaction", + "properties": { + "function_invocation": { + "description": "the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions)", + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "type": { + "title": "Type", + "type": "string", + "enum": [ + "L1_HANDLER" + ] + } + }, + "required": [ + "function_invocation", + "type" + ] + } + ] + }, + "SIMULATION_FLAG": { + "type": "string", + "enum": [ + "SKIP_VALIDATE", + "SKIP_FEE_CHARGE" + ], + "description": "Flags that indicate how to simulate a given transaction. By default, the sequencer behavior is replicated locally (enough funds are expected to be in the account, and fee will be deducted from the balance before the simulation of the next transaction). To skip the fee charge, use the SKIP_FEE_CHARGE flag." + }, + "NESTED_CALL": { + "$ref": "#/components/schemas/FUNCTION_INVOCATION" + }, + "FUNCTION_INVOCATION": { + "allOf": [ + { + "$ref": "#/components/schemas/FUNCTION_CALL" + }, + { + "type": "object", + "properties": { + "caller_address": { + "title": "Caller Address", + "description": "The address of the invoking contract. 0 for the root invocation", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the class being called", + "$ref": "#/components/schemas/FELT" + }, + "entry_point_type": { + "$ref": "#/components/schemas/ENTRY_POINT_TYPE" + }, + "call_type": { + "$ref": "#/components/schemas/CALL_TYPE" + }, + "result": { + "title": "Invocation Result", + "description": "The value returned from the function invocation", + "type": "array", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "calls": { + "title": "Nested Calls", + "description": "The calls made by this invocation", + "type": "array", + "items": { + "$ref": "#/components/schemas/NESTED_CALL" + } + }, + "events": { + "title": "Invocation Events", + "description": "The events emitted in this invocation", + "type": "array", + "items": { + "$ref": "#/components/schemas/ORDERED_EVENT" + } + }, + "messages": { + "title": "L1 Messages", + "description": "The messages sent by this invocation to L1", + "type": "array", + "items": { + "$ref": "#/components/schemas/ORDERED_MESSAGE" + } + } + }, + "required": [ + "caller_address", + "class_hash", + "entry_point_type", + "call_type", + "result", + "calls", + "events", + "messages" + ] + } + ] + }, + "ENTRY_POINT_TYPE": { + "type": "string", + "enum": [ + "EXTERNAL", + "L1_HANDLER", + "CONSTRUCTOR" + ] + }, + "CALL_TYPE": { + "type": "string", + "enum": [ + "LIBRARY_CALL", + "CALL" + ] + }, + "ORDERED_EVENT": { + "type": "object", + "title": "orderedEvent", + "description": "an event alongside its order within the transaction", + "allOf": [ + { + "type": "object", + "properties": { + "order": { + "title": "order", + "description": "the order of the event within the transaction", + "type": "integer" + } + } + }, + { + "$ref": "#/components/schemas/EVENT" + } + ] + }, + "ORDERED_MESSAGE": { + "type": "object", + "title": "orderedMessage", + "description": "a message alongside its order within the transaction", + "allOf": [ + { + "type": "object", + "properties": { + "order": { + "title": "order", + "description": "the order of the message within the transaction", + "type": "integer" + } + } + }, + { + "$ref": "#/components/schemas/MSG_TO_L1" + } + ] + }, + "FELT": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/FELT" + }, + "FUNCTION_CALL": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL" + }, + "EVENT": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/EVENT_CONTENT" + }, + "MSG_TO_L1": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/MSG_TO_L1" + }, + "BLOCK_ID": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/BLOCK_ID" + }, + "FEE_ESTIMATE": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/FEE_ESTIMATE" + }, + "BROADCASTED_TXN": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_TXN" + }, + "STATE_DIFF": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/STATE_DIFF" + } + }, + "errors": { + "NO_TRACE_AVAILABLE": { + "code": 10, + "message": "No trace available for transaction", + "data": { + "type": "object", + "description": "Extra information on why trace is not available. Either it wasn't executed yet (RECEIVED), or the transaction failed (REJECTED)", + "properties": { + "status": { + "type": "string", + "enum": [ + "RECEIVED", + "REJECTED" + ] + } + } + } + }, + "CONTRACT_NOT_FOUND": { + "code": 20, + "message": "Contract not found" + }, + "INVALID_TXN_HASH": { + "code": 25, + "message": "Invalid transaction hash" + }, + "BLOCK_NOT_FOUND": { + "code": 24, + "message": "Block not found" + }, + "CONTRACT_ERROR": { + "code": 40, + "message": "Contract error" + } + } + } +} \ No newline at end of file diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.rs b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.rs new file mode 100644 index 0000000..413edf0 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.rs @@ -0,0 +1,418 @@ +// +// This file was automatically generated by openrpc-gen. +// +// Do not edit it manually and instead edit either the source OpenRPC document, +// the configuration file, or open an issue or pull request on the openrpc-gen +// GitHub repository. +// +// https://github.com/nils-mathieu/openrpc-gen +// + +use super::{ + BlockId, BroadcastedTxn, Event, FeeEstimate, Felt, FunctionCall, MsgToL1, StateDiff, TxnHash, +}; +use alloc::string::String; +use alloc::vec::Vec; +use serde::ser::SerializeMap; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum CallType { + #[serde(rename = "CALL")] + Regular, + #[serde(rename = "LIBRARY_CALL")] + Library, +} + +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum EntryPointType { + #[serde(rename = "CONSTRUCTOR")] + Constructor, + #[serde(rename = "EXTERNAL")] + External, + #[serde(rename = "L1_HANDLER")] + L1Handler, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FunctionInvocation { + #[serde(flatten)] + pub function_call: FunctionCall, + pub call_type: CallType, + /// The address of the invoking contract. 0 for the root invocation + pub caller_address: Felt, + /// The calls made by this invocation + pub calls: Vec, + /// The hash of the class being called + pub class_hash: Felt, + pub entry_point_type: EntryPointType, + /// The events emitted in this invocation + pub events: Vec, + /// The messages sent by this invocation to L1 + pub messages: Vec, + /// The value returned from the function invocation + pub result: Vec, +} + +pub type NestedCall = FunctionInvocation; + +/// an event alongside its order within the transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct OrderedEvent { + /// the order of the event within the transaction + #[serde(default)] + pub order: Option, + #[serde(flatten)] + pub event: Event, +} + +/// a message alongside its order within the transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct OrderedMessage { + /// the order of the message within the transaction + #[serde(default)] + pub order: Option, + #[serde(flatten)] + pub msg_to_l_1: MsgToL1, +} + +/// Flags that indicate how to simulate a given transaction. By default, the sequencer behavior is replicated locally (enough funds are expected to be in the account, and fee will be deducted from the balance before the simulation of the next transaction). To skip the fee charge, use the SKIP_FEE_CHARGE flag. +#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)] +pub enum SimulationFlag { + #[serde(rename = "SKIP_FEE_CHARGE")] + FeeCharge, + #[serde(rename = "SKIP_VALIDATE")] + Validate, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(tag = "type")] +pub enum TransactionTrace { + /// the execution trace of an invoke transaction + #[serde(rename = "INVOKE")] + Invoke(InvokeTransactionTrace), + /// the execution trace of a declare transaction + #[serde(rename = "DECLARE")] + Declare(DeclareTransactionTrace), + /// the execution trace of a deploy account transaction + #[serde(rename = "DEPLOY_ACCOUNT")] + DeployAccount(DeployAccountTransactionTrace), + /// the execution trace of an L1 handler transaction + #[serde(rename = "L1_HANDLER")] + L1Handler(L1HandlerTransactionTrace), +} + +/// the execution trace of an invoke transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InvokeTransactionTrace { + /// the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) + pub execute_invocation: ExecuteInvocation, + pub fee_transfer_invocation: FunctionInvocation, + /// the state diffs induced by the transaction + pub state_diff: StateDiff, + pub validate_invocation: FunctionInvocation, +} + +/// the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(untagged)] +pub enum ExecuteInvocation { + FunctionInvocation(FunctionInvocation), + Anon(RevertedInvocation), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RevertedInvocation { + /// the revert reason for the failed execution + #[serde(default)] + pub revert_reason: Option, +} + +/// the execution trace of a declare transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeclareTransactionTrace { + pub fee_transfer_invocation: FunctionInvocation, + /// the state diffs induced by the transaction + pub state_diff: StateDiff, + pub validate_invocation: FunctionInvocation, +} + +/// the execution trace of a deploy account transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeployAccountTransactionTrace { + /// the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) + pub constructor_invocation: FunctionInvocation, + pub fee_transfer_invocation: FunctionInvocation, + /// the state diffs induced by the transaction + pub state_diff: StateDiff, + pub validate_invocation: FunctionInvocation, +} + +/// the execution trace of an L1 handler transaction +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct L1HandlerTransactionTrace { + /// the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) + pub function_invocation: FunctionInvocation, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SimulateTransactionsResult { + #[serde(default)] + pub fee_estimation: Option, + #[serde(default)] + pub transaction_trace: Option, +} + +/// A single pair of transaction hash and corresponding trace +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TraceBlockTransactionsResult { + #[serde(default)] + pub trace_root: Option, + #[serde(default)] + pub transaction_hash: Option, +} + +/// Parameters of the `starknet_traceTransaction` method. +#[derive(Debug, Clone)] +pub struct TraceTransactionParams { + /// The hash of the transaction to trace + pub transaction_hash: TxnHash, +} + +impl Serialize for TraceTransactionParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("transaction_hash", &self.transaction_hash)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for TraceTransactionParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = TraceTransactionParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_traceTransaction`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let transaction_hash: TxnHash = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(TraceTransactionParams { transaction_hash }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + transaction_hash: TxnHash, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(TraceTransactionParams { + transaction_hash: helper.transaction_hash, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_simulateTransactions` method. +#[derive(Debug, Clone)] +pub struct SimulateTransactionsParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag, for the block referencing the state or call the transaction on. + pub block_id: BlockId, + /// The transactions to simulate + pub transactions: Vec, + /// describes what parts of the transaction should be executed + pub simulation_flags: Vec, +} + +impl Serialize for SimulateTransactionsParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.serialize_entry("transactions", &self.transactions)?; + map.serialize_entry("simulation_flags", &self.simulation_flags)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for SimulateTransactionsParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = SimulateTransactionsParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_simulateTransactions`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 3 parameters"))?; + let transactions: Vec = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &"expected 3 parameters"))?; + let simulation_flags: Vec = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(3, &"expected 3 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 4, + &"expected 3 parameters", + )); + } + + Ok(SimulateTransactionsParams { + block_id, + transactions, + simulation_flags, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + transactions: Vec, + simulation_flags: Vec, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(SimulateTransactionsParams { + block_id: helper.block_id, + transactions: helper.transactions, + simulation_flags: helper.simulation_flags, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_traceBlockTransactions` method. +#[derive(Debug, Clone)] +pub struct TraceBlockTransactionsParams { + /// The hash of the requested block, or number (height) of the requested block, or a block tag + pub block_id: BlockId, +} + +impl Serialize for TraceBlockTransactionsParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("block_id", &self.block_id)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for TraceBlockTransactionsParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = TraceBlockTransactionsParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_traceBlockTransactions`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let block_id: BlockId = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(TraceBlockTransactionsParams { block_id }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + block_id: BlockId, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(TraceBlockTransactionsParams { + block_id: helper.block_id, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.toml b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.toml new file mode 100644 index 0000000..07a0164 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_trace_api_openrpc.toml @@ -0,0 +1,50 @@ +debug-path = false +run-rustfmt = true + +[generation] +additional-imports = [ + "super::{Felt, FunctionCall, Event, MsgToL1, BlockId, FeeEstimate, BroadcastedTxn, StateDiff, TxnHash}", + "alloc::vec::Vec", + "alloc::string::String", +] +method-name-prefix = "starknet_" +param-types = true +use-core = true + +[formatters] +num-as-hex = "NumAsHex" + +[fixes] +strip-enum-variants = true + +[fixes.replace] +"#/components/schemas/FELT" = "Felt" +"#/components/schemas/FUNCTION_CALL" = "FunctionCall" +"#/components/schemas/EVENT" = "Event" +"#/components/schemas/MSG_TO_L1" = "MsgToL1" +"#/components/schemas/BLOCK_ID" = "BlockId" +"#/components/schemas/FEE_ESTIMATE" = "FeeEstimate" +"#/components/schemas/BROADCASTED_TXN" = "BroadcastedTxn" +"#/components/schemas/STATE_DIFF" = "StateDiff" +"./starknet_api_openrpc.json#/components/schemas/TXN_HASH" = "TxnHash" + +[fixes.rename] +"#/components/schemas/CALL_TYPE/CALL" = "Regular" +"#/components/schemas/TRANSACTION_TRACE/variant0" = "Invoke" +"#/components/schemas/TRANSACTION_TRACE/variant0/_anon" = "InvokeTransactionTrace" +"#/components/schemas/TRANSACTION_TRACE/variant1" = "Declare" +"#/components/schemas/TRANSACTION_TRACE/variant1/_anon" = "DeclareTransactionTrace" +"#/components/schemas/TRANSACTION_TRACE/variant2" = "DeployAccount" +"#/components/schemas/TRANSACTION_TRACE/variant2/_anon" = "DeployAccountTransactionTrace" +"#/components/schemas/TRANSACTION_TRACE/variant3" = "L1Handler" +"#/components/schemas/TRANSACTION_TRACE/variant3/_anon" = "L1HandlerTransactionTrace" +"#/components/schemas/TRANSACTION_TRACE/variant0/_anon/execute_invocation/_anon/variant1/_anon" = "RevertedInvocation" +"#/components/schemas/TRANSACTION_TRACE/variant0/_anon/execute_invocation/_anon" = "ExecuteInvocation" +"#/methods/starknet_simulateTransactions/result/_anon/_anon" = "SimulateTransactionsResult" +"#/methods/starknet_traceBlockTransactions/result/_anon/_anon" = "TraceBlockTransactionsResult" + +[fixes.tagged-enums] +"#/components/schemas/TRANSACTION_TRACE" = "type" + +[primitives] +integer = "u64" \ No newline at end of file diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.json b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.json new file mode 100644 index 0000000..545725c --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.json @@ -0,0 +1,298 @@ +{ + "openrpc": "1.0.0-rc1", + "info": { + "version": "0.5.0", + "title": "StarkNet Node Write API", + "license": {} + }, + "servers": [], + "methods": [ + { + "name": "starknet_addInvokeTransaction", + "summary": "Submit a new transaction to be added to the chain", + "params": [ + { + "name": "invoke_transaction", + "description": "The information needed to invoke the function (or account, for version 1 transactions)", + "required": true, + "schema": { + "$ref": "#/components/schemas/BROADCASTED_INVOKE_TXN" + } + } + ], + "result": { + "name": "result", + "description": "The result of the transaction submission", + "schema": { + "type": "object", + "properties": { + "transaction_hash": { + "title": "The hash of the invoke transaction", + "$ref": "#/components/schemas/TXN_HASH" + } + }, + "required": [ + "transaction_hash" + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/INSUFFICIENT_ACCOUNT_BALANCE" + }, + { + "$ref": "#/components/errors/INSUFFICIENT_MAX_FEE" + }, + { + "$ref": "#/components/errors/INVALID_TRANSACTION_NONCE" + }, + { + "$ref": "#/components/errors/VALIDATION_FAILURE" + }, + { + "$ref": "#/components/errors/NON_ACCOUNT" + }, + { + "$ref": "#/components/errors/DUPLICATE_TX" + }, + { + "$ref": "#/components/errors/UNSUPPORTED_TX_VERSION" + }, + { + "$ref": "#/components/errors/UNEXPECTED_ERROR" + } + ] + }, + { + "name": "starknet_addDeclareTransaction", + "summary": "Submit a new class declaration transaction", + "params": [ + { + "name": "declare_transaction", + "description": "Declare transaction required to declare a new class on Starknet", + "required": true, + "schema": { + "title": "Declare transaction", + "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN" + } + } + ], + "result": { + "name": "result", + "description": "The result of the transaction submission", + "schema": { + "type": "object", + "properties": { + "transaction_hash": { + "title": "The hash of the declare transaction", + "$ref": "#/components/schemas/TXN_HASH" + }, + "class_hash": { + "title": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "transaction_hash", + "class_hash" + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/CLASS_ALREADY_DECLARED" + }, + { + "$ref": "#/components/errors/COMPILATION_FAILED" + }, + { + "$ref": "#/components/errors/COMPILED_CLASS_HASH_MISMATCH" + }, + { + "$ref": "#/components/errors/INSUFFICIENT_ACCOUNT_BALANCE" + }, + { + "$ref": "#/components/errors/INSUFFICIENT_MAX_FEE" + }, + { + "$ref": "#/components/errors/INVALID_TRANSACTION_NONCE" + }, + { + "$ref": "#/components/errors/VALIDATION_FAILURE" + }, + { + "$ref": "#/components/errors/NON_ACCOUNT" + }, + { + "$ref": "#/components/errors/DUPLICATE_TX" + }, + { + "$ref": "#/components/errors/CONTRACT_CLASS_SIZE_IS_TOO_LARGE" + }, + { + "$ref": "#/components/errors/UNSUPPORTED_TX_VERSION" + }, + { + "$ref": "#/components/errors/UNSUPPORTED_CONTRACT_CLASS_VERSION" + }, + { + "$ref": "#/components/errors/UNEXPECTED_ERROR" + } + ] + }, + { + "name": "starknet_addDeployAccountTransaction", + "summary": "Submit a new deploy account transaction", + "params": [ + { + "name": "deploy_account_transaction", + "description": "The deploy account transaction", + "required": true, + "schema": { + "$ref": "#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" + } + } + ], + "result": { + "name": "result", + "description": "The result of the transaction submission", + "schema": { + "type": "object", + "properties": { + "transaction_hash": { + "title": "The hash of the deploy transaction", + "$ref": "#/components/schemas/TXN_HASH" + }, + "contract_address": { + "title": "The address of the new contract", + "$ref": "#/components/schemas/FELT" + } + }, + "required": [ + "transaction_hash", + "contract_address" + ] + } + }, + "errors": [ + { + "$ref": "#/components/errors/INSUFFICIENT_ACCOUNT_BALANCE" + }, + { + "$ref": "#/components/errors/INSUFFICIENT_MAX_FEE" + }, + { + "$ref": "#/components/errors/INVALID_TRANSACTION_NONCE" + }, + { + "$ref": "#/components/errors/VALIDATION_FAILURE" + }, + { + "$ref": "#/components/errors/NON_ACCOUNT" + }, + { + "$ref": "#/components/errors/CLASS_HASH_NOT_FOUND" + }, + { + "$ref": "#/components/errors/DUPLICATE_TX" + }, + { + "$ref": "#/components/errors/UNSUPPORTED_TX_VERSION" + }, + { + "$ref": "#/components/errors/UNEXPECTED_ERROR" + } + ] + } + ], + "components": { + "contentDescriptors": {}, + "schemas": { + "NUM_AS_HEX": { + "title": "An integer number in hex format (0x...)", + "type": "string", + "pattern": "^0x[a-fA-F0-9]+$" + }, + "SIGNATURE": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/SIGNATURE" + }, + "FELT": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/FELT" + }, + "TXN_HASH": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/TXN_HASH" + }, + "BROADCASTED_INVOKE_TXN": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_INVOKE_TXN" + }, + "DECLARE_TXN": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/DECLARE_TXN" + }, + "BROADCASTED_DEPLOY_ACCOUNT_TXN": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" + }, + "FUNCTION_CALL": { + "$ref": "./starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL" + } + }, + "errors": { + "CLASS_HASH_NOT_FOUND": { + "code": 28, + "message": "Class hash not found" + }, + "CLASS_ALREADY_DECLARED": { + "code": 51, + "message": "Class already declared" + }, + "INVALID_TRANSACTION_NONCE": { + "code": 52, + "message": "Invalid transaction nonce" + }, + "INSUFFICIENT_MAX_FEE": { + "code": 53, + "message": "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)" + }, + "INSUFFICIENT_ACCOUNT_BALANCE": { + "code": 54, + "message": "Account balance is smaller than the transaction's max_fee" + }, + "VALIDATION_FAILURE": { + "code": 55, + "message": "Account validation failed" + }, + "COMPILATION_FAILED": { + "code": 56, + "message": "Compilation failed" + }, + "CONTRACT_CLASS_SIZE_IS_TOO_LARGE": { + "code": 57, + "message": "Contract class size it too large" + }, + "NON_ACCOUNT": { + "code": 58, + "message": "Sender address in not an account contract" + }, + "DUPLICATE_TX": { + "code": 59, + "message": "A transaction with the same hash already exists in the mempool" + }, + "COMPILED_CLASS_HASH_MISMATCH": { + "code": 60, + "message": "the compiled class hash did not match the one supplied in the transaction" + }, + "UNSUPPORTED_TX_VERSION": { + "code": 61, + "message": "the transaction version is not supported" + }, + "UNSUPPORTED_CONTRACT_CLASS_VERSION": { + "code": 62, + "message": "the contract class version is not supported" + }, + "UNEXPECTED_ERROR": { + "code": 63, + "message": "An unexpected error occurred", + "data": "string" + } + } + } +} diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.rs b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.rs new file mode 100644 index 0000000..0065288 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.rs @@ -0,0 +1,268 @@ +// +// This file was automatically generated by openrpc-gen. +// +// Do not edit it manually and instead edit either the source OpenRPC document, +// the configuration file, or open an issue or pull request on the openrpc-gen +// GitHub repository. +// +// https://github.com/nils-mathieu/openrpc-gen +// + +use super::{ + BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn, Felt, TxnHash, +}; +use serde::ser::SerializeMap; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClassAndTxnHash { + pub class_hash: Felt, + pub transaction_hash: TxnHash, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ContractAndTxnHash { + pub contract_address: Felt, + pub transaction_hash: TxnHash, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AddInvokeTransactionResult { + pub transaction_hash: TxnHash, +} + +/// Parameters of the `starknet_addInvokeTransaction` method. +#[derive(Debug, Clone)] +pub struct AddInvokeTransactionParams { + /// The information needed to invoke the function (or account, for version 1 transactions) + pub invoke_transaction: BroadcastedInvokeTxn, +} + +impl Serialize for AddInvokeTransactionParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("invoke_transaction", &self.invoke_transaction)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for AddInvokeTransactionParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = AddInvokeTransactionParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_addInvokeTransaction`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let invoke_transaction: BroadcastedInvokeTxn = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(AddInvokeTransactionParams { invoke_transaction }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + invoke_transaction: BroadcastedInvokeTxn, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(AddInvokeTransactionParams { + invoke_transaction: helper.invoke_transaction, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_addDeclareTransaction` method. +#[derive(Debug, Clone)] +pub struct AddDeclareTransactionParams { + /// Declare transaction required to declare a new class on Starknet + pub declare_transaction: BroadcastedDeclareTxn, +} + +impl Serialize for AddDeclareTransactionParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry("declare_transaction", &self.declare_transaction)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for AddDeclareTransactionParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = AddDeclareTransactionParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "the parameters for `starknet_addDeclareTransaction`") + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let declare_transaction: BroadcastedDeclareTxn = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &"expected 1 parameters"))?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(AddDeclareTransactionParams { + declare_transaction, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + declare_transaction: BroadcastedDeclareTxn, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(AddDeclareTransactionParams { + declare_transaction: helper.declare_transaction, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} + +/// Parameters of the `starknet_addDeployAccountTransaction` method. +#[derive(Debug, Clone)] +pub struct AddDeployAccountTransactionParams { + /// The deploy account transaction + pub deploy_account_transaction: BroadcastedDeployAccountTxn, +} + +impl Serialize for AddDeployAccountTransactionParams { + #[allow(unused_mut)] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let mut map = serializer.serialize_map(None)?; + map.serialize_entry( + "deploy_account_transaction", + &self.deploy_account_transaction, + )?; + map.end() + } +} + +impl<'de> Deserialize<'de> for AddDeployAccountTransactionParams { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = AddDeployAccountTransactionParams; + + fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!( + f, + "the parameters for `starknet_addDeployAccountTransaction`" + ) + } + + #[allow(unused_mut)] + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let deploy_account_transaction: BroadcastedDeployAccountTxn = + seq.next_element()?.ok_or_else(|| { + serde::de::Error::invalid_length(1, &"expected 1 parameters") + })?; + + if seq.next_element::()?.is_some() { + return Err(serde::de::Error::invalid_length( + 2, + &"expected 1 parameters", + )); + } + + Ok(AddDeployAccountTransactionParams { + deploy_account_transaction, + }) + } + + #[allow(unused_variables)] + fn visit_map(self, map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + #[derive(Deserialize)] + struct Helper { + deploy_account_transaction: BroadcastedDeployAccountTxn, + } + + let helper = + Helper::deserialize(serde::de::value::MapAccessDeserializer::new(map))?; + + Ok(AddDeployAccountTransactionParams { + deploy_account_transaction: helper.deploy_account_transaction, + }) + } + } + + deserializer.deserialize_any(Visitor) + } +} diff --git a/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.toml b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.toml new file mode 100644 index 0000000..f452d94 --- /dev/null +++ b/crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.toml @@ -0,0 +1,35 @@ +debug-path = false +run-rustfmt = true + +[generation] +additional-imports = [ + "super::{BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn, Felt, TxnHash}", +] +method-name-prefix = "starknet_" +param-types = true +use-core = true +result-types = false + +[formatters] +num-as-hex = "NumAsHex" + +[fixes] +strip-enum-variants = true + +[fixes.replace] +"#/components/schemas/BROADCASTED_DECLARE_TXN" = "BroadcastedDeclareTxn" +"#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" = "BroadcastedDeployAccountTxn" +"#/components/schemas/BROADCASTED_INVOKE_TXN" = "BroadcastedInvokeTxn" +"#/components/schemas/DECLARE_TXN" = "DeclareTxn" +"#/components/schemas/FELT" = "Felt" +"#/components/schemas/FUNCTION_CALL" = "FunctionCall" +"#/components/schemas/SIGNATURE" = "Signature" +"#/components/schemas/TXN_HASH" = "TxnHash" + +[fixes.rename] +"#/methods/starknet_addDeclareTransaction/result/_anon" = "ClassAndTxnHash" +"#/methods/starknet_addDeployAccountTransaction/result/_anon" = "ContractAndTxnHash" +"#/methods/starknet_addInvokeTransaction/result/_anon" = "AddInvokeTransactionResult" + +[primitives] +integer = "u64"