mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Make digest compilation work.
This commit is contained in:
@@ -38,7 +38,7 @@ pub mod runtime;
|
||||
use runtime_std::prelude::*;
|
||||
use codec::{Slicable, Joiner};
|
||||
use runtime_std::print;
|
||||
use primitives::{Block, Header, BlockNumber, UncheckedTransaction};
|
||||
use primitives::{Block, Header, UncheckedTransaction};
|
||||
|
||||
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
|
||||
/// empty vector.
|
||||
@@ -49,10 +49,10 @@ pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
||||
let number = BlockNumber::from_slice(&input[0..8]).unwrap();
|
||||
let utx = UncheckedTransaction::from_slice(&input[8..]).unwrap();
|
||||
runtime::system::internal::execute_transaction(&utx, Header::from_block_number(number));
|
||||
Vec::new()
|
||||
let header = Header::from_slice(input).unwrap();
|
||||
let utx = UncheckedTransaction::from_slice(&input[Header::size_of(input).unwrap()..]).unwrap();
|
||||
let header = runtime::system::internal::execute_transaction(&utx, header);
|
||||
Vec::new().join(&header)
|
||||
}
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
|
||||
#[derive(Clone, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "with-std", derive(Debug))]
|
||||
/// The digest of a block, useful for light-clients.
|
||||
pub struct Digest {
|
||||
/// All logs that have happened in the block.
|
||||
|
||||
@@ -51,11 +51,8 @@ pub mod internal {
|
||||
use super::*;
|
||||
|
||||
/// Deposits a log and ensures it matches the blocks log data.
|
||||
pub fn deposit_log(log: &[u8]) {
|
||||
with_env(|e| {
|
||||
assert_eq!(log, &e.digest.logs[e.next_log_index][..]);
|
||||
e.next_log_index += 1;
|
||||
});
|
||||
pub fn deposit_log(log: Vec<u8>) {
|
||||
with_env(|e| e.digest.logs.push(log));
|
||||
}
|
||||
|
||||
/// Actually execute all transitioning for `block`.
|
||||
@@ -63,8 +60,6 @@ pub mod internal {
|
||||
// populate environment from header.
|
||||
with_env(|e| {
|
||||
e.block_number = block.header.number;
|
||||
mem::swap(&mut e.digest, &mut block.header.digest);
|
||||
e.next_log_index = 0;
|
||||
});
|
||||
|
||||
let ref header = block.header;
|
||||
@@ -104,15 +99,19 @@ pub mod internal {
|
||||
|
||||
/// Execute a transaction outside of the block execution function.
|
||||
/// This doesn't attempt to validate anything regarding the block.
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction, mut header: Header) {
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction, mut header: Header) -> Header {
|
||||
// populate environment from header.
|
||||
with_env(|e| {
|
||||
e.block_number = header.number;
|
||||
mem::swap(&mut e.digest, &mut header.digest);
|
||||
e.next_log_index = 0;
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
|
||||
super::execute_transaction(utx);
|
||||
|
||||
with_env(|e| {
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
header
|
||||
}
|
||||
|
||||
/// Finalise the block - it is up the caller to ensure that all header fields are valid
|
||||
@@ -122,6 +121,9 @@ pub mod internal {
|
||||
session::internal::check_rotate_session();
|
||||
|
||||
header.state_root = storage_root();
|
||||
with_env(|e| {
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
|
||||
post_finalise(&header);
|
||||
|
||||
@@ -160,7 +162,7 @@ fn execute_transaction(utx: &UncheckedTransaction) {
|
||||
|
||||
fn final_checks(_block: &Block) {
|
||||
with_env(|e| {
|
||||
assert_eq!(e.next_log_index, e.digest.logs.len());
|
||||
assert!(_block.header.digest == e.digest);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ pub struct Environment {
|
||||
pub block_number: BlockNumber,
|
||||
/// The current block digest.
|
||||
pub digest: Digest,
|
||||
/// The number of log items in this block that have been accounted for so far.
|
||||
pub next_log_index: usize,
|
||||
}
|
||||
|
||||
/// Do something with the environment and return its value. Keep the function short.
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user