Skip to content

Commit

Permalink
doc: fix indentation, punctuation, and links (#237)
Browse files Browse the repository at this point in the history
* doc: fix indentation, punctuation, and links

Clippy was complaining about list indentation and paragraph separation,
so I fixed that and a few other issues (links to types, etc.).

* move todo out
  • Loading branch information
Stebalien authored Aug 6, 2024
1 parent 42deb4b commit 2082b87
Show file tree
Hide file tree
Showing 35 changed files with 626 additions and 561 deletions.
31 changes: 16 additions & 15 deletions frc42_dispatch/hasher/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use thiserror::Error;

/// Minimal interface for a hashing function
/// Minimal interface for a hashing function.
///
/// Hasher::hash() must return a digest that is at least 4 bytes long so that it can be cast to a
/// u32
/// [`Hasher::hash()`] must return a digest that is at least 4 bytes long so that it can be cast to
/// a [`u32`].
pub trait Hasher {
/// For an input of bytes return a digest that is at least 4 bytes long
/// For an input of bytes return a digest that is at least 4 bytes long.
fn hash(&self, bytes: &[u8]) -> Vec<u8>;
}

/// Hasher that uses the hash_blake2b syscall provided by the FVM
/// Hasher that uses the blake2b hash syscall provided by the FVM.
#[cfg(feature = "use_sdk")]
#[derive(Default)]
pub struct Blake2bSyscall {}
Expand All @@ -24,7 +24,7 @@ impl Hasher for Blake2bSyscall {
}

/// Uses an underlying hashing function (blake2b by convention) to generate method numbers from
/// method names
/// method names.
#[derive(Default)]
pub struct MethodResolver<T: Hasher> {
hasher: T,
Expand Down Expand Up @@ -54,12 +54,12 @@ impl<T: Hasher> MethodResolver<T> {
const FIRST_METHOD_NUMBER: u64 = 1 << 24;
const DIGEST_CHUNK_LENGTH: usize = 4;

/// Creates a MethodResolver with an instance of a hasher (blake2b by convention)
/// Creates a [`MethodResolver`] with an instance of a hasher (blake2b by convention).
pub fn new(hasher: T) -> Self {
Self { hasher }
}

/// Generates a standard FRC-0042 compliant method number
/// Generates a standard FRC-0042 compliant method number.
///
/// The method number is calculated as the first four bytes of `hash(method-name)`.
/// The name `Constructor` is always hashed to 1 and other method names that hash to
Expand Down Expand Up @@ -91,10 +91,10 @@ impl<T: Hasher> MethodResolver<T> {
}
}

/// Checks that a method name is valid and compliant with the FRC-0042 standard recommendations
/// Checks that a method name is valid and compliant with the FRC-0042 standard recommendations.
///
/// - Only ASCII characters in `[a-zA-Z0-9_]` are allowed
/// - Starts with a character in `[A-Z_]`
/// - Only ASCII characters in `[a-zA-Z0-9_]` are allowed.
/// - Starts with a character in `[A-Z_]`.
fn check_method_name(method_name: &str) -> Result<(), MethodNameErr> {
if method_name.is_empty() {
return Err(MethodNameErr::EmptyString);
Expand All @@ -114,10 +114,11 @@ fn check_method_name(method_name: &str) -> Result<(), MethodNameErr> {
Ok(())
}

/// Takes a byte array and interprets it as a u32 number
/// Takes a byte array and interprets it as a u32 number.
///
/// Using big-endian order interperets the first four bytes to an int.
/// The slice passed to this must be at least length 4
///
/// The slice passed to this must be at least length 4.
fn as_u32(bytes: &[u8]) -> u32 {
u32::from_be_bytes(bytes[0..4].try_into().expect("bytes was not at least length 4"))
}
Expand Down Expand Up @@ -171,7 +172,7 @@ mod tests {
);
}

/// Fake hasher that always returns a digest beginning with b"\0\0\0\0"
/// Fake hasher that always returns a digest beginning with b"\0\0\0\0".
#[derive(Clone, Copy)]
struct FakeHasher0 {}
impl Hasher for FakeHasher0 {
Expand All @@ -183,7 +184,7 @@ mod tests {
}
}

/// Fake hasher that always returns a digest beginning with b"\0\0\0\1"
/// Fake hasher that always returns a digest beginning with b"\0\0\0\1".
#[derive(Clone, Copy)]
struct FakeHasher1 {}
impl Hasher for FakeHasher1 {
Expand Down
2 changes: 1 addition & 1 deletion frc42_dispatch/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::hash::Blake2bHasher;
struct MethodName(LitStr);

impl MethodName {
/// Hash the method name
/// Hash the method name.
fn hash(&self) -> u64 {
let resolver = MethodResolver::new(Blake2bHasher {});
resolver.method_number(&self.0.value()).unwrap()
Expand Down
6 changes: 3 additions & 3 deletions frc42_dispatch/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use thiserror::Error;

use crate::hash::{Hasher, MethodNameErr, MethodResolver};

/// Utility to invoke standard methods on deployed actors
/// Utility to invoke standard methods on deployed actors.
#[derive(Default)]
pub struct MethodMessenger<T: Hasher> {
method_resolver: MethodResolver<T>,
Expand All @@ -21,13 +21,13 @@ pub enum MethodMessengerError {
}

impl<T: Hasher> MethodMessenger<T> {
/// Creates a new method messenger using a specified hashing function (blake2b by default)
/// Creates a new method messenger using a specified hashing function (blake2b by default).
pub fn new(hasher: T) -> Self {
Self { method_resolver: MethodResolver::new(hasher) }
}

/// Calls a method (by name) on a specified actor by constructing and publishing the underlying
/// on-chain Message
/// on-chain message.
#[cfg(feature = "use_sdk")]
pub fn call_method(
&self,
Expand Down
16 changes: 8 additions & 8 deletions frc46_token/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait FRC46ReceiverHook<T: RecipientData> {
}

impl<T: RecipientData> FRC46ReceiverHook<T> for ReceiverHook<T> {
/// Construct a new FRC46 ReceiverHook call
/// Construct a new FRC46 [`ReceiverHook`] call.
fn new_frc46(
address: Address,
frc46_params: FRC46TokenReceived,
Expand All @@ -30,19 +30,19 @@ impl<T: RecipientData> FRC46ReceiverHook<T> for ReceiverHook<T> {
}
}

/// Receive parameters for an FRC46 token
/// Receive parameters for an FRC46 token.
#[derive(Serialize_tuple, Deserialize_tuple, PartialEq, Eq, Clone, Debug)]
pub struct FRC46TokenReceived {
/// The account that the tokens are being pulled from (the token actor address itself for mint)
/// The account that the tokens are being pulled from (the token actor address itself for mint).
pub from: ActorID,
/// The account that the tokens are being sent to (the receiver address)
/// The account that the tokens are being sent to (the receiver address).
pub to: ActorID,
/// Address of the operator that initiated the transfer/mint
/// Address of the operator that initiated the transfer/mint.
pub operator: ActorID,
/// Amount of tokens being transferred/minted
/// Amount of tokens being transferred/minted.
pub amount: TokenAmount,
/// Data specified by the operator during transfer/mint
/// Data specified by the operator during transfer/mint.
pub operator_data: RawBytes,
/// Additional data specified by the token-actor during transfer/mint
/// Additional data specified by the token-actor during transfer/mint.
pub token_data: RawBytes,
}
Loading

0 comments on commit 2082b87

Please sign in to comment.