Skip to content

Commit

Permalink
update to the latest version of the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-mathieu committed Nov 6, 2023
1 parent 30e0df9 commit 7275cc3
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 70 deletions.
2 changes: 1 addition & 1 deletion crates/starknet-types-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default = ["std"]
std = ["serde/std", "starknet-types-core/std"]

[dependencies]
starknet-types-core = { path = "../starknet-types-core", default-features = false }
starknet-types-core = { path = "../starknet-types-core", default-features = false, features = ["serde"] }
serde = { version = "1", default-features = false, features = ["derive"] }

[dev-dependencies]
Expand Down
360 changes: 332 additions & 28 deletions crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.json

Large diffs are not rendered by default.

102 changes: 78 additions & 24 deletions crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// https://github.com/nils-mathieu/openrpc-gen
//

use crate::custom_serde::NumAsHex;
use crate::{
use super::{
BlockId, BroadcastedDeclareTxn, BroadcastedDeployAccountTxn, BroadcastedInvokeTxn, Felt,
};
use crate::custom_serde::NumAsHex;
use alloc::string::String;
use alloc::vec::Vec;
use serde::ser::SerializeMap;
Expand Down Expand Up @@ -135,7 +135,7 @@ pub type ChainId = u64;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommonReceiptProperties {
/// The fee that was charged by the sequencer
pub actual_fee: Felt,
pub actual_fee: FeePayment,
pub block_hash: BlockHash,
pub block_number: BlockNumber,
/// The events emitted as part of this transaction
Expand Down Expand Up @@ -211,6 +211,8 @@ pub enum DeclareTxn {
V1(DeclareTxnV1),
#[serde(rename = "0x2")]
V2(DeclareTxnV2),
#[serde(rename = "0x3")]
V3(DeclareTxnV3),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -256,6 +258,20 @@ pub struct DeclareTxnV2 {
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
Expand All @@ -269,7 +285,9 @@ pub struct DeployedContractItem {
#[serde(tag = "version")]
pub enum DeployAccountTxn {
#[serde(rename = "0x1")]
DeployAccountV1(DeployAccountTxnV1),
V1(DeployAccountTxnV1),
#[serde(rename = "0x3")]
V3(DeployAccountTxnV3),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -295,6 +313,21 @@ pub struct DeployAccountTxnV1 {
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<Felt>,
/// 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
Expand Down Expand Up @@ -432,6 +465,22 @@ pub struct FeeEstimate {
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<TypedParameter>,
Expand Down Expand Up @@ -474,6 +523,8 @@ pub enum InvokeTxn {
V0(InvokeTxnV0),
#[serde(rename = "0x1")]
V1(InvokeTxnV1),
#[serde(rename = "0x3")]
V3(InvokeTxnV3),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -505,6 +556,17 @@ pub struct InvokeTxnV1 {
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<Felt>,
/// 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
Expand Down Expand Up @@ -584,7 +646,7 @@ pub struct PendingBlockWithTxHashes {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PendingCommonReceiptProperties {
/// The fee that was charged by the sequencer
pub actual_fee: Felt,
pub actual_fee: FeePayment,
/// The events emitted as part of this transaction
pub events: Vec<Event>,
/// The resources consumed by the transaction
Expand All @@ -598,8 +660,6 @@ pub struct PendingCommonReceiptProperties {
pub revert_reason: Option<String>,
/// The hash identifying the transaction
pub transaction_hash: TxnHash,
#[serde(rename = "type")]
pub ty: TxnType,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -653,12 +713,21 @@ pub enum PendingTxnReceipt {
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(default)]
#[serde(with = "NumAsHex")]
pub price_in_strk: Option<u64>,
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,
Expand Down Expand Up @@ -835,21 +904,6 @@ pub enum TxnStatus {
Rejected,
}

/// The type of the transaction
#[derive(Serialize, Deserialize, Copy, PartialEq, Eq, Hash, Clone, Debug)]
pub enum TxnType {
#[serde(rename = "DECLARE")]
Declare,
#[serde(rename = "DEPLOY")]
Deploy,
#[serde(rename = "DEPLOY_ACCOUNT")]
DeployAccount,
#[serde(rename = "INVOKE")]
Invoke,
#[serde(rename = "L1_HANDLER")]
L1Handler,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypedParameter {
/// The parameter's name
Expand Down
17 changes: 11 additions & 6 deletions crates/starknet-types-rpc/src/v0_5_0/starknet_api_openrpc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,21 @@ preserve = [
"#/components/schemas/TXN" = "type"
"#/components/schemas/TXN_RECEIPT" = "type"
"#/components/schemas/PENDING_TXN_RECEIPT" = "type"
"#/components/schemas/BROADCASTED_TXN" = "type"
"#/components/schemas/DEPLOY_ACCOUNT_TXN" = "version"
"#/components/schemas/BROADCASTED_DECLARE_TXN" = "version"
"#/components/schemas/BROADCASTED_INVOKE_TXN" = "version"
"#/components/schemas/BROADCASTED_TXN" = "type"

[fixes.make-keyword]
"#/components/schemas/INVOKE_TXN_V1/_anon/version" = "0x1"
"#/components/schemas/DEPLOY_ACCOUNT_TXN_V1/version" = "0x1"
[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"
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
"order": {
"title": "order",
"description": "the order of the event within the transaction",
"type": "number"
"type": "integer"
}
}
},
Expand All @@ -418,7 +418,7 @@
"order": {
"title": "order",
"description": "the order of the message within the transaction",
"type": "number"
"type": "integer"
}
}
},
Expand Down Expand Up @@ -480,7 +480,7 @@
},
"BLOCK_NOT_FOUND": {
"code": 24,
"message": "Invalid block hash"
"message": "Block not found"
},
"CONTRACT_ERROR": {
"code": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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};

Expand Down Expand Up @@ -59,7 +61,7 @@ pub type NestedCall = FunctionInvocation;
pub struct OrderedEvent {
/// the order of the event within the transaction
#[serde(default)]
pub order: Option<f64>,
pub order: Option<u64>,
#[serde(flatten)]
pub event: Event,
}
Expand All @@ -69,7 +71,7 @@ pub struct OrderedEvent {
pub struct OrderedMessage {
/// the order of the message within the transaction
#[serde(default)]
pub order: Option<f64>,
pub order: Option<u64>,
#[serde(flatten)]
pub msg_to_l_1: MsgToL1,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ run-rustfmt = true

[generation]
additional-imports = [
"super::{Felt, FunctionCall, Event, MsgToL1, BlockId, FeeEstimate, BroadcastedTxn, StateDiff, TxnHash}"
"super::{Felt, FunctionCall, Event, MsgToL1, BlockId, FeeEstimate, BroadcastedTxn, StateDiff, TxnHash}",
"alloc::vec::Vec",
"alloc::string::String",
]
method-name-prefix = "starknet_"
param-types = true
Expand Down
7 changes: 2 additions & 5 deletions crates/starknet-types-rpc/src/v0_5_0/starknet_write_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,13 @@
"$ref": "./starknet_api_openrpc.json#/components/schemas/TXN_HASH"
},
"BROADCASTED_INVOKE_TXN": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/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_DECLARE_TXN": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/BROADCASTED_DECLARE_TXN"
},
"BROADCASTED_DEPLOY_ACCOUNT_TXN": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/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"
Expand Down

0 comments on commit 7275cc3

Please sign in to comment.