Skip to content

Commit 78a2890

Browse files
authored
Merge pull request #2821 from input-output-hk/djo/2758/stabilize-cdb-v2-phase4-client-wasm
feat: stabilize cardano database v2 - phase4 - wasm client
2 parents 1591ba9 + d51e440 commit 78a2890

File tree

9 files changed

+878
-127
lines changed

9 files changed

+878
-127
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ As a minor extension, we have adopted a slightly different versioning convention
1010
## Mithril Distribution [XXXX] - UNRELEASED
1111

1212
- Client library, CLI and WASM:
13-
- **DEPRECATED**: The `cardano_db` function have been deprecated and the `snapshot` function was removed in the `Client` struct of the library.
13+
- Support for stable cardano database v2 methods in the client WASM library.
14+
15+
- **DEPRECATED**: The `cardano_db` function has been deprecated and the `snapshot` function was removed in the `Client` struct of the library, there WASM counterparts were deprecated too.
1416

1517
- **DEPRECATED**: The flag `--backend v1` of the `cardano-db` command has been deprecated CLI, use the `--backend v2` instead.
1618

@@ -32,7 +34,7 @@ As a minor extension, we have adopted a slightly different versioning convention
3234
- Client library, CLI and WASM:
3335
- **DEPRECATED**: The `with_aggregator_client` and `new` functions have been deprecated in the `ClientBuilder` struct of the library.
3436

35-
- Support for default incremental backend (`v2`) for Cardano database restoration in the client library, CLI and WASM.
37+
- Support for default incremental backend (`v2`) for Cardano database restoration in the client library and CLI.
3638

3739
- Enhanced verification of a Cardano database which now provides a list of tampered and missing files in case of failure.
3840

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-wasm-nodejs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/client-wasm-web/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-client-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-wasm"
3-
version = "0.9.7"
3+
version = "0.9.8"
44
description = "Mithril client WASM"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-wasm/ci-test/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-client-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mithril-dev/mithril-client-wasm",
3-
"version": "0.9.7",
3+
"version": "0.9.8",
44
"description": "Mithril client WASM",
55
"license": "Apache-2.0",
66
"collaborators": [

mithril-client-wasm/src/client_wasm.rs

Lines changed: 73 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,12 @@ impl MithrilClient {
158158
)))
159159
}
160160

