mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 04:11:07 +00:00
Introduce hex/string printing in runtime.
This commit is contained in:
@@ -78,13 +78,18 @@ impl WritePrimitive<u32> for MemoryInstance {
|
||||
}
|
||||
|
||||
impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
ext_print(utf8_data: *const u8, utf8_len: u32) => {
|
||||
ext_print_utf8(utf8_data: *const u8, utf8_len: u32) => {
|
||||
if let Ok(utf8) = this.memory.get(utf8_data, utf8_len as usize) {
|
||||
if let Ok(message) = String::from_utf8(utf8) {
|
||||
println!("Runtime: {}", message);
|
||||
}
|
||||
}
|
||||
},
|
||||
ext_print_hex(data: *const u8, len: u32) => {
|
||||
if let Ok(hex) = this.memory.get(data, len as usize) {
|
||||
println!("Runtime: {}", HexDisplay::from(&hex));
|
||||
}
|
||||
},
|
||||
ext_print_num(number: u64) => {
|
||||
println!("Runtime: {}", number);
|
||||
},
|
||||
|
||||
@@ -40,6 +40,7 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
pub use polkadot_state_machine::{Externalities, ExternalitiesError};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
|
||||
// TODO: use the real error, not NoError.
|
||||
|
||||
@@ -111,9 +112,13 @@ pub trait Printable {
|
||||
|
||||
impl<'a> Printable for &'a [u8] {
|
||||
fn print(self) {
|
||||
if let Ok(s) = ::std::str::from_utf8(self) {
|
||||
println!("Runtime: {}", s);
|
||||
}
|
||||
println!("Runtime: {}", HexDisplay::from(&self));
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Printable for &'a str {
|
||||
fn print(self) {
|
||||
println!("Runtime: {}", self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ pub trait AsBytesRef {
|
||||
fn as_bytes_ref(&self) -> &[u8];
|
||||
}
|
||||
|
||||
impl<'a> AsBytesRef for &'a [u8] {
|
||||
fn as_bytes_ref(&self) -> &[u8] { self }
|
||||
}
|
||||
|
||||
impl AsBytesRef for [u8] {
|
||||
fn as_bytes_ref(&self) -> &[u8] { &self }
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ pub fn execute_block(mut block: Block) {
|
||||
|
||||
/// Execute a given transaction.
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction) {
|
||||
print(&b"HERE"[..]);
|
||||
// Verify the signature is good.
|
||||
assert!(utx.ed25519_verify(), "All transactions should be properly signed");
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ extern crate pwasm_alloc;
|
||||
#[no_mangle]
|
||||
pub extern fn panic_fmt(_fmt: ::core::fmt::Arguments, _file: &'static str, _line: u32, _col: u32) {
|
||||
unsafe {
|
||||
ext_print(_file.as_ptr() as *const u8, _file.len() as u32);
|
||||
ext_print_utf8(_file.as_ptr() as *const u8, _file.len() as u32);
|
||||
ext_print_num(_line as u64);
|
||||
ext_print_num(_col as u64);
|
||||
::core::intrinsics::abort()
|
||||
@@ -36,7 +36,8 @@ pub extern fn panic_fmt(_fmt: ::core::fmt::Arguments, _file: &'static str, _line
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn ext_print(utf8_data: *const u8, utf8_len: u32);
|
||||
fn ext_print_utf8(utf8_data: *const u8, utf8_len: u32);
|
||||
fn ext_print_hex(data: *const u8, len: u32);
|
||||
fn ext_print_num(value: u64);
|
||||
fn ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32);
|
||||
fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8;
|
||||
@@ -142,7 +143,15 @@ pub trait Printable {
|
||||
impl<'a> Printable for &'a [u8] {
|
||||
fn print(self) {
|
||||
unsafe {
|
||||
ext_print(self.as_ptr(), self.len() as u32);
|
||||
ext_print_hex(self.as_ptr(), self.len() as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Printable for &'a str {
|
||||
fn print(self) {
|
||||
unsafe {
|
||||
ext_print_utf8(self.as_ptr() as *const u8, self.len() as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -30,16 +30,16 @@ fn test_ed25519_verify(input: &[u8]) -> Vec<u8> {
|
||||
}
|
||||
|
||||
fn test_data_in(input: &[u8]) -> Vec<u8> {
|
||||
print(b"set_storage" as &[u8]);
|
||||
print("set_storage");
|
||||
set_storage(b"input", &input);
|
||||
|
||||
print(b"storage" as &[u8]);
|
||||
print("storage");
|
||||
let foo = storage(b"foo");
|
||||
|
||||
print(b"set_storage" as &[u8]);
|
||||
print("set_storage");
|
||||
set_storage(b"baz", &foo);
|
||||
|
||||
print(b"finished!" as &[u8]);
|
||||
print("finished!");
|
||||
b"all ok!".to_vec()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user