mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 06:48:01 +00:00
3402f169a7
* Introduce basic skeleton for Polkador runtime. * Clean up the runtime skeleton. * Make initial runtime skeleton compile. * Compile polkadot-runtime both for Wasm ad native, allowing for testing and direct usage. * More fleshing out on runtime. * Update native support. * Fix warning. * Update gitignore * Update path. * Fix path. * Remove accidentally committed files. * Add wasm binaries. * Fix test. * Native storage support API. * Add environmental module * Add native environment to make native source-code compatible with wasm. Also tests. * Finish up & polish environment stuff. * Avoid using reentrancy issues. * Add some docs and a test. * Remove unneeded function. * Documentation * Tweak docs * Remove TODOs. * Balance transfers + util methods. * Rejig tests and ensure authorities are addressed consistently. * Add marshaller for xfer function * Transaction dispatch test. * Minor fix. * Add test for ser/de transaction. * Add ser/de for header. * Add tests for header ser/de * Introduce basic block decoding/execution framework. * Introduce block decoding/execution framework (p2) * Big refactor. * Split out joiner. * Hide away support modules. * Fix up wasm runtime. * use externalities for chain_id * Clean up (Test)Externalities. * Repot and introduce keccak-256 external. * Signing with crypto. * fix unsafety hole in environmental using function * Introduce Ed25519 crypto. * Repotting. * Add ed25519_verify external. * Introduce Ed25519 verify as an external. * fix unsafety hole around unwinding * Compile fixes. * use new environmental API * Tests for ed25519 verify. * Polish * Introduce UncheckedTransaction & test. * Implement basic block and tx processing * Introduce static hex and valid signature for block test. * Repot session. * comments. * Refactor and timestamp test * Remove fluff * Remove fluff. * Staking eras and tests. * Implement sessions. * Polish * Test sessions. * Introduce better hashing. - Blake2 for secure hashing - XX for fast hashing * Fix tests. * Introduce staking. * Tests for simple staking system. * Build fix for wasm. * Fix tests. * Repotting and docs. * Docs and licence. * Documentation. * Remove superfluous code. * Remove dummy key. * Remove other superfluous file. * Optimise with swap_remove
107 lines
3.4 KiB
Rust
107 lines
3.4 KiB
Rust
// Copyright 2017 Parity Technologies (UK) Ltd.
|
|
// This file is part of Polkadot.
|
|
|
|
// Polkadot is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Polkadot is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Hashing functions.
|
|
|
|
use blake2_rfc;
|
|
use twox_hash;
|
|
|
|
/// Do a Blake2 512-bit hash and place result in `dest`.
|
|
pub fn blake2_512_into(data: &[u8], dest: &mut[u8; 64]) {
|
|
dest.copy_from_slice(blake2_rfc::blake2b::blake2b(64, &[], data).as_bytes());
|
|
}
|
|
|
|
/// Do a Blake2 512-bit hash and return result.
|
|
pub fn blake2_512(data: &[u8]) -> [u8; 64] {
|
|
let mut r: [u8; 64] = unsafe { ::std::mem::uninitialized() };
|
|
blake2_512_into(data, &mut r);
|
|
r
|
|
}
|
|
|
|
/// Do a Blake2 256-bit hash and place result in `dest`.
|
|
pub fn blake2_256_into(data: &[u8], dest: &mut[u8; 32]) {
|
|
dest.copy_from_slice(blake2_rfc::blake2b::blake2b(32, &[], data).as_bytes());
|
|
}
|
|
|
|
/// Do a Blake2 256-bit hash and return result.
|
|
pub fn blake2_256(data: &[u8]) -> [u8; 32] {
|
|
let mut r: [u8; 32] = unsafe { ::std::mem::uninitialized() };
|
|
blake2_256_into(data, &mut r);
|
|
r
|
|
}
|
|
|
|
/// Do a Blake2 128-bit hash and place result in `dest`.
|
|
pub fn blake2_128_into(data: &[u8], dest: &mut[u8; 16]) {
|
|
dest.copy_from_slice(blake2_rfc::blake2b::blake2b(16, &[], data).as_bytes());
|
|
}
|
|
|
|
/// Do a Blake2 128-bit hash and return result.
|
|
pub fn blake2_128(data: &[u8]) -> [u8; 16] {
|
|
let mut r: [u8; 16] = unsafe { ::std::mem::uninitialized() };
|
|
blake2_128_into(data, &mut r);
|
|
r
|
|
}
|
|
|
|
/// Do a XX 128-bit hash and place result in `dest`.
|
|
pub fn twox_128_into(data: &[u8], dest: &mut [u8; 16]) {
|
|
use ::std::hash::Hasher;
|
|
let mut h0 = twox_hash::XxHash::with_seed(0);
|
|
let mut h1 = twox_hash::XxHash::with_seed(1);
|
|
h0.write(data);
|
|
h1.write(data);
|
|
let r0 = h0.finish();
|
|
let r1 = h1.finish();
|
|
use byteorder::{ByteOrder, LittleEndian};
|
|
LittleEndian::write_u64(&mut dest[0..8], r0);
|
|
LittleEndian::write_u64(&mut dest[8..16], r1);
|
|
}
|
|
|
|
/// Do a XX 128-bit hash and return result.
|
|
pub fn twox_128(data: &[u8]) -> [u8; 16] {
|
|
let mut r: [u8; 16] = unsafe { ::std::mem::uninitialized() };
|
|
twox_128_into(data, &mut r);
|
|
r
|
|
}
|
|
|
|
/// Do a XX 256-bit hash and place result in `dest`.
|
|
pub fn twox_256_into(data: &[u8], dest: &mut [u8; 32]) {
|
|
use ::std::hash::Hasher;
|
|
use byteorder::{ByteOrder, LittleEndian};
|
|
let mut h0 = twox_hash::XxHash::with_seed(0);
|
|
let mut h1 = twox_hash::XxHash::with_seed(1);
|
|
let mut h2 = twox_hash::XxHash::with_seed(2);
|
|
let mut h3 = twox_hash::XxHash::with_seed(3);
|
|
h0.write(data);
|
|
h1.write(data);
|
|
h2.write(data);
|
|
h3.write(data);
|
|
let r0 = h0.finish();
|
|
let r1 = h1.finish();
|
|
let r2 = h2.finish();
|
|
let r3 = h3.finish();
|
|
LittleEndian::write_u64(&mut dest[0..8], r0);
|
|
LittleEndian::write_u64(&mut dest[8..16], r1);
|
|
LittleEndian::write_u64(&mut dest[16..24], r2);
|
|
LittleEndian::write_u64(&mut dest[24..32], r3);
|
|
}
|
|
|
|
/// Do a XX 256-bit hash and return result.
|
|
pub fn twox_256(data: &[u8]) -> [u8; 32] {
|
|
let mut r: [u8; 32] = unsafe { ::std::mem::uninitialized() };
|
|
twox_256_into(data, &mut r);
|
|
r
|
|
}
|