161-
#[deprecated(since = "0.8.4", note = "supersede by `get_cardano_database_snapshot`")]
162-
/// Call the client to get a snapshot from a digest
163-
#[wasm_bindgen]
164-
pub async fn get_snapshot(&self, digest: &str) -> WasmResult {
165-
self.get_cardano_database_snapshot(digest).await
166-
}
167-
168161
/// Call the client to get a snapshot from a digest
162+
///
163+
/// @deprecated superseded by `get_cardano_database_v2_snapshot`
169164
#[wasm_bindgen]
170165
pub async fn get_cardano_database_snapshot(&self, digest: &str) -> WasmResult {
166+
#[allow(deprecated)]
171167
let result = self
172168
.client
173169
.cardano_database()
@@ -181,29 +177,81 @@ impl MithrilClient {
181177
Ok(serde_wasm_bindgen::to_value(&result)?)
182178
}
183179

184-
#[deprecated(
185-
since = "0.8.4",
186-
note = "supersede by `list_cardano_database_snapshots`"
187-
)]
188180
/// Call the client to get the list of available snapshots
181+
///
182+
/// @deprecated superseded by `list_cardano_database_v2`
189183
#[wasm_bindgen]
190-
pub async fn list_snapshots(&self) -> WasmResult {
191-
self.list_cardano_database_snapshots().await
184+
pub async fn list_cardano_database_snapshots(&self) -> WasmResult {
185+
#[allow(deprecated)]
186+
let result = self
187+
.client
188+
.cardano_database()
189+
.list()
190+
.await
191+
.map_err(|err| format!("{err:?}"))?;
192+
193+
Ok(serde_wasm_bindgen::to_value(&result)?)
192194
}
193195

194-
/// Call the client to get the list of available snapshots
196+
/// Call the client to get a cardano database snapshot from a hash
195197
#[wasm_bindgen]
196-
pub async fn list_cardano_database_snapshots(&self) -> WasmResult {
198+
pub async fn get_cardano_database_v2(&self, hash: &str) -> WasmResult {
197199
let result = self
198200
.client
199-
.cardano_database()
201+
.cardano_database_v2()
202+
.get(hash)
203+
.await
204+
.map_err(|err| format!("{err:?}"))?
205+
.ok_or(JsValue::from_str(&format!(
206+
"No cardano database snapshot found for hash: '{hash}'"
207+
)))?;
208+
209+
Ok(serde_wasm_bindgen::to_value(&result)?)
210+
}
211+
212+
/// Call the client for the list of available cardano database snapshots
213+
#[wasm_bindgen]
214+
pub async fn list_cardano_database_v2(&self) -> WasmResult {
215+
let result = self
216+
.client
217+
.cardano_database_v2()
200218
.list()
201219
.await
202220
.map_err(|err| format!("{err:?}"))?;
203221

204222
Ok(serde_wasm_bindgen::to_value(&result)?)
205223
}
206224

225+
/// Call the client for the list of available cardano database snapshots for a given epoch
226+
#[wasm_bindgen]
227+
pub async fn list_cardano_database_v2_per_epoch(&self, epoch: u64) -> WasmResult {
228+
let result = self
229+
.client
230+
.cardano_database_v2()
231+
.list_by_epoch(Epoch(epoch))
232+
.await
233+
.map_err(|err| format!("{err:?}"))?;
234+
235+
Ok(serde_wasm_bindgen::to_value(&result)?)
236+
}
237+
238+
/// Call the client for the list of available cardano database snapshots for the latest epoch
239+
///
240+
/// An optional offset can be provided
241+
#[wasm_bindgen]
242+
pub async fn list_cardano_database_v2_for_latest_epoch(&self, param: JsValue) -> WasmResult {
243+
let options = LatestEpochOptions::parse_from_js_value(param)?;
244+
let client = self.client.cardano_database_v2();
245+
246+
let result = match options.offset {
247+
None => client.list_for_latest_epoch().await,
248+
Some(offset) => client.list_for_latest_epoch_with_offset(offset).await,
249+
}
250+
.map_err(|err| format!("{err:?}"))?;
251+
252+
Ok(serde_wasm_bindgen::to_value(&result)?)
253+
}
254+
207255
/// Call the client to get a mithril stake distribution from a hash
208256
#[wasm_bindgen]
209257
pub async fn get_mithril_stake_distribution(&self, hash: &str) -> WasmResult {
@@ -493,80 +541,6 @@ impl MithrilClient {
493541
Ok(())
494542
}
495543

496-
/// Call the client to get a cardano database snapshot from a hash
497-
///
498-
/// Warning: this function is unstable and may be modified in the future
499-
#[wasm_bindgen]
500-
pub async fn get_cardano_database_v2(&self, hash: &str) -> WasmResult {
501-
self.guard_unstable()?;
502-
503-
let result = self
504-
.client
505-
.cardano_database_v2()
506-
.get(hash)
507-
.await
508-
.map_err(|err| format!("{err:?}"))?
509-
.ok_or(JsValue::from_str(&format!(
510-
"No cardano database snapshot found for hash: '{hash}'"
511-
)))?;
512-
513-
Ok(serde_wasm_bindgen::to_value(&result)?)
514-
}
515-
516-
/// Call the client for the list of available cardano database snapshots
517-
///
518-
/// Warning: this function is unstable and may be modified in the future
519-
#[wasm_bindgen]
520-
pub async fn list_cardano_database_v2(&self) -> WasmResult {
521-
self.guard_unstable()?;
522-
523-
let result = self
524-
.client
525-
.cardano_database_v2()
526-
.list()
527-
.await
528-
.map_err(|err| format!("{err:?}"))?;
529-
530-
Ok(serde_wasm_bindgen::to_value(&result)?)
531-
}
532-
533-
/// Call the client for the list of available cardano database snapshots for a given epoch
534-
///
535-
/// Warning: this function is unstable and may be modified in the future
536-
#[wasm_bindgen]
537-
pub async fn list_cardano_database_v2_per_epoch(&self, epoch: u64) -> WasmResult {
538-
self.guard_unstable()?;
539-
540-
let result = self
541-
.client
542-
.cardano_database_v2()
543-
.list_by_epoch(Epoch(epoch))
544-
.await
545-
.map_err(|err| format!("{err:?}"))?;
546-
547-
Ok(serde_wasm_bindgen::to_value(&result)?)
548-
}
549-
550-
/// Call the client for the list of available cardano database snapshots for the latest epoch
551-
///
552-
/// An optionnal offset can be provided
553-
///
554-
/// Warning: this function is unstable and may be modified in the future
555-
#[wasm_bindgen]
556-
pub async fn list_cardano_database_v2_for_latest_epoch(&self, param: JsValue) -> WasmResult {
557-
self.guard_unstable()?;
558-
let options = LatestEpochOptions::parse_from_js_value(param)?;
559-
let client = self.client.cardano_database_v2();
560-
561-
let result = match options.offset {
562-
None => client.list_for_latest_epoch().await,
563-
Some(offset) => client.list_for_latest_epoch_with_offset(offset).await,
564-
}
565-
.map_err(|err| format!("{err:?}"))?;
566-
567-
Ok(serde_wasm_bindgen::to_value(&result)?)
568-
}
569-
570544
/// `unstable` Reset the certificate verifier cache if enabled
571545
#[wasm_bindgen]
572546
pub async fn reset_certificate_verifier_cache(&self) -> Result<(), JsValue> {
@@ -693,11 +667,11 @@ mod tests {
693667
}
694668

695669
#[wasm_bindgen_test]
696-
async fn list_snapshots_should_return_value_convertible_in_rust_type() {
670+
async fn list_cardano_database_snapshots_should_return_value_convertible_in_rust_type() {
697671
let snapshots_list_js_value = get_mithril_client_stable()
698-
.list_snapshots()
672+
.list_cardano_database_snapshots()
699673
.await
700-
.expect("list_snapshots should not fail");
674+
.expect("list_cardano_database_snapshots should not fail");
701675
let snapshots_list =
702676
serde_wasm_bindgen::from_value::<Vec<SnapshotListItem>>(snapshots_list_js_value)
703677
.expect("conversion should not fail");
@@ -710,23 +684,23 @@ mod tests {
710684
}
711685

712686
#[wasm_bindgen_test]
713-
async fn get_snapshot_should_return_value_convertible_in_rust_type() {
687+
async fn get_cardano_database_snapshot_should_return_value_convertible_in_rust_type() {
714688
let snapshot_js_value = get_mithril_client_stable()
715-
.get_snapshot(test_data::snapshot_digests()[0])
689+
.get_cardano_database_snapshot(test_data::snapshot_digests()[0])
716690
.await
717-
.expect("get_snapshot should not fail");
691+
.expect("get_cardano_database_snapshot should not fail");
718692
let snapshot = serde_wasm_bindgen::from_value::<Snapshot>(snapshot_js_value)
719693
.expect("conversion should not fail");
720694

721695
assert_eq!(snapshot.digest, test_data::snapshot_digests()[0]);
722696
}
723697

724698
#[wasm_bindgen_test]
725-
async fn get_snapshot_should_fail_with_unknown_digest() {
699+
async fn get_cardano_database_snapshot_should_fail_with_unknown_digest() {
726700
get_mithril_client_stable()
727-
.get_snapshot("whatever")
701+
.get_cardano_database_snapshot("whatever")
728702
.await
729-
.expect_err("get_snapshot should fail");
703+
.expect_err("get_cardano_database_snapshot should fail");
730704
}
731705

732706
#[wasm_bindgen_test]

0 commit comments

Comments
 (0)