Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sequencing): add cetral deploy account transaction written object #2872

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"tx": {
"hash_value": "0x429cb4dc45610a80a96800ab350a11ff50e2d69e25c7723c002934e66b5a282",
"version": "0x3",
"signature": [],
"nonce": "0x0",
"sender_address": "0x4c2e031b0ddaa38e06fd9b1bf32bff739965f9d64833006204c67cbc879a57c",
"nonce_data_availability_mode": 0,
"fee_data_availability_mode": 0,
"resource_bounds": {
"L1_GAS": {
"max_amount": "0x1",
"max_price_per_unit": "0x1"
},
"L2_GAS": {
"max_amount": "0x0",
"max_price_per_unit": "0x0"
},
"L1_DATA": {
"max_amount": "0x0",
"max_price_per_unit": "0x0"
}
},
"tip": "0x0",
"paymaster_data": [],
"contract_address_salt": "0x2",
"class_hash": "0x1b5a0b09f23b091d5d1fa2f660ddfad6bcfce607deba23806cd7328ccfb8ee9",
"constructor_calldata": [],
"type": "DEPLOY_ACCOUNT"
},
"time_created": 1734601616
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ use starknet_api::block::{
};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::executable_transaction::{AccountTransaction, InvokeTransaction, Transaction};
use starknet_api::executable_transaction::{
AccountTransaction,
DeployAccountTransaction,
InvokeTransaction,
Transaction,
};
use starknet_api::state::StorageKey;
use starknet_api::transaction::fields::{
AccountDeploymentData,
Calldata,
ContractAddressSalt,
PaymasterData,
Tip,
TransactionSignature,
Expand Down Expand Up @@ -112,8 +118,8 @@ pub struct CentralInvokeTransactionV3 {
pub tip: Tip,
pub paymaster_data: PaymasterData,
pub account_deployment_data: AccountDeploymentData,
pub nonce_data_availability_mode: u8,
pub fee_data_availability_mode: u8,
pub nonce_data_availability_mode: u32,
pub fee_data_availability_mode: u32,
pub hash_value: TransactionHash,
}

Expand All @@ -129,40 +135,80 @@ impl From<InvokeTransaction> for CentralInvokeTransactionV3 {
tip: tx.tip(),
paymaster_data: tx.paymaster_data(),
account_deployment_data: tx.account_deployment_data(),
nonce_data_availability_mode: into_u8(tx.nonce_data_availability_mode()),
fee_data_availability_mode: into_u8(tx.fee_data_availability_mode()),
nonce_data_availability_mode: tx.nonce_data_availability_mode().into(),
fee_data_availability_mode: tx.fee_data_availability_mode().into(),
hash_value: tx.tx_hash(),
}
}
}

