From 9996e3a4f7dc4a8ea070cd0866cc761668f649f2 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 12 Apr 2018 21:57:05 +0300 Subject: [PATCH] Store prefix of output script hash --- src/index.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/index.rs b/src/index.rs index a5260f6..68c2281 100644 --- a/src/index.rs +++ b/src/index.rs @@ -44,7 +44,7 @@ fn full_hash(hash: &Sha256dHash) -> FullHash { #[derive(Serialize, Deserialize)] struct TxOutKey { code: u8, - script_hash: FullHash, + script_hash_prefix: HashPrefix, txid_prefix: HashPrefix, } @@ -65,13 +65,14 @@ struct TxValue { confirmed_height: u32, } -fn digest(data: &[u8]) -> FullHash { +fn digest(data: &[u8]) -> HashPrefix { + let mut hash = FullHash::default(); let mut sha2 = Sha256::new(); sha2.input(data); - - let mut hash = [0u8; HASH_LEN]; sha2.result(&mut hash); - hash + let mut prefix = HashPrefix::default(); + prefix.copy_from_slice(&hash[..HASH_PREFIX_LEN]); + prefix } fn txin_row(input: &txn::TxIn, txid: &Sha256dHash) -> Row { @@ -91,7 +92,7 @@ fn txout_row(output: &txn::TxOut, txid: &Sha256dHash) -> Row { Row { key: bincode::serialize(&TxOutKey { code: b'O', - script_hash: digest(&output.script_pubkey[..]), + script_hash_prefix: digest(&output.script_pubkey[..]), txid_prefix: hash_prefix(&txid), }).unwrap(), value: vec![],