Skip to content

Commit

Permalink
chore: remove rusqlite_migration dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd committed Sep 3, 2024
1 parent 2b0ad77 commit 685f7cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 51 deletions.
8 changes: 3 additions & 5 deletions crates/rust-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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 }
Expand All @@ -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 }
Expand Down
5 changes: 0 additions & 5 deletions crates/rust-client/src/store/sqlite_store/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ use crate::store::StoreError;
// STORE ERROR
// ================================================================================================

impl From<rusqlite_migration::Error> for StoreError {
fn from(value: rusqlite_migration::Error) -> Self {
Self::DatabaseError(value.to_string())
}
}
impl From<rusqlite::Error> for StoreError {
fn from(value: rusqlite::Error) -> Self {
match value {
Expand Down
20 changes: 0 additions & 20 deletions crates/rust-client/src/store/sqlite_store/migrations.rs

This file was deleted.

12 changes: 5 additions & 7 deletions crates/rust-client/src/store/sqlite_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod accounts;
mod chain_data;
pub mod config;
mod errors;
pub(crate) mod migrations;
mod notes;
mod sync;
mod transactions;
Expand Down Expand Up @@ -100,9 +99,9 @@ impl SqliteStore {

/// Returns a new instance of [Store] instantiated with the specified configuration options.
pub fn new(config: &SqliteStoreConfig) -> Result<Self, StoreError> {
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) })
}
Expand Down Expand Up @@ -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) }
}
}
28 changes: 14 additions & 14 deletions crates/rust-client/src/store/sqlite_store/store.sql
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
-- 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
PRIMARY KEY (account_id)
);

-- 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.
Expand All @@ -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.
Expand All @@ -62,15 +62,15 @@ 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

PRIMARY KEY (script_hash)
);

-- 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -177,15 +177,15 @@ 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

PRIMARY KEY (script_hash)
);

-- 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)
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 685f7cf

Please sign in to comment.