Skip to content

Commit f924e6f

Browse files
committed
feat(wasm-dpp): use u64 (bigint) when possible
1 parent f0984e9 commit f924e6f

File tree

7 files changed

+45
-48
lines changed

7 files changed

+45
-48
lines changed

packages/wasm-dpp/src/data_contract/data_contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ impl DataContractWasm {
313313
}
314314

315315
#[wasm_bindgen(js_name=setIdentityNonce)]
316-
pub fn set_identity_nonce(&mut self, e: u64) -> Result<(), JsValue> {
317-
self.identity_nonce = Some(e);
316+
pub fn set_identity_nonce(&mut self, nonce: u64) -> Result<(), JsValue> {
317+
self.identity_nonce = Some(nonce);
318318
Ok(())
319319
}
320320

packages/wasm-dpp/src/document/state_transition/document_batch_transition/document_transition/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use dpp::{
1717
use serde::Serialize;
1818
use serde_json::Value as JsonValue;
1919
use wasm_bindgen::prelude::*;
20+
use dpp::prelude::Revision;
2021
use dpp::fee::Credits;
2122
use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter;
2223
use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
@@ -95,12 +96,8 @@ impl DocumentTransitionWasm {
9596
}
9697

9798
#[wasm_bindgen(js_name=getRevision)]
98-
pub fn get_revision(&self) -> JsValue {
99-
if let Some(revision) = self.0.revision() {
100-
(revision as f64).into()
101-
} else {
102-
JsValue::NULL
103-
}
99+
pub fn get_revision(&self) -> Option<Revision> {
100+
self.0.revision()
104101
}
105102
#[wasm_bindgen(js_name=getEntropy)]
106103
pub fn get_entropy(&self) -> Option<Vec<u8>> {

packages/wasm-dpp/src/document/state_transition/document_batch_transition/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ impl DocumentsBatchTransitionWasm {
138138
}
139139

140140
#[wasm_bindgen(js_name=setIdentityContractNonce)]
141-
pub fn set_identity_contract_nonce(&mut self, nonce: u32) {
142-
self.0.set_identity_contract_nonce(nonce as u64);
141+
pub fn set_identity_contract_nonce(&mut self, nonce: u64) {
142+
self.0.set_identity_contract_nonce(nonce);
143143
}
144144

145145
// #[wasm_bindgen(js_name=toJSON)]

packages/wasm-dpp/src/errors/consensus/fee/balance_is_not_enough_error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ impl BalanceIsNotEnoughErrorWasm {
2929
}
3030

3131
#[wasm_bindgen(js_name=getBalance)]
32-
pub fn get_balance(&self) -> f64 {
33-
self.inner.balance() as f64
32+
pub fn get_balance(&self) -> u64 {
33+
self.inner.balance()
3434
}
3535

3636
#[wasm_bindgen(js_name=getFee)]
37-
pub fn get_fee(&self) -> f64 {
38-
self.inner.fee() as f64
37+
pub fn get_fee(&self) -> u64 {
38+
self.inner.fee() as u64
3939
}
4040

4141
#[wasm_bindgen(js_name=getCode)]

packages/wasm-dpp/src/identity/identity.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,38 @@ impl IdentityWasm {
105105
}
106106

107107
#[wasm_bindgen(getter)]
108-
pub fn balance(&self) -> f64 {
109-
self.inner.balance() as f64
108+
pub fn balance(&self) -> u64 {
109+
self.inner.balance()
110110
}
111111

112112
#[wasm_bindgen(js_name=getBalance)]
113-
pub fn get_balance(&self) -> f64 {
114-
self.inner.balance() as f64
113+
pub fn get_balance(&self) -> u64 {
114+
self.inner.balance()
115115
}
116116

117117
#[wasm_bindgen(js_name=setBalance)]
118-
pub fn set_balance(&mut self, balance: f64) {
119-
self.inner.set_balance(balance as u64);
118+
pub fn set_balance(&mut self, balance: u64) {
119+
self.inner.set_balance(balance);
120120
}
121121

122122
#[wasm_bindgen(js_name=increaseBalance)]
123-
pub fn increase_balance(&mut self, amount: f64) -> f64 {
124-
self.inner.increase_balance(amount as u64) as f64
123+
pub fn increase_balance(&mut self, amount: u64) -> u64 {
124+
self.inner.increase_balance(amount)
125125
}
126126

127127
#[wasm_bindgen(js_name=reduceBalance)]
128-
pub fn reduce_balance(&mut self, amount: f64) -> f64 {
129-
self.inner.reduce_balance(amount as u64) as f64
128+
pub fn reduce_balance(&mut self, amount: u64) -> u64 {
129+
self.inner.reduce_balance(amount)
130130
}
131131

132132
#[wasm_bindgen(js_name=setRevision)]
133-
pub fn set_revision(&mut self, revision: f64) {
134-
self.inner.set_revision(revision as u64);
133+
pub fn set_revision(&mut self, revision: u64) {
134+
self.inner.set_revision(revision);
135135
}
136136

137137
#[wasm_bindgen(js_name=getRevision)]
138-
pub fn get_revision(&self) -> f64 {
139-
self.inner.revision() as f64
138+
pub fn get_revision(&self) -> u64 {
139+
self.inner.revision() as u64
140140
}
141141

142142
#[wasm_bindgen(js_name=setMetadata)]

packages/wasm-dpp/src/identity/state_transition/identity_credit_transfer_transition/transition.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ impl IdentityCreditTransferTransitionWasm {
9090
}
9191

9292
#[wasm_bindgen(js_name=getAmount)]
93-
pub fn get_amount(&self) -> f64 {
94-
self.0.amount() as f64
93+
pub fn get_amount(&self) -> u64 {
94+
self.0.amount()
9595
}
9696

9797
#[wasm_bindgen(js_name=setAmount)]
98-
pub fn set_amount(&mut self, amount: f64) {
99-
self.0.set_amount(amount as u64);
98+
pub fn set_amount(&mut self, amount: u64) {
99+
self.0.set_amount(amount);
100100
}
101101

102102
#[wasm_bindgen(js_name=getUserFeeIncrease)]
@@ -181,7 +181,7 @@ impl IdentityCreditTransferTransitionWasm {
181181
js_sys::Reflect::set(
182182
&js_object,
183183
&"amount".to_owned().into(),
184-
&JsValue::from_f64(object.amount as f64),
184+
&JsValue::bigint_from_str(&object.amount.to_string()),
185185
)?;
186186

187187
Ok(js_object.into())
@@ -256,7 +256,7 @@ impl IdentityCreditTransferTransitionWasm {
256256
js_sys::Reflect::set(
257257
&js_object,
258258
&"amount".to_owned().into(),
259-
&JsValue::from_f64(object.amount as f64),
259+
&JsValue::bigint_from_str(&object.amount.to_string()),
260260
)?;
261261

262262
Ok(js_object.into())

packages/wasm-dpp/src/metadata.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ impl MetadataWasm {
3737
pub fn new(options: JsValue) -> Result<MetadataWasm, JsValue> {
3838
let metadata_options = options.with_serde_to_json_value()?;
3939
let block_height = metadata_options
40-
.get_f64("blockHeight")
40+
.get_u64("blockHeight")
4141
.map_err(|e| JsError::new(&e.to_string()))?;
4242
let core_chain_locked_height = metadata_options
43-
.get_f64("coreChainLockedHeight")
43+
.get_u32("coreChainLockedHeight")
4444
.map_err(|e| JsError::new(&e.to_string()))?;
4545
let time_ms = metadata_options
46-
.get_f64("timeMs")
46+
.get_u64("timeMs")
4747
.map_err(|e| JsError::new(&e.to_string()))?;
4848
let protocol_version = metadata_options
49-
.get_f64("protocolVersion")
49+
.get_u32("protocolVersion")
5050
.map_err(|e| JsError::new(&e.to_string()))?;
5151

5252
let inner = Metadata {
53-
block_height: block_height as u64,
53+
block_height: block_height,
5454
core_chain_locked_height: core_chain_locked_height as u64,
55-
time_ms: time_ms as u64,
55+
time_ms: time_ms,
5656
protocol_version: protocol_version as u64 as ProtocolVersion,
5757
};
5858
Ok(inner.into())
@@ -77,22 +77,22 @@ impl MetadataWasm {
7777
}
7878

7979
#[wasm_bindgen(js_name=getBlockHeight)]
80-
pub fn block_height(&self) -> f64 {
81-
self.0.block_height as f64
80+
pub fn block_height(&self) -> u64 {
81+
self.0.block_height
8282
}
8383

8484
#[wasm_bindgen(js_name=getCoreChainLockedHeight)]
85-
pub fn core_chain_locked_height(&self) -> f64 {
86-
self.0.core_chain_locked_height as f64
85+
pub fn core_chain_locked_height(&self) -> u32 {
86+
self.0.core_chain_locked_height as u32
8787
}
8888

8989
#[wasm_bindgen(js_name=getTimeMs)]
90-
pub fn time_ms(&self) -> f64 {
91-
self.0.time_ms as f64
90+
pub fn time_ms(&self) -> u64 {
91+
self.0.time_ms as u64
9292
}
9393

9494
#[wasm_bindgen(js_name=getProtocolVersion)]
95-
pub fn protocol_version(&self) -> f64 {
96-
self.0.protocol_version as f64
95+
pub fn protocol_version(&self) -> u32 {
96+
self.0.protocol_version as u32
9797
}
9898
}

0 commit comments

Comments
 (0)