Skip to content

Commit 8eaf4a0

Browse files
committed
pallet: introduce custom error code type
1 parent 6a5607f commit 8eaf4a0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

sugondat-chain/pallets/blobs/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ sp-io = { git = "https://github.com/paritytech/polkadot-sdk", default-features =
3131
# Substrate
3232
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.2.0" }
3333

34+
# Local
35+
sugondat-primitives = { path = "../../primitives", default-features = false }
36+
3437
[features]
3538
default = ["std"]
3639
runtime-benchmarks = [
@@ -48,5 +51,6 @@ std = [
4851
"frame-system/std",
4952
"sp-std/std",
5053
"sugondat-nmt/native",
54+
"sugondat-primitives/std",
5155
]
5256
try-runtime = [ "frame-support/try-runtime" ]

sugondat-chain/pallets/blobs/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use sp_runtime::{
2222
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
2323
},
2424
};
25+
use sugondat_primitives::InvalidTransactionCustomError;
2526

2627
use frame_support::traits::{Get, IsSubType};
2728

@@ -313,7 +314,10 @@ where
313314
// This causes the transaction to be expunged from the transaction pool.
314315
// It will not be valid unless the configured limit is increased by governance,
315316
// which is a rare event.
316-
return Err(InvalidTransaction::Custom(0).into());
317+
return Err(InvalidTransaction::Custom(
318+
InvalidTransactionCustomError::BlobExceedsSizeLimit,
319+
)
320+
.into());
317321
}
318322
}
319323
}

sugondat-chain/primitives/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ pub mod opaque {
4444
/// Opaque block hash type.
4545
pub type Hash = <BlakeTwo256 as HashT>::Output;
4646
}
47+
48+
/// Invalid transaction custom errors for Sugondat Runtimes
49+
#[repr(u8)]
50+
pub enum InvalidTransactionCustomError {
51+
/// The blob exceeds the configured per-blob size limit.
52+
BlobExceedsSizeLimit = 100,
53+
}

0 commit comments

Comments
 (0)