Conversation
📝 WalkthroughWalkthroughAdds a 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
6ac848c to
382a569
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/adder/main.go`:
- Around line 46-55: Update the command Long help string that documents plugins
(the multiline string assigned to the Cobra command's Long/description) by
replacing the inaccurate filters line ("Filters: address, asset, policy,
pool, drep, event type") with the corrected line: "Filters: cardano
(address, asset, policy, pool, drep), event" so the help text reflects the
actual registered filter plugins `cardano` and `event`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6148251f-2b78-4e14-a465-0125e55287f4
📒 Files selected for processing (3)
cmd/adder/main.gofilter/cardano/plugin.gointernal/config/config.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@filter/cardano/plugin.go`:
- Around line 123-130: The DRep token list is passed raw from
cmdlineOptions.drepId into WithDRepIds causing empty/whitespace or uppercase
tokens to flip hasDRepFilter but never match; before appending WithDRepIds,
split and sanitize each token by trimming whitespace, dropping empty strings,
and normalizing case (e.g., strings.ToLower) so matching logic
(HasPrefix("drep") checks) works; also ensure hasDRepFilter is only enabled when
at least one valid sanitized token remains (i.e., only call WithDRepIds with the
cleaned slice or guard enabling of hasDRepFilter when cleaned slice length > 0).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 256c2ee0-ab3b-49ef-aa81-2bff62fc0b2f
📒 Files selected for processing (3)
cmd/adder/main.gofilter/cardano/plugin.gointernal/config/config.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/config/config.go
- cmd/adder/main.go
382a569 to
e1b0d5f
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
filter/cardano/option.go (1)
154-199:⚠️ Potential issue | 🟠 MajorReject malformed DRep IDs before turning the filter on.
Line 196 only checks whether anything was stored, but Lines 159-161 and 175-177 store raw tokens before validating them. That means
fooor an invaliddrep...string still enableshasDRepFilter; after that, the guards infilter/cardano/cardano.go:129-165,167-181, and340-369make governance/DRep matching restrictive, so these bad inputs silently filter everything out.Proposed fix
func WithDRepIds(drepIds []string) CardanoOptionFunc { return func(c *Cardano) { if c.filterSet.dreps == nil { c.filterSet.dreps = &drepFilter{ hexDRepIds: make(map[string]struct{}), bech32DRepIds: make(map[string]struct{}), hexToBech32: make(map[string]string), bytesDRepIds: make(map[string][]byte), bytesLookup: make(map[string]struct{}), } } for _, drepId := range drepIds { - if drepId == "" { + drepId = strings.ToLower(strings.TrimSpace(drepId)) + if drepId == "" { continue } if strings.HasPrefix(drepId, "drep") { - // bech32 format (drep1xxx or drep_script1xxx) - c.filterSet.dreps.bech32DRepIds[drepId] = struct{}{} - // Try to decode and compute hex representation if _, data, err := bech32.Decode(drepId); err == nil { + c.filterSet.dreps.bech32DRepIds[drepId] = struct{}{} if decoded, err := bech32.ConvertBits(data, 5, 8, false); err == nil { hexId := hex.EncodeToString(decoded) c.filterSet.dreps.hexDRepIds[hexId] = struct{}{} c.filterSet.dreps.hexToBech32[hexId] = drepId - // Pre-compute byte slice for direct comparison - c.filterSet.dreps.bytesDRepIds[hexId] = decoded // Store as byte string for O(1) lookup without encoding + c.filterSet.dreps.bytesDRepIds[hexId] = decoded c.filterSet.dreps.bytesLookup[string(decoded)] = struct{}{} } } - } else { - // Assume hex format - store hex + } else if hexBytes, err := hex.DecodeString(drepId); err == nil { c.filterSet.dreps.hexDRepIds[drepId] = struct{}{} - // Compute both bech32 variants (drep and drep_script) - if hexBytes, err := hex.DecodeString(drepId); err == nil { - // Pre-compute byte slice for direct comparison - c.filterSet.dreps.bytesDRepIds[drepId] = hexBytes - // Store as byte string for O(1) lookup without encoding - c.filterSet.dreps.bytesLookup[string(hexBytes)] = struct{}{} - if convData, err := bech32.ConvertBits(hexBytes, 8, 5, true); err == nil { - // Store as key hash version - if encoded, err := bech32.Encode("drep", convData); err == nil { - c.filterSet.dreps.bech32DRepIds[encoded] = struct{}{} - c.filterSet.dreps.hexToBech32[drepId] = encoded - } - // Also store as script hash version - if encoded, err := bech32.Encode("drep_script", convData); err == nil { - c.filterSet.dreps.bech32DRepIds[encoded] = struct{}{} - } + c.filterSet.dreps.bytesDRepIds[drepId] = hexBytes + c.filterSet.dreps.bytesLookup[string(hexBytes)] = struct{}{} + if convData, err := bech32.ConvertBits(hexBytes, 8, 5, true); err == nil { + if encoded, err := bech32.Encode("drep", convData); err == nil { + c.filterSet.dreps.bech32DRepIds[encoded] = struct{}{} + c.filterSet.dreps.hexToBech32[drepId] = encoded + } + if encoded, err := bech32.Encode("drep_script", convData); err == nil { + c.filterSet.dreps.bech32DRepIds[encoded] = struct{}{} } } } } if len(c.filterSet.dreps.hexDRepIds) > 0 || len(c.filterSet.dreps.bech32DRepIds) > 0 { c.filterSet.hasDRepFilter = true🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@filter/cardano/option.go` around lines 154 - 199, The code currently stores raw tokens into c.filterSet.dreps (bech32DRepIds and hexDRepIds) before validating them, which can cause malformed IDs like "foo" to enable hasDRepFilter and then filter out everything; fix by only inserting into c.filterSet.dreps.* maps after successful validation/decoding. Concretely: in the bech32 branch remove the initial unconditional c.filterSet.dreps.bech32DRepIds[drepId] assignment and only add the bech32 key after bech32.Decode and bech32.ConvertBits succeed (use the decoded/converted values to populate hexDRepIds, hexToBech32, bytesDRepIds, bytesLookup); in the hex branch do not call c.filterSet.dreps.hexDRepIds[drepId] until hex.DecodeString succeeds and the subsequent bech32.ConvertBits/bech32.Encode steps succeed where applicable; ensure hasDRepFilter (c.filterSet.hasDRepFilter) is set only when at least one validated entry exists.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@filter/cardano/option.go`:
- Around line 154-199: The code currently stores raw tokens into
c.filterSet.dreps (bech32DRepIds and hexDRepIds) before validating them, which
can cause malformed IDs like "foo" to enable hasDRepFilter and then filter out
everything; fix by only inserting into c.filterSet.dreps.* maps after successful
validation/decoding. Concretely: in the bech32 branch remove the initial
unconditional c.filterSet.dreps.bech32DRepIds[drepId] assignment and only add
the bech32 key after bech32.Decode and bech32.ConvertBits succeed (use the
decoded/converted values to populate hexDRepIds, hexToBech32, bytesDRepIds,
bytesLookup); in the hex branch do not call c.filterSet.dreps.hexDRepIds[drepId]
until hex.DecodeString succeeds and the subsequent
bech32.ConvertBits/bech32.Encode steps succeed where applicable; ensure
hasDRepFilter (c.filterSet.hasDRepFilter) is set only when at least one
validated entry exists.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a4c6bfb2-6b08-4acb-af85-0ce5fe6b09f9
📒 Files selected for processing (4)
cmd/adder/main.gofilter/cardano/option.gofilter/cardano/plugin.gointernal/config/config.go
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/adder/main.go
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
e1b0d5f to
18a9657
Compare
Summary by cubic
Adds
--filter-drepto filter Cardano events by DRep IDs (comma-separated bech32 or hex). The filter only turns on when at least one valid ID is valid; invalid-only input is ignored.adderhelp; lists inputs, outputs, filters, and/eventsAPI.--api-address,--api-port,--logging-level,--debug-address,--debug-port(set--debug-port=0to disable).Written for commit 18a9657. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes