Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename domain macro and add more docs #147

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions crates/sol-types/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,37 @@ impl Eip712Domain {
}

// This was generated by excel meta-programming
/// Instantiate an EIP-712 domain.
/// Convenience macro to instantiate an EIP-712 domain.
///
/// This macro allows you to instantiate an Eip712Domain struct without
/// manually writing `None` for unused fields. It may be used to declare
/// a domain with any combination of fields. Each field must be labeled
/// with the name of the field, and the fields must be in order. The
/// fields for the domain are:
/// - `name`
/// - `version`
/// - `chain_id`
/// - `verifying_contract`
/// - `salt`
///
/// ```
/// # use alloy_sol_types::{Eip712Domain, eip712_domain};
/// # use alloy_primitives::keccak256;
///
/// const my_domain: Eip712Domain = eip712_domain!{
/// name: "MyCoolProtocol",
/// };
///
/// # fn main() {
/// let my_other_domain: Eip712Domain = eip712_domain!{
/// name: "MyCoolProtocol",
/// version: "1.0.0",
/// salt: keccak256("my domain salt"),
/// };
/// # }
/// ```
#[macro_export]
macro_rules! domain {
macro_rules! eip712_domain {
(salt: $salt:expr,) => {
$crate::Eip712Domain::new(
None,
Expand Down Expand Up @@ -666,7 +694,7 @@ macro_rules! domain {
#[cfg(test)]
mod tests {
use super::*;
const _DOMAIN: Eip712Domain = domain! {
const _DOMAIN: Eip712Domain = eip712_domain! {
name: "abcd",
version: "1",
chain_id: U256::from_limbs([1, 0, 0, 0]),
Expand Down
5 changes: 3 additions & 2 deletions crates/sol-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
//! c: vec![Default::default()],
//! };
//!
//! // The domain macro lets you easily define an EIP-712 domain object :)
//! let my_domain = alloy_sol_types::domain!(
//! // The `eip712_domain` macro lets you easily define an EIP-712 domain
//! // object :)
//! let my_domain = alloy_sol_types::eip712_domain!(
//! name: "MyDomain",
//! version: "1",
//! );
Expand Down
4 changes: 2 additions & 2 deletions crates/sol-types/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_sol_types::{define_udt, domain};
use alloy_sol_types::{define_udt, eip712_domain};

#[allow(clippy::missing_const_for_fn)]
fn ret_ok<T>(_: T) -> alloy_sol_types::Result<()> {
Expand All @@ -20,7 +20,7 @@ define_udt!(

#[test]
fn expand_and_use_macros() {
let domain = domain! {
let domain = eip712_domain! {
name: "Hello World",
};
assert_eq!(domain.name.as_deref(), Some("Hello World"));
Expand Down