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

build: serde transactions #943

Closed
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
188 changes: 188 additions & 0 deletions crates/blockifier/src/transaction/invoke_transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
[
{
"transaction_hash": "0x65dce6b502bc2f3437b4ed9f32f614293d0abc12cbadefdaff0922721b693ee",
"version": "0x1",
"max_fee": "0x1238e4db0778",
"signature": [
"0x16a4c849ddc37556eafffe84cf6914bb5220ae0107f5ac225df449de5e2e033",
"0x5f71e739a33f8b6c0f2109eb3100320d7c180d84e6b5251915cc30344e2be09"
],
"nonce": "0xb9",
"sender_address": "0x55f4c3b05617824f196cb6d23097cd74bac1b5b4ced55e509d028b161d146b2",
"calldata": [
"0x1",
"0x3400b164983fb20930d0151d99d8bfa927a33ab36190feacd3c739287553aa0",
"0x34cc13b274446654ca3233ed2c1620d4c5d1d32fd20b47146a3371064bdc57d",
"0x83",
"0x414e595f43414c4c4552",
"0x64a626f654f3e6579f5bbf3b9aa6e704127ab50479cc0567534428d5652fcb2",
"0x0",
"0x66e98cc4",
"0x1",
"0x18108b32cea514a78ef1b0e4a0753e855cdf620bc0565202c02456f618c4dc4",
"0x1f64d317ff277789ba74de95db50418ab0fa47c09241400b7379b50d6334c3a",
"0x2",
"0x19fb",
"0x1",
"0x78",
"0x73657373696f6e2d746f6b656e",
"0x66fbc820",
"0x517c6df0b19d89ed39fb54a1f1e417a0913e6812e694c19ecb1f35737aa6f8b",
"0x0",
"0x26e0600d35374d1af77cc40f6bbc3ab520185e8a4721755dd4b64a23ef1c0b5",
"0x1",
"0x63",
"0x2",
"0x4",
"0x16",
"0x68",
"0x74",
"0x74",
"0x70",
"0x73",
"0x3a",
"0x2f",
"0x2f",
"0x78",
"0x2e",
"0x63",
"0x61",
"0x72",
"0x74",
"0x72",
"0x69",
"0x64",
"0x67",
"0x65",
"0x2e",
"0x67",
"0x67",
"0x9d0aec9905466c9adf79584fa75fed3",
"0x20a97ec3f8efbc2aca0cf7cabb420b4a",
"0xf1233b562422efa26a6502ce18714d1a",
"0xfd663435e61ae6bf6c2d434f7b4275ee",
"0x3a",
"0x2c",
"0x22",
"0x74",
"0x6f",
"0x70",
"0x4f",
"0x72",
"0x69",
"0x67",
"0x69",
"0x6e",
"0x22",
"0x3a",
"0x22",
"0x68",
"0x74",
"0x74",
"0x70",
"0x73",
"0x3a",
"0x2f",
"0x2f",
"0x6c",
"0x6f",
"0x6f",
"0x74",
"0x73",
"0x75",
"0x72",
"0x76",
"0x69",
"0x76",
"0x6f",
"0x72",
"0x2e",
"0x69",
"0x6f",
"0x22",
"0x2c",
"0x22",
"0x63",
"0x72",
"0x6f",
"0x73",
"0x73",
"0x4f",
"0x72",
"0x69",
"0x67",
"0x69",
"0x6e",
"0x22",
"0x3a",
"0x74",
"0x72",
"0x75",
"0x65",
"0x7d",
"0x1d",
"0x0",
"0x9350efeb916b20e2a080806966484b83",
"0xa2007d553f440f9f170f72bbff955b7f",
"0x81a403ab28e5eee86f5f821c77e1ec08",
"0x7b1d0a796c987c5d21ec142c87c41d9a",
"0x1",
"0x0",
"0x1e6a6f52e47fe42e024287b729bc47e58019fcc7e1cc8b141bb8d669b779b49",
"0x3da7a832c7cb69055b3dce69676169f12d1a89597fa577cac1fccc921c40e32",
"0x5011e1298a7be98ff33bea1de871d02936732c14a78d152432df8d6fdaebedb",
"0x0",
"0x7271a0ae52abc979468f49690029d322068f1ffcaeb583f6605c0e9e4bf5c70",
"0x6c7853acc5cd30ad8ac04819cd451fd5c5cb0f506045e0af8fba65fc038d68e",
"0x5fd99ef4ba1a34129f064083787c318237d2921101b5de2e22d28aebd192d7e",
"0x0",
"0x1e6a6f52e47fe42e024287b729bc47e58019fcc7e1cc8b141bb8d669b779b49",
"0x7c813742a629f85045a81857a69e2991077cb389d7b398e0489e6089da59c9",
"0x363940542b2b7456ab724f60d859a46159283d9d98e84ae6971f0fbb21e2bf1",
"0x1",
"0x4",
"0x2e239144ace2594bff2e9c6cd92a59fd49be14815e0a6d446e1723447293b46",
"0x65cac0b5cd4d201f2a6d4c4b0f95e144f7097ec087332cac45f65eb35796e2",
"0x387631103c9a13c4661233f967e41c65c804cc195adfd74f9c69d87568e74cd",
"0x6a8e4151fd49dcb4bb8df7c51c5b1b0df60ed486cfff9514039807cab500ded"
],
"type": "INVOKE_FUNCTION"
},
{
"transaction_hash": "0x6ec9973cedc15676a76e7c7ae30e1d6b0a830e7785bd6cc8e3fe68920bd2353",
"version": "0x3",
"signature": [
"0x73b8ce72843046c31d80edc23686a5ba054d23dc861338a648ab752bbe6b204",
"0x6217e35ace56edf90e865e5e98c0d5ed3ec24c4d5dc0f6721226b1d8d297b29",
"0x459c06fce35167462641d234f81553ae12e407ed9fb10305a318b01f7915c8a",
"0x631ec36f4ea322df27179c7c7ed19e89a1a29dbe7cfb6019cfbe390bc2266b5"
],
"nonce": "0x4",
"nonce_data_availability_mode": 0,
"fee_data_availability_mode": 0,
"resource_bounds": {
"L1_GAS": {
"max_amount": "0x5c",
"max_price_per_unit": "0x36ca225192c0"
},
"L2_GAS": {
"max_amount": "0x0",
"max_price_per_unit": "0x0"
}
},
"tip": "0x0",
"paymaster_data": [],
"sender_address": "0x61549dbfe1ce777ccd18745d730fb151e1e0a12f86c9879dcf7dfdff87bb455",
"calldata": [
"0x1",
"0x61549dbfe1ce777ccd18745d730fb151e1e0a12f86c9879dcf7dfdff87bb455",
"0xf2f7c15cbe06c8d94597cd91fd7f3369eae842359235712def5584f8d270cd",
"0x3",
"0x36078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f",
"0x1",
"0x0"
],
"account_deployment_data": [],
"type": "INVOKE_FUNCTION"
}
]
9 changes: 6 additions & 3 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde::{Deserialize, Serialize};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::{
Expand Down Expand Up @@ -324,7 +325,7 @@ impl TransactionInfoCreator for DeclareTransaction {
}
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeployAccountTransaction {
pub tx: starknet_api::executable_transaction::DeployAccountTransaction,
// Indicates the presence of the only_query bit in the version.
Expand Down Expand Up @@ -440,10 +441,12 @@ impl TransactionInfoCreator for DeployAccountTransaction {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvokeTransaction {
#[serde(flatten)]
pub tx: starknet_api::executable_transaction::InvokeTransaction,
// Indicates the presence of the only_query bit in the version.
#[serde(default)]
pub only_query: bool,
}

Expand Down Expand Up @@ -564,7 +567,7 @@ impl TransactionInfoCreator for InvokeTransaction {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct L1HandlerTransaction {
pub tx: starknet_api::transaction::L1HandlerTransaction,
pub tx_hash: TransactionHash,
Expand Down
24 changes: 14 additions & 10 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::sync::{Arc, LazyLock};

use assert_matches::assert_matches;
Expand All @@ -13,17 +14,10 @@ use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::{
Calldata,
EventContent,
EventData,
EventKey,
Fee,
L2ToL1Payload,
Resource,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
Calldata, EventContent, EventData, EventKey, Fee, L2ToL1Payload, Resource, TransactionSignature, TransactionVersion, ValidResourceBounds
};
use starknet_api::transaction::InvokeTransaction::V1 as V1;
use starknet_api::transaction::InvokeTransaction::V3 as V3;
use starknet_api::{
calldata,
class_hash,
Expand Down Expand Up @@ -137,6 +131,8 @@ use crate::{
retdata,
};

use super::InvokeTransaction;

static VERSIONED_CONSTANTS: LazyLock<VersionedConstants> =
LazyLock::new(VersionedConstants::create_for_testing);

Expand Down Expand Up @@ -2167,3 +2163,11 @@ fn test_balance_print() {
let int = balance_to_big_uint(&Felt::from(16_u64), &Felt::from(1_u64));
assert!(format!("{}", int) == (BigUint::from(u128::MAX) + BigUint::from(17_u128)).to_string());
}

#[test]
fn test_deserialize_invoke_tx() {
let raw_invoke = File::open("./src/transaction/invoke_transactions.json").unwrap();
let invoke_transactions = serde_json::from_reader::<_, Vec<InvokeTransaction>>(raw_invoke).unwrap();
assert_matches!(&invoke_transactions[0].tx.tx, V1 { .. });
assert_matches!(&invoke_transactions[1].tx.tx, V3 { .. });
}
2 changes: 2 additions & 0 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ impl DeployAccountTransaction {

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct InvokeTransaction {
#[serde(flatten)]
pub tx: crate::transaction::InvokeTransaction,
#[serde(rename = "transaction_hash")]
pub tx_hash: TransactionHash,
}

Expand Down
1 change: 1 addition & 0 deletions crates/starknet_api/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ impl TransactionHasher for InvokeTransactionV3 {
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord, From)]
#[serde(untagged)]
pub enum InvokeTransaction {
V0(InvokeTransactionV0),
V1(InvokeTransactionV1),
Expand Down
Loading