mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Add documentation to SubmitSignedTransaction and actually make it work (#4200)
* Add documentation to signed transactions and actually make them work. * Fix naming and bounds. * Forgotten import. * Remove warning. * Make accounts optional, fix logic. * Split the method to avoid confusing type error message. * Move executor tests to integration. * Add submit transactions tests. * Make `submit_transaction` tests compile * Remove a file that was accidently committed * Add can_sign helper function. * Fix compilation. * Add a key to keystore. * Fix the tests. * Remove env_logger. * Fix sending multiple transactions. * Remove commented code. * Bring back criterion. * Remove stray debug log. * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Make sure to initialize block correctly. * Initialize block for offchain workers. * Add test for transaction validity. * Fix tests. * Review suggestions. * Remove redundant comment. * Make sure to use correct block number of authoring. * Change the runtime API. * Support both versions. * Bump spec version, fix RPC test. Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Gavin Wood <github@gavwood.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
Gavin Wood
parent
a1e0076aa8
commit
74d6e660c6
@@ -82,7 +82,7 @@ use sp_runtime::{
|
||||
generic::Digest, ApplyExtrinsicResult,
|
||||
traits::{
|
||||
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize,
|
||||
NumberFor, Block as BlockT, OffchainWorker, Dispatchable,
|
||||
NumberFor, Block as BlockT, OffchainWorker, Dispatchable, Saturating,
|
||||
},
|
||||
transaction_validity::TransactionValidity,
|
||||
};
|
||||
@@ -154,9 +154,23 @@ where
|
||||
{
|
||||
/// Start the execution of a particular block.
|
||||
pub fn initialize_block(header: &System::Header) {
|
||||
let mut digests = <DigestOf<System>>::default();
|
||||
header.digest().logs().iter().for_each(|d| if d.as_pre_runtime().is_some() { digests.push(d.clone()) });
|
||||
Self::initialize_block_impl(header.number(), header.parent_hash(), header.extrinsics_root(), &digests);
|
||||
let digests = Self::extract_pre_digest(&header);
|
||||
Self::initialize_block_impl(
|
||||
header.number(),
|
||||
header.parent_hash(),
|
||||
header.extrinsics_root(),
|
||||
&digests
|
||||
);
|
||||
}
|
||||
|
||||
fn extract_pre_digest(header: &System::Header) -> DigestOf<System> {
|
||||
let mut digest = <DigestOf<System>>::default();
|
||||
header.digest().logs()
|
||||
.iter()
|
||||
.for_each(|d| if d.as_pre_runtime().is_some() {
|
||||
digest.push(d.clone())
|
||||
});
|
||||
digest
|
||||
}
|
||||
|
||||
fn initialize_block_impl(
|
||||
@@ -165,7 +179,13 @@ where
|
||||
extrinsics_root: &System::Hash,
|
||||
digest: &Digest<System::Hash>,
|
||||
) {
|
||||
<frame_system::Module<System>>::initialize(block_number, parent_hash, extrinsics_root, digest);
|
||||
<frame_system::Module<System>>::initialize(
|
||||
block_number,
|
||||
parent_hash,
|
||||
extrinsics_root,
|
||||
digest,
|
||||
frame_system::InitKind::Full,
|
||||
);
|
||||
<AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number);
|
||||
<frame_system::Module<System>>::register_extra_weight_unchecked(
|
||||
<AllModules as WeighBlock<System::BlockNumber>>::on_initialize(*block_number)
|
||||
@@ -310,8 +330,24 @@ where
|
||||
}
|
||||
|
||||
/// Start an offchain worker and generate extrinsics.
|
||||
pub fn offchain_worker(n: System::BlockNumber) {
|
||||
<AllModules as OffchainWorker<System::BlockNumber>>::offchain_worker(n)
|
||||
pub fn offchain_worker(header: &System::Header) {
|
||||
// We need to keep events available for offchain workers,
|
||||
// hence we initialize the block manually.
|
||||
// OffchainWorker RuntimeApi should skip initialization.
|
||||
let digests = Self::extract_pre_digest(header);
|
||||
|
||||
<frame_system::Module<System>>::initialize(
|
||||
header.number(),
|
||||
header.parent_hash(),
|
||||
header.extrinsics_root(),
|
||||
&digests,
|
||||
frame_system::InitKind::Inspection,
|
||||
);
|
||||
<AllModules as OffchainWorker<System::BlockNumber>>::offchain_worker(
|
||||
// to maintain backward compatibility we call module offchain workers
|
||||
// with parent block number.
|
||||
header.number().saturating_sub(1.into())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user