mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
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:
@@ -14,6 +14,7 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
array-bytes = "4.1"
|
||||
async-trait = "0.1"
|
||||
asynchronous-codec = "0.6"
|
||||
bitflags = "1.3.2"
|
||||
@@ -24,7 +25,6 @@ either = "1.5.3"
|
||||
fnv = "1.0.6"
|
||||
futures = "0.3.21"
|
||||
futures-timer = "3.0.2"
|
||||
hex = "0.4.0"
|
||||
ip_network = "0.4.1"
|
||||
libp2p = "0.46.1"
|
||||
linked_hash_set = "0.1.3"
|
||||
|
||||
@@ -17,11 +17,11 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
prost-build = "0.10"
|
||||
|
||||
[dependencies]
|
||||
array-bytes = "4.1"
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [
|
||||
"derive",
|
||||
] }
|
||||
futures = "0.3.21"
|
||||
hex = "0.4.0"
|
||||
libp2p = "0.46.1"
|
||||
log = "0.4.16"
|
||||
prost = "0.10"
|
||||
|
||||
@@ -27,10 +27,11 @@ use std::time::Duration;
|
||||
|
||||
/// Generate the light client protocol name from the genesis hash and fork id.
|
||||
fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
|
||||
let genesis_hash = genesis_hash.as_ref();
|
||||
if let Some(fork_id) = fork_id {
|
||||
format!("/{}/{}/light/2", hex::encode(genesis_hash), fork_id)
|
||||
format!("/{}/{}/light/2", array_bytes::bytes2hex("", genesis_hash), fork_id)
|
||||
} else {
|
||||
format!("/{}/light/2", hex::encode(genesis_hash))
|
||||
format!("/{}/light/2", array_bytes::bytes2hex("", genesis_hash))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
prost-build = "0.10"
|
||||
|
||||
[dependencies]
|
||||
array-bytes = "4.1"
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [
|
||||
"derive",
|
||||
] }
|
||||
futures = "0.3.21"
|
||||
hex = "0.4.0"
|
||||
libp2p = "0.46.1"
|
||||
log = "0.4.17"
|
||||
lru = "0.7.5"
|
||||
|
||||
@@ -80,10 +80,11 @@ pub fn generate_protocol_config<Hash: AsRef<[u8]>>(
|
||||
|
||||
/// Generate the block protocol name from the genesis hash and fork id.
|
||||
fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
|
||||
let genesis_hash = genesis_hash.as_ref();
|
||||
if let Some(fork_id) = fork_id {
|
||||
format!("/{}/{}/sync/2", hex::encode(genesis_hash), fork_id)
|
||||
format!("/{}/{}/sync/2", array_bytes::bytes2hex("", genesis_hash), fork_id)
|
||||
} else {
|
||||
format!("/{}/sync/2", hex::encode(genesis_hash))
|
||||
format!("/{}/sync/2", array_bytes::bytes2hex("", genesis_hash))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +69,11 @@ pub fn generate_protocol_config<Hash: AsRef<[u8]>>(
|
||||
|
||||
/// Generate the state protocol name from the genesis hash and fork id.
|
||||
fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
|
||||
let genesis_hash = genesis_hash.as_ref();
|
||||
if let Some(fork_id) = fork_id {
|
||||
format!("/{}/{}/state/2", hex::encode(genesis_hash), fork_id)
|
||||
format!("/{}/{}/state/2", array_bytes::bytes2hex("", genesis_hash), fork_id)
|
||||
} else {
|
||||
format!("/{}/state/2", hex::encode(genesis_hash))
|
||||
format!("/{}/state/2", array_bytes::bytes2hex("", genesis_hash))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,10 +54,11 @@ pub fn generate_request_response_config<Hash: AsRef<[u8]>>(
|
||||
|
||||
/// Generate the grandpa warp sync protocol name from the genesi hash and fork id.
|
||||
fn generate_protocol_name<Hash: AsRef<[u8]>>(genesis_hash: Hash, fork_id: Option<&str>) -> String {
|
||||
let genesis_hash = genesis_hash.as_ref();
|
||||
if let Some(fork_id) = fork_id {
|
||||
format!("/{}/{}/sync/warp", hex::encode(genesis_hash), fork_id)
|
||||
format!("/{}/{}/sync/warp", array_bytes::bytes2hex("", genesis_hash), fork_id)
|
||||
} else {
|
||||
format!("/{}/sync/warp", hex::encode(genesis_hash))
|
||||
format!("/{}/sync/warp", array_bytes::bytes2hex("", genesis_hash))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user