mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
* Use beefy branch with scale-info * Add patches * Sprinkle some TypeInfo derives * Add some TypeInfo deriv * Cargo.lock * Derive TypeInfo and skip type params for Xcm types * Cargo.lock * Fix up scale_info bounds attributes * Fix up dependencies * Use my own beefy-primitives branch * Bump BEEFY * Update patches * Add some scale-info dependencies and TypeInfo derives * More TypeInfo decoration * Update scale-info * Some TypeInfos and remove more Event pallet::metadata * Moar TypeInfos * TypeInfos galore, fix up metadata runtime API * TypeInfo * TypeInfos, update other runtime metadata APIs * Fix up Kusama, comment out some `usize` QueueSize parameter types * Remove local diener patches * Cargo.lock * Cargo.lock * Update to scale-info crates.io release * Update primitive-types branch * Update pallet-beefy to use custom branch * Update other parity-common deps * Update parity-common patches * bump a bunch of deps in parity-common * Remove parity-common patches * Bump finality-grandpa version * Cargo.lock * Update scale-info to 0.9.1 * Add recursion_limit for runtime-parachains * Add some scale_info attributes * Cargo.lock * Revert finality-grandpa bump * Cargo.lock, scale-info update * cargo update * Make sure using patched version of finality-grandpa * Use patched scale-info * Update to scale-info 0.10.0 * Update finality-grandpa * Cargo.lock * Update beefy deps * Update beefy deps again * Add scale-info dependency * Remove deprecated pallet::metadata attributes. * Add some missing scale-info deps and derives * Use some variant struct call syntax * Add missing TypeInfo impl * Add some more TypeInfo impls * Convert some call enum struct variant constructors * More scale-info deps and derives * Call enum struct variants * TypeInfo derives * Call enum variant structs * scale-info deps and derives * Call enum variant struct constructors * Use beefy-primitives scale-info feature * Use grandpa-bridge-gadget master branch * Remove finality-grandpa patch * Add missing scale_info dependency and derive * Fix up some call variant constructors * Add missing scale_info dependency * Fix some test errors * More TypeInfo derives * More call variant structs * Call variant structs in tests * Cargo.lock * Fmt * Fix more call struct variants * Another call struct variant * add scale-info/std features explicitly * More call struct variants * Add missing scale-info dependency * Fmt * review: activate scale-info/std where missing * Remove some duplicate std feature activation * review: add scale_info bounds() attr * More call variant structs * Remove recursion limit * Update beefy-primitives * Update beefy-primitives * Fix simnet call variant struct errors * Fmt * cargo update -p beefy-primitives * Add some missing TypeInfo derives * Fix some call variants * Fix some call variant underscores * Cargo.lock * Cargo.lock * Add missing TypeInfo derive * Add some more missing TypeInfo derives * Even more missing TypeInfo derives * Add TypeInfo derives to new xcm types * Fmt * Cargo.lock * Add missing TypeInfo impls * Cargo.lock * More missing TypeInfos * Fixes * Cargo.lock * Cargo.lock * Add TypeInfo impls to xcm v2 * Update to scale-info 1.0 * Update finality-grandpa 0.14.4, patch for now * Update beefy * Remove patched finality-grandpa * Add TypeInfo impl to Outcome * Fixes * Call variant struct * Call variant struct * Fix test * Add TypeInfo impl * Cargo.lock * Cargo.lock * Cargo.lock * git checkout master Cargo.lock * update Substrate * Add missing scale-info features for beefy-primitives * Fmt * Remove check for now * Update beefy-primitives, removes scale-info feature * Update beefy-primitives again Co-authored-by: adoerr <0xad@gmx.net> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
@@ -24,6 +24,7 @@ use frame_support::{
|
||||
pub use pallet::*;
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use primitives::v1::ValidityError;
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
|
||||
@@ -71,7 +72,7 @@ impl WeightInfo for TestWeightInfo {
|
||||
}
|
||||
|
||||
/// The kind of statement an account needs to make for a claim to be valid.
|
||||
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug)]
|
||||
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum StatementKind {
|
||||
/// Statement required to be made by non-SAFT holders.
|
||||
@@ -105,7 +106,7 @@ impl Default for StatementKind {
|
||||
/// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account).
|
||||
///
|
||||
/// This gets serialized to the 0x-prefixed hex representation.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)]
|
||||
pub struct EthereumAddress([u8; 20]);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -141,7 +142,7 @@ impl<'de> Deserialize<'de> for EthereumAddress {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Clone)]
|
||||
#[derive(Encode, Decode, Clone, TypeInfo)]
|
||||
pub struct EcdsaSignature(pub [u8; 65]);
|
||||
|
||||
impl PartialEq for EcdsaSignature {
|
||||
@@ -180,7 +181,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pallet::metadata(T::AccountId = "AccountId", BalanceOf<T> = "Balance")]
|
||||
pub enum Event<T: Config> {
|
||||
/// Someone claimed some DOTs. `[who, ethereum_address, amount]`
|
||||
Claimed(T::AccountId, EthereumAddress, BalanceOf<T>),
|
||||
@@ -473,14 +473,14 @@ pub mod pallet {
|
||||
// <weight>
|
||||
// The weight of this logic is included in the `claim` dispatchable.
|
||||
// </weight>
|
||||
Call::claim(account, ethereum_signature) => {
|
||||
Call::claim { dest: account, ethereum_signature } => {
|
||||
let data = account.using_encoded(to_ascii_hex);
|
||||
(Self::eth_recover(ðereum_signature, &data, &[][..]), None)
|
||||
},
|
||||
// <weight>
|
||||
// The weight of this logic is included in the `claim_attest` dispatchable.
|
||||
// </weight>
|
||||
Call::claim_attest(account, ethereum_signature, statement) => {
|
||||
Call::claim_attest { dest: account, ethereum_signature, statement } => {
|
||||
let data = account.using_encoded(to_ascii_hex);
|
||||
(
|
||||
Self::eth_recover(ðereum_signature, &data, &statement),
|
||||
@@ -588,7 +588,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are
|
||||
/// otherwise free to place on chain.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct PrevalidateAttests<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>)
|
||||
where
|
||||
<T as frame_system::Config>::Call: IsSubType<Call<T>>;
|
||||
@@ -643,7 +644,7 @@ where
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
if let Some(local_call) = call.is_sub_type() {
|
||||
if let Call::attest(attested_statement) = local_call {
|
||||
if let Call::attest { statement: attested_statement } = local_call {
|
||||
let signer = Preclaims::<T>::get(who)
|
||||
.ok_or(InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()))?;
|
||||
if let Some(s) = Signing::<T>::get(signer) {
|
||||
@@ -1035,7 +1036,9 @@ mod tests {
|
||||
fn valid_attest_transactions_are_free() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let p = PrevalidateAttests::<Test>::new();
|
||||
let c = Call::Claims(ClaimsCall::attest(StatementKind::Saft.to_text().to_vec()));
|
||||
let c = Call::Claims(ClaimsCall::attest {
|
||||
statement: StatementKind::Saft.to_text().to_vec(),
|
||||
});
|
||||
let di = c.get_dispatch_info();
|
||||
assert_eq!(di.pays_fee, Pays::No);
|
||||
let r = p.validate(&42, &c, &di, 20);
|
||||
@@ -1047,11 +1050,15 @@ mod tests {
|
||||
fn invalid_attest_transactions_are_recognized() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let p = PrevalidateAttests::<Test>::new();
|
||||
let c = Call::Claims(ClaimsCall::attest(StatementKind::Regular.to_text().to_vec()));
|
||||
let c = Call::Claims(ClaimsCall::attest {
|
||||
statement: StatementKind::Regular.to_text().to_vec(),
|
||||
});
|
||||
let di = c.get_dispatch_info();
|
||||
let r = p.validate(&42, &c, &di, 20);
|
||||
assert!(r.is_err());
|
||||
let c = Call::Claims(ClaimsCall::attest(StatementKind::Saft.to_text().to_vec()));
|
||||
let c = Call::Claims(ClaimsCall::attest {
|
||||
statement: StatementKind::Saft.to_text().to_vec(),
|
||||
});
|
||||
let di = c.get_dispatch_info();
|
||||
let r = p.validate(&69, &c, &di, 20);
|
||||
assert!(r.is_err());
|
||||
@@ -1282,7 +1289,10 @@ mod tests {
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(
|
||||
source,
|
||||
&ClaimsCall::claim(1, sig::<Test>(&alice(), &1u64.encode(), &[][..]))
|
||||
&ClaimsCall::claim {
|
||||
dest: 1,
|
||||
ethereum_signature: sig::<Test>(&alice(), &1u64.encode(), &[][..])
|
||||
}
|
||||
),
|
||||
Ok(ValidTransaction {
|
||||
priority: 100,
|
||||
@@ -1295,19 +1305,26 @@ mod tests {
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(
|
||||
source,
|
||||
&ClaimsCall::claim(0, EcdsaSignature([0; 65]))
|
||||
&ClaimsCall::claim { dest: 0, ethereum_signature: EcdsaSignature([0; 65]) }
|
||||
),
|
||||
InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(),
|
||||
);
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(
|
||||
source,
|
||||
&ClaimsCall::claim(1, sig::<Test>(&bob(), &1u64.encode(), &[][..]))
|
||||
&ClaimsCall::claim {
|
||||
dest: 1,
|
||||
ethereum_signature: sig::<Test>(&bob(), &1u64.encode(), &[][..])
|
||||
}
|
||||
),
|
||||
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
|
||||
);
|
||||
let s = sig::<Test>(&dave(), &1u64.encode(), StatementKind::Regular.to_text());
|
||||
let call = ClaimsCall::claim_attest(1, s, StatementKind::Regular.to_text().to_vec());
|
||||
let call = ClaimsCall::claim_attest {
|
||||
dest: 1,
|
||||
ethereum_signature: s,
|
||||
statement: StatementKind::Regular.to_text().to_vec(),
|
||||
};
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(source, &call),
|
||||
Ok(ValidTransaction {
|
||||
@@ -1321,31 +1338,43 @@ mod tests {
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(
|
||||
source,
|
||||
&ClaimsCall::claim_attest(
|
||||
1,
|
||||
EcdsaSignature([0; 65]),
|
||||
StatementKind::Regular.to_text().to_vec()
|
||||
)
|
||||
&ClaimsCall::claim_attest {
|
||||
dest: 1,
|
||||
ethereum_signature: EcdsaSignature([0; 65]),
|
||||
statement: StatementKind::Regular.to_text().to_vec()
|
||||
}
|
||||
),
|
||||
InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(),
|
||||
);
|
||||
|
||||
let s = sig::<Test>(&bob(), &1u64.encode(), StatementKind::Regular.to_text());
|
||||
let call = ClaimsCall::claim_attest(1, s, StatementKind::Regular.to_text().to_vec());
|
||||
let call = ClaimsCall::claim_attest {
|
||||
dest: 1,
|
||||
ethereum_signature: s,
|
||||
statement: StatementKind::Regular.to_text().to_vec(),
|
||||
};
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(source, &call),
|
||||
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
|
||||
);
|
||||
|
||||
let s = sig::<Test>(&dave(), &1u64.encode(), StatementKind::Saft.to_text());
|
||||
let call = ClaimsCall::claim_attest(1, s, StatementKind::Regular.to_text().to_vec());
|
||||
let call = ClaimsCall::claim_attest {
|
||||
dest: 1,
|
||||
ethereum_signature: s,
|
||||
statement: StatementKind::Regular.to_text().to_vec(),
|
||||
};
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(source, &call),
|
||||
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
|
||||
);
|
||||
|
||||
let s = sig::<Test>(&dave(), &1u64.encode(), StatementKind::Saft.to_text());
|
||||
let call = ClaimsCall::claim_attest(1, s, StatementKind::Saft.to_text().to_vec());
|
||||
let call = ClaimsCall::claim_attest {
|
||||
dest: 1,
|
||||
ethereum_signature: s,
|
||||
statement: StatementKind::Saft.to_text().to_vec(),
|
||||
};
|
||||
assert_eq!(
|
||||
<Pallet<Test>>::validate_unsigned(source, &call),
|
||||
InvalidTransaction::Custom(ValidityError::InvalidStatement.into()).into(),
|
||||
@@ -1414,7 +1443,7 @@ mod benchmarking {
|
||||
super::Pallet::<T>::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?;
|
||||
assert_eq!(Claims::<T>::get(eth_address), Some(VALUE.into()));
|
||||
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
||||
let call = Call::<T>::claim(account.clone(), signature.clone());
|
||||
let call = Call::<T>::claim { dest: account.clone(), ethereum_signature: signature.clone() };
|
||||
}: {
|
||||
super::Pallet::<T>::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?;
|
||||
super::Pallet::<T>::claim(RawOrigin::None.into(), account, signature)?;
|
||||
@@ -1459,7 +1488,7 @@ mod benchmarking {
|
||||
let signature = sig::<T>(&secret_key, &account.encode(), statement.to_text());
|
||||
super::Pallet::<T>::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?;
|
||||
assert_eq!(Claims::<T>::get(eth_address), Some(VALUE.into()));
|
||||
let call = Call::<T>::claim_attest(account.clone(), signature.clone(), StatementKind::Regular.to_text().to_vec());
|
||||
let call = Call::<T>::claim_attest { dest: account.clone(), ethereum_signature: signature.clone(), statement: StatementKind::Regular.to_text().to_vec() };
|
||||
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
||||
}: {
|
||||
super::Pallet::<T>::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?;
|
||||
@@ -1489,10 +1518,10 @@ mod benchmarking {
|
||||
Preclaims::<T>::insert(&account, eth_address);
|
||||
assert_eq!(Claims::<T>::get(eth_address), Some(VALUE.into()));
|
||||
|
||||
let call = super::Call::attest(StatementKind::Regular.to_text().to_vec());
|
||||
let call = super::Call::attest { statement: StatementKind::Regular.to_text().to_vec() };
|
||||
// We have to copy the validate statement here because of trait issues... :(
|
||||
let validate = |who: &T::AccountId, call: &super::Call<T>| -> DispatchResult {
|
||||
if let Call::attest(attested_statement) = call {
|
||||
if let Call::attest{ statement: attested_statement } = call {
|
||||
let signer = Preclaims::<T>::get(who).ok_or("signer has no claim")?;
|
||||
if let Some(s) = Signing::<T>::get(signer) {
|
||||
ensure!(&attested_statement[..] == s.to_text(), "invalid statement");
|
||||
|
||||
Reference in New Issue
Block a user