Skip to content

Commit e9b2a2a

Browse files
committed
style: fix formatting
1 parent 547937d commit e9b2a2a

File tree

24 files changed

+1506
-1191
lines changed

24 files changed

+1506
-1191
lines changed

packages/wasm-sdk/src/dpns.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,24 @@ impl WasmSdk {
5656
identity_id,
5757
dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58,
5858
)
59-
.map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?;
59+
.map_err(|e| WasmSdkError::invalid_argument(format!("Invalid identity ID: {}", e)))?;
6060

6161
// Fetch the identity
6262
let identity = Identity::fetch(self.as_ref(), identity_id_parsed)
6363
.await?
6464
.ok_or_else(|| WasmSdkError::not_found("Identity not found"))?;
6565

6666
// Create signer
67-
let signer = SingleKeySigner::new(private_key_wif)
68-
.map_err(|e| WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e)))?;
67+
let signer = SingleKeySigner::new(private_key_wif).map_err(|e| {
68+
WasmSdkError::invalid_argument(format!("Invalid private key WIF: {}", e))
69+
})?;
6970

7071
// Get the specific identity public key
7172
let identity_public_key = identity
7273
.get_public_key_by_id(public_key_id.into())
73-
.ok_or_else(|| WasmSdkError::not_found(format!("Public key with ID {} not found", public_key_id)))?
74+
.ok_or_else(|| {
75+
WasmSdkError::not_found(format!("Public key with ID {} not found", public_key_id))
76+
})?
7477
.clone();
7578

7679
// Store the JS callback in a thread-local variable that we can access from the closure
@@ -120,10 +123,7 @@ impl WasmSdk {
120123
};
121124

122125
// Register the name
123-
let result = self
124-
.as_ref()
125-
.register_dpns_name(input)
126-
.await?;
126+
let result = self.as_ref().register_dpns_name(input).await?;
127127

