Skip to content

Commit

Permalink
chore: Bump version to v0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
duanyytop committed Dec 5, 2022
1 parent 5484f9f commit accb6a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -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<Value, Error> {
pub async fn register_rpc(params: Params) -> Result<Value, Error> {
info!("Register cota cells request: {:?}", params);
let registries: Vec<Value> = 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())?;
Expand Down
6 changes: 3 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ pub fn get_syncer_tip_block_number() -> Result<u64, Error> {
fn parse_registries(registries: Vec<Registry>) -> 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()
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions src/smt/entry.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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 {
Expand All @@ -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(|| {
Expand Down

0 comments on commit accb6a9

Please sign in to comment.