Skip to content

Commit 03d0a45

Browse files
quantumquantum
authored andcommitted
fixes
1 parent 422e728 commit 03d0a45

File tree

9 files changed

+61
-29
lines changed

9 files changed

+61
-29
lines changed

packages/dapi-grpc/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,17 @@ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", vers
4343

4444
prost = { version = "0.13" }
4545
futures-core = "0.3.30"
46-
tonic = { version = "0.13.0", features = [
47-
"codegen",
48-
"prost",
49-
"tls-ring",
50-
], default-features = false }
5146
serde = { version = "1.0.219", optional = true, features = ["derive"] }
5247
serde_bytes = { version = "0.11.12", optional = true }
5348
serde_json = { version = "1.0", optional = true }
5449
dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
5550
platform-version = { path = "../rs-platform-version" }
5651

5752
[target.'cfg(target_arch = "wasm32")'.dependencies]
53+
tonic = { version = "0.13.0", features = [
54+
"codegen",
55+
"prost",
56+
], default-features = false }
5857
getrandom = { version = "0.2", features = ["js"] }
5958

6059
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

packages/rs-dapi-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ gloo-timers = { version = "0.3.0", features = ["futures"] }
3131
tonic-web-wasm-client = { version = "0.7.0" }
3232
wasm-bindgen-futures = { version = "0.4.49" }
3333
getrandom = { version = "0.2", features = ["js"] }
34+
tower-service = { version = "0.3" }
35+
http-body-util = { version = "0.1" }
3436

3537
[dependencies]
3638
backon = { version = "1.3", default-features = false }

packages/rs-dapi-client/src/transport/wasm_channel.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,27 @@ impl WasmClient {
4343
}
4444
}
4545

