Skip to content

Commit

Permalink
better ::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakuhito committed Nov 13, 2024
1 parent d4c2395 commit 14a9299
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions crates/chia-sdk-driver/src/layers/p2_eip712_message_layer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use chia_protocol::{Bytes32, BytesImpl};
use chia_sdk_types::{MAINNET_CONSTANTS, TESTNET11_CONSTANTS};
use clvm_traits::{FromClvm, ToClvm};
use clvm_utils::{CurriedProgram, TreeHash};
use clvmr::{Allocator, NodePtr};
Expand Down Expand Up @@ -47,18 +46,17 @@ pub struct P2Eip712MessageSolution<P, S> {
}

impl P2Eip712MessageLayer {
pub fn new(pubkey: EthPubkeyBytes, testnet: bool) -> Self {
Self::new_with_genesis_challenge(
pub fn new(
pubkey: EthPubkeyBytes,
prefix_and_domain_separator: Eip712PrefixAndDomainSeparator,
) -> Self {
Self {
prefix_and_domain_separator,
pubkey,
if testnet {
TESTNET11_CONSTANTS.genesis_challenge
} else {
MAINNET_CONSTANTS.genesis_challenge
},
)
}
}

pub fn new_with_genesis_challenge(pubkey: EthPubkeyBytes, genesis_challenge: Bytes32) -> Self {
pub fn from_genesis_challenge(pubkey: EthPubkeyBytes, genesis_challenge: Bytes32) -> Self {
Self {
prefix_and_domain_separator: P2Eip712MessageLayer::prefix_and_domain_separator(
genesis_challenge,
Expand Down Expand Up @@ -287,7 +285,7 @@ mod tests {
let mut sim = Simulator::new();

let pubkey = signing_key.verifying_key().to_sec1_bytes().to_vec();
let layer = P2Eip712MessageLayer::new_with_genesis_challenge(
let layer = P2Eip712MessageLayer::from_genesis_challenge(
pubkey.try_into().unwrap(),
TEST_CONSTANTS.genesis_challenge,
);
Expand Down

0 comments on commit 14a9299

Please sign in to comment.