refactor(client): decouple grpc connect from wallet address and add explicit wallet configuration

This commit is contained in:
CleverWild
2026-03-19 18:21:09 +01:00
parent c87456ae2f
commit 3993d3a8cc

View File

@@ -145,6 +145,9 @@ enum ClientSignError {
#[error("Remote signing was rejected")] #[error("Remote signing was rejected")]
Rejected, Rejected,
#[error("Wallet address is not configured")]
WalletAddressNotConfigured,
} }
struct ClientTransport { struct ClientTransport {
@@ -171,32 +174,27 @@ impl ClientTransport {
pub struct ArbiterSigner { pub struct ArbiterSigner {
transport: Mutex<ClientTransport>, transport: Mutex<ClientTransport>,
address: Address, address: Option<Address>,
chain_id: Option<ChainId>, chain_id: Option<ChainId>,
} }
impl ArbiterSigner { impl ArbiterSigner {
pub async fn connect_grpc( pub async fn connect_grpc(url: ArbiterUrl) -> std::result::Result<Self, ConnectError> {
url: ArbiterUrl,
address: Address,
) -> std::result::Result<Self, ConnectError> {
let storage = FileSigningKeyStorage::from_default_location()?; let storage = FileSigningKeyStorage::from_default_location()?;
Self::connect_grpc_with_storage(url, address, &storage).await Self::connect_grpc_with_storage(url, &storage).await
} }
pub async fn connect_grpc_with_storage<S: SigningKeyStorage>( pub async fn connect_grpc_with_storage<S: SigningKeyStorage>(
url: ArbiterUrl, url: ArbiterUrl,
address: Address,
storage: &S, storage: &S,
) -> std::result::Result<Self, ConnectError> { ) -> std::result::Result<Self, ConnectError> {
let key = storage.load_or_create()?; let key = storage.load_or_create()?;
Self::connect_grpc_with_key(url, key, address).await Self::connect_grpc_with_key(url, key).await
} }
pub async fn connect_grpc_with_key( pub async fn connect_grpc_with_key(
url: ArbiterUrl, url: ArbiterUrl,
key: ed25519_dalek::SigningKey, key: ed25519_dalek::SigningKey,
address: Address,
) -> std::result::Result<Self, ConnectError> { ) -> std::result::Result<Self, ConnectError> {
let anchor = webpki::anchor_from_trusted_cert(&url.ca_cert)?.to_owned(); let anchor = webpki::anchor_from_trusted_cert(&url.ca_cert)?.to_owned();
let tls = ClientTlsConfig::new().trust_anchor(anchor); let tls = ClientTlsConfig::new().trust_anchor(anchor);
@@ -221,11 +219,29 @@ impl ArbiterSigner {
Ok(Self { Ok(Self {
transport: Mutex::new(transport), transport: Mutex::new(transport),
address, address: None,
chain_id: None, chain_id: None,
}) })
} }
pub fn wallet_address(&self) -> Option<Address> {
self.address
}
pub fn set_wallet_address(&mut self, address: Option<Address>) {
self.address = address;
}
pub fn with_wallet_address(mut self, address: Address) -> Self {
self.address = Some(address);
self
}
pub fn with_chain_id(mut self, chain_id: ChainId) -> Self {
self.chain_id = Some(chain_id);
self
}
async fn sign_transaction_via_arbiter( async fn sign_transaction_via_arbiter(
&self, &self,
tx: &mut dyn SignableTransaction<Signature>, tx: &mut dyn SignableTransaction<Signature>,
@@ -242,10 +258,14 @@ impl ArbiterSigner {
let mut rlp_transaction = Vec::new(); let mut rlp_transaction = Vec::new();
tx.encode_for_signing(&mut rlp_transaction); tx.encode_for_signing(&mut rlp_transaction);
let wallet_address = self
.address
.ok_or_else(|| Error::other(ClientSignError::WalletAddressNotConfigured))?;
let request = ClientRequest { let request = ClientRequest {
payload: Some(ClientRequestPayload::EvmSignTransaction( payload: Some(ClientRequestPayload::EvmSignTransaction(
EvmSignTransactionRequest { EvmSignTransactionRequest {
wallet_address: self.address.as_slice().to_vec(), wallet_address: wallet_address.as_slice().to_vec(),
rlp_transaction, rlp_transaction,
}, },
)), )),
@@ -342,7 +362,7 @@ impl Signer for ArbiterSigner {
} }
fn address(&self) -> Address { fn address(&self) -> Address {
self.address self.address.unwrap_or(Address::ZERO)
} }
fn chain_id(&self) -> Option<ChainId> { fn chain_id(&self) -> Option<ChainId> {
@@ -357,7 +377,7 @@ impl Signer for ArbiterSigner {
#[async_trait] #[async_trait]
impl TxSigner<Signature> for ArbiterSigner { impl TxSigner<Signature> for ArbiterSigner {
fn address(&self) -> Address { fn address(&self) -> Address {
self.address self.address.unwrap_or(Address::ZERO)
} }
async fn sign_transaction( async fn sign_transaction(