mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +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
@@ -22,7 +22,7 @@
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use frame_support::{
|
||||
construct_runtime, parameter_types,
|
||||
construct_runtime, parameter_types, debug,
|
||||
weights::Weight,
|
||||
traits::{SplitTwoWays, Currency, Randomness},
|
||||
};
|
||||
@@ -35,7 +35,7 @@ use sp_runtime::{
|
||||
use sp_runtime::curve::PiecewiseLinear;
|
||||
use sp_runtime::transaction_validity::TransactionValidity;
|
||||
use sp_runtime::traits::{
|
||||
self, BlakeTwo256, Block as BlockT, NumberFor, StaticLookup, SaturatedConversion,
|
||||
self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion,
|
||||
OpaqueKeys,
|
||||
};
|
||||
use sp_version::RuntimeVersion;
|
||||
@@ -448,7 +448,8 @@ impl pallet_sudo::Trait for Runtime {
|
||||
type Proposal = Call;
|
||||
}
|
||||
|
||||
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
|
||||
/// A runtime transaction submitter.
|
||||
pub type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
|
||||
|
||||
parameter_types! {
|
||||
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
|
||||
@@ -517,7 +518,11 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
|
||||
.checked_next_power_of_two()
|
||||
.map(|c| c / 2)
|
||||
.unwrap_or(2) as u64;
|
||||
let current_block = System::block_number().saturated_into::<u64>();
|
||||
let current_block = System::block_number()
|
||||
.saturated_into::<u64>()
|
||||
// The `System::block_number` is initialized with `n+1`,
|
||||
// so the actual block number is `n`.
|
||||
.saturating_sub(1);
|
||||
let tip = 0;
|
||||
let extra: SignedExtra = (
|
||||
frame_system::CheckVersion::<Runtime>::new(),
|
||||
@@ -528,7 +533,9 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
|
||||
Default::default(),
|
||||
);
|
||||
let raw_payload = SignedPayload::new(call, extra).ok()?;
|
||||
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
|
||||
debug::warn!("Unable to create signed payload: {:?}", e);
|
||||
}).ok()?;
|
||||
let signature = TSigner::sign(public, &raw_payload)?;
|
||||
let address = Indices::unlookup(account);
|
||||
let (call, extra, _) = raw_payload.deconstruct();
|
||||
@@ -649,8 +656,8 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(number: NumberFor<Block>) {
|
||||
Executive::offchain_worker(number)
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,22 +757,29 @@ impl_runtime_apis! {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use frame_system::offchain::SubmitSignedTransaction;
|
||||
|
||||
fn is_submit_signed_transaction<T>(_arg: T) where
|
||||
T: SubmitSignedTransaction<
|
||||
Runtime,
|
||||
Call,
|
||||
Extrinsic=UncheckedExtrinsic,
|
||||
CreateTransaction=Runtime,
|
||||
Signer=ImOnlineId,
|
||||
>,
|
||||
{}
|
||||
use frame_system::offchain::{SignAndSubmitTransaction, SubmitSignedTransaction};
|
||||
|
||||
#[test]
|
||||
fn validate_bounds() {
|
||||
let x = SubmitTransaction::default();
|
||||
is_submit_signed_transaction(x);
|
||||
fn validate_transaction_submitter_bounds() {
|
||||
fn is_submit_signed_transaction<T>() where
|
||||
T: SubmitSignedTransaction<
|
||||
Runtime,
|
||||
Call,
|
||||
>,
|
||||
{}
|
||||
|
||||
fn is_sign_and_submit_transaction<T>() where
|
||||
T: SignAndSubmitTransaction<
|
||||
Runtime,
|
||||
Call,
|
||||
Extrinsic=UncheckedExtrinsic,
|
||||
CreateTransaction=Runtime,
|
||||
Signer=ImOnlineId,
|
||||
>,
|
||||
{}
|
||||
|
||||
is_submit_signed_transaction::<SubmitTransaction>();
|
||||
is_sign_and_submit_transaction::<SubmitTransaction>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user