diff --git a/crates/rust-client/Cargo.toml b/crates/rust-client/Cargo.toml index 244b3bb91..efa401e55 100644 --- a/crates/rust-client/Cargo.toml +++ b/crates/rust-client/Cargo.toml @@ -20,7 +20,7 @@ async = ["miden-tx/async"] concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"] default = ["std"] idxdb = ["async", "dep:base64", "dep:serde-wasm-bindgen", "dep:wasm-bindgen", "dep:wasm-bindgen-futures"] -sqlite = ["dep:rusqlite", "dep:rusqlite_migration", "dep:lazy_static", "std"] +sqlite = ["dep:rusqlite", "std"] std = ["miden-objects/std"] testing = ["miden-objects/testing", "miden-lib/testing"] tonic = ["dep:hex", "dep:prost", "dep:tonic", "std", "tonic/transport"] @@ -31,14 +31,12 @@ base64 = { version = "0.22", optional = true } chrono = { version = "0.4", optional = false } getrandom = { version = "0.2", features = ["js"], optional = true } hex = { version = "0.4" , optional = true} -lazy_static = { version = "1.5", optional = true } miden-lib = { workspace = true } miden-objects = { workspace = true } miden-tx = { workspace = true } prost = { version = "0.13", optional = true, default-features = false, features = ["derive"] } rand = { workspace = true } -rusqlite = { version = "0.31", features = ["vtab", "array", "bundled"], optional = true } -rusqlite_migration = { version = "1.2", optional = true } +rusqlite = { version = "0.32", features = ["vtab", "array", "bundled"], optional = true } serde = { workspace = true } serde_json = { workspace = true } serde-wasm-bindgen = { version = "0.6", optional = true } @@ -58,7 +56,7 @@ miden-objects = { workspace = true, default-features = false, features = ["serde uuid = { version = "1.10", features = ["serde", "v4"] } [build-dependencies] -miden-rpc-proto = { version = "0.5" } +miden-rpc-proto = { git = "https://github.com/0xPolygonMiden/miden-node", branch = "tomyrd-fix-shadowing" } miette = { version = "7.2", features = ["fancy"] } prost = { version = "0.13", default-features = false, features = ["derive"] } prost-build = { version = "0.13", default-features = false } diff --git a/crates/rust-client/src/store/sqlite_store/errors.rs b/crates/rust-client/src/store/sqlite_store/errors.rs index 2cf1164d8..1006f0b27 100644 --- a/crates/rust-client/src/store/sqlite_store/errors.rs +++ b/crates/rust-client/src/store/sqlite_store/errors.rs @@ -5,11 +5,6 @@ use crate::store::StoreError; // STORE ERROR // ================================================================================================ -impl From for StoreError { - fn from(value: rusqlite_migration::Error) -> Self { - Self::DatabaseError(value.to_string()) - } -} impl From for StoreError { fn from(value: rusqlite::Error) -> Self { match value { diff --git a/crates/rust-client/src/store/sqlite_store/migrations.rs b/crates/rust-client/src/store/sqlite_store/migrations.rs deleted file mode 100644 index 4cdd1aae0..000000000 --- a/crates/rust-client/src/store/sqlite_store/migrations.rs +++ /dev/null @@ -1,20 +0,0 @@ -use lazy_static::lazy_static; -use rusqlite::Connection; -use rusqlite_migration::{Migrations, M}; - -use crate::store::StoreError; - -// MIGRATIONS -// ================================================================================================ - -lazy_static! { - static ref MIGRATIONS: Migrations<'static> = - Migrations::new(vec![M::up(include_str!("store.sql")),]); -} - -// PUBLIC FUNCTIONS -// ================================================================================================ - -pub(crate) fn update_to_latest(conn: &mut Connection) -> Result<(), StoreError> { - Ok(MIGRATIONS.to_latest(conn)?) -} diff --git a/crates/rust-client/src/store/sqlite_store/mod.rs b/crates/rust-client/src/store/sqlite_store/mod.rs index 42e0c825a..3ea17c0ba 100644 --- a/crates/rust-client/src/store/sqlite_store/mod.rs +++ b/crates/rust-client/src/store/sqlite_store/mod.rs @@ -24,7 +24,6 @@ mod accounts; mod chain_data; pub mod config; mod errors; -pub(crate) mod migrations; mod notes; mod sync; mod transactions; @@ -100,9 +99,9 @@ impl SqliteStore { /// Returns a new instance of [Store] instantiated with the specified configuration options. pub fn new(config: &SqliteStoreConfig) -> Result { - let mut db = Connection::open(config.database_filepath.clone())?; + let db = Connection::open(config.database_filepath.clone())?; array::load_module(&db)?; - migrations::update_to_latest(&mut db)?; + db.execute_batch(include_str!("store.sql")).unwrap(); Ok(Self { db: RefCell::new(db) }) } @@ -301,15 +300,14 @@ pub mod tests { use rusqlite::{vtab::array, Connection}; - use super::{migrations, SqliteStore}; + use super::SqliteStore; use crate::mock::create_test_store_path; pub(crate) fn create_test_store() -> SqliteStore { let temp_file = create_test_store_path(); - let mut db = Connection::open(temp_file).unwrap(); + let db = Connection::open(temp_file).unwrap(); array::load_module(&db).unwrap(); - migrations::update_to_latest(&mut db).unwrap(); - + db.execute_batch(include_str!("store.sql")).unwrap(); SqliteStore { db: RefCell::new(db) } } } diff --git a/crates/rust-client/src/store/sqlite_store/store.sql b/crates/rust-client/src/store/sqlite_store/store.sql index 5c88228f2..f6d1ed33d 100644 --- a/crates/rust-client/src/store/sqlite_store/store.sql +++ b/crates/rust-client/src/store/sqlite_store/store.sql @@ -1,26 +1,26 @@ -- Create account_code table -CREATE TABLE account_code ( +CREATE TABLE IF NOT EXISTS account_code ( root BLOB NOT NULL, -- root of the Merkle tree for all exported procedures in account module. code BLOB NOT NULL, -- serialized account code. PRIMARY KEY (root) ); -- Create account_storage table -CREATE TABLE account_storage ( +CREATE TABLE IF NOT EXISTS account_storage ( root BLOB NOT NULL, -- root of the account storage Merkle tree. slots BLOB NOT NULL, -- serialized key-value pair of non-empty account slots. PRIMARY KEY (root) ); -- Create account_vaults table -CREATE TABLE account_vaults ( +CREATE TABLE IF NOT EXISTS account_vaults ( root BLOB NOT NULL, -- root of the Merkle tree for the account asset vault. assets BLOB NOT NULL, -- serialized account vault assets. PRIMARY KEY (root) ); -- Create account_auth table -CREATE TABLE account_auth ( +CREATE TABLE IF NOT EXISTS account_auth ( account_id UNSIGNED BIG INT NOT NULL, -- ID of the account auth_info BLOB NOT NULL, -- Serialized representation of information needed for authentication pub_key BLOB NOT NULL, -- Public key for easier authenticator use @@ -28,7 +28,7 @@ CREATE TABLE account_auth ( ); -- Create accounts table -CREATE TABLE accounts ( +CREATE TABLE IF NOT EXISTS accounts ( id UNSIGNED BIG INT NOT NULL, -- Account ID. code_root BLOB NOT NULL, -- Root of the account_code storage_root BLOB NOT NULL, -- Root of the account_storage Merkle tree. @@ -45,10 +45,10 @@ CREATE TABLE accounts ( CONSTRAINT check_seed_nonzero CHECK (NOT (nonce = 0 AND account_seed IS NULL)) ); -CREATE UNIQUE INDEX idx_account_hash ON accounts(account_hash); +CREATE UNIQUE INDEX IF NOT EXISTS idx_account_hash ON accounts(account_hash); -- Create transactions table -CREATE TABLE transactions ( +CREATE TABLE IF NOT EXISTS transactions ( id BLOB NOT NULL, -- Transaction ID (hash of various components) account_id UNSIGNED BIG INT NOT NULL, -- ID of the account against which the transaction was executed. init_account_state BLOB NOT NULL, -- Hash of the account state before the transaction was executed. @@ -62,7 +62,7 @@ CREATE TABLE transactions ( PRIMARY KEY (id) ); -CREATE TABLE transaction_scripts ( +CREATE TABLE IF NOT EXISTS transaction_scripts ( script_hash BLOB NOT NULL, -- Transaction script Hash script BLOB, -- serialized Transaction script @@ -70,7 +70,7 @@ CREATE TABLE transaction_scripts ( ); -- Create input notes table -CREATE TABLE input_notes ( +CREATE TABLE IF NOT EXISTS input_notes ( note_id BLOB NOT NULL, -- the note id recipient BLOB NOT NULL, -- the note recipient assets BLOB NOT NULL, -- the serialized NoteAssets, including vault hash and list of assets @@ -119,7 +119,7 @@ CREATE TABLE input_notes ( ); -- Create output notes table -CREATE TABLE output_notes ( +CREATE TABLE IF NOT EXISTS output_notes ( note_id BLOB NOT NULL, -- the note id recipient BLOB NOT NULL, -- the note recipient assets BLOB NOT NULL, -- the serialized NoteAssets, including vault hash and list of assets @@ -177,7 +177,7 @@ CREATE TABLE output_notes ( -- Create note's scripts table, used for both input and output notes -- TODO: can't do FOREIGN KEY over json fields, sure we're ok? -CREATE TABLE notes_scripts ( +CREATE TABLE IF NOT EXISTS notes_scripts ( script_hash BLOB NOT NULL, -- Note script Hash serialized_note_script BLOB, -- NoteScript, serialized @@ -185,7 +185,7 @@ CREATE TABLE notes_scripts ( ); -- Create state sync table -CREATE TABLE state_sync ( +CREATE TABLE IF NOT EXISTS state_sync ( block_num UNSIGNED BIG INT NOT NULL, -- the block number of the most recent state sync tags BLOB NOT NULL, -- the serialized list of tags PRIMARY KEY (block_num) @@ -199,7 +199,7 @@ WHERE ( ) = 0; -- Create block headers table -CREATE TABLE block_headers ( +CREATE TABLE IF NOT EXISTS block_headers ( block_num UNSIGNED BIG INT NOT NULL, -- block number header BLOB NOT NULL, -- serialized block header chain_mmr_peaks BLOB NOT NULL, -- serialized peaks of the chain MMR at this block @@ -208,7 +208,7 @@ CREATE TABLE block_headers ( ); -- Create chain mmr nodes -CREATE TABLE chain_mmr_nodes ( +CREATE TABLE IF NOT EXISTS chain_mmr_nodes ( id UNSIGNED BIG INT NOT NULL, -- in-order index of the internal MMR node node BLOB NOT NULL, -- internal node value (hash) PRIMARY KEY (id)