From accb6a959549ea53a40a54760d1b4b09112237e4 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Tue, 6 Dec 2022 01:15:53 +0800 Subject: [PATCH] chore: Bump version to v0.6.1 --- src/api.rs | 5 ++--- src/db.rs | 6 +++--- src/main.rs | 4 ++-- src/smt/entry.rs | 9 +++------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/api.rs b/src/api.rs index 7a611ae..4e88d5d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,16 +1,15 @@ use crate::db::{check_lock_hashes_registered, get_syncer_tip_block_number}; -use crate::smt::db::db::RocksDB; use crate::smt::entry::generate_registry_smt; use crate::utils::parse_request_param; use jsonrpc_http_server::jsonrpc_core::serde_json::{Map, Number}; use jsonrpc_http_server::jsonrpc_core::{Error, Params, Value}; use log::info; -pub async fn register_rpc(params: Params, db: &RocksDB) -> Result { +pub async fn register_rpc(params: Params) -> Result { info!("Register cota cells request: {:?}", params); let registries: Vec = Params::parse(params)?; let lock_hashes = parse_request_param::<32>(registries).map_err(|err| err.into())?; - let (root_hash, registry_entry) = generate_registry_smt(db, lock_hashes) + let (root_hash, registry_entry) = generate_registry_smt(lock_hashes) .await .map_err(|err| err.into())?; let block_number = get_syncer_tip_block_number().map_err(|err| err.into())?; diff --git a/src/db.rs b/src/db.rs index 87d5b6f..477ab8c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -88,10 +88,10 @@ pub fn get_syncer_tip_block_number() -> Result { fn parse_registries(registries: Vec) -> Vec<(H256, u64)> { registries .into_iter() - .map(|regsitry| { + .map(|registry| { ( - H256::from(parse_bytes_n::<32>(regsitry.lock_hash).unwrap()), - regsitry.ccid, + H256::from(parse_bytes_n::<32>(registry.lock_hash).unwrap()), + registry.ccid, ) }) .collect() diff --git a/src/main.rs b/src/main.rs index a298323..07233a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ mod smt; mod utils; lazy_static! { - static ref DB: RocksDB = RocksDB::default().expect("RocksDB open error"); + static ref ROCKS_DB: RocksDB = RocksDB::default().expect("RocksDB open error"); static ref POOL: SqlConnectionPool = init_connection_pool(); } @@ -31,7 +31,7 @@ fn main() { .init(); let mut io = IoHandler::default(); - io.add_method("register_cota_cells", |req| register_rpc(req, &DB)); + io.add_method("register_cota_cells", register_rpc); io.add_method("check_registered_lock_hashes", check_registered_rpc); let server = ServerBuilder::new(io) diff --git a/src/smt/entry.rs b/src/smt/entry.rs index 5618bbc..06b4b62 100644 --- a/src/smt/entry.rs +++ b/src/smt/entry.rs @@ -1,9 +1,9 @@ use crate::db::check_lock_hashes_registered; use crate::error::Error; use crate::indexer::index::{get_registry_info, RegistryInfo}; -use crate::smt::db::db::RocksDB; use crate::smt::smt::{generate_history_smt, init_smt, Extension}; use crate::smt::transaction::store_transaction::StoreTransaction; +use crate::ROCKS_DB; use cota_smt::common::{Byte32, BytesBuilder}; use cota_smt::molecule::prelude::*; use cota_smt::registry::{ @@ -20,10 +20,7 @@ lazy_static! { Arc::new((Mutex::new(false), Condvar::new())); } -pub async fn generate_registry_smt( - db: &RocksDB, - lock_hashes: Vec<[u8; 32]>, -) -> Result<(String, String), Error> { +pub async fn generate_registry_smt(lock_hashes: Vec<[u8; 32]>) -> Result<(String, String), Error> { let update_leaves_count = lock_hashes.len(); let registry_state = check_lock_hashes_registered(lock_hashes.clone())?.0; if registry_state { @@ -40,7 +37,7 @@ pub async fn generate_registry_smt( previous_leaves.push((key, H256::zero())); } - let transaction = &StoreTransaction::new(db.transaction()); + let transaction = &StoreTransaction::new((&ROCKS_DB).transaction()); let mut smt = init_smt(transaction)?; with_lock(|| {