mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
extract out all primitives
This commit is contained in:
@@ -12,11 +12,11 @@ pwasm-alloc = { path = "../wasm-runtime/pwasm-alloc", version = "0.1" }
|
||||
pwasm-libc = { path = "../wasm-runtime/pwasm-libc", version = "0.1" }
|
||||
environmental = { path = "../environmental", version = "0.1", optional = true }
|
||||
polkadot-state-machine = { path = "../state-machine", version = "0.1", optional = true }
|
||||
polkadot-primitives = { path = "../primitives", version = "0.1", optional = true }
|
||||
polkadot-primitives = { path = "../primitives", version = "0.1", default_features = false }
|
||||
triehash = { version = "0.1", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["environmental", "polkadot-state-machine", "polkadot-primitives", "triehash"]
|
||||
std = ["environmental", "polkadot-state-machine", "triehash", "polkadot-primitives/std"]
|
||||
nightly = []
|
||||
strict = []
|
||||
|
||||
@@ -28,8 +28,6 @@ include!("../with_std.rs");
|
||||
#[cfg(not(feature = "std"))]
|
||||
include!("../without_std.rs");
|
||||
|
||||
|
||||
|
||||
/// Prelude of common useful imports.
|
||||
///
|
||||
/// This should include only things which are in the normal std prelude.
|
||||
@@ -37,3 +35,49 @@ pub mod prelude {
|
||||
pub use ::vec::Vec;
|
||||
pub use ::boxed::Box;
|
||||
}
|
||||
|
||||
/// Type definitions and helpers for transactions.
|
||||
pub mod transaction {
|
||||
pub use primitives::transaction::{Transaction, UncheckedTransaction};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::ops;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::ops;
|
||||
|
||||
/// A type-safe indicator that a transaction has been checked.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct CheckedTransaction(UncheckedTransaction);
|
||||
|
||||
impl CheckedTransaction {
|
||||
/// Get a reference to the checked signature.
|
||||
pub fn signature(&self) -> &[u8; 64] {
|
||||
&self.0.signature
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Deref for CheckedTransaction {
|
||||
type Target = Transaction;
|
||||
|
||||
fn deref(&self) -> &Transaction {
|
||||
&self.0.transaction
|
||||
}
|
||||
}
|
||||
|
||||
/// Check the signature on a transaction.
|
||||
///
|
||||
/// On failure, return the transaction back.
|
||||
pub fn check(tx: UncheckedTransaction) -> Result<CheckedTransaction, UncheckedTransaction> {
|
||||
// TODO: requires canonical serialization of transaction.
|
||||
let msg = unimplemented!();
|
||||
if ed25519_verify(&tx.signature, &msg, &tx.transaction.signed) {
|
||||
Ok(CheckedTransaction(tx))
|
||||
} else {
|
||||
Err(tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check a transaction
|
||||
pub struct CheckedTransaction(primitives::UncheckedTransaction);
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#[macro_use]
|
||||
extern crate environmental;
|
||||
|
||||
@@ -32,18 +31,14 @@ pub use std::boxed;
|
||||
pub use std::slice;
|
||||
pub use std::mem;
|
||||
|
||||
// re-export hashing functions.
|
||||
pub use primitives::{blake2_256, twox_128, twox_256};
|
||||
|
||||
pub use polkadot_state_machine::{Externalities, ExternalitiesError, TestExternalities};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
|
||||
// TODO: use the real error, not NoError.
|
||||
|
||||
#[derive(Debug)]
|
||||
/// As it says - an empty type we use for errors.
|
||||
pub struct NoError;
|
||||
impl fmt::Display for NoError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "") }
|
||||
}
|
||||
|
||||
environmental!(ext : trait Externalities);
|
||||
|
||||
/// Get `key` from storage and return a `Vec`, empty if there's a problem.
|
||||
@@ -97,9 +92,6 @@ pub fn enumerated_trie_root(serialised_values: &[&[u8]]) -> [u8; 32] {
|
||||
triehash::ordered_trie_root(serialised_values.iter().map(|s| s.to_vec())).0
|
||||
}
|
||||
|
||||
/// Conduct a Keccak-256 hash of the given data.
|
||||
pub use primitives::{blake2_256, twox_128, twox_256};
|
||||
|
||||
/// Verify a ed25519 signature.
|
||||
pub fn ed25519_verify(sig: &[u8; 64], msg: &[u8], pubkey: &[u8; 32]) -> bool {
|
||||
ed25519::verify(&sig[..], msg, &pubkey[..])
|
||||
|
||||
@@ -6,6 +6,8 @@ extern crate pwasm_libc;
|
||||
#[cfg(feature = "nightly")]
|
||||
extern crate pwasm_alloc;
|
||||
|
||||
extern crate polkadot_primitives as primitives;;
|
||||
|
||||
pub use alloc::vec;
|
||||
pub use alloc::boxed;
|
||||
pub use alloc::rc;
|
||||
|
||||
Reference in New Issue
Block a user