diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index c4752bae06d46..195128c698c66 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -715,20 +715,27 @@ mod tests { use super::*; use system::offchain::SubmitSignedTransaction; - fn is_submit_signed_transaction(_arg: T) where - T: SubmitSignedTransaction< - Runtime, - Call, - Extrinsic=UncheckedExtrinsic, - CreateTransaction=Runtime, - Signer=ImOnlineId, - >, - {} - #[test] fn validate_bounds() { - let x = SubmitTransaction::default(); - is_submit_signed_transaction(x); + fn is_submit_signed_transaction() where + T: SubmitSignedTransaction< + Runtime, + Call, + >, + {} + + fn is_sign_and_submit_transaction(_arg: T) where + T: SignAndSubmitTransaction< + Runtime, + Call, + Extrinsic=UncheckedExtrinsic, + CreateTransaction=Runtime, + Signer=ImOnlineId, + >, + {} + + is_submit_signed_transaction::(); + is_sign_and_submit_transaction::(); } #[test] diff --git a/frame/system/src/offchain.rs b/frame/system/src/offchain.rs index f4ff79e6aecd4..bfbbcee134d7a 100644 --- a/frame/system/src/offchain.rs +++ b/frame/system/src/offchain.rs @@ -94,12 +94,12 @@ impl Signer for TAnyAppPubl } } -/// Retrieves a public key type for given `SubmitSignedTransaction`. +/// Retrieves a public key type for given `SignAndSubmitTransaction`. pub type PublicOf = < - >::CreateTransaction + >::CreateTransaction as - CreateTransaction>::Extrinsic> + CreateTransaction>::Extrinsic> >::Public; /// A trait to sign and submit transactions in offchain calls. @@ -107,7 +107,7 @@ pub type PublicOf = /// NOTE: Most likely you should not implement this trait yourself. /// There is an implementation for `TransactionSubmitter` type, which /// you should use. -pub trait SubmitSignedTransaction { +pub trait SignAndSubmitTransaction { /// Unchecked extrinsic type. type Extrinsic: ExtrinsicT + codec::Encode; @@ -168,9 +168,9 @@ pub trait SubmitUnsignedTransaction { /// NOTE: Most likely you should not implement this trait yourself. /// There is an implementation for `TransactionSubmitter` type, which /// you should use. -pub trait SigningAccountFinder { - /// A `SubmitSignedTransaction` implementation. - type SubmitTransaction: SubmitSignedTransaction; +pub trait SubmitSignedTransaction { + /// A `SignAndSubmitTransaction` implementation. + type SignAndSubmit: SignAndSubmitTransaction; /// Find local keys that match given list of accounts. /// @@ -181,7 +181,7 @@ pub trait SigningAccountFinder { /// Such accounts can later be used to sign a payload or send signed transactions. fn find_local_keys(accounts: impl IntoIterator) -> Vec<( T::AccountId, - PublicOf, + PublicOf, )>; /// Create and submit signed transactions from supported accounts. @@ -201,7 +201,7 @@ pub trait SigningAccountFinder { let call = call.clone().into(); ( account, - Self::SubmitTransaction::sign_and_submit(call, pub_key) + Self::SignAndSubmit::sign_and_submit(call, pub_key) ) }).collect() } @@ -211,9 +211,9 @@ pub trait SigningAccountFinder { /// A default type used to submit transactions to the pool. /// /// This is passed into each runtime as an opaque associated type that can have either of: -/// - [`SubmitSignedTransaction`] +/// - [`SignAndSubmitTransaction`] /// - [`SubmitUnsignedTransaction`] -/// - [`SigningAccountFinder`] +/// - [`SubmitSignedTransaction`] /// and used accordingly. /// /// This struct should be constructed by providing the following generic parameters: @@ -237,7 +237,7 @@ impl Default for TransactionSubmitter { } /// A blanket implementation to simplify creation of transaction signer & submitter in the runtime. -impl SubmitSignedTransaction for TransactionSubmitter where +impl SignAndSubmitTransaction for TransactionSubmitter where T: crate::Trait, C: CreateTransaction, S: Signer<>::Public, >::Signature>, @@ -257,35 +257,28 @@ impl SubmitUnsignedTransaction for TransactionSubmitt } /// A blanket implementation to support local keystore of application-crypto types. -impl SigningAccountFinder for TransactionSubmitter where +impl SubmitSignedTransaction for TransactionSubmitter where T: crate::Trait, C: CreateTransaction, E: ExtrinsicT + codec::Encode, S: Signer<>::Public, >::Signature>, - S: RuntimeAppPublic - + AppPublic - // TODO remove AppPublic? - + Into<::Generic> - + From<::Generic>, + // Make sure we can unwrap the app crypto key. + S: RuntimeAppPublic + AppPublic + Into<::Generic>, + // Make sure we can convert from wrapped crypto to public key (e.g. `MultiSigner`) S::Generic: Into>, - PublicOf: TryInto<::Generic>, - ::Signature: AppSignature, - // >::Signature: From< - // <::Signature as app_crypto::AppSignature>::Generic - // >, - < as SubmitSignedTransaction>::CreateTransaction as CreateTransaction as SubmitSignedTransaction>::Extrinsic>>::Signature: From<<::Signature as app_crypto::AppSignature>::Generic>, - Self: SubmitSignedTransaction, + // For simplicity we require the same trait to implement `SignAndSubmitTransaction` too. + Self: SignAndSubmitTransaction, { - type SubmitTransaction = Self; + type SignAndSubmit = Self; fn find_local_keys(accounts: impl IntoIterator) -> Vec<( T::AccountId, - PublicOf, + PublicOf, )> { // Convert app-specific keys into generic ones. let local_keys = S::all().into_iter().map(|app_key| { app_key.into() - }).collect::::Generic>>(); + }).collect::::Generic>>(); // lookup accountids for the pub keys. let mut local_accounts = local_keys.clone().into_iter().map(|pub_key| {