Skip to content

fix: update CLI flags: --filter-drep#654

Merged
wolf31o2 merged 1 commit intomainfrom
fix/cli-filter-drep
Mar 13, 2026
Merged

fix: update CLI flags: --filter-drep#654
wolf31o2 merged 1 commit intomainfrom
fix/cli-filter-drep

Conversation

@wolf31o2
Copy link
Copy Markdown
Member

@wolf31o2 wolf31o2 commented Mar 10, 2026


Summary by cubic

Adds --filter-drep to 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.

  • New Features
    • Expanded adder help; lists inputs, outputs, filters, and /events API.
    • New flags: --api-address, --api-port, --logging-level, --debug-address, --debug-port (set --debug-port=0 to disable).

Written for commit 18a9657. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Improved CLI help with clearer short and multi-line long descriptions.
    • Cardano plugin: added DRep filtering (accepts comma-separated DRep IDs).
    • New CLI flags to configure API address/port, logging level, and debug address/port.
  • Bug Fixes

    • DRep filter now only activates when valid DRep IDs are provided.

@wolf31o2 wolf31o2 requested a review from a team as a code owner March 10, 2026 14:11
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

Adds a drep CLI option to the Cardano filter plugin that accepts comma-separated DRep IDs, normalizes them (lowercase/trim), and only enables the DRep filter when at least one valid ID is parsed. Wires WithDRepIds(...) into plugin options. Updates the root Cobra command to include Short and a multi-line Long description. Adds CLI flags in internal/config: api-address, api-port, logging-level, debug-address, and debug-port. No exported/public signatures were changed.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title mentions '--filter-drep' which is one of the changes, but omits significant additions like API/debug/logging configuration flags that are equally important.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cli-filter-drep
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wolf31o2 wolf31o2 force-pushed the fix/cli-filter-drep branch from 6ac848c to 382a569 Compare March 10, 2026 14:14
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 25e8c4e and 6ac848c.

📒 Files selected for processing (3)
  • cmd/adder/main.go
  • filter/cardano/plugin.go
  • internal/config/config.go

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ac848c and 382a569.

📒 Files selected for processing (3)
  • cmd/adder/main.go
  • filter/cardano/plugin.go
  • internal/config/config.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/config/config.go
  • cmd/adder/main.go

@wolf31o2 wolf31o2 force-pushed the fix/cli-filter-drep branch from 382a569 to e1b0d5f Compare March 10, 2026 14:50
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Reject 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 foo or an invalid drep... string still enables hasDRepFilter; after that, the guards in filter/cardano/cardano.go:129-165, 167-181, and 340-369 make 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

📥 Commits

Reviewing files that changed from the base of the PR and between 382a569 and e1b0d5f.

📒 Files selected for processing (4)
  • cmd/adder/main.go
  • filter/cardano/option.go
  • filter/cardano/plugin.go
  • internal/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>
@wolf31o2 wolf31o2 force-pushed the fix/cli-filter-drep branch from e1b0d5f to 18a9657 Compare March 12, 2026 23:05
@wolf31o2 wolf31o2 merged commit f014a60 into main Mar 13, 2026
11 checks passed
@wolf31o2 wolf31o2 deleted the fix/cli-filter-drep branch March 13, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants