feat(chain): add unified TxOutIndex<K> indexer#20
Open
evanlinjin wants to merge 2 commits into
Open
Conversation
`TxOutIndex<K>` collapses the wildcard/non-wildcard descriptor + raw-spk split that previously required composing `KeychainTxOutIndex<K>` and `SpkTxOutIndex<W>` (with a bridging `Indexer` impl per project) into a single indexer keyed on `K`. The kind of script — wildcard descriptor, non-wildcard descriptor, or raw spk registered via `insert_spk` — is dispatched internally, so callers carry one keychain enum, one generic parameter, and one `ChangeSet` type. Overlap is rejected at insert time: a script pubkey can have exactly one owning keychain, so `index_of_spk` always answers unambiguously and applications carry multi-claim semantics as their own metadata. This is additive; the existing `KeychainTxOutIndex` / `SpkTxOutIndex` types are unchanged.
Replace the duplicated state with two sub-indexers:
pub struct TxOutIndex<K> {
wildcard: KeychainTxOutIndex<K>,
fixed: SpkTxOutIndex<(K, u32)>,
}
`KeychainTxOutIndex` already owns derivation, lookahead, and spk-cache
machinery for wildcard descriptors. Non-wildcard descriptors and raw
spks are operationally identical — one script per keychain at index 0,
no derivation — so they share storage on the fixed side. The descriptor
object for non-wildcards isn't retained because nothing in the indexer
needs it after the spk has been derived.
Methods are one-line delegations or chained iterators across the two
sides. Overlap detection runs against the lookahead window at insert
time. Net `-408` lines on the implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TxOutIndex<K>collapses the wildcard/non-wildcard descriptor + raw-spksplit that previously required composing
KeychainTxOutIndex<K>andSpkTxOutIndex<W>(with a bridgingIndexerimpl per project) into asingle indexer keyed on
K. The kind of script — wildcard descriptor,non-wildcard descriptor, or raw spk registered via
insert_spk— isdispatched internally, so callers carry one keychain enum, one generic
parameter, and one
ChangeSettype.Overlap is rejected at insert time: a script pubkey can have exactly one
owning keychain, so
index_of_spkalways answers unambiguously andapplications carry multi-claim semantics as their own metadata.
This is additive; the existing
KeychainTxOutIndex/SpkTxOutIndextypes are unchanged.