pallet的调试
1. 概述
在pallet开发时主要有以下几种调试方式:
- logging uilities
- printable trait
- print函数
- if_std
2. logging uilities
加入依赖:
1 2 3 4 5 6 7 8 9
| [dependencies] log = { version = "0.4.14", default-features = false }
[features] default = ["std"] std = [ "log/std", ]
|
在pallet中,需要打印的地方,直接使用:
1
| log::info!("|||||||||||||||||||||| called by {:?}", who);
|
3. printable trait
需要为需要打印的类型实现printable trait,这里为Error类型实现对应的trait,然后再进行打印,需要修改代码如下:
pallet的lib.rs中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| use sp_runtime::traits::Printable; use sp_runtime::print;
#[pallet::error] pub enum Error<T> { NoneValue, StorageOverflow, }
impl<T: Config> Printable for Error<T> { fn print(&self) { match self { Error::NoneValue => "Invalid Value".print(), Error::StorageOverflow => "++++++++++++++++++++++++++ Value Exceeded and Overflowed".print(), _ => "Invalid Error Case".print(), } } }
print(Error::<T>::NoneValue);
|
4. print函数
直接使用print进行打印
1 2 3
| use sp_runtime::print;
print("After storing my_val");
|
5. if_std
没用过,暂不考虑
总结
本文编辑完毕