|
2 | 2 |
|
3 | 3 | //---------------------------------------------------------------------------------------------------- Import |
4 | 4 | use curve25519_dalek::edwards::CompressedEdwardsY; |
5 | | -use monero_serai::transaction::{Timelock, Transaction}; |
| 5 | +use monero_serai::transaction::Timelock; |
6 | 6 |
|
7 | 7 | use cuprate_database::{ |
8 | 8 | DbResult, RuntimeError, {DatabaseRo, DatabaseRw}, |
9 | 9 | }; |
10 | | -use cuprate_helper::{cast::u32_to_usize, crypto::compute_zero_commitment}; |
11 | | -use cuprate_helper::{cast::u64_to_usize, map::u64_to_timelock}; |
| 10 | +use cuprate_helper::{ |
| 11 | + cast::{u32_to_usize, u64_to_usize}, |
| 12 | + crypto::compute_zero_commitment, |
| 13 | + map::u64_to_timelock, |
| 14 | +}; |
12 | 15 | use cuprate_types::OutputOnChain; |
13 | 16 |
|
14 | 17 | use crate::{ |
15 | | - ops::macros::{doc_add_block_inner_invariant, doc_error}, |
| 18 | + ops::{ |
| 19 | + macros::{doc_add_block_inner_invariant, doc_error}, |
| 20 | + tx::get_tx_from_id, |
| 21 | + }, |
16 | 22 | tables::{ |
17 | 23 | BlockInfos, BlockTxsHashes, Outputs, RctOutputs, Tables, TablesMut, TxBlobs, TxUnlockTime, |
18 | 24 | }, |
@@ -175,14 +181,16 @@ pub fn output_to_output_on_chain( |
175 | 181 |
|
176 | 182 | let txid = if get_txid { |
177 | 183 | let height = u32_to_usize(output.height); |
178 | | - let tx_idx = u64_to_usize(output.tx_idx); |
179 | | - let txid = if let Some(hash) = table_block_txs_hashes.get(&height)?.get(tx_idx) { |
180 | | - *hash |
| 184 | + |
| 185 | + let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index; |
| 186 | + |
| 187 | + let txid = if miner_tx_id == output.tx_idx { |
| 188 | + get_tx_from_id(&miner_tx_id, table_tx_blobs)?.hash() |
181 | 189 | } else { |
182 | | - let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index; |
183 | | - let tx_blob = table_tx_blobs.get(&miner_tx_id)?; |
184 | | - Transaction::read(&mut tx_blob.0.as_slice())?.hash() |
| 190 | + let idx = u64_to_usize(output.tx_idx - miner_tx_id - 1); |
| 191 | + table_block_txs_hashes.get(&height)?[idx] |
185 | 192 | }; |
| 193 | + |
186 | 194 | Some(txid) |
187 | 195 | } else { |
188 | 196 | None |
@@ -234,8 +242,7 @@ pub fn rct_output_to_output_on_chain( |
234 | 242 | let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index; |
235 | 243 |
|
236 | 244 | let txid = if miner_tx_id == rct_output.tx_idx { |
237 | | - let tx_blob = table_tx_blobs.get(&miner_tx_id)?; |
238 | | - Transaction::read(&mut tx_blob.0.as_slice())?.hash() |
| 245 | + get_tx_from_id(&miner_tx_id, table_tx_blobs)?.hash() |
239 | 246 | } else { |
240 | 247 | let idx = u64_to_usize(rct_output.tx_idx - miner_tx_id - 1); |
241 | 248 | table_block_txs_hashes.get(&height)?[idx] |
|
0 commit comments