Skip to content

Commit ff95937

Browse files
Replace unstable byte-array API with stable slice/inner API
- Replace secp256k1::SecretKey::from_byte_array with from_slice - Replace bitcoin_hashes::Hash::to_byte_array() with into_inner() - Updates across 30+ files for MSRV compatibility - Fixes deprecated API usage in preparation for future Rust versions
1 parent e893309 commit ff95937

File tree

34 files changed

+83
-88
lines changed

34 files changed

+83
-88
lines changed

dash-spv/src/mempool_filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ mod tests {
277277
let mut data = seed.to_vec();
278278
data.extend_from_slice(&index.to_le_bytes());
279279

280-
let secret_bytes = sha256::Hash::hash(&data).to_byte_array();
280+
let secret_bytes = sha256::Hash::hash(&data).into_inner();
281281

282282
// Try to create secp256k1 SecretKey from the hash
283-
match secp256k1::SecretKey::from_byte_array(&secret_bytes) {
283+
match secp256k1::SecretKey::from_slice(&secret_bytes) {
284284
Ok(secret_key) => {
285285
// Create PrivateKey from SecretKey
286286
let private_key = PrivateKey::new(secret_key, network);

dash-spv/src/sync/filters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
952952
data[32..].copy_from_slice(prev_header.as_byte_array());
953953

954954
let filter_header =
955-
FilterHeader::from_byte_array(sha256d::Hash::hash(&data).to_byte_array());
955+
FilterHeader::from_byte_array(sha256d::Hash::hash(&data).into_inner());
956956

957957
if i < 1 || i >= cf_headers.filter_hashes.len() - 1 {
958958
tracing::trace!(

dash-spv/tests/filter_header_verification_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn calculate_expected_filter_header(
199199
let mut data = [0u8; 64];
200200
data[..32].copy_from_slice(filter_hash.as_byte_array());
201201
data[32..].copy_from_slice(prev_filter_header.as_byte_array());
202-
FilterHeader::from_byte_array(sha256d::Hash::hash(&data).to_byte_array())
202+
FilterHeader::from_byte_array(sha256d::Hash::hash(&data).into_inner())
203203
}
204204

205205
#[ignore = "mock implementation incomplete"]
@@ -488,7 +488,7 @@ async fn test_overlapping_batches_from_different_peers() {
488488
.expect("Should have filter header at height 1499");
489489

490490
// Simulate Peer B having computed this header differently - create a slightly different value
491-
let mut peer_b_prev_bytes = peer_b_prev_filter_header_stored.to_byte_array();
491+
let mut peer_b_prev_bytes = peer_b_prev_filter_header_stored.into_inner();
492492
peer_b_prev_bytes[0] ^= 0x01; // Flip one bit to make it different
493493
let peer_b_prev_filter_header = FilterHeader::from_byte_array(peer_b_prev_bytes);
494494

dash/src/bip158.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub struct BlockFilterWriter<'a, W> {
177177
impl<'a, W: io::Write> BlockFilterWriter<'a, W> {
178178
/// Creates a new [`BlockFilterWriter`] from `block`.
179179
pub fn new(writer: &'a mut W, block: &'a Block) -> BlockFilterWriter<'a, W> {
180-
let block_hash_as_int = block.block_hash().to_byte_array();
180+
let block_hash_as_int = block.block_hash().into_inner();
181181
let k0 = u64::from_le_bytes(block_hash_as_int[0..8].try_into().expect("8 byte slice"));
182182
let k1 = u64::from_le_bytes(block_hash_as_int[8..16].try_into().expect("8 byte slice"));
183183
let writer = GcsFilterWriter::new(writer, k0, k1, M, P);
@@ -239,7 +239,7 @@ pub struct BlockFilterReader {
239239
impl BlockFilterReader {
240240
/// Creates a new [`BlockFilterReader`] from `block_hash`.
241241
pub fn new(block_hash: &BlockHash) -> BlockFilterReader {
242-
let block_hash_as_int = block_hash.to_byte_array();
242+
let block_hash_as_int = block_hash.into_inner();
243243
let k0 = u64::from_le_bytes(block_hash_as_int[0..8].try_into().expect("8 byte slice"));
244244
let k1 = u64::from_le_bytes(block_hash_as_int[8..16].try_into().expect("8 byte slice"));
245245
BlockFilterReader {

dash/src/blockdata/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ChainHash {
228228

229229
/// Converts genesis block hash into `ChainHash`.
230230
pub fn from_genesis_block_hash(block_hash: crate::BlockHash) -> Self {
231-
ChainHash(block_hash.to_byte_array())
231+
ChainHash(block_hash.into_inner())
232232
}
233233
}
234234

dash/src/crypto/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl PublicKey {
164164
pub fn wpubkey_hash(&self) -> Option<WPubkeyHash> {
165165
if self.compressed {
166166
Some(WPubkeyHash::from_byte_array(
167-
hash160::Hash::hash(&self.inner.serialize()).to_byte_array(),
167+
hash160::Hash::hash(&self.inner.serialize()).into_inner(),
168168
))
169169
} else {
170170
// We can't create witness pubkey hashes for an uncompressed
@@ -398,7 +398,7 @@ impl PrivateKey {
398398
}
399399

400400
pub fn from_byte_array(data: &[u8; 32], network: Network) -> Result<PrivateKey, Error> {
401-
Ok(PrivateKey::new(secp256k1::SecretKey::from_byte_array(data)?, network))
401+
Ok(PrivateKey::new(secp256k1::SecretKey::from_slice(data)?, network))
402402
}
403403

404404
/// Format the private key to WIF format.
@@ -450,7 +450,7 @@ impl PrivateKey {
450450
Ok(PrivateKey {
451451
compressed,
452452
network,
453-
inner: secp256k1::SecretKey::from_byte_array(
453+
inner: secp256k1::SecretKey::from_slice(
454454
<&[u8; 32]>::try_from(&data[1..33]).expect("expected 32 bytes"),
455455
)?,
456456
})

dash/src/crypto/sighash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ mod tests {
12601260
let mut enc = TapSighash::engine();
12611261
enc.input(&bytes);
12621262
let hash = TapSighash::from_engine(enc);
1263-
assert_eq!(expected, hash.to_byte_array());
1263+
assert_eq!(expected, hash.into_inner());
12641264
}
12651265

12661266
#[ignore]
@@ -1526,7 +1526,7 @@ mod tests {
15261526
.taproot_signature_hash(input_index, &prevouts, annex, leaf_hash, sighash_type)
15271527
.unwrap();
15281528
let expected = hex!(expected_hash);
1529-
assert_eq!(expected, hash.to_byte_array());
1529+
assert_eq!(expected, hash.into_inner());
15301530
}
15311531

15321532
#[cfg(feature = "serde")]
@@ -1708,7 +1708,7 @@ mod tests {
17081708
.taproot_signature_hash(tx_ind, &Prevouts::All(&utxos), None, None, hash_ty)
17091709
.unwrap();
17101710

1711-
let msg = secp256k1::Message::from_digest(sighash.to_byte_array());
1711+
let msg = secp256k1::Message::from_digest(sighash.into_inner());
17121712
let key_spend_sig =
17131713
secp.sign_schnorr_with_aux_rand(msg.as_ref(), &tweaked_keypair, &[0u8; 32]);
17141714

dash/src/hash_types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ mod newtypes {
160160

161161
impl Ord for ScoreHash {
162162
fn cmp(&self, other: &Self) -> Ordering {
163-
let mut self_bytes = self.0.to_byte_array();
164-
let mut other_bytes = other.0.to_byte_array();
163+
let mut self_bytes = self.0.into_inner();
164+
let mut other_bytes = other.0.into_inner();
165165

166166
self_bytes.reverse();
167167
other_bytes.reverse();
@@ -268,9 +268,9 @@ mod newtypes {
268268
if let Some(confirmed_hash_hashed_with_pro_reg_tx) =
269269
confirmed_hash_hashed_with_pro_reg_tx
270270
{
271-
bytes.append(&mut confirmed_hash_hashed_with_pro_reg_tx.to_byte_array().to_vec());
271+
bytes.append(&mut confirmed_hash_hashed_with_pro_reg_tx.into_inner().to_vec());
272272
}
273-
bytes.append(&mut modifier.to_byte_array().to_vec());
273+
bytes.append(&mut modifier.into_inner().to_vec());
274274
Self::hash(bytes.as_slice())
275275
}
276276
}
@@ -333,15 +333,15 @@ mod newtypes {
333333

334334
/// Hashes the members
335335
pub fn hash_members(pro_tx_hash: &ProTxHash, confirmed_hash: &ConfirmedHash) -> Self {
336-
Self::hash(&[pro_tx_hash.to_byte_array(), confirmed_hash.to_byte_array()].concat())
336+
Self::hash(&[pro_tx_hash.into_inner(), confirmed_hash.into_inner()].concat())
337337
}
338338
/// Hashes the members
339339
pub fn hash_members_confirmed_hash_optional(
340340
pro_tx_hash: &ProTxHash,
341341
confirmed_hash: Option<&ConfirmedHash>,
342342
) -> Option<Self> {
343343
confirmed_hash.map(|confirmed_hash| {
344-
Self::hash(&[pro_tx_hash.to_byte_array(), confirmed_hash.to_byte_array()].concat())
344+
Self::hash(&[pro_tx_hash.into_inner(), confirmed_hash.into_inner()].concat())
345345
})
346346
}
347347
}

dash/src/merkle_tree/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl PartialMerkleTree {
317317
if hash_used != self.hashes.len() as u32 {
318318
return Err(NotAllHashesConsumed);
319319
}
320-
Ok(TxMerkleNode::from_byte_array(hash_merkle_root.to_byte_array()))
320+
Ok(TxMerkleNode::from_byte_array(hash_merkle_root.into_inner()))
321321
}
322322

323323
/// Helper function to efficiently calculate the number of nodes at given height
@@ -331,7 +331,7 @@ impl PartialMerkleTree {
331331
fn calc_hash(&self, height: u32, pos: u32, txids: &[Txid]) -> TxMerkleNode {
332332
if height == 0 {
333333
// Hash at height 0 is the txid itself
334-
TxMerkleNode::from_byte_array(txids[pos as usize].to_byte_array())
334+
TxMerkleNode::from_byte_array(txids[pos as usize].into_inner())
335335
} else {
336336
// Calculate left hash
337337
let left = self.calc_hash(height - 1, pos * 2, txids);
@@ -396,7 +396,7 @@ impl PartialMerkleTree {
396396
*hash_used += 1;
397397
if height == 0 && parent_of_match {
398398
// in case of height 0, we have a matched txid
399-
matches.push(Txid::from_byte_array(hash.to_byte_array()));
399+
matches.push(Txid::from_byte_array(hash.into_inner()));
400400
indexes.push(pos);
401401
}
402402
Ok(hash)
@@ -763,7 +763,7 @@ mod tests {
763763
let n = rng.gen_range(0..self.hashes.len());
764764
let bit = rng.r#gen::<u8>();
765765
let hashes = &mut self.hashes;
766-
let mut hash = hashes[n].to_byte_array();
766+
let mut hash = hashes[n].into_inner();
767767
hash[(bit >> 3) as usize] ^= 1 << (bit & 7);
768768
hashes[n] = TxMerkleNode::from_slice(&hash).unwrap();
769769
}

dash/src/pow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Target {
210210
/// to the target.
211211
pub fn is_met_by(&self, hash: BlockHash) -> bool {
212212
use hashes::Hash;
213-
let hash = U256::from_le_bytes(hash.to_byte_array());
213+
let hash = U256::from_le_bytes(hash.into_inner());
214214
hash <= self.0
215215
}
216216

@@ -1598,7 +1598,7 @@ mod tests {
15981598
let hash =
15991599
BlockHash::from_str("ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c")
16001600
.expect("failed to parse block hash");
1601-
let target = Target(U256::from_le_bytes(hash.to_byte_array()));
1601+
let target = Target(U256::from_le_bytes(hash.into_inner()));
16021602
assert!(target.is_met_by(hash));
16031603
}
16041604

0 commit comments

Comments
 (0)