mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 09:05:41 +00:00
Introduce safe types for handling imbalances (#2048)
* Be a little safer with total issuance. * PairT instead of _Pair * Remove rev causing upset * Remove fees stuff. * Fix build (including tests) * Update runtime, bump version * Fix * Handle gas refunds properly. * Rename identifier ala #2025 * Address grumbles * New not-quite-linear-typing API * Slimmer API * More linear-type test fixes * Fix tests * Tidy * Fix some grumbles * Keep unchecked functions private * Remove another less-than-safe currency function and ensure that contracts module can never create cash. * Address a few grumbles and fix tests
This commit is contained in:
committed by
Robert Habermeier
parent
f9e224e7b8
commit
dcd77a147c
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::{collections::HashMap, ops::Deref};
|
||||
use lazy_static::lazy_static;
|
||||
use substrate_primitives::{ed25519::{Pair, Public, Signature}, Pair as _Pair, H256};
|
||||
use substrate_primitives::{ed25519::{Pair, Public, Signature}, Pair as PairT, H256};
|
||||
pub use substrate_primitives::ed25519;
|
||||
|
||||
/// Set of test accounts.
|
||||
@@ -162,7 +162,7 @@ impl Deref for Keyring {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use substrate_primitives::{ed25519::Pair, Pair as _Pair};
|
||||
use substrate_primitives::{ed25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use lazy_static::lazy_static;
|
||||
use substrate_primitives::{sr25519::{Pair, Public, Signature}, Pair as _Pair, H256};
|
||||
use substrate_primitives::{sr25519::{Pair, Public, Signature}, Pair as PairT, H256};
|
||||
pub use substrate_primitives::sr25519;
|
||||
|
||||
/// Set of test accounts.
|
||||
@@ -167,7 +167,7 @@ impl Deref for Keyring {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use substrate_primitives::{sr25519::Pair, Pair as _Pair};
|
||||
use substrate_primitives::{sr25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
|
||||
@@ -28,7 +28,7 @@ use std::io::{self, Write};
|
||||
use error_chain::{bail, error_chain, error_chain_processing, impl_error_chain_processed,
|
||||
impl_extract_backtrace, impl_error_chain_kind};
|
||||
|
||||
use substrate_primitives::{ed25519::{Pair, Public}, Pair as _Pair};
|
||||
use substrate_primitives::{ed25519::{Pair, Public}, Pair as PairT};
|
||||
|
||||
pub use crypto::KEY_ITERATIONS;
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ impl Pair {
|
||||
mod test {
|
||||
use super::*;
|
||||
use hex_literal::{hex, hex_impl};
|
||||
use crate::{Pair as _Pair, crypto::DEV_PHRASE};
|
||||
use crate::{Pair as PairT, crypto::DEV_PHRASE};
|
||||
|
||||
#[test]
|
||||
fn default_phrase_should_be_used() {
|
||||
|
||||
@@ -501,7 +501,7 @@ impl Pair {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{Pair as _Pair, crypto::{Ss58Codec, DEV_PHRASE, DEV_ADDRESS}};
|
||||
use crate::{Pair as PairT, crypto::{Ss58Codec, DEV_PHRASE, DEV_ADDRESS}};
|
||||
use hex_literal::{hex, hex_impl};
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -30,7 +30,7 @@ pub use serde_derive;
|
||||
pub use runtime_io::{StorageOverlay, ChildrenStorageOverlay};
|
||||
|
||||
use rstd::prelude::*;
|
||||
use substrate_primitives::{ed25519, sr25519, hash::{H256, H512}};
|
||||
use substrate_primitives::{ed25519, sr25519, hash::H512};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -379,16 +379,17 @@ impl Verify for MultiSignature {
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub struct AnySignature(H512);
|
||||
|
||||
/// Public key for any known crypto algorithm.
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Default, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub struct AnySigner(H256);
|
||||
|
||||
impl Verify for AnySignature {
|
||||
type Signer = AnySigner;
|
||||
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &AnySigner) -> bool {
|
||||
runtime_io::sr25519_verify(self.0.as_fixed_bytes(), msg.get(), &signer.0.as_bytes()) ||
|
||||
runtime_io::ed25519_verify(self.0.as_fixed_bytes(), msg.get(), &signer.0.as_bytes())
|
||||
type Signer = sr25519::Public;
|
||||
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &sr25519::Public) -> bool {
|
||||
runtime_io::sr25519_verify(self.0.as_fixed_bytes(), msg.get(), &signer.0) ||
|
||||
runtime_io::ed25519_verify(self.0.as_fixed_bytes(), msg.get(), &signer.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<sr25519::Signature> for AnySignature {
|
||||
fn from(s: sr25519::Signature) -> AnySignature {
|
||||
AnySignature(s.0.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ mod tests {
|
||||
use runtime_io::{with_externalities, twox_128, TestExternalities};
|
||||
use parity_codec::{Joiner, KeyedVec};
|
||||
use substrate_test_client::{AuthorityKeyring, AccountKeyring};
|
||||
use crate::{Header, Extrinsic, Transfer};
|
||||
use crate::{Header, Transfer};
|
||||
use primitives::{Blake2Hasher, map};
|
||||
use primitives::storage::well_known_keys;
|
||||
use substrate_executor::WasmExecutor;
|
||||
|
||||
+19
-1
@@ -1227,6 +1227,23 @@ dependencies = [
|
||||
"subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schnorrkel"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "0.3.3"
|
||||
@@ -1672,7 +1689,7 @@ dependencies = [
|
||||
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)",
|
||||
"schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -2334,6 +2351,7 @@ dependencies = [
|
||||
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
|
||||
"checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347"
|
||||
"checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)" = "<none>"
|
||||
"checksum schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
Reference in New Issue
Block a user