-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
peer-store, wasm: use path
as database name in wasm peer-store implementation
#4760
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ pub async fn get_db<P: AsRef<Path>>(path: P) -> &'static Storage { | |
DB.get_or_init(|| Storage::new(path)).await | ||
} | ||
|
||
const STORE_NAME: &str = "main-store"; | ||
|
||
#[derive(Clone)] | ||
pub struct Storage { | ||
chan: tokio::sync::mpsc::Sender<Request>, | ||
|
@@ -67,15 +69,14 @@ pub struct Storage { | |
impl Storage { | ||
pub async fn new<P: AsRef<Path>>(path: P) -> Self { | ||
let factory = Factory::new().unwrap(); | ||
let mut open_request = factory.open("network", Some(1)).unwrap(); | ||
let store_name = path.as_ref().to_str().unwrap().to_owned(); | ||
let store_name_clone = store_name.clone(); | ||
let database_name = path.as_ref().to_str().unwrap().to_owned(); | ||
let mut open_request = factory.open(&database_name, Some(1)).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, wasm target‘s secret_key isn't stored on this path. The user manually passes it to ckb |
||
open_request.on_upgrade_needed(move |event| { | ||
let database = event.database().unwrap(); | ||
let store_params = ObjectStoreParams::new(); | ||
|
||
let store = database | ||
.create_object_store(&store_name_clone, store_params) | ||
.create_object_store(STORE_NAME, store_params) | ||
.unwrap(); | ||
let mut index_params = IndexParams::new(); | ||
index_params.unique(true); | ||
|
@@ -92,9 +93,9 @@ impl Storage { | |
match request.cmd { | ||
CommandRequest::Read { key } => { | ||
let tran = db | ||
.transaction(&[&store_name], TransactionMode::ReadOnly) | ||
.transaction(&[STORE_NAME], TransactionMode::ReadOnly) | ||
.unwrap(); | ||
let store = tran.object_store(&store_name).unwrap(); | ||
let store = tran.object_store(STORE_NAME).unwrap(); | ||
let key = serde_wasm_bindgen::to_value(&key).unwrap(); | ||
let value = store | ||
.get(key) | ||
|
@@ -107,9 +108,9 @@ impl Storage { | |
} | ||
CommandRequest::Put { kv } => { | ||
let tran = db | ||
.transaction(&[&store_name], TransactionMode::ReadWrite) | ||
.transaction(&[STORE_NAME], TransactionMode::ReadWrite) | ||
.unwrap(); | ||
let store = tran.object_store(&store_name).unwrap(); | ||
let store = tran.object_store(STORE_NAME).unwrap(); | ||
|
||
let key = serde_wasm_bindgen::to_value(&kv.key).unwrap(); | ||
let value = serde_wasm_bindgen::to_value(&kv).unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path needs to be added with the network name. No matter what network is passed in, the same path is used now.
By the way,if we use
network
with DB name, a different path as the object store name, is it ok?(I think the current problem is that the path is the same value regardless of the network.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.