diff --git a/src/api.rs b/src/api.rs index f5c418e..78613f1 100644 --- a/src/api.rs +++ b/src/api.rs @@ -13,7 +13,7 @@ pub async fn register_rpc(params: Params, db: &RocksDB) -> 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, output_account_num) = generate_registry_smt(db, lock_hashes) .await .map_err(|err| err.into())?; let block_number = get_syncer_tip_block_number().map_err(|err| err.into())?; @@ -23,6 +23,10 @@ pub async fn register_rpc(params: Params, db: &RocksDB) -> Result "registry_smt_entry".to_string(), Value::String(registry_entry), ); + response.insert( + "output_account_num".to_string(), + Value::Number(Number::from(output_account_num)), + ); response.insert( "block_number".to_string(), Value::Number(Number::from(block_number)), @@ -51,7 +55,7 @@ pub async fn check_registered_rpc(params: Params) -> Result { pub async fn update_registered_ccid_rpc(db: &RocksDB) -> Result { info!("Update registered ccid request"); let lock_hashes = get_50_registered_lock_hashes().map_err(|err| err.into())?; - let (root_hash, registry_entry) = generate_registry_smt(db, lock_hashes) + let (root_hash, registry_entry, output_account_num) = generate_registry_smt(db, lock_hashes) .await .map_err(|err| err.into())?; let block_number = get_syncer_tip_block_number().map_err(|err| err.into())?; @@ -61,6 +65,10 @@ pub async fn update_registered_ccid_rpc(db: &RocksDB) -> Result { "registry_smt_entry".to_string(), Value::String(registry_entry), ); + response.insert( + "output_account_num".to_string(), + Value::Number(Number::from(output_account_num)), + ); response.insert( "block_number".to_string(), Value::Number(Number::from(block_number)), diff --git a/src/smt/entry.rs b/src/smt/entry.rs index 25d0cdb..765278d 100644 --- a/src/smt/entry.rs +++ b/src/smt/entry.rs @@ -23,7 +23,7 @@ lazy_static! { pub async fn generate_registry_smt( db: &RocksDB, lock_hashes: Vec<[u8; 32]>, -) -> Result<(String, String), Error> { +) -> Result<(String, String, u64), Error> { let update_leaves_count = lock_hashes.len(); let registry_state = check_lock_hashes_registered(lock_hashes.clone())?.0; if registry_state == RegistryState::WithCCID { @@ -36,6 +36,7 @@ pub async fn generate_registry_smt( smt_root, account_num, } = get_registry_info().await?; + let output_account_num = account_num + lock_hashes.len() as u64; for (index, lock_hash) in lock_hashes.into_iter().enumerate() { let key: H256 = H256::from(lock_hash); registry_value[0..8].copy_from_slice(&(account_num + index as u64).to_be_bytes()); @@ -103,7 +104,7 @@ pub async fn generate_registry_smt( let registry_entry = hex::encode(registry_entries.as_slice()); - Ok((root_hash, registry_entry)) + Ok((root_hash, registry_entry, output_account_num)) } fn with_lock(mut operator: F) -> Result<(), Error>