fix(client): evm-feature's code for new proto
This commit was merged in pull request #49.
This commit is contained in:
@@ -9,4 +9,4 @@ pub use client::{ArbiterClient, Error};
|
|||||||
pub use storage::{FileSigningKeyStorage, SigningKeyStorage, StorageError};
|
pub use storage::{FileSigningKeyStorage, SigningKeyStorage, StorageError};
|
||||||
|
|
||||||
#[cfg(feature = "evm")]
|
#[cfg(feature = "evm")]
|
||||||
pub use wallets::evm::ArbiterEvmWallet;
|
pub use wallets::evm::{ArbiterEvmSignTransactionError, ArbiterEvmWallet};
|
||||||
|
|||||||
@@ -10,14 +10,48 @@ use tokio::sync::Mutex;
|
|||||||
|
|
||||||
use arbiter_proto::proto::{
|
use arbiter_proto::proto::{
|
||||||
client::{
|
client::{
|
||||||
ClientRequest, client_request::Payload as ClientRequestPayload,
|
ClientRequest,
|
||||||
|
client_request::Payload as ClientRequestPayload,
|
||||||
client_response::Payload as ClientResponsePayload,
|
client_response::Payload as ClientResponsePayload,
|
||||||
|
evm::{
|
||||||
|
self as proto_evm, request::Payload as EvmRequestPayload,
|
||||||
|
response::Payload as EvmResponsePayload,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
evm::evm_sign_transaction_response::Result as EvmSignTransactionResult,
|
evm::{
|
||||||
|
EvmSignTransactionRequest,
|
||||||
|
evm_sign_transaction_response::Result as EvmSignTransactionResult,
|
||||||
|
},
|
||||||
|
shared::evm::TransactionEvalError,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::transport::{ClientTransport, next_request_id};
|
use crate::transport::{ClientTransport, next_request_id};
|
||||||
|
|
||||||
|
/// A typed error payload returned by [`ArbiterEvmWallet`] transaction signing.
|
||||||
|
///
|
||||||
|
/// This is wrapped into `alloy::signers::Error::Other`, so consumers can downcast by [`TryFrom`] and
|
||||||
|
/// interpret the concrete policy evaluation failure instead of parsing strings.
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum ArbiterEvmSignTransactionError {
|
||||||
|
#[error("transaction rejected by policy: {0:?}")]
|
||||||
|
PolicyEval(TransactionEvalError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TryFrom<&'a Error> for &'a ArbiterEvmSignTransactionError {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(value: &'a Error) -> Result<Self, Self::Error> {
|
||||||
|
if let Error::Other(inner) = value
|
||||||
|
&& let Some(eval_error) = inner.downcast_ref()
|
||||||
|
{
|
||||||
|
Ok(eval_error)
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ArbiterEvmWallet {
|
pub struct ArbiterEvmWallet {
|
||||||
transport: Arc<Mutex<ClientTransport>>,
|
transport: Arc<Mutex<ClientTransport>>,
|
||||||
address: Address,
|
address: Address,
|
||||||
@@ -96,12 +130,14 @@ impl TxSigner<Signature> for ArbiterEvmWallet {
|
|||||||
transport
|
transport
|
||||||
.send(ClientRequest {
|
.send(ClientRequest {
|
||||||
request_id,
|
request_id,
|
||||||
payload: Some(ClientRequestPayload::EvmSignTransaction(
|
payload: Some(ClientRequestPayload::Evm(proto_evm::Request {
|
||||||
arbiter_proto::proto::evm::EvmSignTransactionRequest {
|
payload: Some(EvmRequestPayload::SignTransaction(
|
||||||
wallet_address: self.address.to_vec(),
|
EvmSignTransactionRequest {
|
||||||
rlp_transaction,
|
wallet_address: self.address.to_vec(),
|
||||||
},
|
rlp_transaction,
|
||||||
)),
|
},
|
||||||
|
)),
|
||||||
|
})),
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::other("failed to send evm sign transaction request"))?;
|
.map_err(|_| Error::other("failed to send evm sign transaction request"))?;
|
||||||
@@ -121,12 +157,21 @@ impl TxSigner<Signature> for ArbiterEvmWallet {
|
|||||||
.payload
|
.payload
|
||||||
.ok_or_else(|| Error::other("missing evm sign transaction response payload"))?;
|
.ok_or_else(|| Error::other("missing evm sign transaction response payload"))?;
|
||||||
|
|
||||||
let ClientResponsePayload::EvmSignTransaction(response) = payload else {
|
let ClientResponsePayload::Evm(proto_evm::Response {
|
||||||
|
payload: Some(payload),
|
||||||
|
}) = payload
|
||||||
|
else {
|
||||||
return Err(Error::other(
|
return Err(Error::other(
|
||||||
"unexpected response payload for evm sign transaction request",
|
"unexpected response payload for evm sign transaction request",
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let EvmResponsePayload::SignTransaction(response) = payload else {
|
||||||
|
return Err(Error::other(
|
||||||
|
"unexpected evm response payload for sign transaction request",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
let result = response
|
let result = response
|
||||||
.result
|
.result
|
||||||
.ok_or_else(|| Error::other("missing evm sign transaction result"))?;
|
.ok_or_else(|| Error::other("missing evm sign transaction result"))?;
|
||||||
@@ -136,9 +181,9 @@ impl TxSigner<Signature> for ArbiterEvmWallet {
|
|||||||
Signature::try_from(signature.as_slice())
|
Signature::try_from(signature.as_slice())
|
||||||
.map_err(|_| Error::other("invalid signature returned by server"))
|
.map_err(|_| Error::other("invalid signature returned by server"))
|
||||||
}
|
}
|
||||||
EvmSignTransactionResult::EvalError(eval_error) => Err(Error::other(format!(
|
EvmSignTransactionResult::EvalError(eval_error) => Err(Error::other(
|
||||||
"transaction rejected by policy: {eval_error:?}"
|
ArbiterEvmSignTransactionError::PolicyEval(eval_error),
|
||||||
))),
|
)),
|
||||||
EvmSignTransactionResult::Error(code) => Err(Error::other(format!(
|
EvmSignTransactionResult::Error(code) => Err(Error::other(format!(
|
||||||
"server failed to sign transaction with error code {code}"
|
"server failed to sign transaction with error code {code}"
|
||||||
))),
|
))),
|
||||||
|
|||||||
Reference in New Issue
Block a user