mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Offchain signing followup (#1017)
* Use the fishermanId for AppCrypto on runtimes * Make sure at least one transaction was submitted * Use find_map
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_std::result;
|
use sp_std::result;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
|
use sp_core::sr25519;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
KeyTypeId, Perbill, RuntimeDebug,
|
KeyTypeId, Perbill, RuntimeDebug,
|
||||||
traits::{
|
traits::{
|
||||||
@@ -41,19 +41,23 @@ use frame_support::{
|
|||||||
use primitives::{
|
use primitives::{
|
||||||
Balance,
|
Balance,
|
||||||
BlockNumber,
|
BlockNumber,
|
||||||
|
Signature,
|
||||||
parachain::{
|
parachain::{
|
||||||
Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement, ParachainDispatchOrigin,
|
Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement, ParachainDispatchOrigin,
|
||||||
UpwardMessage, ValidatorId, ActiveParas, CollatorId, Retriable, OmittedValidationData,
|
UpwardMessage, ValidatorId, ActiveParas, CollatorId, Retriable, OmittedValidationData,
|
||||||
CandidateReceipt, GlobalValidationSchedule, AbridgedCandidateReceipt,
|
CandidateReceipt, GlobalValidationSchedule, AbridgedCandidateReceipt,
|
||||||
LocalValidationData, Scheduling, ValidityAttestation, NEW_HEADS_IDENTIFIER, PARACHAIN_KEY_TYPE_ID,
|
LocalValidationData, Scheduling, ValidityAttestation, NEW_HEADS_IDENTIFIER, PARACHAIN_KEY_TYPE_ID,
|
||||||
ValidatorSignature, SigningContext, HeadData, ValidationCode,
|
ValidatorSignature, SigningContext, HeadData, ValidationCode, FishermanId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
Parameter, dispatch::DispatchResult, decl_storage, decl_module, decl_error, ensure,
|
Parameter, dispatch::DispatchResult, decl_storage, decl_module, decl_error, ensure,
|
||||||
traits::{Currency, Get, WithdrawReason, ExistenceRequirement, Randomness},
|
traits::{Currency, Get, WithdrawReason, ExistenceRequirement, Randomness},
|
||||||
};
|
};
|
||||||
use sp_runtime::transaction_validity::InvalidTransaction;
|
use sp_runtime::{
|
||||||
|
transaction_validity::InvalidTransaction,
|
||||||
|
traits::Verify,
|
||||||
|
};
|
||||||
|
|
||||||
use inherents::{ProvideInherent, InherentData, MakeFatalError, InherentIdentifier};
|
use inherents::{ProvideInherent, InherentData, MakeFatalError, InherentIdentifier};
|
||||||
|
|
||||||
@@ -64,23 +68,12 @@ use system::{
|
|||||||
use crate::attestations::{self, IncludedBlocks};
|
use crate::attestations::{self, IncludedBlocks};
|
||||||
use crate::registrar::Registrar;
|
use crate::registrar::Registrar;
|
||||||
|
|
||||||
pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"para");
|
// An `AppCrypto` type to facilitate submitting signed transactions.
|
||||||
|
pub struct FishermanAuthorityId;
|
||||||
pub mod crypto {
|
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
|
||||||
use super::KEY_TYPE;
|
type RuntimeAppPublic = FishermanId;
|
||||||
use sp_runtime::{
|
type GenericSignature = sr25519::Signature;
|
||||||
app_crypto::{app_crypto, sr25519},
|
type GenericPublic = sp_core::sr25519::Public;
|
||||||
traits::Verify,
|
|
||||||
};
|
|
||||||
use sp_core::sr25519::Signature as Sr25519Signature;
|
|
||||||
app_crypto!(sr25519, KEY_TYPE);
|
|
||||||
|
|
||||||
pub struct AuthorityId;
|
|
||||||
impl system::offchain::AppCrypto<<Sr25519Signature as Verify>::Signer, Sr25519Signature> for AuthorityId {
|
|
||||||
type RuntimeAppPublic = Public;
|
|
||||||
type GenericSignature = Sr25519Signature;
|
|
||||||
type GenericPublic = sp_core::sr25519::Public;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ranges for iteration of general block number don't work, so this
|
// ranges for iteration of general block number don't work, so this
|
||||||
@@ -818,8 +811,9 @@ impl<T: Trait> Module<T> {
|
|||||||
move |_account| {
|
move |_account| {
|
||||||
Call::report_double_vote(report.clone())
|
Call::report_double_vote(report.clone())
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
return Some(())
|
.iter()
|
||||||
|
.find_map(|(_, res)| res.ok().map(|_| ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dispatch some messages from a parachain.
|
/// Dispatch some messages from a parachain.
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ use runtime_common::{attestations, claims, parachains, registrar, slots,
|
|||||||
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
|
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
|
||||||
MaximumBlockLength,
|
MaximumBlockLength,
|
||||||
};
|
};
|
||||||
use sp_core::sr25519;
|
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
|
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
|
||||||
@@ -517,7 +516,7 @@ parameter_types! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl parachains::Trait for Runtime {
|
impl parachains::Trait for Runtime {
|
||||||
type AuthorityId = FishermanAuthorityId;
|
type AuthorityId = parachains::FishermanAuthorityId;
|
||||||
type Origin = Origin;
|
type Origin = Origin;
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
type ParachainCurrency = Balances;
|
type ParachainCurrency = Balances;
|
||||||
@@ -539,13 +538,6 @@ impl parachains::Trait for Runtime {
|
|||||||
type BlockHashConversion = sp_runtime::traits::Identity;
|
type BlockHashConversion = sp_runtime::traits::Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FishermanAuthorityId;
|
|
||||||
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
|
|
||||||
type RuntimeAppPublic = parachain::FishermanId;
|
|
||||||
type GenericSignature = sr25519::Signature;
|
|
||||||
type GenericPublic = sr25519::Public;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
||||||
Call: From<LocalCall>,
|
Call: From<LocalCall>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ use primitives::{
|
|||||||
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
|
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
|
||||||
parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError,
|
parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError,
|
||||||
};
|
};
|
||||||
use sp_core::sr25519;
|
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
|
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Perquintill, RuntimeDebug,
|
||||||
@@ -524,7 +523,7 @@ parameter_types! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl parachains::Trait for Runtime {
|
impl parachains::Trait for Runtime {
|
||||||
type AuthorityId = FishermanAuthorityId;
|
type AuthorityId = parachains::FishermanAuthorityId;
|
||||||
type Origin = Origin;
|
type Origin = Origin;
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
type ParachainCurrency = Balances;
|
type ParachainCurrency = Balances;
|
||||||
@@ -546,13 +545,6 @@ impl parachains::Trait for Runtime {
|
|||||||
type BlockHashConversion = sp_runtime::traits::Identity;
|
type BlockHashConversion = sp_runtime::traits::Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FishermanAuthorityId;
|
|
||||||
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
|
|
||||||
type RuntimeAppPublic = parachain::FishermanId;
|
|
||||||
type GenericSignature = sr25519::Signature;
|
|
||||||
type GenericPublic = sr25519::Public;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
||||||
Call: From<LocalCall>,
|
Call: From<LocalCall>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ use runtime_common::{attestations, parachains, registrar,
|
|||||||
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
|
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
|
||||||
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
|
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
|
||||||
};
|
};
|
||||||
use sp_core::sr25519;
|
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
ApplyExtrinsicResult, KeyTypeId, Perbill, Perquintill, RuntimeDebug,
|
ApplyExtrinsicResult, KeyTypeId, Perbill, Perquintill, RuntimeDebug,
|
||||||
@@ -387,7 +386,7 @@ parameter_types! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl parachains::Trait for Runtime {
|
impl parachains::Trait for Runtime {
|
||||||
type AuthorityId = FishermanAuthorityId;
|
type AuthorityId = parachains::FishermanAuthorityId;
|
||||||
type Origin = Origin;
|
type Origin = Origin;
|
||||||
type Call = Call;
|
type Call = Call;
|
||||||
type ParachainCurrency = Balances;
|
type ParachainCurrency = Balances;
|
||||||
@@ -409,13 +408,6 @@ impl parachains::Trait for Runtime {
|
|||||||
type BlockHashConversion = sp_runtime::traits::Identity;
|
type BlockHashConversion = sp_runtime::traits::Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FishermanAuthorityId;
|
|
||||||
impl system::offchain::AppCrypto<<Signature as Verify>::Signer, Signature> for FishermanAuthorityId {
|
|
||||||
type RuntimeAppPublic = parachain::FishermanId;
|
|
||||||
type GenericSignature = sr25519::Signature;
|
|
||||||
type GenericPublic = sr25519::Public;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Runtime where
|
||||||
Call: From<LocalCall>,
|
Call: From<LocalCall>,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user