Skip to content

Commit

Permalink
Add rustdoc to public methods
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
sisou committed Nov 14, 2024
1 parent b43a7ea commit ae61f7f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions web-client/src/common/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
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
Expand Down
3 changes: 3 additions & 0 deletions web-client/src/common/hashed_time_locked_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlainTransactionRecipientDataType, JsError> {
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<PlainTransactionProofType, JsError> {
let plain = HashedTimeLockedContract::parse_proof(proof)?;
Expand Down
2 changes: 2 additions & 0 deletions web-client/src/common/signature_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlainTransactionProofType, JsError> {
let plain = self.to_plain_transaction_proof();
Ok(serde_wasm_bindgen::to_value(&plain)?.into())
Expand Down
3 changes: 3 additions & 0 deletions web-client/src/common/staking_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlainTransactionRecipientDataType, JsError> {
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<PlainTransactionProofType, JsError> {
let plain = StakingContract::parse_proof(proof)?;
Expand Down
3 changes: 3 additions & 0 deletions web-client/src/common/vesting_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlainTransactionRecipientDataType, JsError> {
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<PlainTransactionProofType, JsError> {
let plain = VestingContract::parse_proof(proof)?;
Expand Down
5 changes: 5 additions & 0 deletions web-client/src/primitives/es256_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions web-client/src/primitives/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions web-client/src/primitives/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ae61f7f

Please sign in to comment.