Use array-bytes for All Array/Bytes/Hex Operations (#12190)

* Use `array-bytes` for All Array/Bytes/Hex Operations

Signed-off-by: Xavier Lau <xavier@inv.cafe>

* Reorder

* Self Review

* Format

* Fix Tests

* Bump `array-bytes`

* Optimize large test res

Signed-off-by: Xavier Lau <xavier@inv.cafe>
Co-authored-by: parity-processbot <>
This commit is contained in:
Xavier Lau
2022-09-21 14:12:20 +08:00
committed by GitHub
parent e4b6f4a66d
commit 86198c5471
79 changed files with 520 additions and 510 deletions
+1 -1
View File
@@ -585,7 +585,7 @@ impl NodeKeyConfig {
f,
|mut b| match String::from_utf8(b.to_vec()).ok().and_then(|s| {
if s.len() == 64 {
hex::decode(&s).ok()
array_bytes::hex2bytes(&s).ok()
} else {
None
}
+7 -2
View File
@@ -369,10 +369,15 @@ where
let block_announces_protocol = {
let genesis_hash =
chain.hash(0u32.into()).ok().flatten().expect("Genesis block exists; qed");
let genesis_hash = genesis_hash.as_ref();
if let Some(fork_id) = fork_id {
format!("/{}/{}/block-announces/1", hex::encode(genesis_hash), fork_id)
format!(
"/{}/{}/block-announces/1",
array_bytes::bytes2hex("", genesis_hash),
fork_id
)
} else {
format!("/{}/block-announces/1", hex::encode(genesis_hash))
format!("/{}/block-announces/1", array_bytes::bytes2hex("", genesis_hash))
}
};
+3 -2
View File
@@ -143,10 +143,11 @@ impl TransactionsHandlerPrototype {
genesis_hash: Hash,
fork_id: Option<String>,
) -> Self {
let genesis_hash = genesis_hash.as_ref();
let protocol_name = if let Some(fork_id) = fork_id {
format!("/{}/{}/transactions/1", hex::encode(genesis_hash), fork_id)
format!("/{}/{}/transactions/1", array_bytes::bytes2hex("", genesis_hash), fork_id)
} else {
format!("/{}/transactions/1", hex::encode(genesis_hash))
format!("/{}/transactions/1", array_bytes::bytes2hex("", genesis_hash))
};
let legacy_protocol_name = format!("/{}/transactions/1", protocol_id.as_ref());