46-
impl tonic::client::GrpcService<tonic::body::BoxBody> for WasmClient {
46+
47+
impl tonic::client::GrpcService<tonic::body::Body> for WasmClient {
4748
type Future = BoxFuture<'static, Result<http::Response<Self::ResponseBody>, Self::Error>>;
48-
type ResponseBody = tonic::body::BoxBody;
49+
type ResponseBody = tonic::body::Body;
4950
type Error = Status;
5051

51-
fn call(&mut self, request: http::Request<tonic::body::BoxBody>) -> Self::Future {
52+
fn call(&mut self, request: http::Request<tonic::body::Body>) -> Self::Future {
5253
let mut client = self.client.clone();
53-
let fut = client.call(request).map(|res| match res {
54-
Ok(resp) => {
55-
let body = tonic::body::boxed(resp.into_body());
56-
Ok(Response::new(body))
54+
55+
let fut = async move {
56+
match client.call(request).await {
57+
Ok(resp) => {
58+
let (parts, body) = resp.into_parts();
59+
let tonic_body = tonic::body::Body::new(body);
60+
Ok(Response::from_parts(parts, tonic_body))
61+
}
62+
Err(e) => Err(wasm_client_error_to_status(e)),
5763
}
58-
Err(e) => Err(wasm_client_error_to_status(e)),
59-
});
64+
};
6065

66+
// For WASM, we need to use into_send to make the future Send
6167
into_send(fut)
6268
}
6369

packages/wasm-sdk/Cargo.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[workspace]
2+
members = ["."]
3+
14
[package]
25
name = "wasm-sdk"
36
edition = "2021"
@@ -7,7 +10,7 @@ publish = false
710
crate-type = ["cdylib"]
811

912
[dependencies]
10-
dash-sdk = { path = "../rs-sdk", default-features = false }
13+
dash-sdk = { path = "../rs-sdk", default-features = false, features = ["mocks"] }
1114
console_error_panic_hook = { version = "0.1.6" }
1215
thiserror = { version = "2.0.12" }
1316
web-sys = { version = "0.3.4", features = [
@@ -20,7 +23,7 @@ web-sys = { version = "0.3.4", features = [
2023
] }
2124
wasm-bindgen = { version = "=0.2.100" }
2225
wasm-bindgen-futures = { version = "0.4.49" }
23-
drive-proof-verifier = { path = "../rs-drive-proof-verifier" } # TODO: I think it's not needed (LKl)
26+
drive-proof-verifier = { path = "../rs-drive-proof-verifier", default-features = false } # TODO: I think it's not needed (LKl)
2427
# tonic = { version = "*", features = ["transport"], default-features = false }
2528
# client = [
2629
# "tonic/channel", FAIL
@@ -30,17 +33,22 @@ drive-proof-verifier = { path = "../rs-drive-proof-verifier" } # TODO: I think i
3033
# "tonic/tls-webpki-roots",
3134
# "platform",
3235
# ]
33-
tracing-wasm = { version = "0.2.1" }
36+
# tracing-wasm = { version = "0.2.1" }
3437
wee_alloc = "0.4"
3538
platform-value = { path = "../rs-platform-value", features = ["json"] }
3639
serde-wasm-bindgen = { version = "0.6.5" }
40+
getrandom = { version = "0.2", features = ["js"] }
3741

3842
[profile.release]
39-
lto = "fat"
4043
opt-level = "z"
4144
panic = "abort"
4245
debug = false
46+
lto = false
4347

4448
#[package.metadata.wasm-pack.profile.release]
4549
#wasm-opt = ['-g', '-O'] # -g for profiling
4650
# -Oz -Oz -g
51+
52+
[patch.crates-io]
53+
# Override ring to use the wasm-compatible version
54+
ring = { git = "https://github.com/briansmith/ring", branch = "main" }

packages/wasm-sdk/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
set -ex -o pipefail
99

10+
# Disable LTO for WebAssembly builds
11+
export CARGO_PROFILE_RELEASE_LTO=false
12+
export RUSTFLAGS="-C lto=off"
13+
1014
wasm-pack build --target web --release --no-opt
1115
wasm-opt -tnh --flatten --rereloop -Oz --gufa -Oz --gufa -Oz -o pkg/optimized.wasm pkg/wasm_sdk_bg.wasm
1216
ls -lah pkg

packages/wasm-sdk/src/context_provider.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use dash_sdk::{
44
dpp::{
55
prelude::CoreBlockHeight,
66
util::vec::{decode_hex, encode_hex},
7+
version::PlatformVersion,
8+
data_contract::TokenConfiguration,
79
},
810
error::ContextProviderError,
911
platform::{DataContract, Identifier},
1012
};
11-
use drive_proof_verifier::ContextProvider;
13+
use dash_sdk::platform::ContextProvider;
1214
use wasm_bindgen::prelude::wasm_bindgen;
1315

1416
#[wasm_bindgen]
@@ -91,10 +93,18 @@ impl ContextProvider for WasmContext {
9193
fn get_data_contract(
9294
&self,
9395
_id: &Identifier,
96+
_platform_version: &PlatformVersion,
9497
) -> Result<Option<Arc<DataContract>>, ContextProviderError> {
9598
todo!()
9699
}
97100

101+
fn get_token_configuration(
102+
&self,
103+
_token_id: &Identifier,
104+
) -> Result<Option<TokenConfiguration>, ContextProviderError> {
105+
todo!()
106+
}
107+
98108
fn get_platform_activation_height(&self) -> Result<CoreBlockHeight, ContextProviderError> {
99109
todo!()
100110
}

packages/wasm-sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub async fn start() -> Result<(), JsValue> {
1818
// * https://crates.io/crates/tracing-web
1919
console_error_panic_hook::set_once();
2020

21-
tracing_wasm::set_as_global_default();
21+
// tracing_wasm::set_as_global_default();
2222

2323
Ok(())
2424
}

packages/wasm-sdk/src/sdk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub async fn docs_testing(sdk: &WasmSdk) {
184184
.document_type_for_name("aaa")
185185
.expect("document type for name");
186186
let doc_serialized = doc
187-
.serialize(document_type, sdk.version())
187+
.serialize(document_type, &dc, sdk.version())
188188
.expect("serialize document");
189189

190190
let msg = js_sys::JsString::from_str(&format!("{:?} {:?} ", dcs, doc_serialized))

packages/wasm-sdk/src/state_transitions/documents.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use crate::error::to_js_error;
22
use dash_sdk::dpp::identity::KeyID;
33
use dash_sdk::dpp::serialization::PlatformSerializable;
4-
use dash_sdk::dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0;
5-
use dash_sdk::dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
6-
use dash_sdk::dpp::state_transition::documents_batch_transition::document_create_transition::DocumentCreateTransitionV0;
7-
use dash_sdk::dpp::state_transition::documents_batch_transition::document_transition::DocumentTransition;
8-
use dash_sdk::dpp::state_transition::documents_batch_transition::{
9-
DocumentCreateTransition, DocumentsBatchTransition, DocumentsBatchTransitionV0,
4+
use dash_sdk::dpp::state_transition::StateTransition;
5+
use dash_sdk::dpp::state_transition::batch_transition::batched_transition::document_base_transition::v0::DocumentBaseTransitionV0;
6+
use dash_sdk::dpp::state_transition::batch_transition::batched_transition::document_base_transition::DocumentBaseTransition;
7+
use dash_sdk::dpp::state_transition::batch_transition::batched_transition::document_create_transition::DocumentCreateTransitionV0;
8+
use dash_sdk::dpp::state_transition::batch_transition::batched_transition::document_transition::DocumentTransition;
9+
use dash_sdk::dpp::state_transition::batch_transition::{
10+
document_create_transition::DocumentCreateTransition, BatchTransition, BatchTransitionV0,
1011
};
1112
use wasm_bindgen::prelude::*;
1213
use web_sys::js_sys::{Number, Uint8Array};
@@ -60,15 +61,17 @@ fn create_batch_transition(
6061
)));
6162
};
6263

63-
let document_batch_transition = DocumentsBatchTransition::V0(DocumentsBatchTransitionV0 {
64+
let document_batch_transition = BatchTransition::V0(BatchTransitionV0 {
6465
owner_id: Default::default(),
6566
transitions,
6667
user_fee_increase: 0,
6768
signature_public_key_id,
6869
signature: Default::default(),
6970
});
7071

71-
document_batch_transition
72+
let state_transition: StateTransition = document_batch_transition.into();
73+
74+
state_transition
7275
.serialize_to_bytes()
7376
.map_err(to_js_error)
7477
.map(|bytes| Uint8Array::from(bytes.as_slice()))

0 commit comments

Comments
 (0)