fn into_u8(data_availability_mode: DataAvailabilityMode) -> u8 {
match data_availability_mode {
DataAvailabilityMode::L1 => 0,
DataAvailabilityMode::L2 => 1,
#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "version")]
pub enum CentralInvokeTransaction {
#[serde(rename = "0x3")]
V3(CentralInvokeTransactionV3),
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct CentralDeployAccountTransactionV3 {
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
pub nonce_data_availability_mode: u32,
pub fee_data_availability_mode: u32,
pub paymaster_data: PaymasterData,
pub hash_value: TransactionHash,
pub sender_address: ContractAddress,
}

impl From<DeployAccountTransaction> for CentralDeployAccountTransactionV3 {
fn from(tx: DeployAccountTransaction) -> CentralDeployAccountTransactionV3 {
CentralDeployAccountTransactionV3 {
resource_bounds: tx.resource_bounds(),
tip: tx.tip(),
signature: tx.signature(),
nonce: tx.nonce(),
class_hash: tx.class_hash(),
contract_address_salt: tx.contract_address_salt(),
constructor_calldata: tx.constructor_calldata(),
nonce_data_availability_mode: tx.nonce_data_availability_mode().into(),
fee_data_availability_mode: tx.fee_data_availability_mode().into(),
paymaster_data: tx.paymaster_data(),
hash_value: tx.tx_hash(),
sender_address: tx.contract_address,
}
}
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "version")]
pub enum CentralInvokeTransaction {
pub enum CentralDeployAccountTransaction {
#[serde(rename = "0x3")]
V3(CentralInvokeTransactionV3),
V3(CentralDeployAccountTransactionV3),
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum CentralTransaction {
#[serde(rename = "INVOKE_FUNCTION")]
Invoke(CentralInvokeTransaction),
#[serde(rename = "DEPLOY_ACCOUNT")]
DeployAccount(CentralDeployAccountTransaction),
}

impl From<Transaction> for CentralTransaction {
fn from(tx: Transaction) -> CentralTransaction {
match tx {
Transaction::Account(AccountTransaction::Invoke(invoke_tx)) => {
CentralTransaction::Invoke(CentralInvokeTransaction::V3(
CentralInvokeTransactionV3::from(invoke_tx),
CentralTransaction::Invoke(CentralInvokeTransaction::V3(invoke_tx.into()))
}
Transaction::Account(AccountTransaction::DeployAccount(deploy_tx)) => {
CentralTransaction::DeployAccount(CentralDeployAccountTransaction::V3(
deploy_tx.into(),
))
}
Transaction::Account(_) => unimplemented!(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ use starknet_api::block::{
};
use starknet_api::core::{ClassHash, CompiledClassHash, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::executable_transaction::InvokeTransaction;
use starknet_api::executable_transaction::{DeployAccountTransaction, InvokeTransaction};
use starknet_api::execution_resources::GasAmount;
use starknet_api::test_utils::read_json_file;
use starknet_api::transaction::fields::{
AllResourceBounds,
Calldata,
ContractAddressSalt,
ResourceBounds,
ValidResourceBounds,
};
use starknet_api::transaction::{InvokeTransactionV3, TransactionHash};
use starknet_api::transaction::{DeployAccountTransactionV3, InvokeTransactionV3, TransactionHash};
use starknet_api::{contract_address, felt, storage_key};

use super::{
CentralBlockInfo,
CentralDeployAccountTransaction,
CentralInvokeTransaction,
CentralResourcePrice,
CentralStateDiff,
Expand All @@ -35,6 +37,7 @@ use super::{

pub const CENTRAL_STATE_DIFF_JSON_PATH: &str = "central_state_diff.json";
pub const CENTRAL_INVOKE_TX_JSON_PATH: &str = "central_invoke_tx.json";
pub const CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH: &str = "central_deploy_account_tx.json";

fn central_state_diff() -> CentralStateDiff {
// TODO(yael): compute the CentralStateDiff with into().
Expand Down Expand Up @@ -74,7 +77,7 @@ fn central_state_diff() -> CentralStateDiff {
}
}

fn central_invoke_transaction_json() -> Value {
fn central_invoke_tx_json() -> Value {
let invoke_tx = InvokeTransaction {
tx: starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 {
resource_bounds: ValidResourceBounds::AllResources(AllResourceBounds {
Expand Down Expand Up @@ -111,9 +114,52 @@ fn central_invoke_transaction_json() -> Value {
serde_json::to_value(central_transaction_written).unwrap()
}

fn central_deploy_account_tx_json() -> Value {
let deploy_account_tx = DeployAccountTransaction {
tx: starknet_api::transaction::DeployAccountTransaction::V3(DeployAccountTransactionV3 {
resource_bounds: ValidResourceBounds::AllResources(AllResourceBounds {
l1_gas: ResourceBounds {
max_amount: GasAmount(1),
max_price_per_unit: GasPrice(1),
},
l2_gas: ResourceBounds::default(),
l1_data_gas: ResourceBounds::default(),
}),
signature: Default::default(),
nonce: Default::default(),
tip: Default::default(),
paymaster_data: Default::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,

class_hash: ClassHash(felt!(
"0x1b5a0b09f23b091d5d1fa2f660ddfad6bcfce607deba23806cd7328ccfb8ee9"
)),
contract_address_salt: ContractAddressSalt(felt!(2_u8)),
constructor_calldata: Default::default(),
}),
tx_hash: TransactionHash(felt!(
"0x429cb4dc45610a80a96800ab350a11ff50e2d69e25c7723c002934e66b5a282"
)),
contract_address: contract_address!(
"0x4c2e031b0ddaa38e06fd9b1bf32bff739965f9d64833006204c67cbc879a57c"
),
};

let central_transaction_written = CentralTransactionWritten {
tx: CentralTransaction::DeployAccount(CentralDeployAccountTransaction::V3(
deploy_account_tx.into(),
)),
time_created: 1734601616,
};

serde_json::to_value(central_transaction_written).unwrap()
}

#[rstest]
#[case::state_diff(serde_json::to_value(central_state_diff()).unwrap(), CENTRAL_STATE_DIFF_JSON_PATH)]
#[case::invoke_tx(central_invoke_transaction_json(), CENTRAL_INVOKE_TX_JSON_PATH)]
#[case::invoke_tx(central_invoke_tx_json(), CENTRAL_INVOKE_TX_JSON_PATH)]
#[case::deploy_account_tx(central_deploy_account_tx_json(), CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH)]
fn serialize_central_objects(#[case] rust_json: Value, #[case] python_json_path: &str) {
let python_json = read_json_file(python_json_path);

Expand Down
Loading