Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat(eip712): add raw_salt attribute #2331

Merged
merged 16 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
10 changes: 9 additions & 1 deletion ethers-contract/ethers-contract-derive/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils;
use ethers_core::{
abi::{Address, ParamType},
macros::ethers_core_crate,
types::transaction::eip712::EIP712Domain,
types::{transaction::eip712::EIP712Domain, H256},
utils::keccak256,
};
use inflector::Inflector;
Expand Down Expand Up @@ -109,12 +109,20 @@ fn parse_attributes(input: &DeriveInput) -> Result<EIP712Domain> {
litstr.value().parse().map_err(|e| Error::new(litstr.span(), e))?;
domain.verifying_contract = Some(addr);
}
// hash string
"salt", domain.salt => {
meta.input.parse::<Token![=]>()?;
let litstr: LitStr = meta.input.parse()?;
let hash = keccak256(litstr.value());
domain.salt = Some(hash);
}
// parse string as H256
"raw_salt", domain.salt => {
meta.input.parse::<Token![=]>()?;
let litstr: LitStr = meta.input.parse()?;
let bytes = litstr.value().parse::<H256>().map_err(|e| Error::new(litstr.span(), e))?;
domain.salt = Some(bytes.0);
}
);
Ok(domain)
}
Expand Down
5 changes: 3 additions & 2 deletions ethers-contract/tests/it/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use ethers_core::{

#[test]
fn test_derive_eip712() {
#[derive(Debug, Clone, Eip712, EthAbiType)]
#[derive(Clone, Eip712, EthAbiType)]
#[eip712(
name = "Radicle",
version = "1",
chain_id = 1,
verifying_contract = "0x0000000000000000000000000000000000000001"
verifying_contract = "0x0000000000000000000000000000000000000001",
raw_salt = "0x3000000000000000000000000000000000000000000000000000000000000000"
)]
pub struct Puzzle {
pub organization: H160,
Expand Down