mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add support for eth_signTransaction (#12500)
This commit is contained in:
@ -278,7 +278,13 @@ where
|
||||
.await
|
||||
.unwrap();
|
||||
EthApiClient::<Transaction, Block, Receipt>::syncing(client).await.unwrap();
|
||||
EthApiClient::<Transaction, Block, Receipt>::send_transaction(client, transaction_request)
|
||||
EthApiClient::<Transaction, Block, Receipt>::send_transaction(
|
||||
client,
|
||||
transaction_request.clone(),
|
||||
)
|
||||
.await
|
||||
.unwrap_err();
|
||||
EthApiClient::<Transaction, Block, Receipt>::sign_transaction(client, transaction_request)
|
||||
.await
|
||||
.unwrap_err();
|
||||
EthApiClient::<Transaction, Block, Receipt>::hashrate(client).await.unwrap();
|
||||
@ -318,12 +324,6 @@ where
|
||||
.err()
|
||||
.unwrap()
|
||||
));
|
||||
assert!(is_unimplemented(
|
||||
EthApiClient::<Transaction, Block, Receipt>::sign_transaction(client, call_request.clone())
|
||||
.await
|
||||
.err()
|
||||
.unwrap()
|
||||
));
|
||||
}
|
||||
|
||||
async fn test_basic_debug_calls<C>(client: &C)
|
||||
|
||||
@ -780,8 +780,9 @@ where
|
||||
}
|
||||
|
||||
/// Handler for: `eth_signTransaction`
|
||||
async fn sign_transaction(&self, _transaction: TransactionRequest) -> RpcResult<Bytes> {
|
||||
Err(internal_rpc_err("unimplemented"))
|
||||
async fn sign_transaction(&self, request: TransactionRequest) -> RpcResult<Bytes> {
|
||||
trace!(target: "rpc::eth", ?request, "Serving eth_signTransaction");
|
||||
Ok(EthTransactions::sign_transaction(self, request).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_signTypedData`
|
||||
|
||||
@ -400,16 +400,10 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
|
||||
txn: TransactionRequest,
|
||||
) -> impl Future<Output = Result<TransactionSigned, Self::Error>> + Send {
|
||||
async move {
|
||||
let signers: Vec<_> = self.signers().read().iter().cloned().collect();
|
||||
for signer in signers {
|
||||
if signer.is_signer_for(from) {
|
||||
return match signer.sign_transaction(txn, from).await {
|
||||
Ok(tx) => Ok(tx),
|
||||
Err(e) => Err(e.into_eth_err()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(EthApiError::InvalidTransactionSignature.into())
|
||||
self.find_signer(from)?
|
||||
.sign_transaction(txn, from)
|
||||
.await
|
||||
.map_err(Self::Error::from_eth_err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,6 +424,22 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Signs a transaction request using the given account in request
|
||||
/// Returns the EIP-2718 encoded signed transaction.
|
||||
fn sign_transaction(
|
||||
&self,
|
||||
request: TransactionRequest,
|
||||
) -> impl Future<Output = Result<Bytes, Self::Error>> + Send {
|
||||
async move {
|
||||
let from = match request.from {
|
||||
Some(from) => from,
|
||||
None => return Err(SignError::NoAccount.into_eth_err()),
|
||||
};
|
||||
|
||||
Ok(self.sign_request(&from, request).await?.encoded_2718().into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Encodes and signs the typed data according EIP-712. Payload must implement Eip712 trait.
|
||||
fn sign_typed_data(&self, data: &TypedData, account: Address) -> Result<Bytes, Self::Error> {
|
||||
Ok(self
|
||||
|
||||
Reference in New Issue
Block a user