mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 15:58:02 +00:00
Extend Utility pallet with multisig and pseudonyms (#4462)
* Add subaccounts functionality * More work * Multisig prototyped with tests * Add timepoints to prevent replay * Remove TODO * Check for the right owner in cancel. * Test the timepoint stuff * Batch works with any origin * Refactor tuples into structs. * Finalise function docs/complexity and also add proper weights. * Fix wasm * Module-level docs * Fix typo * Runtime fix * Better deposit system; more tests. * Fix typo * Switch +1 for -1 * Add Blake2_128Concat; fix insecurity; change return policy. * Fix typo * Update frame/utility/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/utility/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Update bin/node/runtime/src/lib.rs Co-Authored-By: Sergei Pepyakin <sergei@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
This commit is contained in:
@@ -128,9 +128,21 @@ impl frame_system::Trait for Runtime {
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
// One storage item; value is size 4+4+16+32 bytes = 56 bytes.
|
||||
pub const MultisigDepositBase: Balance = 30 * CENTS;
|
||||
// Additional storage item size of 32 bytes.
|
||||
pub const MultisigDepositFactor: Balance = 5 * CENTS;
|
||||
pub const MaxSignatories: u16 = 100;
|
||||
}
|
||||
|
||||
impl pallet_utility::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
type Currency = Balances;
|
||||
type MultisigDepositBase = MultisigDepositBase;
|
||||
type MultisigDepositFactor = MultisigDepositFactor;
|
||||
type MaxSignatories = MaxSignatories;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -515,7 +527,7 @@ construct_runtime!(
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: frame_system::{Module, Call, Storage, Config, Event},
|
||||
Utility: pallet_utility::{Module, Call, Event},
|
||||
Utility: pallet_utility::{Module, Call, Storage, Event<T>, Error},
|
||||
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
|
||||
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
|
||||
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
|
||||
|
||||
@@ -223,7 +223,6 @@ decl_error! {
|
||||
/// Balance should be non-zero
|
||||
BalanceZero,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
|
||||
@@ -273,6 +273,7 @@ impl sp_std::fmt::Debug for DefaultByteGetter {
|
||||
pub enum StorageHasher {
|
||||
Blake2_128,
|
||||
Blake2_256,
|
||||
Blake2_128Concat,
|
||||
Twox128,
|
||||
Twox256,
|
||||
Twox64Concat,
|
||||
|
||||
@@ -153,6 +153,7 @@ use proc_macro::TokenStream;
|
||||
/// * `twox_64_concat` - TwoX with 64bit + key concatenated.
|
||||
/// * `twox_128` - TwoX with 128bit.
|
||||
/// * `twox_256` - TwoX with with 256bit.
|
||||
/// * `blake2_128_concat` - Blake2 with 128bit + key concatenated.
|
||||
/// * `blake2_128` - Blake2 with 128bit.
|
||||
/// * `blake2_256` - Blake2 with 256bit.
|
||||
///
|
||||
|
||||
@@ -368,6 +368,7 @@ pub struct ExtraGenesisLineDef {
|
||||
pub enum HasherKind {
|
||||
Blake2_256,
|
||||
Blake2_128,
|
||||
Blake2_128Concat,
|
||||
Twox256,
|
||||
Twox128,
|
||||
Twox64Concat,
|
||||
@@ -378,6 +379,7 @@ impl HasherKind {
|
||||
match self {
|
||||
HasherKind::Blake2_256 => quote!( Blake2_256 ),
|
||||
HasherKind::Blake2_128 => quote!( Blake2_128 ),
|
||||
HasherKind::Blake2_128Concat => quote!( Blake2_128Concat ),
|
||||
HasherKind::Twox256 => quote!( Twox256 ),
|
||||
HasherKind::Twox128 => quote!( Twox128 ),
|
||||
HasherKind::Twox64Concat => quote!( Twox64Concat ),
|
||||
@@ -388,6 +390,7 @@ impl HasherKind {
|
||||
match self {
|
||||
HasherKind::Blake2_256 => quote!( StorageHasher::Blake2_256 ),
|
||||
HasherKind::Blake2_128 => quote!( StorageHasher::Blake2_128 ),
|
||||
HasherKind::Blake2_128Concat => quote!( StorageHasher::Blake2_128Concat ),
|
||||
HasherKind::Twox256 => quote!( StorageHasher::Twox256 ),
|
||||
HasherKind::Twox128 => quote!( StorageHasher::Twox128 ),
|
||||
HasherKind::Twox64Concat => quote!( StorageHasher::Twox64Concat ),
|
||||
|
||||
@@ -31,6 +31,7 @@ mod keyword {
|
||||
syn::custom_keyword!(double_map);
|
||||
syn::custom_keyword!(blake2_256);
|
||||
syn::custom_keyword!(blake2_128);
|
||||
syn::custom_keyword!(blake2_128_concat);
|
||||
syn::custom_keyword!(twox_256);
|
||||
syn::custom_keyword!(twox_128);
|
||||
syn::custom_keyword!(twox_64_concat);
|
||||
@@ -179,6 +180,7 @@ struct DeclStorageDoubleMap {
|
||||
enum Hasher {
|
||||
Blake2_256(keyword::blake2_256),
|
||||
Blake2_128(keyword::blake2_128),
|
||||
Blake2_128Concat(keyword::blake2_128_concat),
|
||||
Twox256(keyword::twox_256),
|
||||
Twox128(keyword::twox_128),
|
||||
Twox64Concat(keyword::twox_64_concat),
|
||||
@@ -207,6 +209,7 @@ impl From<Hasher> for super::HasherKind {
|
||||
match hasher {
|
||||
Hasher::Blake2_256(_) => super::HasherKind::Blake2_256,
|
||||
Hasher::Blake2_128(_) => super::HasherKind::Blake2_128,
|
||||
Hasher::Blake2_128Concat(_) => super::HasherKind::Blake2_128Concat,
|
||||
Hasher::Twox256(_) => super::HasherKind::Twox256,
|
||||
Hasher::Twox128(_) => super::HasherKind::Twox128,
|
||||
Hasher::Twox64Concat(_) => super::HasherKind::Twox64Concat,
|
||||
|
||||
@@ -24,6 +24,7 @@ use sp_io::hashing::{blake2_128, blake2_256, twox_64, twox_128, twox_256};
|
||||
pub trait Hashable: Sized {
|
||||
fn blake2_128(&self) -> [u8; 16];
|
||||
fn blake2_256(&self) -> [u8; 32];
|
||||
fn blake2_128_concat(&self) -> Vec<u8>;
|
||||
fn twox_128(&self) -> [u8; 16];
|
||||
fn twox_256(&self) -> [u8; 32];
|
||||
fn twox_64_concat(&self) -> Vec<u8>;
|
||||
@@ -36,6 +37,9 @@ impl<T: Codec> Hashable for T {
|
||||
fn blake2_256(&self) -> [u8; 32] {
|
||||
self.using_encoded(blake2_256)
|
||||
}
|
||||
fn blake2_128_concat(&self) -> Vec<u8> {
|
||||
self.using_encoded(Blake2_128Concat::hash)
|
||||
}
|
||||
fn twox_128(&self) -> [u8; 16] {
|
||||
self.using_encoded(twox_128)
|
||||
}
|
||||
@@ -66,6 +70,19 @@ impl StorageHasher for Twox64Concat {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash storage keys with `concat(blake2_128(key), key)`
|
||||
pub struct Blake2_128Concat;
|
||||
impl StorageHasher for Blake2_128Concat {
|
||||
type Output = Vec<u8>;
|
||||
fn hash(x: &[u8]) -> Vec<u8> {
|
||||
blake2_128(x)
|
||||
.iter()
|
||||
.chain(x.into_iter())
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash storage keys with blake2 128
|
||||
pub struct Blake2_128;
|
||||
impl StorageHasher for Blake2_128 {
|
||||
@@ -111,4 +128,10 @@ mod tests {
|
||||
let r = Twox64Concat::hash(b"foo");
|
||||
assert_eq!(r.split_at(8), (&twox_128(b"foo")[..8], &b"foo"[..]))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blake2_128_concat() {
|
||||
let r = Blake2_128Concat::hash(b"foo");
|
||||
assert_eq!(r.split_at(16), (&blake2_128(b"foo")[..], &b"foo"[..]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,9 @@ pub mod error;
|
||||
pub mod traits;
|
||||
pub mod weights;
|
||||
|
||||
pub use self::hash::{Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat, Hashable};
|
||||
pub use self::hash::{
|
||||
Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat, Blake2_128Concat, Hashable
|
||||
};
|
||||
pub use self::storage::{
|
||||
StorageValue, StorageMap, StorageLinkedMap, StorageDoubleMap, StoragePrefixedMap
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ serde = { version = "1.0.101", optional = true }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
|
||||
frame-support = { version = "2.0.0", default-features = false, path = "../support" }
|
||||
frame-system = { version = "2.0.0", default-features = false, path = "../system" }
|
||||
sp-core = { version = "2.0.0", default-features = false, path = "../../primitives/core" }
|
||||
sp-runtime = { version = "2.0.0", default-features = false, path = "../../primitives/runtime" }
|
||||
sp-std = { version = "2.0.0", default-features = false, path = "../../primitives/std" }
|
||||
sp-io = { version = "2.0.0", default-features = false, path = "../../primitives/io" }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -384,6 +384,17 @@ pub enum DispatchError {
|
||||
},
|
||||
}
|
||||
|
||||
impl DispatchError {
|
||||
/// Return the same error but without the attached message.
|
||||
pub fn stripped(self) -> Self {
|
||||
match self {
|
||||
DispatchError::Module { index, error, message: Some(_) }
|
||||
=> DispatchError::Module { index, error, message: None },
|
||||
m => m,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::traits::LookupError> for DispatchError {
|
||||
fn from(_: crate::traits::LookupError) -> Self {
|
||||
Self::CannotLookup
|
||||
|
||||
Reference in New Issue
Block a user