Skip to content

Commit

Permalink
PR review, align to current wasm-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Dec 12, 2024
1 parent 9c6493c commit 6a7b71c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 27 deletions.
21 changes: 10 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion grpc/tests/tonic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
//! gRPC tests

use celestia_grpc::types::auth::Account;
use celestia_grpc::types::tx::sign_tx;
Expand Down
1 change: 0 additions & 1 deletion grpc/tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
//! Utilities for grpc tests

use std::{env, fs};

Expand Down
2 changes: 1 addition & 1 deletion node-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tokio = { version = "1.38.0", features = ["sync"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["time"] }
tracing-web = "0.1.3"
wasm-bindgen = "0.2.95"
wasm-bindgen = "0.2.93"
wasm-bindgen-futures = "0.4.43"
web-sys = { version = "0.3.70", features = [
"BroadcastChannel",
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pin-project = "1.1.5"
rexie = "0.6.2"
send_wrapper = { version = "0.6.0", features = ["futures"] }
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = "0.2.97"
wasm-bindgen = "0.2.93"
wasm-bindgen-futures = "0.4.43"
libp2p-websocket-websys = "0.3.3"

Expand Down
4 changes: 2 additions & 2 deletions rpc/tests/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;
use celestia_rpc::blob::BlobsAtHeight;
use celestia_rpc::prelude::*;
use celestia_types::consts::appconsts::AppVersion;
use celestia_types::Blob;
use celestia_types::{Blob, Commitment};
use jsonrpsee::core::client::Subscription;

pub mod utils;
Expand Down Expand Up @@ -194,7 +194,7 @@ async fn blob_get_get_proof_wrong_commitment() {
let namespace = random_ns();
let data = random_bytes(5);
let blob = Blob::new(namespace, data, AppVersion::V2).unwrap();
let commitment = random_bytes_array().into();
let commitment = Commitment::new(random_bytes_array());

let submitted_height = blob_submit(&client, &[blob.clone()]).await.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion types/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod tests {
#[test]
fn validate_blob_commitment_mismatch() {
let mut blob = sample_blob();
blob.commitment = [7; 32].into();
blob.commitment = Commitment::new([7; 32]);

blob.validate(AppVersion::V2).unwrap_err();
}
Expand Down
14 changes: 7 additions & 7 deletions types/src/blob/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use crate::nmt::{Namespace, NamespacedHashExt, NamespacedSha2Hasher, Nmt, RawNam
use crate::{Error, Result};
use crate::{InfoByte, Share};

// TODO: once https://github.com/rustwasm/wasm-bindgen/pull/4351 is merged,
// this can be replaced with a single common type definition
/// A merkle hash used to identify the [`Blob`]s data.
///
/// In Celestia network, the transaction which pays for the blob's inclusion
Expand Down Expand Up @@ -56,11 +58,15 @@ use crate::{InfoByte, Share};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Commitment {
/// hash of the commitment
#[cfg_attr(all(feature = "wasm-bindgen", target_arch = "wasm32"), wasm_bindgen(skip))]
hash: merkle::Hash,
}

impl Commitment {
/// Create a new commitment with hash
pub fn new(hash: merkle::Hash) -> Self {
Commitment { hash }
}

/// Generate the share commitment from the given blob data.
pub fn from_blob(
namespace: Namespace,
Expand Down Expand Up @@ -133,12 +139,6 @@ impl From<Commitment> for merkle::Hash {
}
}

impl From<merkle::Hash> for Commitment {
fn from(hash: merkle::Hash) -> Self {
Commitment { hash }
}
}

impl Serialize for Commitment {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
4 changes: 2 additions & 2 deletions types/src/blob/msg_pay_for_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl From<MsgPayForBlobs> for RawMsgPayForBlobs {
let share_commitments = msg
.share_commitments
.into_iter()
.map(|c| Hash::from(c).to_vec())
.map(|c| c.hash().to_vec())
.collect();

RawMsgPayForBlobs {
Expand All @@ -108,7 +108,7 @@ impl TryFrom<RawMsgPayForBlobs> for MsgPayForBlobs {
.into_iter()
.map(|c| {
let hash = Hash::try_from(c).map_err(|_| Error::InvalidComittmentLength)?;
Ok(hash.into())
Ok(Commitment::new(hash))
})
.collect::<Result<_, Error>>()?;

Expand Down

0 comments on commit 6a7b71c

Please sign in to comment.