Skip to content

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Dec 4, 2025

Closes #550
Closes #551


Summary by cubic

Upgraded gouroboros to 0.142.0 and plutigo to 0.0.16, updating metadata handling and CIP-20 parsing to the new ledger/common types. Added block body hash support in chain sync tests and set Swagger template delimiters.

  • Dependencies

    • gouroboros v0.142.0
    • plutigo v0.0.16
  • Refactors

    • TransactionEvent.Metadata now uses lcommon.TransactionMetadatum
    • CIP-20 extraction rewritten for MetaMap and Meta* types, with metadatumToAny helper
    • MockBlockHeader/MockBlock implement BlockBodyHash
    • Swagger docs set LeftDelim/RightDelim and package comment
    • Minor import order and YAML tag alignment fixes

Written for commit cb88405. Summary will update automatically on new commits.

Summary by CodeRabbit

  • New Features

    • API docs/templates updated to support custom template delimiters.
  • Refactor

    • Transaction metadata handling and CIP-20 extraction rewritten for stronger type safety and more robust JSON encoding.
    • Module dependencies bumped to newer releases.
  • Style

    • Configuration tags reformatted for consistency.
  • Tests

    • Improved block mocks and cleaned up test imports.

✏️ Tip: You can customize this high-level summary in your review settings.

@wolf31o2 wolf31o2 requested a review from a team as a code owner December 4, 2025 20:15
@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

📝 Walkthrough

Walkthrough

This PR updates module requirements (github.com/blinklabs-io/gouroboros → v0.142.0, github.com/blinklabs-io/plutigo → v0.0.16), adds Swagger template delimiters in docs/docs.go (LeftDelim: "{{", RightDelim: "}}"), changes TransactionEvent.Metadata from *cbor.LazyValue to lcommon.TransactionMetadatum and removes the cbor import, refactors metadata handling in output/push/push.go to operate on structured metadatum types with new helpers (metadatumToAny, keyToString), adds BlockBodyHash support to test mocks in input/chainsync/block_test.go, and includes minor formatting/import cleanups.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • pay special attention to:
    • output/push/push.go — new metadatumToAny/keyToString helpers, revised extractCIP20FromMetadata signature and JSON conversion paths (many type branches).
    • event/tx.go — public type change: TransactionEvent.Metadata from pointer CBOR type → lcommon.TransactionMetadatum and removal of cbor import; verify callers and serialization.
    • go.mod — dependency bumps to gouroboros v0.142.0 and plutigo v0.0.16; confirm API changes are correctly used.
    • input/chainsync/block_test.go — added blockBodyHash field and BlockBodyHash() methods on mocks; ensure tests still satisfy interfaces.

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main dependency updates (gouroboros 0.142.0 and plutigo 0.0.16) which are the primary focus of the pull request and go.mod changes.
Linked Issues check ✅ Passed The PR fulfills requirements from both linked issues: plutigo bumped to 0.0.15 (note: PR mentions 0.0.16, likely due to transitive dependencies), gouroboros bumped to 0.142.0, and required code refactors (metadata handling, CIP-20 extraction, mock updates) are implemented to support API changes.
Out of Scope Changes check ✅ Passed All changes are directly related to supporting the dependency upgrades: TransactionEvent.Metadata refactor, CIP-20 extraction rewrite, MockBlockHeader/MockBlock enhancements, Swagger config, and formatting align with upstream gouroboros API changes and requirements.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/gouroboros-plutigo

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.

Copy link

@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 8 files

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 917cf38 and fdf3a7c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • docs/docs.go (2 hunks)
  • event/tx.go (1 hunks)
  • go.mod (1 hunks)
  • input/chainsync/block_test.go (3 hunks)
  • internal/config/config.go (1 hunks)
  • openapi/test/api_default_test.go (1 hunks)
  • output/push/push.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (9)
openapi/test/api_default_test.go (1)

12-19: LGTM!

Import organization looks correct. The testing import is properly grouped with standard library imports.

docs/docs.go (1)

175-176: LGTM!

The addition of LeftDelim and RightDelim fields with default Go template delimiters ("{{" and "}}") is consistent with regenerated swagger documentation. These are the default values and don't change template parsing behavior.

input/chainsync/block_test.go (2)

34-34: LGTM!

The blockBodyHash field and accessor method are correctly added to MockBlockHeader, following the same pattern as other hash fields (hash, prevHash).

Also applies to: 69-71


95-97: LGTM!

