diff --git a/src/db/cache/index_cache.rs b/src/db/cache/index_cache.rs index bab51ef..f81456d 100644 --- a/src/db/cache/index_cache.rs +++ b/src/db/cache/index_cache.rs @@ -100,6 +100,15 @@ impl IndexCache { ctx, ) .await; + #[cfg(not(feature = "release"))] + { + for (rune_id, balances) in input_runes.iter() { + try_debug!(ctx, "INPUT {rune_id} {balances:?} {location}"); + } + if input_runes.len() > 0 { + try_debug!(ctx, "First output: {first_eligible_output:?}, total_outputs: {total_outputs}"); + } + } self.tx_cache = TransactionCache::new( location, input_runes, @@ -126,7 +135,9 @@ impl IndexCache { ctx: &Context, ) { try_debug!(ctx, "{:?} {}", runestone, self.tx_cache.location); - self.tx_cache.apply_runestone_pointer(runestone, ctx); + if let Some(new_pointer) = runestone.pointer { + self.tx_cache.output_pointer = Some(new_pointer); + } } pub async fn apply_cenotaph( diff --git a/src/db/cache/transaction_cache.rs b/src/db/cache/transaction_cache.rs index 77813ab..c8d3d76 100644 --- a/src/db/cache/transaction_cache.rs +++ b/src/db/cache/transaction_cache.rs @@ -5,7 +5,7 @@ use std::{ use bitcoin::ScriptBuf; use chainhook_sdk::utils::Context; -use ordinals::{Cenotaph, Edict, Etching, Rune, RuneId, Runestone}; +use ordinals::{Cenotaph, Edict, Etching, Rune, RuneId}; use crate::{ db::{ @@ -30,20 +30,20 @@ pub struct InputRuneBalance { /// Holds cached data relevant to a single transaction during indexing. pub struct TransactionCache { pub location: TransactionLocation, - /// Index of the ledger entry we're inserting next for this transaction. + /// Sequential index of the ledger entry we're inserting next for this transaction. Will be increased with each generated + /// entry. next_event_index: u32, - /// Rune etched during this transaction + /// Rune etched during this transaction, if any. pub etching: Option, - /// The output where all unallocated runes will be transferred to. - pointer: Option, + /// The output where all unallocated runes will be transferred to. Set to the first eligible output by default but can be + /// overridden by a Runestone. + pub output_pointer: Option, /// Holds input runes for the current transaction (input to this tx, premined or minted). Balances in the vector are in the /// order in which they were input to this transaction. input_runes: HashMap>, /// Non-OP_RETURN outputs in this transaction eligible_outputs: HashMap, - /// Index of the output that should receive unallocated runes if there is no `pointer` present. - first_eligible_output: Option, - /// Total outputs contained in this transaction, including OP_RETURN outputs + /// Total outputs contained in this transaction, including non-eligible outputs. total_outputs: u32, } @@ -59,25 +59,13 @@ impl TransactionCache { location, next_event_index: 0, etching: None, - pointer: None, + output_pointer: first_eligible_output, input_runes, eligible_outputs, - first_eligible_output, total_outputs, } } - /// Takes the runestone's output pointer and keeps a record of eligible outputs to send runes to. - pub fn apply_runestone_pointer(&mut self, runestone: &Runestone, _ctx: &Context) { - self.pointer = if runestone.pointer.is_some() { - runestone.pointer - } else if self.first_eligible_output.is_some() { - self.first_eligible_output - } else { - None - }; - } - /// Burns the rune balances input to this transaction. pub fn apply_cenotaph_input_burn(&mut self, _cenotaph: &Cenotaph) -> Vec { let mut results = vec![]; @@ -104,12 +92,13 @@ impl TransactionCache { pub fn allocate_remaining_balances(&mut self, ctx: &Context) -> Vec { let mut results = vec![]; for (rune_id, unallocated) in self.input_runes.iter_mut() { - #[cfg(feature = "debug")] + #[cfg(not(feature = "release"))] for input in unallocated.iter() { try_debug!( ctx, - "Assign unallocated {} {:?} ({}) {}", + "Assign unallocated {} to pointer {:?} {:?} ({}) {}", rune_id, + self.output_pointer, input.address, input.amount, self.location @@ -117,7 +106,7 @@ impl TransactionCache { } results.extend(move_rune_balance_to_output( &self.location, - self.pointer, + self.output_pointer, rune_id, unallocated, &self.eligible_outputs, diff --git a/src/db/index.rs b/src/db/index.rs index 2929718..df63041 100644 --- a/src/db/index.rs +++ b/src/db/index.rs @@ -27,8 +27,8 @@ pub fn get_rune_genesis_block_height(network: Network) -> u64 { } } -/// Transforms a Bitcoin transaction from a Chainhook format to a rust bitcoin format so it can be consumed by ord. Also, takes -/// all non-OP_RETURN outputs and returns them so they can be used later to receive runes. +/// Transforms a Bitcoin transaction from a Chainhook format to a rust bitcoin crate format so it can be parsed by the ord crate +/// to look for `Artifact`s. Also, takes all non-OP_RETURN outputs and returns them so they can be used later to receive runes. fn bitcoin_tx_from_chainhook_tx( block: &BitcoinBlockData, tx: &BitcoinTransactionData,