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
@@ -9,12 +9,12 @@ description = "BEEFY Client gadget for substrate"
homepage = "https://substrate.io"
[dependencies]
array-bytes = "4.1"
async-trait = "0.1.57"
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
fnv = "1.0.6"
futures = "0.3"
futures-timer = "3.0.1"
hex = "0.4.2"
log = "0.4"
parking_lot = "0.12.1"
thiserror = "1.0"
+3 -2
View File
@@ -69,9 +69,10 @@ pub(crate) mod beefy_protocol_name {
genesis_hash: &Hash,
chain_spec: &Box<dyn ChainSpec>,
) -> ProtocolName {
let genesis_hash = genesis_hash.as_ref();
let chain_prefix = match chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", hex::encode(genesis_hash), fork_id),
None => format!("/{}", hex::encode(genesis_hash)),
Some(fork_id) => format!("/{}/{}", array_bytes::bytes2hex("", genesis_hash), fork_id),
None => format!("/{}", array_bytes::bytes2hex("", genesis_hash)),
};
format!("{}{}", chain_prefix, NAME).into()
}
+1 -1
View File
@@ -99,7 +99,7 @@ fn beefy_protocol_name() {
// Create protocol name using random genesis hash.
let genesis_hash = H256::random();
let expected = format!("/{}/beefy/1", hex::encode(genesis_hash));
let expected = format!("/{}/beefy/1", array_bytes::bytes2hex("", genesis_hash.as_ref()));
let proto_name = beefy_protocol_name::standard_name(&genesis_hash, &chain_spec);
assert_eq!(proto_name.to_string(), expected);