Skip to main content

polyoxide_relay/
account.rs

1use crate::config::BuilderConfig;
2use crate::error::RelayError;
3use alloy::primitives::Address;
4use alloy::signers::local::PrivateKeySigner;
5
6#[derive(Clone, Debug)]
7pub struct BuilderAccount {
8    pub(crate) signer: PrivateKeySigner,
9    pub(crate) config: Option<BuilderConfig>,
10}
11
12impl BuilderAccount {
13    pub fn new(
14        private_key: impl Into<String>,
15        config: Option<BuilderConfig>,
16    ) -> Result<Self, RelayError> {
17        let signer = private_key
18            .into()
19            .parse::<PrivateKeySigner>()
20            .map_err(|e| RelayError::Signer(format!("Failed to parse private key: {}", e)))?;
21
22        Ok(Self { signer, config })
23    }
24
25    pub fn address(&self) -> Address {
26        self.signer.address()
27    }
28
29    pub fn signer(&self) -> &PrivateKeySigner {
30        &self.signer
31    }
32
33    pub fn config(&self) -> Option<&BuilderConfig> {
34        self.config.as_ref()
35    }
36}