Skip to content

Commit 8789a5d

Browse files
Merge pull request #4 from yangby-cryptape/refactor/simplify-apis
refactor: replace specialized types, which used in APIs, with primitive rust types
2 parents 798bd82 + 8940ed3 commit 8789a5d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

prover/src/tests/service.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,17 @@ fn test_spv_client(
143143

144144
log::debug!(">>> with confirmations {confirmations}");
145145

146+
let txid_array = txid.as_ref();
146147
let verify_result = tip_client
147-
.verify_transaction(&txid, tx_proof.as_reader(), confirmations - 1)
148+
.verify_transaction(txid_array, tx_proof.as_reader(), confirmations - 1)
148149
.map_err(|err| err as i8);
149150
assert!(verify_result.is_ok());
150151
let verify_result = tip_client
151-
.verify_transaction(&txid, tx_proof.as_reader(), confirmations)
152+
.verify_transaction(txid_array, tx_proof.as_reader(), confirmations)
152153
.map_err(|err| err as i8);
153154
assert!(verify_result.is_ok());
154155
let verify_result = tip_client
155-
.verify_transaction(&txid, tx_proof.as_reader(), confirmations + 1)
156+
.verify_transaction(txid_array, tx_proof.as_reader(), confirmations + 1)
156157
.map_err(|err| err as i8);
157158
assert!(verify_result.is_err());
158159
}

verifier/src/types/extension/packed.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl packed::SpvClient {
268268
let tx: core::Transaction =
269269
deserialize(tx).map_err(|_| VerifyTxError::DecodeTransaction)?;
270270
let txid = tx.txid();
271-
let header = self.verify_transaction(&txid, tx_proof, confirmations)?;
271+
let header = self.verify_transaction(txid.as_ref(), tx_proof, confirmations)?;
272272
Ok((header, tx))
273273
}
274274

@@ -286,7 +286,7 @@ impl packed::SpvClient {
286286
/// If you don't need it, just ignore it.
287287
pub fn verify_transaction(
288288
&self,
289-
txid: &core::Txid,
289+
txid: &[u8; 32],
290290
tx_proof: packed::TransactionProofReader,
291291
confirmations: u32,
292292
) -> Result<core::Header, VerifyTxError> {
@@ -328,8 +328,9 @@ impl packed::SpvClient {
328328
.position(|v| v == tx_index)
329329
.map(|i| matches[i])
330330
.ok_or(VerifyTxError::TxOutProofInvalidTxIndex)
331-
.and_then(|ref id| {
332-
if id == txid {
331+
.and_then(|id| {
332+
let id_bytes: &[u8; 32] = id.as_ref();
333+
if id_bytes == txid {
333334
Ok(())
334335
} else {
335336
Err(VerifyTxError::TxOutProofInvalidTxId)

0 commit comments

Comments
 (0)