From ae61f7f9ecbf0114bdec863cdb854bcc2e4e5372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Wed, 13 Nov 2024 20:09:33 -0600 Subject: [PATCH] Add rustdoc to public methods [skip ci] --- web-client/src/common/address.rs | 6 ++++++ web-client/src/common/hashed_time_locked_contract.rs | 3 +++ web-client/src/common/signature_proof.rs | 2 ++ web-client/src/common/staking_contract.rs | 3 +++ web-client/src/common/vesting_contract.rs | 3 +++ web-client/src/primitives/es256_public_key.rs | 5 +++++ web-client/src/primitives/private_key.rs | 1 + web-client/src/primitives/public_key.rs | 5 +++++ 8 files changed, 28 insertions(+) diff --git a/web-client/src/common/address.rs b/web-client/src/common/address.rs index 6430cb5e97..9e37e68625 100644 --- a/web-client/src/common/address.rs +++ b/web-client/src/common/address.rs @@ -87,16 +87,22 @@ impl Address { self.inner.to_hex() } + /// Returns the byte representation of the address. #[cfg(feature = "primitives")] pub fn serialize(&self) -> Vec { self.inner.serialize_to_vec() } + /// Returns if this address is equal to the other address. #[cfg(feature = "primitives")] pub fn equals(&self, other: &Address) -> bool { self.inner == other.inner } + /// Compares this address to the other address. + /// + /// Returns -1 if this address is smaller than the other address, 0 if they are equal, + /// and 1 if this address is larger than the other address. #[cfg(feature = "primitives")] pub fn compare(&self, other: &Address) -> i32 { self.inner.cmp(&other.inner) as i32 diff --git a/web-client/src/common/hashed_time_locked_contract.rs b/web-client/src/common/hashed_time_locked_contract.rs index 3b4f754133..d61023b45e 100644 --- a/web-client/src/common/hashed_time_locked_contract.rs +++ b/web-client/src/common/hashed_time_locked_contract.rs @@ -12,18 +12,21 @@ use crate::common::transaction::{ #[cfg(feature = "primitives")] use crate::common::transaction::{PlainTransactionProofType, PlainTransactionRecipientDataType}; +/// Utility class providing methods to parse Hashed Time Locked Contract transaction data and proofs. #[wasm_bindgen] pub struct HashedTimeLockedContract; #[cfg(feature = "primitives")] #[wasm_bindgen] impl HashedTimeLockedContract { + /// Parses the data of a Hashed Time Locked Contract creation transaction into a plain object. #[wasm_bindgen(js_name = dataToPlain)] pub fn data_to_plain(data: &[u8]) -> Result { let plain = HashedTimeLockedContract::parse_data(data)?; Ok(serde_wasm_bindgen::to_value(&plain)?.into()) } + /// Parses the proof of a Hashed Time Locked Contract settlement transaction into a plain object. #[wasm_bindgen(js_name = proofToPlain)] pub fn proof_to_plain(proof: &[u8]) -> Result { let plain = HashedTimeLockedContract::parse_proof(proof)?; diff --git a/web-client/src/common/signature_proof.rs b/web-client/src/common/signature_proof.rs index f80c257abe..56c64be79c 100644 --- a/web-client/src/common/signature_proof.rs +++ b/web-client/src/common/signature_proof.rs @@ -181,6 +181,8 @@ impl SignatureProof { self.inner.serialize_to_vec() } + /// Creates a JSON-compatible plain object representing the signature proof. + #[wasm_bindgen(js_name = toPlain)] pub fn to_plain(&self) -> Result { let plain = self.to_plain_transaction_proof(); Ok(serde_wasm_bindgen::to_value(&plain)?.into()) diff --git a/web-client/src/common/staking_contract.rs b/web-client/src/common/staking_contract.rs index 20bb2f617e..e55095f5bd 100644 --- a/web-client/src/common/staking_contract.rs +++ b/web-client/src/common/staking_contract.rs @@ -14,18 +14,21 @@ use crate::common::{ }, }; +/// Utility class providing methods to parse Staking Contract transaction data and proofs. #[wasm_bindgen] pub struct StakingContract; #[cfg(feature = "primitives")] #[wasm_bindgen] impl StakingContract { + /// Parses the data of a Staking Contract incoming transaction into a plain object. #[wasm_bindgen(js_name = dataToPlain)] pub fn data_to_plain(data: &[u8]) -> Result { let plain = StakingContract::parse_data(data)?; Ok(serde_wasm_bindgen::to_value(&plain)?.into()) } + /// Parses the proof of a Staking Contract outgoing transaction into a plain object. #[wasm_bindgen(js_name = proofToPlain)] pub fn proof_to_plain(proof: &[u8]) -> Result { let plain = StakingContract::parse_proof(proof)?; diff --git a/web-client/src/common/vesting_contract.rs b/web-client/src/common/vesting_contract.rs index e26ad6eb6f..b01300b4f8 100644 --- a/web-client/src/common/vesting_contract.rs +++ b/web-client/src/common/vesting_contract.rs @@ -9,18 +9,21 @@ use crate::common::{ transaction::{PlainTransactionProof, PlainTransactionRecipientData, PlainVestingData}, }; +/// Utility class providing methods to parse Vesting Contract transaction data and proofs. #[wasm_bindgen] pub struct VestingContract; #[cfg(feature = "primitives")] #[wasm_bindgen] impl VestingContract { + /// Parses the data of a Vesting Contract creation transaction into a plain object. #[wasm_bindgen(js_name = dataToPlain)] pub fn data_to_plain(data: &[u8]) -> Result { let plain = VestingContract::parse_data(data)?; Ok(serde_wasm_bindgen::to_value(&plain)?.into()) } + /// Parses the proof of a Vesting Contract claiming transaction into a plain object. #[wasm_bindgen(js_name = proofToPlain)] pub fn proof_to_plain(proof: &[u8]) -> Result { let plain = VestingContract::parse_proof(proof)?; diff --git a/web-client/src/primitives/es256_public_key.rs b/web-client/src/primitives/es256_public_key.rs index 4804aa14b5..aefde42d27 100644 --- a/web-client/src/primitives/es256_public_key.rs +++ b/web-client/src/primitives/es256_public_key.rs @@ -116,10 +116,15 @@ impl ES256PublicKey { Address::from(nimiq_keys::Address::from(&self.inner)) } + /// Returns if this public key is equal to the other public key. pub fn equals(&self, other: &ES256PublicKey) -> bool { self.inner == other.inner } + /// Compares this public key to the other public key. + /// + /// Returns -1 if this public key is smaller than the other public key, 0 if they are equal, + /// and 1 if this public key is larger than the other public key. pub fn compare(&self, other: &ES256PublicKey) -> i32 { self.inner.cmp(&other.inner) as i32 } diff --git a/web-client/src/primitives/private_key.rs b/web-client/src/primitives/private_key.rs index 1e457fd90b..2130999a9f 100644 --- a/web-client/src/primitives/private_key.rs +++ b/web-client/src/primitives/private_key.rs @@ -71,6 +71,7 @@ impl PrivateKey { self.inner.to_hex() } + /// Returns if this private key is equal to the other private key. pub fn equals(&self, other: &PrivateKey) -> bool { self.inner == other.inner } diff --git a/web-client/src/primitives/public_key.rs b/web-client/src/primitives/public_key.rs index 75c8305e55..c0ea87f2de 100644 --- a/web-client/src/primitives/public_key.rs +++ b/web-client/src/primitives/public_key.rs @@ -112,10 +112,15 @@ impl PublicKey { Address::from(nimiq_keys::Address::from(&self.inner)) } + /// Returns if this public key is equal to the other public key. pub fn equals(&self, other: &PublicKey) -> bool { self.inner == other.inner } + /// Compares this public key to the other public key. + /// + /// Returns -1 if this public key is smaller than the other public key, 0 if they are equal, + /// and 1 if this public key is larger than the other public key. pub fn compare(&self, other: &PublicKey) -> i32 { self.inner.cmp(&other.inner) as i32 }