mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 22:07:58 +00:00
Allow runtime to return transaction validation error codes (#1534)
* Allow runtime to return more detailed transaction validation errors. * Re-use ApplyError codes and update test-runtime. * Fix pool tests. * Revert using Compact for validity.
This commit is contained in:
@@ -24,14 +24,14 @@ use error_chain::{
|
||||
error_chain! {
|
||||
errors {
|
||||
/// Transaction is not verifiable yet, but might be in the future.
|
||||
UnknownTransactionValidity {
|
||||
UnknownTransactionValidity(e: i8) {
|
||||
description("Runtime cannot determine validity of the transaction yet."),
|
||||
display("Unkown Transaction Validity"),
|
||||
display("Unkown Transaction Validity. Error code: {}", e),
|
||||
}
|
||||
/// Transaction is invalid
|
||||
InvalidTransaction {
|
||||
InvalidTransaction(e: i8) {
|
||||
description("Runtime check for the transaction failed."),
|
||||
display("Invalid Transaction"),
|
||||
display("Invalid Transaction. Error Code: {}", e),
|
||||
}
|
||||
/// The transaction is temporarily baned
|
||||
TemporarilyBanned {
|
||||
|
||||
@@ -118,12 +118,12 @@ impl<B: ChainApi> Pool<B> {
|
||||
valid_till: block_number.as_().saturating_add(longevity),
|
||||
})
|
||||
},
|
||||
TransactionValidity::Invalid => {
|
||||
bail!(error::Error::from(error::ErrorKind::InvalidTransaction))
|
||||
TransactionValidity::Invalid(e) => {
|
||||
bail!(error::Error::from(error::ErrorKind::InvalidTransaction(e)))
|
||||
},
|
||||
TransactionValidity::Unknown => {
|
||||
TransactionValidity::Unknown(e) => {
|
||||
self.listener.write().invalid(&hash);
|
||||
bail!(error::Error::from(error::ErrorKind::UnknownTransactionValidity))
|
||||
bail!(error::Error::from(error::ErrorKind::UnknownTransactionValidity(e)))
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -247,7 +247,7 @@ impl<B: ChainApi> Pool<B> {
|
||||
// Collect the hashes of transactions that now became invalid (meaning that they are succesfuly pruned).
|
||||
let hashes = results.into_iter().enumerate().filter_map(|(idx, r)| match r.map_err(error::IntoPoolError::into_pool_error) {
|
||||
Err(Ok(err)) => match err.kind() {
|
||||
error::ErrorKind::InvalidTransaction => Some(hashes[idx].clone()),
|
||||
error::ErrorKind::InvalidTransaction(_) => Some(hashes[idx].clone()),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
@@ -413,7 +413,7 @@ mod tests {
|
||||
let nonce = uxt.transfer().nonce;
|
||||
|
||||
if nonce < block_number {
|
||||
Ok(TransactionValidity::Invalid)
|
||||
Ok(TransactionValidity::Invalid(0))
|
||||
} else {
|
||||
Ok(TransactionValidity::Valid {
|
||||
priority: 4,
|
||||
|
||||
Reference in New Issue
Block a user