diff --git a/starknet_devnet/blueprints/rpc/call.py b/starknet_devnet/blueprints/rpc/call.py index c277c64b5..e40af9ee4 100644 --- a/starknet_devnet/blueprints/rpc/call.py +++ b/starknet_devnet/blueprints/rpc/call.py @@ -54,14 +54,14 @@ async def call(request: RpcFunctionCall, block_id: BlockId) -> List[Felt]: return [rpc_felt(res) for res in result["result"]] except StarkException as ex: if ex.code.name == "TRANSACTION_FAILED" and ex.code.value == 39: - raise RpcError.from_spec_name("INVALID_CALL_DATA") from ex + raise RpcError.from_spec_name("CONTRACT_ERROR") from ex if ( f"Entry point {gateway_felt(request['entry_point_selector'])} not found" in ex.message ): - raise RpcError.from_spec_name("INVALID_MESSAGE_SELECTOR") from ex + raise RpcError.from_spec_name("CONTRACT_ERROR") from ex if "While handling calldata" in ex.message: - raise RpcError.from_spec_name("INVALID_CALL_DATA") from ex + raise RpcError.from_spec_name("CONTRACT_ERROR") from ex raise RpcError( code=PredefinedRpcErrorCode.INTERNAL_ERROR.value, message=ex.message ) from ex diff --git a/starknet_devnet/blueprints/rpc/misc.py b/starknet_devnet/blueprints/rpc/misc.py index 75e70cfd9..3cc0936cb 100644 --- a/starknet_devnet/blueprints/rpc/misc.py +++ b/starknet_devnet/blueprints/rpc/misc.py @@ -37,8 +37,10 @@ def check_address(address, event): """ Check address. + + If no address is set in the filter, it returns True. """ - return event.from_address == int(address, 0) + return address is None or event.from_address == int(address, 0) def _check_keys(keys: List[List[Felt]], event): @@ -135,8 +137,10 @@ async def get_events( and chunk it later which is not an optimal solution. """ # Required parameters - from_block = await get_block_by_block_id(filter.get("from_block")) - to_block = await get_block_by_block_id(filter.get("to_block")) + from_block = await get_block_by_block_id( + filter.get("from_block", {"block_number": 0}) + ) + to_block = await get_block_by_block_id(filter.get("to_block", "latest")) block_range = await _get_events_range(from_block, to_block) try: diff --git a/starknet_devnet/blueprints/rpc/rpc_spec.py b/starknet_devnet/blueprints/rpc/rpc_spec.py index ce9acd110..5d61f637d 100644 --- a/starknet_devnet/blueprints/rpc/rpc_spec.py +++ b/starknet_devnet/blueprints/rpc/rpc_spec.py @@ -1,6 +1,7 @@ # pylint: disable=too-many-lines, missing-module-docstring -# NOTE: This is modified version of 0.3.0-rc1 spec +# NOTE: This is modified version of 0.3.0 spec # All usages of "oneOf" have been replaced by "anyOf" +# and the required field from STRUCT_MEMBER was removed. RPC_SPECIFICATION = r""" { "openrpc": "1.0.0-rc1", @@ -20,6 +21,7 @@ "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" } } @@ -28,11 +30,14 @@ "name": "result", "description": "The resulting block information with transaction hashes", "schema": { + "title": "Starknet get block hash with tx hashes result", "anyOf": [ { + "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" } ] @@ -53,6 +58,7 @@ "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" } } @@ -61,11 +67,14 @@ "name": "result", "description": "The resulting block information with full transactions", "schema": { + "title": "Starknet get block with txs result", "anyOf": [ { + "title": "Block with transactions", "$ref": "#/components/schemas/BLOCK_WITH_TXS" }, { + "title": "Pending block with transactions", "$ref": "#/components/schemas/PENDING_BLOCK_WITH_TXS" } ] @@ -86,6 +95,7 @@ "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" } } @@ -94,11 +104,14 @@ "name": "result", "description": "The information about the state update of the requested block", "schema": { + "title": "Starknet get state update result", "anyOf": [ { + "title": "State update", "$ref": "#/components/schemas/STATE_UPDATE" }, { + "title": "Pending state update", "$ref": "#/components/schemas/PENDING_STATE_UPDATE" } ] @@ -120,6 +133,7 @@ "summary": "The address of the contract to read from", "required": true, "schema": { + "title": "Address", "$ref": "#/components/schemas/ADDRESS" } }, @@ -129,6 +143,7 @@ "summary": "The key to the storage value for the given contract", "required": true, "schema": { + "title": "Storage key", "$ref": "#/components/schemas/STORAGE_KEY" } }, @@ -137,6 +152,7 @@ "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" } } @@ -146,6 +162,7 @@ "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" } }, @@ -168,6 +185,7 @@ "summary": "The hash of the requested transaction", "required": true, "schema": { + "title": "Transaction hash", "$ref": "#/components/schemas/TXN_HASH" } } @@ -175,6 +193,7 @@ "result": { "name": "result", "schema": { + "title": "Transaction", "$ref": "#/components/schemas/TXN" } }, @@ -194,6 +213,7 @@ "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" } }, @@ -202,6 +222,7 @@ "summary": "The index in the block to search for the transaction", "required": true, "schema": { + "title": "Index", "type": "integer", "minimum": 0 } @@ -210,6 +231,7 @@ "result": { "name": "transactionResult", "schema": { + "title": "Transaction", "$ref": "#/components/schemas/TXN" } }, @@ -232,6 +254,7 @@ "summary": "The hash of the requested transaction", "required": true, "schema": { + "title": "Transaction hash", "$ref": "#/components/schemas/TXN_HASH" } } @@ -239,6 +262,7 @@ "result": { "name": "result", "schema": { + "title": "Transaction receipt", "$ref": "#/components/schemas/TXN_RECEIPT" } }, @@ -257,6 +281,7 @@ "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" } }, @@ -265,6 +290,7 @@ "description": "The hash of the requested contract class", "required": true, "schema": { + "title": "Field element", "$ref": "#/components/schemas/FELT" } } @@ -273,11 +299,14 @@ "name": "result", "description": "The contract class, if found", "schema": { + "title": "Starknet get class result", "anyOf": [ { + "title": "Deprecated contract class", "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" }, { + "title": "Contract class", "$ref": "#/components/schemas/CONTRACT_CLASS" } ] @@ -301,6 +330,7 @@ "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" } }, @@ -309,6 +339,7 @@ "description": "The address of the contract whose class hash will be returned", "required": true, "schema": { + "title": "Address", "$ref": "#/components/schemas/ADDRESS" } } @@ -317,6 +348,7 @@ "name": "result", "description": "The class hash of the given contract", "schema": { + "title": "Field element", "$ref": "#/components/schemas/FELT" } }, @@ -338,6 +370,7 @@ "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" } }, @@ -346,6 +379,7 @@ "description": "The address of the contract whose class definition will be returned", "required": true, "schema": { + "title": "Address", "$ref": "#/components/schemas/ADDRESS" } } @@ -354,11 +388,14 @@ "name": "result", "description": "The contract class", "schema": { + "title": "Starknet get class at result", "anyOf": [ { + "title": "Deprecated contract class", "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" }, { + "title": "Contract class", "$ref": "#/components/schemas/CONTRACT_CLASS" } ] @@ -383,6 +420,7 @@ "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" } } @@ -392,6 +430,7 @@ "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 } @@ -411,6 +450,7 @@ "name": "request", "summary": "The details of the function call", "schema": { + "title": "Function call", "$ref": "#/components/schemas/FUNCTION_CALL" }, "required": true @@ -420,6 +460,7 @@ "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" } } @@ -430,6 +471,7 @@ "description": "The function's return value, as defined in the Cairo output", "schema": { "type": "array", + "title": "Field element", "items": { "$ref": "#/components/schemas/FELT" } @@ -439,12 +481,6 @@ { "$ref": "#/components/errors/CONTRACT_NOT_FOUND" }, - { - "$ref": "#/components/errors/INVALID_MESSAGE_SELECTOR" - }, - { - "$ref": "#/components/errors/INVALID_CALL_DATA" - }, { "$ref": "#/components/errors/CONTRACT_ERROR" }, @@ -464,6 +500,7 @@ "schema": { "type": "array", "description": "a sequence of transactions to estimate, running each transaction on the state resulting from applying all the previous ones", + "title": "Broadcasted transaction", "items": { "$ref": "#/components/schemas/BROADCASTED_TXN" } @@ -475,6 +512,7 @@ "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" } } @@ -483,6 +521,7 @@ "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": { @@ -494,12 +533,6 @@ { "$ref": "#/components/errors/CONTRACT_NOT_FOUND" }, - { - "$ref": "#/components/errors/INVALID_MESSAGE_SELECTOR" - }, - { - "$ref": "#/components/errors/INVALID_CALL_DATA" - }, { "$ref": "#/components/errors/CONTRACT_ERROR" }, @@ -516,6 +549,7 @@ "name": "result", "description": "The latest block number", "schema": { + "title": "Block number", "$ref": "#/components/schemas/BLOCK_NUMBER" } }, @@ -533,15 +567,22 @@ "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": [ @@ -558,6 +599,7 @@ "name": "result", "description": "The chain id this node is connected to", "schema": { + "title": "Chain id", "$ref": "#/components/schemas/CHAIN_ID" } } @@ -586,12 +628,15 @@ "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", "anyOf": [ { "type": "boolean", + "title": "False", "description": "only legal value is FALSE here" }, { + "title": "Sync status", "$ref": "#/components/schemas/SYNC_STATUS" } ] @@ -608,11 +653,14 @@ "summary": "The conditions used to filter the returned events", "required": true, "schema": { + "title": "Event emitter", "allOf": [ { + "title": "Event filter", "$ref": "#/components/schemas/EVENT_FILTER" }, { + "title": "Result page request", "$ref": "#/components/schemas/RESULT_PAGE_REQUEST" } ] @@ -623,6 +671,7 @@ "name": "events", "description": "All the event objects matching the filter", "schema": { + "title": "Events chunk", "$ref": "#/components/schemas/EVENTS_CHUNK" } }, @@ -650,6 +699,7 @@ "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" } }, @@ -658,6 +708,7 @@ "description": "The address of the contract whose nonce we're seeking", "required": true, "schema": { + "title": "Address", "$ref": "#/components/schemas/ADDRESS" } } @@ -666,6 +717,7 @@ "name": "result", "description": "The last nonce used for the given contract.", "schema": { + "title": "Field element", "$ref": "#/components/schemas/FELT" } }, @@ -683,6 +735,7 @@ "contentDescriptors": {}, "schemas": { "EVENTS_CHUNK": { + "title": "Events chunk", "type": "object", "properties": { "events": { @@ -693,6 +746,7 @@ } }, "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" } @@ -702,13 +756,16 @@ ] }, "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 } @@ -718,27 +775,32 @@ ] }, "EMITTED_EVENT": { - "title": "An event emitted as a result of transaction execution", - "description": "Event information decorated with metadata on where it was emitted", + "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": "The event information", + "title": "Event", + "description": "The event information", "$ref": "#/components/schemas/EVENT" }, { - "title": "The event emission information", + "title": "Event context", + "description": "The event emission information", "type": "object", "properties": { "block_hash": { - "title": "The hash of the block in which the event was emitted", + "title": "Block hash", + "description": "The hash of the block in which the event was emitted", "$ref": "#/components/schemas/BLOCK_HASH" }, "block_number": { - "title": "The number of the block in which the event was emitted", + "title": "Block number", + "description": "The number of the block in which the event was emitted", "$ref": "#/components/schemas/BLOCK_NUMBER" }, "transaction_hash": { - "title": "The transaction that emitted the event", + "title": "Transaction hash", + "description": "The transaction that emitted the event", "$ref": "#/components/schemas/TXN_HASH" } }, @@ -751,12 +813,15 @@ ] }, "EVENT": { - "title": "A StarkNet event", + "title": "Event", + "description": "A StarkNet event", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "from_address": { + "title": "From address", "$ref": "#/components/schemas/ADDRESS" } }, @@ -765,23 +830,26 @@ ] }, { + "title": "Event content", "$ref": "#/components/schemas/EVENT_CONTENT" } ] }, "EVENT_CONTENT": { - "title": "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" } @@ -793,7 +861,8 @@ ] }, "EVENT_FILTER": { - "title": "An event filter/query", + "title": "Event filter", + "description": "An event filter/query", "type": "object", "properties": { "from_block": { @@ -809,11 +878,11 @@ "$ref": "#/components/schemas/ADDRESS" }, "keys": { - "title": "filter key values", + "title": "Keys", "description": "The values used to filter the events", "type": "array", "items": { - "title": "Possible values, per key", + "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": { @@ -822,20 +891,18 @@ } } }, - "required": [ - "from_block", - "to_block", - "address", - "keys" - ] + "required": [] }, "BLOCK_ID": { - "title": "Block hash, number or tag", + "title": "Block id", + "description": "Block hash, number or tag", "anyOf": [ { + "title": "Block hash", "type": "object", "properties": { "block_hash": { + "title": "Block hash", "$ref": "#/components/schemas/BLOCK_HASH" } }, @@ -844,9 +911,11 @@ ] }, { + "title": "Block number", "type": "object", "properties": { "block_number": { + "title": "Block number", "$ref": "#/components/schemas/BLOCK_NUMBER" } }, @@ -855,11 +924,13 @@ ] }, { + "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": [ @@ -868,30 +939,37 @@ ] }, "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/NUM_AS_HEX" }, "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/NUM_AS_HEX" }, "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/NUM_AS_HEX" } @@ -906,26 +984,31 @@ ] }, "NUM_AS_HEX": { - "title": "An integer number in hex format (0x...)", + "title": "Number as hex", + "description": "An integer number in hex format (0x...)", "type": "string", "pattern": "^0x[a-fA-F0-9]+$" }, "CHAIN_ID": { - "title": "chainId", + "title": "Chain id", "description": "StarkNet chain id, given in hex representation.", "type": "string", "pattern": "^0x[a-fA-F0-9]+$" }, "STATE_UPDATE": { + "title": "State update", "type": "object", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "block_hash": { + "title": "Block hash", "$ref": "#/components/schemas/BLOCK_HASH" }, "new_root": { + "title": "New root", "description": "The new global state root", "$ref": "#/components/schemas/FELT" } @@ -936,22 +1019,28 @@ ] }, { + "title": "Pending state update", "$ref": "#/components/schemas/PENDING_STATE_UPDATE" } ] }, "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", "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", @@ -959,6 +1048,7 @@ } }, "deprecated_declared_classes": { + "title": "Deprecated declared classes", "type": "array", "items": { "description": "The hash of the declared class", @@ -966,16 +1056,20 @@ } }, "declared_classes": { + "title": "Declared classes", "type": "array", "items": { - "description": "The declared class hash and compiled class hash", + "title": "Event emitter", "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" } @@ -983,6 +1077,7 @@ } }, "deployed_contracts": { + "title": "Deployed contracts", "type": "array", "items": { "description": "A new contract deployed as part of the state update", @@ -990,16 +1085,20 @@ } }, "replaced_classes": { + "title": "Replaced classes", "type": "array", "items": { "description": "The list of contracts whose class was replaced", + "title": "Event emitter", "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" } @@ -1007,16 +1106,20 @@ } }, "nonces": { + "title": "Nonces", "type": "array", "items": { + "title": "Event emitter", "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" } @@ -1040,16 +1143,18 @@ ] }, "ADDRESS": { + "title": "Address", "$ref": "#/components/schemas/FELT" }, "STORAGE_KEY": { "type": "string", - "title": "A storage key", + "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", @@ -1058,7 +1163,7 @@ "TXN_HASH": { "$ref": "#/components/schemas/FELT", "description": "The transaction hash, as assigned in StarkNet", - "title": "A transaction's hash" + "title": "Transaction hash" }, "FELT": { "type": "string", @@ -1067,17 +1172,21 @@ "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", "description": "The hashes of the transactions included in this block", "type": "array", "items": { @@ -1091,9 +1200,11 @@ ] }, "BLOCK_BODY_WITH_TXS": { + "title": "Block body with transactions", "type": "object", "properties": { "transactions": { + "title": "Transactions", "description": "The transactions in this block", "type": "array", "items": { @@ -1106,29 +1217,36 @@ ] }, "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" } @@ -1143,12 +1261,15 @@ ] }, "BLOCK_WITH_TX_HASHES": { - "title": "The block object", + "title": "Block with transaction hashes", + "description": "The block object", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "status": { + "title": "Status", "$ref": "#/components/schemas/BLOCK_STATUS" } }, @@ -1157,20 +1278,25 @@ ] }, { + "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": "The block object", + "title": "Block with transactions", + "description": "The block object", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "status": { + "title": "Status", "$ref": "#/components/schemas/BLOCK_STATUS" } }, @@ -1179,32 +1305,40 @@ ] }, { + "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": "Event emitter", "type": "object", "properties": { "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" }, "parent_hash": { + "title": "Parent hash", "description": "The hash of this block's parent", "$ref": "#/components/schemas/BLOCK_HASH" } @@ -1213,24 +1347,30 @@ ] }, "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" }, { "type": "object", + "title": "Event emitter", "properties": { "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" }, "parent_hash": { + "title": "Parent hash", "description": "The hash of this block's parent", "$ref": "#/components/schemas/BLOCK_HASH" } @@ -1239,13 +1379,16 @@ ] }, "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" } @@ -1256,23 +1399,29 @@ ] }, "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": "Event emitter", "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" } @@ -1290,60 +1439,74 @@ "description": "The transaction schema, as it appears inside a block", "anyOf": [ { + "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" } ] }, "BROADCASTED_TXN": { + "title": "Broadcasted transaction", "description": "the transaction's representation when it's sent to the sequencer (but not yet in a block)", - "title": "Transaction", "anyOf": [ { + "title": "Broadcasted invoke transaction", "$ref": "#/components/schemas/BROADCASTED_INVOKE_TXN" }, { + "title": "Broadcasted declare transaction", "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN" }, { + "title": "Broadcasted deploy account transaction", "$ref": "#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN" } ] }, "SIGNATURE": { - "title": "A transaction signature", + "title": "Signature", + "description": "A transaction signature", "type": "array", "items": { "$ref": "#/components/schemas/FELT" } }, "BROADCASTED_TXN_COMMON_PROPERTIES": { + "title": "Broadcasted transaction common properties", "type": "object", "description": "common properties of a transaction that is sent to the sequencer (but is not yet in a block)", "properties": { "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", "$ref": "#/components/schemas/NUM_AS_HEX" }, "signature": { + "title": "Signature", "$ref": "#/components/schemas/SIGNATURE" }, "nonce": { + "title": "Nonce", "$ref": "#/components/schemas/FELT" } }, @@ -1355,11 +1518,14 @@ ] }, "COMMON_TXN_PROPERTIES": { + "title": "Common transaction properties", "allOf": [ { "type": "object", + "title": "Transaction hash", "properties": { "transaction_hash": { + "title": "Transaction hash", "$ref": "#/components/schemas/TXN_HASH", "description": "The hash identifying the transaction" } @@ -1369,40 +1535,50 @@ ] }, { + "title": "Broadcasted transaction common properties", "$ref": "#/components/schemas/BROADCASTED_TXN_COMMON_PROPERTIES" } ] }, "DECLARE_TXN": { + "title": "Declare transaction", "anyOf": [ { + "title": "Declare transaction V1", "$ref": "#/components/schemas/DECLARE_TXN_V1" }, { + "title": "Declare transaction V2", "$ref": "#/components/schemas/DECLARE_TXN_V2" } ] }, "DECLARE_TXN_V1": { - "title": "Declare Contract Transaction", + "title": "Declare Contract Transaction V1", + "description": "Declare Contract Transaction V1", "allOf": [ { + "title": "Common transaction properties", "$ref": "#/components/schemas/COMMON_TXN_PROPERTIES" }, { "type": "object", + "title": "Event emitter", "properties": { "type": { + "title": "Declare", "type": "string", "enum": [ "DECLARE" ] }, "class_hash": { + "title": "Class hash", "description": "The hash of the declared class", "$ref": "#/components/schemas/FELT" }, "sender_address": { + "title": "Sender address", "description": "The address of the account contract sending the declaration transaction", "$ref": "#/components/schemas/ADDRESS" } @@ -1416,46 +1592,68 @@ ] }, "DECLARE_TXN_V2": { - "title": "Declare Contract Transaction", + "title": "Declare Transaction V2", + "description": "Declare Contract Transaction V2", "allOf": [ { + "title": "Declare transaction V1", "$ref": "#/components/schemas/DECLARE_TXN_V1" }, { "type": "object", + "title": "Event emitter", "properties": { "compiled_class_hash": { + "title": "Compiled class hash", "description": "The hash of the Cairo assembly resulting from the Sierra compilation", "$ref": "#/components/schemas/FELT" } - } + }, + "required": [ + "compiled_class_hash" + ] } ] }, "BROADCASTED_DECLARE_TXN": { + "title": "Broadcasted declare transaction", "anyOf": [ { + "title": "Broadcasted declare transaction V1", "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN_V1" }, { + "title": "Broadcasted declare transaction V2", "$ref": "#/components/schemas/BROADCASTED_DECLARE_TXN_V2" } ] }, "BROADCASTED_DECLARE_TXN_V1": { - "title": "mempool representation of a declare transaction", + "title": "Broadcasted declare transaction V1", + "description": "mempool representation of a declare transaction", "allOf": [ { + "title": "Broadcasted transaction common properties", "$ref": "#/components/schemas/BROADCASTED_TXN_COMMON_PROPERTIES" }, { "type": "object", + "title": "Declare v1", "properties": { + "type": { + "title": "Declare", + "type": "string", + "enum": [ + "DECLARE" + ] + }, "contract_class": { + "title": "Contract class", "description": "The class to be declared", "$ref": "#/components/schemas/DEPRECATED_CONTRACT_CLASS" }, "sender_address": { + "title": "Sender address", "description": "The address of the account contract sending the declaration transaction", "$ref": "#/components/schemas/ADDRESS" } @@ -1464,29 +1662,36 @@ ] }, "BROADCASTED_DECLARE_TXN_V2": { - "title": "mempool representation of a declare transaction", + "title": "Broadcasted declare transaction V2", + "description": "mempool representation of a declare transaction V2", "allOf": [ { + "title": "Broadcasted transaction common properties", "$ref": "#/components/schemas/BROADCASTED_TXN_COMMON_PROPERTIES" }, { "type": "object", + "title": "Event emitter", "properties": { "type": { + "title": "Declare", "type": "string", "enum": [ "DECLARE" ] }, "contract_class": { + "title": "Contract class", "description": "The class to be declared", "$ref": "#/components/schemas/CONTRACT_CLASS" }, "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" } @@ -1494,55 +1699,66 @@ "required": [ "type", "contract_class", - "sender_address" + "sender_address", + "compiled_class_hash" ] } ] }, "DEPLOY_ACCOUNT_TXN": { - "title": "Deploy Account Transaction", + "title": "Deploy account transaction", "description": "Deploys an account contract, charges fee from the pre-funded account addresses", "allOf": [ { + "title": "Common transaction properties", "$ref": "#/components/schemas/COMMON_TXN_PROPERTIES" }, { + "title": "Deploy account transaction properties", "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN_PROPERTIES" } ] }, "BROADCASTED_DEPLOY_ACCOUNT_TXN": { + "title": "Broadcasted deploy account transaction", "description": "Mempool representation of a deploy account transaction", "allOf": [ { + "title": "Broadcasted transaction common properties", "$ref": "#/components/schemas/BROADCASTED_TXN_COMMON_PROPERTIES" }, { + "title": "Deploy account transaction properties", "$ref": "#/components/schemas/DEPLOY_ACCOUNT_TXN_PROPERTIES" } ] }, "DEPLOY_ACCOUNT_TXN_PROPERTIES": { + "title": "Deploy account transaction properties", "type": "object", "properties": { "type": { + "title": "Deploy account", "type": "string", "enum": [ "DEPLOY_ACCOUNT" ] }, "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" } @@ -1560,12 +1776,15 @@ "allOf": [ { "type": "object", + "title": "Event emitter", "properties": { "transaction_hash": { + "title": "Transaction hash", "$ref": "#/components/schemas/TXN_HASH", "description": "The hash identifying the transaction" }, "class_hash": { + "title": "Class hash", "description": "The hash of the deployed contract's class", "$ref": "#/components/schemas/FELT" } @@ -1576,18 +1795,22 @@ ] }, { + "title": "Deploy transaction properties", "$ref": "#/components/schemas/DEPLOY_TXN_PROPERTIES" } ] }, "DEPLOY_TXN_PROPERTIES": { + "title": "Deploy transaction properties", "type": "object", "properties": { "version": { + "title": "Version", "description": "Version of the transaction scheme", "$ref": "#/components/schemas/NUM_AS_HEX" }, "type": { + "title": "Deploy", "type": "string", "enum": [ "DEPLOY" @@ -1595,10 +1818,12 @@ }, "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" @@ -1613,20 +1838,22 @@ ] }, "INVOKE_TXN_V0": { - "title": "version 0 invoke transaction", + "title": "Invoke transaction V0", "description": "invokes a specific function in the desired contract (not necessarily an account)", "$ref": "#/components/schemas/FUNCTION_CALL" }, "INVOKE_TXN_V1": { - "title": "version 1 invoke transaction", + "title": "Invoke transaction V1", "description": "initiates a transaction from a given account", "type": "object", "properties": { "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" @@ -1639,15 +1866,19 @@ ] }, "INVOKE_TXN": { - "title": "Initiate a transaction from an account", + "title": "Invoke transaction", + "description": "Initiate a transaction from an account", "allOf": [ { + "title": "Common transaction properties", "$ref": "#/components/schemas/COMMON_TXN_PROPERTIES" }, { "type": "object", + "title": "Type", "properties": { "type": { + "title": "Type", "type": "string", "enum": [ "INVOKE" @@ -1659,11 +1890,14 @@ ] }, { + "title": "Invoke transaction properties", "anyOf": [ { + "title": "Invoke transaction V0", "$ref": "#/components/schemas/INVOKE_TXN_V0" }, { + "title": "Invoke transaction V1", "$ref": "#/components/schemas/INVOKE_TXN_V1" } ] @@ -1671,15 +1905,19 @@ ] }, "BROADCASTED_INVOKE_TXN": { + "title": "Broadcasted invoke transaction", "description": "mempool representation of an invoke transaction", "allOf": [ { + "title": "Broadcasted transaction common properties", "$ref": "#/components/schemas/BROADCASTED_TXN_COMMON_PROPERTIES" }, { + "title": "Event emitter", "type": "object", "properties": { "type": { + "title": "Type", "type": "string", "enum": [ "INVOKE" @@ -1691,11 +1929,14 @@ ] }, { + "title": "Invoke transaction properties", "anyOf": [ { + "title": "Invoke transaction V0", "$ref": "#/components/schemas/INVOKE_TXN_V0" }, { + "title": "Invoke transaction V1", "$ref": "#/components/schemas/INVOKE_TXN_V1" } ] @@ -1703,27 +1944,32 @@ ] }, "L1_HANDLER_TXN": { + "title": "L1 Handler transaction", "allOf": [ { "type": "object", - "title": "l1-->l2 message transaction", + "title": "L1 handler transaction", "description": "a call to an l1_handler on an L2 contract induced by a message from L1", "properties": { "transaction_hash": { + "title": "Transaction hash", "$ref": "#/components/schemas/TXN_HASH", "description": "The hash identifying the transaction" }, "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" } @@ -1736,39 +1982,48 @@ ] }, { + "title": "Function call", "$ref": "#/components/schemas/FUNCTION_CALL" } ] }, "COMMON_RECEIPT_PROPERTIES": { - "title": "Common properties for a transaction receipt", + "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/FELT", "description": "The fee that was charged by the sequencer" }, "status": { + "title": "Status", "$ref": "#/components/schemas/TXN_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" } }, "events": { "description": "The events emitted as part of this transaction", + "title": "Events", "type": "array", "items": { "$ref": "#/components/schemas/EVENT" @@ -1789,9 +2044,11 @@ "title": "Invoke Transaction Receipt", "allOf": [ { + "title": "Type", "type": "object", "properties": { "type": { + "title": "Type", "type": "string", "enum": [ "INVOKE" @@ -1803,6 +2060,7 @@ ] }, { + "title": "Common receipt properties", "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" } ] @@ -1811,9 +2069,11 @@ "title": "Declare Transaction Receipt", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "type": { + "title": "Declare", "type": "string", "enum": [ "DECLARE" @@ -1825,6 +2085,7 @@ ] }, { + "title": "Common receipt properties", "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" } ] @@ -1833,18 +2094,22 @@ "title": "Deploy Account Transaction Receipt", "allOf": [ { + "title": "Common receipt properties", "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" }, { + "title": "Event emitter", "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" } @@ -1860,18 +2125,22 @@ "title": "Deploy Transaction Receipt", "allOf": [ { + "title": "Common receipt properties", "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" }, { + "title": "Event emitter", "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" } @@ -1884,12 +2153,15 @@ ] }, "L1_HANDLER_TXN_RECEIPT": { - "title": "receipt for l1 handler transaction", + "title": "L1 Handler Transaction Receipt", + "description": "receipt for l1 handler transaction", "allOf": [ { + "title": "Event emitter", "type": "object", "properties": { "type": { + "title": "type", "type": "string", "enum": [ "L1_HANDLER" @@ -1901,55 +2173,69 @@ ] }, { + "title": "Common receipt properties", "$ref": "#/components/schemas/COMMON_RECEIPT_PROPERTIES" } ] }, "TXN_RECEIPT": { + "title": "Transaction Receipt", "anyOf": [ { + "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" }, { + "title": "Pending transaction receipt", "$ref": "#/components/schemas/PENDING_TXN_RECEIPT" } ] }, "PENDING_COMMON_RECEIPT_PROPERTIES": { - "title": "Common properties for a pending transaction receipt", + "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/FELT", "description": "The fee that was charged by the sequencer" }, "type": { + "title": "Transaction type", "$ref": "#/components/schemas/TXN_TYPE" }, "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" @@ -1959,6 +2245,7 @@ "required": [ "transaction_hash", "actual_fee", + "type", "messages_sent", "events" ] @@ -1967,12 +2254,15 @@ "title": "Pending deploy Transaction Receipt", "allOf": [ { + "title": "Common receipt properties", "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" }, { "type": "object", + "title": "Event emitter", "properties": { "contract_address": { + "title": "Contract address", "description": "The address of the deployed contract", "$ref": "#/components/schemas/FELT" } @@ -1981,25 +2271,35 @@ ] }, "PENDING_TXN_RECEIPT": { + "title": "Pending Transaction Receipt", "anyOf": [ { + "title": "Pending deploy transaction receipt", "$ref": "#/components/schemas/PENDING_DEPLOY_TXN_RECEIPT" }, { + "title": "Pending common receipt properties", "$comment": "Used for pending invoke and declare transaction receipts", "$ref": "#/components/schemas/PENDING_COMMON_RECEIPT_PROPERTIES" } ] }, "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" @@ -2007,11 +2307,13 @@ } }, "required": [ + "from_address", "to_address", "payload" ] }, "TXN_STATUS": { + "title": "Transaction status", "type": "string", "enum": [ "PENDING", @@ -2022,6 +2324,7 @@ "description": "The status of the transaction" }, "TXN_TYPE": { + "title": "Transaction type", "type": "string", "enum": [ "DECLARE", @@ -2033,6 +2336,7 @@ "description": "The type of the transaction" }, "BLOCK_STATUS": { + "title": "Block status", "type": "string", "enum": [ "PENDING", @@ -2043,16 +2347,20 @@ "description": "The status of the block" }, "FUNCTION_CALL": { + "title": "Function call", "type": "object", - "title": "Function call information", + "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": { @@ -2067,9 +2375,11 @@ ] }, "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": { @@ -2077,35 +2387,46 @@ } }, "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", - "descripition": "The class ABI, as supplied by the user declaring the class" + "description": "The class ABI, as supplied by the user declaring the class" } }, "required": [ @@ -2115,31 +2436,37 @@ ] }, "DEPRECATED_CONTRACT_CLASS": { - "title": "The definition of a StarkNet 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" } @@ -2147,6 +2474,7 @@ } }, "abi": { + "title": "Contract ABI", "$ref": "#/components/schemas/CONTRACT_ABI" } }, @@ -2156,63 +2484,85 @@ ] }, "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", "anyOf": [ { + "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", @@ -2221,36 +2571,51 @@ ] }, "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": "Event emitter", "properties": { "offset": { + "title": "Offset", "description": "offset of this property within the struct", "type": "integer" } @@ -2259,82 +2624,131 @@ ] }, "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" + ] } }, "errors": { @@ -2346,14 +2760,6 @@ "code": 20, "message": "Contract not found" }, - "INVALID_MESSAGE_SELECTOR": { - "code": 21, - "message": "Invalid message selector" - }, - "INVALID_CALL_DATA": { - "code": 22, - "message": "Invalid call data" - }, "BLOCK_NOT_FOUND": { "code": 24, "message": "Block not found" diff --git a/starknet_devnet/blueprints/rpc/rpc_spec_write.py b/starknet_devnet/blueprints/rpc/rpc_spec_write.py index 4f33ab554..2b13af18a 100644 --- a/starknet_devnet/blueprints/rpc/rpc_spec_write.py +++ b/starknet_devnet/blueprints/rpc/rpc_spec_write.py @@ -69,6 +69,9 @@ "errors": [ { "$ref": "#/components/errors/INVALID_CONTRACT_CLASS" + }, + { + "$ref": "#/components/errors/CLASS_ALREADY_DECLARED" } ] }, @@ -149,6 +152,10 @@ }, "CLASS_HASH_NOT_FOUND": { "$ref": "./api/starknet_api_openrpc.json#/components/errors/CLASS_HASH_NOT_FOUND" + }, + "CLASS_ALREADY_DECLARED": { + "code": 51, + "message": "Class already declared" } } } diff --git a/starknet_devnet/blueprints/rpc/structures/payloads.py b/starknet_devnet/blueprints/rpc/structures/payloads.py index 42551a759..62a43f187 100644 --- a/starknet_devnet/blueprints/rpc/structures/payloads.py +++ b/starknet_devnet/blueprints/rpc/structures/payloads.py @@ -40,7 +40,7 @@ decompress_program, ) from starkware.starkware_utils.error_handling import StarkException -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal, NotRequired, TypedDict from starknet_devnet.blueprints.rpc.structures.types import ( Address, @@ -585,7 +585,7 @@ class StructMember(TypedDict): name: str type: str - offset: int + offset: Optional[int] class FunctionAbiEntry(TypedDict): @@ -595,6 +595,7 @@ class FunctionAbiEntry(TypedDict): name: str inputs: List[TypedParameter] outputs: List[TypedParameter] + stateMutability: NotRequired[Literal["view"]] class EventAbiEntry(TypedDict): @@ -622,13 +623,18 @@ def function_abi_entry(abi_entry: AbiEntryType) -> FunctionAbiEntry: """ Convert function gateway abi entry to rpc FunctionAbiEntry """ - return FunctionAbiEntry( + rpc_function_abi_entry = FunctionAbiEntry( type=abi_entry["type"], name=abi_entry["name"], inputs=abi_entry["inputs"], outputs=abi_entry["outputs"], ) + if "stateMutability" in abi_entry: + rpc_function_abi_entry["stateMutability"] = abi_entry["stateMutability"] + + return rpc_function_abi_entry + def struct_abi_entry(abi_entry: AbiEntryType) -> StructAbiEntry: """ diff --git a/starknet_devnet/blueprints/rpc/transactions.py b/starknet_devnet/blueprints/rpc/transactions.py index bb70b34ac..a301c766d 100644 --- a/starknet_devnet/blueprints/rpc/transactions.py +++ b/starknet_devnet/blueprints/rpc/transactions.py @@ -127,6 +127,18 @@ async def add_declare_transaction( class_hash, transaction_hash = await state.starknet_wrapper.declare( external_tx=make_declare(declare_transaction) ) + status_response = await state.starknet_wrapper.transactions.get_transaction_status( + hex(transaction_hash) + ) + + if status_response["tx_status"] == "REJECTED": + error_message = status_response["tx_failure_reason"].error_message + if ( + "Class with hash" in error_message + and "is already declared" in error_message + ): + raise RpcError.from_spec_name("CLASS_ALREADY_DECLARED") + return RpcDeclareTransactionResult( transaction_hash=rpc_felt(transaction_hash), class_hash=rpc_felt(class_hash), @@ -193,9 +205,9 @@ async def estimate_fee(request: List[RpcBroadcastedTxn], block_id: BlockId) -> l ) except StarkException as ex: if "Entry point" in ex.message and "not found" in ex.message: - raise RpcError.from_spec_name("INVALID_MESSAGE_SELECTOR") from ex + raise RpcError.from_spec_name("CONTRACT_ERROR") from ex if "While handling calldata" in ex.message: - raise RpcError.from_spec_name("INVALID_CALL_DATA") from ex + raise RpcError.from_spec_name("CONTRACT_ERROR") from ex if "is not deployed" in ex.message: raise RpcError.from_spec_name("CONTRACT_NOT_FOUND") from ex raise RpcError(code=-1, message=ex.message) from ex diff --git a/test/rpc/test_rpc_call.py b/test/rpc/test_rpc_call.py index fa9b291d2..b3fa9af3b 100644 --- a/test/rpc/test_rpc_call.py +++ b/test/rpc/test_rpc_call.py @@ -98,7 +98,7 @@ def test_call_raises_on_incorrect_selector(deploy_info): }, ) - assert ex["error"] == {"code": 21, "message": "Invalid message selector"} + assert ex["error"] == {"code": 40, "message": "Contract error"} @pytest.mark.usefixtures("run_devnet_in_background") diff --git a/test/rpc/test_rpc_class.py b/test/rpc/test_rpc_class.py index 3f0ea9c26..1534ba7df 100644 --- a/test/rpc/test_rpc_class.py +++ b/test/rpc/test_rpc_class.py @@ -6,6 +6,7 @@ from test.rpc.rpc_utils import rpc_call from test.shared import ( ABI_1_PATH, + ABI_PATH, CONTRACT_1_PATH, PREDEPLOY_ACCOUNT_CLI_ARGS, PREDEPLOYED_ACCOUNT_ADDRESS, @@ -43,49 +44,6 @@ "L1_HANDLER": [], } -# abi from ABI_PATH (test/shared.py), but with all stateMutability omitted -EXPECTED_ABI = [ - { - "type": "struct", - "name": "Point", - "size": 2, - "members": [ - {"name": "x", "offset": 0, "type": "felt"}, - {"name": "y", "offset": 1, "type": "felt"}, - ], - }, - { - "type": "constructor", - "name": "constructor", - "inputs": [{"name": "initial_balance", "type": "felt"}], - "outputs": [], - }, - { - "type": "function", - "name": "increase_balance", - "inputs": [ - {"name": "amount1", "type": "felt"}, - {"name": "amount2", "type": "felt"}, - ], - "outputs": [], - }, - { - "type": "function", - "name": "get_balance", - "inputs": [], - "outputs": [{"name": "res", "type": "felt"}], - }, - { - "type": "function", - "name": "sum_point_array", - "inputs": [ - {"name": "points_len", "type": "felt"}, - {"name": "points", "type": "Point*"}, - ], - "outputs": [{"name": "res", "type": "Point"}], - }, -] - def assert_correct_cairo_1_contract(contract_class): """ @@ -96,11 +54,12 @@ def assert_correct_cairo_1_contract(contract_class): ) as expected_abi: expected_contract_json = json.loads(expected_contract.read()) expected_abi_json = json.loads(expected_abi.read()) - assert ( - contract_class["entry_points_by_type"] - == expected_contract_json["entry_points_by_type"] - ) - assert contract_class["abi"] == json.dumps(expected_abi_json) + + assert ( + contract_class["entry_points_by_type"] + == expected_contract_json["entry_points_by_type"] + ) + assert contract_class["abi"] == json.dumps(expected_abi_json) @pytest.mark.usefixtures("run_devnet_in_background") @@ -108,6 +67,9 @@ def test_get_deprecated_class(class_hash): """ Test get contract class """ + with open(ABI_PATH, mode="r", encoding="utf-8") as expected_abi: + expected_abi_json = json.loads(expected_abi.read()) + resp = rpc_call( "starknet_getClass", params={"block_id": "latest", "class_hash": class_hash} ) @@ -116,7 +78,7 @@ def test_get_deprecated_class(class_hash): assert contract_class["entry_points_by_type"] == EXPECTED_ENTRY_POINTS assert isinstance(contract_class["program"], str) decompress_program(contract_class["program"]) - assert contract_class["abi"] == EXPECTED_ABI + assert contract_class["abi"] == expected_abi_json @devnet_in_background(*PREDEPLOY_ACCOUNT_CLI_ARGS) @@ -203,16 +165,22 @@ def test_get_deprecated_class_at(deploy_info): """ Test get contract class at given contract address """ + with open(ABI_PATH, mode="r", encoding="utf-8") as expected_abi: + expected_abi_json = json.loads(expected_abi.read()) + contract_address: str = deploy_info["address"] block_id: BlockId = "latest" resp = rpc_call( "starknet_getClassAt", - params={"contract_address": rpc_felt(contract_address), "block_id": block_id}, + params={ + "contract_address": rpc_felt(contract_address), + "block_id": block_id, + }, ) contract_class = resp["result"] assert contract_class["entry_points_by_type"] == EXPECTED_ENTRY_POINTS assert isinstance(contract_class["program"], str) decompress_program(contract_class["program"]) - assert contract_class["abi"] == EXPECTED_ABI + assert contract_class["abi"] == expected_abi_json diff --git a/test/rpc/test_rpc_estimate_fee.py b/test/rpc/test_rpc_estimate_fee.py index cb1252a2d..d08c11d2e 100644 --- a/test/rpc/test_rpc_estimate_fee.py +++ b/test/rpc/test_rpc_estimate_fee.py @@ -293,7 +293,7 @@ def test_estimate_fee_with_invalid_call_data(): "starknet_estimateFee", {"request": [invoke_transaction], "block_id": "latest"} ) - assert ex["error"] == {"code": 22, "message": "Invalid call data"} + assert ex["error"] == {"code": 40, "message": "Contract error"} @pytest.mark.usefixtures("run_devnet_in_background") @@ -340,4 +340,4 @@ def test_estimate_fee_with_invalid_message_selector(): "starknet_estimateFee", {"request": [txn], "block_id": "latest"} ) - assert ex["error"] == {"code": 21, "message": "Invalid message selector"} + assert ex["error"] == {"code": 40, "message": "Contract error"} diff --git a/test/rpc/test_rpc_misc.py b/test/rpc/test_rpc_misc.py index bd34c0a31..b4ff0dc4f 100644 --- a/test/rpc/test_rpc_misc.py +++ b/test/rpc/test_rpc_misc.py @@ -212,6 +212,21 @@ def test_call_method_with_incorrect_type_params(): } +@pytest.mark.usefixtures("run_devnet_in_background") +def test_get_events_empty_filter(): + """ + Test RPC get_events with empty filter. + + Only required field in filter is chunk_size, so it should + work with just that. + """ + + params = {"filter": {"chunk_size": 100}} + resp = rpc_call("starknet_getEvents", params=params) + + assert "result" in resp and "events" in resp["result"] + + @pytest.mark.usefixtures("run_devnet_in_background") def test_get_events_malformed_request(): """ @@ -226,17 +241,6 @@ def test_get_events_malformed_request(): assert resp["error"]["code"] == PredefinedRpcErrorCode.INVALID_PARAMS.value -@pytest.mark.usefixtures("run_devnet_in_background") -def test_get_events_missing_parameter(): - """ - Test RPC get_events with malformed request. - """ - params = create_get_events_filter() - del params["filter"]["address"] - resp = rpc_call("starknet_getEvents", params=params) - assert resp["error"]["code"] == PredefinedRpcErrorCode.INVALID_PARAMS.value - - @pytest.mark.usefixtures("run_devnet_in_background") def test_get_events_wrong_blockid_type(): """ diff --git a/test/rpc/test_rpc_transactions.py b/test/rpc/test_rpc_transactions.py index c9e692431..9d75d89c4 100644 --- a/test/rpc/test_rpc_transactions.py +++ b/test/rpc/test_rpc_transactions.py @@ -611,6 +611,50 @@ def test_add_declare_transaction_v2(): assert is_felt(receipt["class_hash"]) +@pytest.mark.usefixtures("devnet_with_account") +def test_declare_transaction_v2_already_declared(): + """Add declare transaction v2""" + contract_class, _, compiled_class_hash = load_cairo1_contract() + + max_fee = int(4e16) + + def declare_tx(): + nonce = get_nonce(PREDEPLOYED_ACCOUNT_ADDRESS) + + tx_hash = calculate_declare_transaction_hash( + contract_class=contract_class, + compiled_class_hash=compiled_class_hash, + chain_id=StarknetChainId.TESTNET.value, + sender_address=int(PREDEPLOYED_ACCOUNT_ADDRESS, 16), + max_fee=max_fee, + version=SUPPORTED_RPC_DECLARE_TX_VERSION, + nonce=nonce, + ) + + signature = _get_signature(tx_hash, PREDEPLOYED_ACCOUNT_PRIVATE_KEY) + + declare_transaction = RpcBroadcastedDeclareTxnV2( + contract_class=rpc_contract_class(contract_class), + sender_address=PREDEPLOYED_ACCOUNT_ADDRESS, + compiled_class_hash=rpc_felt(compiled_class_hash), + type="DECLARE", + version=rpc_felt(SUPPORTED_RPC_DECLARE_TX_VERSION), + nonce=rpc_felt(nonce), + max_fee=rpc_felt(max_fee), + signature=list(map(rpc_felt, signature)), + ) + + return rpc_call( + "starknet_addDeclareTransaction", + params={"declare_transaction": declare_transaction}, + ) + + declare_tx() + ex = declare_tx() + + assert ex["error"] == {"code": 51, "message": "Class already declared"} + + def _add_declare_transaction(): contract_class = load_contract_class(CONTRACT_PATH) contract_class_dump = contract_class.dump()