这篇文章上次修改于 626 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
[u8] -> H256
let input: [u8];
let tx_hash = H256::from_slice(&input[0..32]);
[u8; n] -> [u8; 4]
let mut buf = [0u8; 4];
buf.copy_from_slice(&input[32..36]);
[0u8; 4] -> u32
let buf = [0u8; 4];
index = u32::from_le_bytes(buf);
u32 -> [0u8; 4]
let input: u32;
input.to_le_bytes()
[u8; 32] 拼接到 Vec
let input1: [u8; 32];
let input2: [u8; 32];
let mut ret = Vec::with_capacity(64);
ret.extend_from_slice(&input);
ret.extend_from_slice(&input1);
&str -> H256
H256(h256!("0xe778611f59d65bc0c558a0a14a7fe12c4a937712f9cae6ca7aa952802703bd5a").0)
&str -> [u8; 32]
h256!("0xe778611f59d65bc0c558a0a14a7fe12c4a937712f9cae6ca7aa952802703bd5a").0
pub fn decode_hex(s: &str) -> [u8; 32] {
let mut buf = [0u8; 32];
hex::decode_to_slice(s, &mut buf).unwrap();
buf
}
对字符串签名
pub static ref ALWAYS_SUCCESS_DEPLOY_TX_HASH: [u8; 32] = Hasher::digest("AlwaysSuccessDeployTx").0;
没有评论