MockBlock.BlockBodyHash() correctly delegates to the embedded MockBlockHeader.BlockBodyHash(), maintaining consistency with the interface pattern.

go.mod (1)

10-11: Dependency versions verified and appropriate for the PR objectives.

Both gouroboros v0.142.0 and plutigo v0.0.16 are valid releases with proper checksums in go.sum. The plutigo bump to v0.0.16 supersedes the v0.0.15 mentioned in issue #550.

event/tx.go (1)

34-34: No action required. The omitempty JSON tag on the Metadata field is correct for its type. The nil check and conditional assignment pattern (line 82) ensures that when metadata is not present, the field remains at its zero value and is properly omitted during JSON serialization.

Likely an incorrect or invalid review comment.

output/push/push.go (2)

22-22: LGTM!

Import additions align with the new gouroboros metadata types: math/big for *big.Int comparison and common package for the ledger metadata interfaces.

Also applies to: 29-29


310-367: LGTM!

The refactored function correctly uses gouroboros ledger metadata types with proper type assertions and structured iteration over Pairs. The key lookups (674, "msg") are type-safe and the error handling is clear.

internal/config/config.go (1)

76-85: LGTM!

Formatting-only changes to align struct field tags. No functional impact.

@wolf31o2 wolf31o2 force-pushed the chore/gouroboros-plutigo branch from fdf3a7c to f85b99b Compare December 4, 2025 20:39
@wolf31o2 wolf31o2 force-pushed the chore/gouroboros-plutigo branch from f85b99b to cb88405 Compare December 4, 2025 20:41
Copy link

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
output/push/push.go (1)

17-25: Fix hex‑format lint by using encoding/hex instead of fmt.Sprintf

keyToString currently formats MetaBytes keys with fmt.Sprintf("%x", v.Value), which golangci‑lint (perfsprint/hex-format) flags. Switching to hex.EncodeToString is both faster and will satisfy the linter.

