|
19 | 19 | use bp_messages::*;
|
20 | 20 | pub use bp_polkadot_core::{
|
21 | 21 | AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, Balance, BlockNumber, Hash, Hasher,
|
22 |
| - Hashing, Header, Index, Nonce, Perbill, PolkadotSignedExtension, Signature, SignedBlock, |
23 |
| - UncheckedExtrinsic, EXTRA_STORAGE_PROOF_SIZE, TX_EXTRA_BYTES, |
| 22 | + Hashing, Header, Index, Nonce, Perbill, Signature, SignedBlock, UncheckedExtrinsic, |
| 23 | + EXTRA_STORAGE_PROOF_SIZE, TX_EXTRA_BYTES, |
24 | 24 | };
|
25 | 25 | use frame_support::{
|
26 | 26 | dispatch::DispatchClass,
|
@@ -124,3 +124,72 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
|
124 | 124 |
|
125 | 125 | /// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
|
126 | 126 | pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
|
| 127 | + |
| 128 | +/// Module with rewarding bridge signed extension support |
| 129 | +pub mod rewarding_bridge_signed_extension { |
| 130 | + use super::*; |
| 131 | + use bp_polkadot_core::PolkadotLike; |
| 132 | + use bp_runtime::extensions::*; |
| 133 | + |
| 134 | + type RewardingBridgeSignedExtra = ( |
| 135 | + CheckNonZeroSender, |
| 136 | + CheckSpecVersion, |
| 137 | + CheckTxVersion, |
| 138 | + CheckGenesis<PolkadotLike>, |
| 139 | + CheckEra<PolkadotLike>, |
| 140 | + CheckNonce<Nonce>, |
| 141 | + CheckWeight, |
| 142 | + ChargeTransactionPayment<PolkadotLike>, |
| 143 | + BridgeRejectObsoleteHeadersAndMessages, |
| 144 | + RefundBridgedParachainMessagesSchema, |
| 145 | + ); |
| 146 | + |
| 147 | + /// The signed extension used by Cumulus and Cumulus-like parachain with bridging and rewarding. |
| 148 | + pub type RewardingBridgeSignedExtension = GenericSignedExtension<RewardingBridgeSignedExtra>; |
| 149 | + |
| 150 | + pub fn from_params( |
| 151 | + spec_version: u32, |
| 152 | + transaction_version: u32, |
| 153 | + era: bp_runtime::TransactionEraOf<PolkadotLike>, |
| 154 | + genesis_hash: Hash, |
| 155 | + nonce: Nonce, |
| 156 | + tip: Balance, |
| 157 | + ) -> RewardingBridgeSignedExtension { |
| 158 | + GenericSignedExtension::<RewardingBridgeSignedExtra>::new( |
| 159 | + ( |
| 160 | + (), // non-zero sender |
| 161 | + (), // spec version |
| 162 | + (), // tx version |
| 163 | + (), // genesis |
| 164 | + era.frame_era(), // era |
| 165 | + nonce.into(), // nonce (compact encoding) |
| 166 | + (), // Check weight |
| 167 | + tip.into(), // transaction payment / tip (compact encoding) |
| 168 | + (), // bridge reject obsolete headers and msgs |
| 169 | + (), // bridge register reward to relayer for message passing |
| 170 | + ), |
| 171 | + Some(( |
| 172 | + (), |
| 173 | + spec_version, |
| 174 | + transaction_version, |
| 175 | + genesis_hash, |
| 176 | + era.signed_payload(genesis_hash), |
| 177 | + (), |
| 178 | + (), |
| 179 | + (), |
| 180 | + (), |
| 181 | + (), |
| 182 | + )), |
| 183 | + ) |
| 184 | + } |
| 185 | + |
| 186 | + /// Return signer nonce, used to craft transaction. |
| 187 | + pub fn nonce(sign_ext: &RewardingBridgeSignedExtension) -> Nonce { |
| 188 | + sign_ext.payload.5.into() |
| 189 | + } |
| 190 | + |
| 191 | + /// Return transaction tip. |
| 192 | + pub fn tip(sign_ext: &RewardingBridgeSignedExtension) -> Balance { |
| 193 | + sign_ext.payload.7.into() |
| 194 | + } |
| 195 | +} |
0 commit comments