128128
// Clear the thread-local callback
129129
PREORDER_CALLBACK.with(|cb| {

packages/wasm-sdk/src/dpp.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use dash_sdk::dpp::platform_value::ReplacementType;
33
use dash_sdk::dpp::serialization::PlatformDeserializable;
44
use dash_sdk::dpp::serialization::ValueConvertible;
55

6+
use crate::WasmSdkError;
67
use dash_sdk::dpp::dashcore::hashes::serde::Serialize;
78
use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters;
89
use dash_sdk::dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
@@ -11,7 +12,6 @@ use dash_sdk::platform::{DataContract, Identity};
1112
use platform_value::string_encoding::Encoding;
1213
use wasm_bindgen::prelude::*;
1314
use web_sys::js_sys;
14-
use crate::WasmSdkError;
1515

1616
#[wasm_bindgen]
1717
#[derive(Clone)]
@@ -38,7 +38,11 @@ impl From<Identity> for IdentityWasm {
3838
impl IdentityWasm {
3939
#[wasm_bindgen(constructor)]
4040
pub fn new(platform_version: u32) -> Result<IdentityWasm, WasmSdkError> {
41-
let platform_version = &PlatformVersion::get(platform_version).map_err(|e| WasmSdkError::invalid_argument(format!("unknown platform version {platform_version}: {e}")))?;
41+
let platform_version = &PlatformVersion::get(platform_version).map_err(|e| {
42+
WasmSdkError::invalid_argument(format!(
43+
"unknown platform version {platform_version}: {e}"
44+
))
45+
})?;
4246

4347
let identity = Identity::default_versioned(platform_version)?;
4448

@@ -158,7 +162,9 @@ impl IdentityWasm {
158162

159163
#[wasm_bindgen(js_name=toJSON)]
160164
pub fn to_json(&self) -> Result<JsValue, WasmSdkError> {
161-
let mut value = self.inner.to_object().map_err(|e| WasmSdkError::serialization(format!("failed to convert identity to Object: {e}")))?;
165+
let mut value = self.inner.to_object().map_err(|e| {
166+
WasmSdkError::serialization(format!("failed to convert identity to Object: {e}"))
167+
})?;
162168

163169
value
164170
.replace_at_paths(
@@ -185,7 +191,8 @@ impl IdentityWasm {
185191
.map_err(|e| WasmSdkError::serialization(e.to_string()))?
186192
.to_string();
187193

188-
js_sys::JSON::parse(&json).map_err(|e| WasmSdkError::serialization(format!("failed to parse JSON: {:?}", e)))
194+
js_sys::JSON::parse(&json)
195+
.map_err(|e| WasmSdkError::serialization(format!("failed to parse JSON: {:?}", e)))
189196
}
190197
//
191198
// #[wasm_bindgen(js_name=toObject)]
@@ -262,7 +269,11 @@ impl IdentityWasm {
262269
#[wasm_bindgen(js_name=fromBuffer)]
263270
pub fn from_buffer(buffer: Vec<u8>) -> Result<IdentityWasm, WasmSdkError> {
264271
let identity: Identity = PlatformDeserializable::deserialize_from_bytes(buffer.as_slice())
265-
.map_err(|e| WasmSdkError::serialization(format!("failed to deserialize identity from bytes: {e}")))?;
272+
.map_err(|e| {
273+
WasmSdkError::serialization(format!(
274+
"failed to deserialize identity from bytes: {e}"
275+
))
276+
})?;
266277
Ok(identity.into())
267278
}
268279
}
@@ -302,11 +313,14 @@ impl DataContractWasm {
302313
pub fn to_json(&self) -> Result<JsValue, WasmSdkError> {
303314
let platform_version = PlatformVersion::first();
304315

305-
let json = self
306-
.0
307-
.to_json(platform_version)
308-
.map_err(|e| WasmSdkError::serialization(format!("failed to convert data contract convert to json: {}", e)))?;
316+
let json = self.0.to_json(platform_version).map_err(|e| {
317+
WasmSdkError::serialization(format!(
318+
"failed to convert data contract convert to json: {}",
319+
e
320+
))
321+
})?;
309322
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
310-
json.serialize(&serializer).map_err(|e| WasmSdkError::serialization(format!("can't serialize to json: {}", e)))
323+
json.serialize(&serializer)
324+
.map_err(|e| WasmSdkError::serialization(format!("can't serialize to json: {}", e)))
311325
}
312326
}

packages/wasm-sdk/src/error.rs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use dash_sdk::{error::StateTransitionBroadcastError, Error as SdkError};
21
use dash_sdk::dpp::ProtocolError;
2+
use dash_sdk::Error::{EpochNotFound, TotalCreditsNotFound};
3+
use dash_sdk::{error::StateTransitionBroadcastError, Error as SdkError};
34
use rs_dapi_client::CanRetry;
45
use std::fmt::Display;
56
use wasm_bindgen::prelude::wasm_bindgen;
6-
use dash_sdk::Error::{EpochNotFound, TotalCreditsNotFound};
77

88
/// Structured error surfaced to JS consumers
99
#[wasm_bindgen]
@@ -53,7 +53,12 @@ pub struct WasmSdkError {
5353
// wasm-bindgen getters defined below in the second impl block
5454

5555
impl WasmSdkError {
56-
fn new<M: Into<String>>(kind: WasmSdkErrorKind, message: M, code: Option<i32>, retriable: bool) -> Self {
56+
fn new<M: Into<String>>(
57+
kind: WasmSdkErrorKind,
58+
message: M,
59+
code: Option<i32>,
60+
retriable: bool,
61+
) -> Self {
5762
Self {
5863
kind,
5964
message: message.into(),
@@ -87,28 +92,46 @@ impl From<SdkError> for WasmSdkError {
8792
AlreadyExists(msg) => Self::new(WasmSdkErrorKind::AlreadyExists, msg, None, retriable),
8893
Config(msg) => Self::new(WasmSdkErrorKind::Config, msg, None, retriable),
8994
Drive(e) => Self::new(WasmSdkErrorKind::Drive, e.to_string(), None, retriable),
90-
DriveProofError(e, _proof, _block_info) => {
91-
Self::new(WasmSdkErrorKind::DriveProofError, e.to_string(), None, retriable)
92-
}
95+
DriveProofError(e, _proof, _block_info) => Self::new(
96+
WasmSdkErrorKind::DriveProofError,
97+
e.to_string(),
98+
None,
99+
retriable,
100+
),
93101
Protocol(e) => Self::new(WasmSdkErrorKind::Protocol, e.to_string(), None, retriable),
94102
Proof(e) => Self::new(WasmSdkErrorKind::Proof, e.to_string(), None, retriable),
95-
InvalidProvedResponse(msg) => {
96-
Self::new(WasmSdkErrorKind::InvalidProvedResponse, msg, None, retriable)
97-
}
98-
DapiClientError(e) => {
99-
Self::new(WasmSdkErrorKind::DapiClientError, e.to_string(), None, retriable)
100-
}
103+
InvalidProvedResponse(msg) => Self::new(
104+
WasmSdkErrorKind::InvalidProvedResponse,
105+
msg,
106+
None,
107+
retriable,
108+
),
109+
DapiClientError(e) => Self::new(
110+
WasmSdkErrorKind::DapiClientError,
111+
e.to_string(),
112+
None,
113+
retriable,
114+
),
101115
#[cfg(feature = "mocks")]
102-
DapiMocksError(e) => {
103-
Self::new(WasmSdkErrorKind::DapiMocksError, e.to_string(), None, retriable)
104-
}
116+
DapiMocksError(e) => Self::new(
117+
WasmSdkErrorKind::DapiMocksError,
118+
e.to_string(),
119+
None,
120+
retriable,
121+
),
105122
CoreError(e) => Self::new(WasmSdkErrorKind::CoreError, e.to_string(), None, retriable),
106-
MerkleBlockError(e) => {
107-
Self::new(WasmSdkErrorKind::MerkleBlockError, e.to_string(), None, retriable)
108-
}
109-
CoreClientError(e) => {
110-
Self::new(WasmSdkErrorKind::CoreClientError, e.to_string(), None, retriable)
111-
}
123+
MerkleBlockError(e) => Self::new(
124+
WasmSdkErrorKind::MerkleBlockError,
125+
e.to_string(),
126+
None,
127+
retriable,
128+
),
129+
CoreClientError(e) => Self::new(
130+
WasmSdkErrorKind::CoreClientError,
131+
e.to_string(),
132+
None,
133+
retriable,
134+
),
112135
MissingDependency(kind, id) => Self::new(
113136
WasmSdkErrorKind::MissingDependency,
114137
format!("Required {} not found: {}", kind, id),
@@ -129,7 +152,11 @@ impl From<SdkError> for WasmSdkError {
129152
),
130153
TimeoutReached(duration, msg) => Self::new(
131154
WasmSdkErrorKind::TimeoutReached,
132-
format!("SDK operation timeout {} secs reached: {}", duration.as_secs(), msg),
155+
format!(
156+
"SDK operation timeout {} secs reached: {}",
157+
duration.as_secs(),
158+
msg
159+
),
133160
None,
134161
retriable,
135162
),

packages/wasm-sdk/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ pub mod context_provider;
44
pub mod dpns;
55
pub mod dpp;
66
pub mod error;
7-
pub mod queries;
87
pub mod logging;
8+
pub mod queries;
99
pub mod sdk;
1010
pub mod state_transitions;
1111
pub mod verify;
1212
pub mod wallet;
1313

1414
// Re-export commonly used items
1515
pub use dpns::*;
16+
pub use error::{WasmSdkError, WasmSdkErrorKind};
1617
pub use queries::{
1718
data_contract::*, document::*, dpns::*, epoch::*, group::*, identity as query_identity,
1819
protocol::*, system::*, token::*, voting::*,
1920
};
2021
pub use sdk::{WasmSdk, WasmSdkBuilder};
2122
pub use state_transitions::identity as state_transition_identity;
2223
pub use wallet::*;
23-
pub use error::{WasmSdkError, WasmSdkErrorKind};
2424

2525
#[global_allocator]
2626
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

packages/wasm-sdk/src/logging.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ pub fn set_log_level(level_or_filter: &str) -> Result<(), WasmSdkError> {
5050
let _ = RELOAD_HANDLE.set(handle);
5151
Ok(())
5252
}
53-

0 commit comments

Comments
 (0)