@@
-import (
-	"context"
-	"encoding/json"
-	"errors"
-	"fmt"
-	"math/big"
-	"os"
+import (
+	"context"
+	"encoding/hex"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"math/big"
+	"os"
@@
 func keyToString(md common.TransactionMetadatum) string {
 	switch v := md.(type) {
 	case common.MetaInt:
 		return v.Value.String()
 	case common.MetaBytes:
-		return fmt.Sprintf("%x", v.Value)
+		return hex.EncodeToString(v.Value)
 	case common.MetaText:
 		return v.Value
 	default:
 		return fmt.Sprintf("%v", metadatumToAny(md))
 	}
 }

Also applies to: 369-380

🧹 Nitpick comments (2)
input/chainsync/block_test.go (1)

24-35: New blockBodyHash field is consistent; consider populating it in test fixtures

Adding blockBodyHash common.Blake2b256 to MockBlockHeader matches the existing hash fields and keeps the mock aligned with the header interface. To fully exercise any logic that consumes the block body hash (e.g., in event.NewBlockContext), consider setting a non‑zero blockBodyHash in at least one test case and asserting the derived behavior where applicable.

output/push/push.go (1)

149-159: CIP‑20 extraction call site is wired correctly; consider using logger instead of fmt.Println

The new te.Metadata != nil guard and call to extractCIP20FromMetadata(te.Metadata) correctly reflect the new metadata representation and avoid nil dereferences. On error you currently fmt.Println("Error:", err); for consistency with the rest of this file, consider logging this via logging.GetLogger().Error(...) instead of printing to stdout, so failures in CIP‑20 parsing are surfaced in structured logs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdf3a7c and f85b99b.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • docs/docs.go (2 hunks)
  • event/tx.go (1 hunks)
  • go.mod (1 hunks)
  • input/chainsync/block_test.go (3 hunks)
  • internal/config/config.go (1 hunks)
  • openapi/test/api_default_test.go (1 hunks)
  • output/push/push.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • go.mod
  • docs/docs.go
  • openapi/test/api_default_test.go
🧰 Additional context used
🪛 GitHub Actions: golangci-lint
output/push/push.go

[error] 374-374: golangci-lint: hex-format: fmt.Sprintf can be replaced with faster hex.EncodeToString (perfsprint)

🪛 GitHub Check: lint
output/push/push.go

[failure] 374-374:
hex-format: fmt.Sprintf can be replaced with faster hex.EncodeToString (perfsprint)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
input/chainsync/block_test.go (2)

69-71: Header BlockBodyHash accessor matches existing pattern

The MockBlockHeader.BlockBodyHash() implementation is straightforward and consistent with the other accessors (Hash, PrevHash, etc.), so the header mock should cleanly satisfy the updated interface.


95-97: Block-level BlockBodyHash passthrough looks good

Delegating MockBlock.BlockBodyHash() to MockBlockHeader.BlockBodyHash() is the right choice and keeps MockBlock behavior consistent with the embedded header.

internal/config/config.go (1)

75-88: Config tag alignment is cosmetic and safe

Only horizontal spacing in the struct tags was adjusted; YAML and envconfig tag values are unchanged. No behavioral impact, and the change is fine as is.

event/tx.go (1)

30-44: Verify JSON marshalling behavior of TransactionMetadatum interface in downstream code

The type migration of TransactionEvent.Metadata from *cbor.LazyValue to lcommon.TransactionMetadatum is architecturally consistent with the new gouroboros API. However, confirm that:

  • All concrete implementations of TransactionMetadatum properly implement json.Marshaler or have correct struct tags for JSON serialization
  • Any code paths that directly serialize TransactionEvent (e.g., in output/push handlers) produce expected JSON structure
  • Edge cases where Metadata is nil are correctly omitted by the omitempty tag
output/push/push.go (1)

310-367: CIP‑20 traversal over TransactionMetadatum and JSON conversion are correctly implemented

The extractCIP20FromMetadata, metadatumToAny, and keyToString functions work together safely:

  • Top-level metadata is enforced as a MetaMap with proper type assertion.
  • CIP‑20 label 674 is located via MetaInt key with big.Int comparison.
  • The nested "msg" key is retrieved from a MetaMap via MetaText lookup.
  • Recursive metadatumToAny conversion builds map[string]any structures, ensuring JSON marshalling will not panic.
  • keyToString consistently converts all metadata keys (MetaInt, MetaBytes, MetaText) to strings for safe map construction.

This implementation safely handles typical CIP‑20 payloads without the previous map[any]any JSON issue.

Copy link

@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: 0

🧹 Nitpick comments (1)
output/push/push.go (1)

383-408: Well-structured recursive conversion.

The past review concern about JSON marshalling with non-string keys has been addressed—MetaMap now correctly builds a map[string]any.

One consideration: MetaBytes returns []byte, which json.Marshal will encode as a base64 string. This is typically acceptable for metadata, but if hex encoding is preferred for consistency with keyToString, you could return hex.EncodeToString(v.Value) instead.

If hex encoding is preferred for JSON output consistency:

 	case common.MetaBytes:
-		return v.Value
+		return hex.EncodeToString(v.Value)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f85b99b and cb88405.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • docs/docs.go (2 hunks)
  • event/tx.go (1 hunks)
  • go.mod (1 hunks)
  • input/chainsync/block_test.go (3 hunks)
  • internal/config/config.go (1 hunks)
  • openapi/test/api_default_test.go (1 hunks)
  • output/push/push.go (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • internal/config/config.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • openapi/test/api_default_test.go
  • event/tx.go
  • docs/docs.go
🔇 Additional comments (6)
input/chainsync/block_test.go (2)

34-34: LGTM!

The new blockBodyHash field follows the existing pattern for other hash fields in the mock.


69-97: LGTM!

The BlockBodyHash() methods are correctly implemented:

  • MockBlockHeader returns the field value directly
  • MockBlock properly delegates to its embedded header

This satisfies the updated interface requirements from gouroboros v0.142.0.

output/push/push.go (3)

17-31: LGTM!

The new imports are properly added and all are utilized in the refactored metadata handling code.


311-368: Clean refactoring of CIP-20 extraction.

The function correctly adapts to the new common.TransactionMetadatum type system:

  • Proper type assertion to MetaMap
  • Correct use of big.Int comparison for the integer key 674
  • Iterative key lookup via Pairs slice is appropriate for the MetaMap structure
  • Clear error messages at each validation step

370-381: LGTM!

The keyToString helper handles all expected Cardano metadata key types appropriately. The fallback to fmt.Sprintf("%v", metadatumToAny(md)) provides a reasonable default for unexpected types.

go.mod (1)

10-11: Dependency updates look good.

The version bumps for gouroboros (v0.142.0) and plutigo (v0.0.16) are both published and available, bringing in upstream improvements and fixes.

@wolf31o2 wolf31o2 merged commit 22f50b0 into main Dec 4, 2025
11 checks passed
@wolf31o2 wolf31o2 deleted the chore/gouroboros-plutigo branch December 4, 2025 23:20
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.

3 participants