Skip to content

feat: show transaction input data on-demand#1261

Merged
williamrusdyputra merged 2 commits into
mainfrom
transacAction
Nov 21, 2025
Merged

feat: show transaction input data on-demand#1261
williamrusdyputra merged 2 commits into
mainfrom
transacAction

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented Nov 20, 2025

resolves: https://github.com/trufnetwork/trufscan/issues/134

Summary by CodeRabbit

  • New Features
    • New query actions to retrieve transaction-related data by transaction ID, including streams, records, taxonomies, metadata, and attestations — improving visibility into transaction inputs for analysis and debugging.
  • Tests
    • Added an integration test suite validating these retrieval actions, typical workflows, and error handling (missing or malformed transaction IDs).

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

@MicBun MicBun self-assigned this Nov 20, 2025
@MicBun MicBun added the type: feat New feature or request label Nov 20, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 20, 2025

Walkthrough

Adds a SQL migration that introduces five public view actions to retrieve transaction input data by tx_id; each action validates and normalizes tx_id (strips leading 0x) and returns ordered rows from the relevant tables.

Changes

Cohort / File(s) Summary
SQL Migration
internal/migrations/028-transaction-input-actions.sql
Adds five public actions: get_transaction_streams, get_transaction_records, get_transaction_taxonomies, get_transaction_metadata, and get_transaction_attestation. Each action requires tx_id, strips a leading 0x if present, validates input, and performs deterministic queries joining to streams, primitive_events, taxonomies, metadata, and attestations, returning ordered results.
Test Suite
tests/streams/transaction_input_data_test.go
New kwiltest-tagged test TestTransactionInputActions exercising the five actions via schema-driven tests: creates streams/records, calls each view, asserts returned rows and fields, and checks edge cases (missing/non-existent tx_id, error messages).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DB as Postgres (Actions)
    participant Streams as streams
    participant Events as primitive_events
    participant Tax as taxonomies
    participant Meta as metadata
    participant Att as attestations

    Client->>DB: CALL get_transaction_streams(tx_id)
    DB->>Streams: SELECT ... WHERE tx_id = normalized(tx_id) ORDER BY ...
    Streams-->>DB: rows
    DB-->>Client: result set

    alt records/taxonomies/metadata/attestation
      Client->>DB: CALL get_transaction_records(tx_id)
      DB->>Events: SELECT ... JOIN streams WHERE tx_id = normalized(tx_id)
      Events-->>DB: rows
      DB-->>Client: result set

      Client->>DB: CALL get_transaction_taxonomies(tx_id)
      DB->>Tax: SELECT ... JOIN streams/child_streams WHERE tx_id = normalized(tx_id)
      Tax-->>DB: rows
      DB-->>Client: result set

      Client->>DB: CALL get_transaction_metadata(tx_id)
      DB->>Meta: SELECT ... JOIN streams WHERE tx_id = normalized(tx_id)
      Meta-->>DB: rows
      DB-->>Client: result set

      Client->>DB: CALL get_transaction_attestation(tx_id)
      DB->>Att: SELECT ... WHERE tx_id = normalized(tx_id)
      Att-->>DB: attestation rows (BYTEA hex)
      DB-->>Client: result set
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to SQL join correctness and ordering in taxonomies and metadata queries.
  • Verify uniform tx_id normalization and validation across all actions (including edge cases).
  • Check returned types for attestation fields (BYTEA/hex) and test assertions in transaction_input_data_test.go.

Possibly related PRs

Suggested reviewers

  • williamrusdyputra
  • outerlook

Poem

🐰 I nudged a tx_id through the field tonight,
Five little views that bring its bits to light.
Streams and records hop into view,
Taxonomies and metadata follow too—
Attestations whisper claims, all tidy and bright.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 describes the main change: adding ability to view transaction input data on-demand through new SQL functions.
Linked Issues check ✅ Passed The PR implements the core objective from issue #134 by adding five public functions (get_transaction_streams, get_transaction_records, get_transaction_taxonomies, get_transaction_metadata, get_transaction_attestation) to enable viewing transaction input data on-demand.
Out of Scope Changes check ✅ Passed All changes directly support the primary objective: SQL migration adds retrieval actions, and test file validates the functionality with comprehensive test coverage.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch transacAction

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f24498 and 6823471.

📒 Files selected for processing (1)
  • internal/migrations/028-transaction-input-actions.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/migrations/028-transaction-input-actions.sql
⏰ 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: acceptance-test

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.

@holdex
Copy link
Copy Markdown

holdex Bot commented Nov 20, 2025

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 8h Update time Nov 21, 2025, 5:17 AM
williamrusdyputra ✅ Submitted 10min Update time Nov 21, 2025, 5:17 AM

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

🧹 Nitpick comments (1)
tests/streams/transaction_input_data_test.go (1)

42-173: Good test coverage for the tested actions, but consider expanding.

The test cases for get_transaction_streams and get_transaction_records are thorough, including edge cases for non-existent and empty tx_id values. The assertions verify data integrity and proper tx_id normalization (with/without 0x prefix).

However, three of the five new actions lack test coverage:

  • get_transaction_taxonomies
  • get_transaction_metadata
  • get_transaction_attestation

Consider adding test cases for these actions to ensure they handle tx_id normalization, joins, and edge cases correctly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 529650d and 3f24498.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • internal/migrations/028-transaction-input-actions.sql (1 hunks)
  • tests/streams/transaction_input_data_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-10T13:00:14.189Z
Learnt from: outerlook
Repo: trufnetwork/node PR: 1207
File: internal/migrations/024-attestation-actions.sql:58-76
Timestamp: 2025-10-10T13:00:14.189Z
Learning: In the attestation system for internal/migrations/024-attestation-actions.sql, the attestation_hash is computed from (version|algo|data_provider|stream_id|action_id|args) and intentionally excludes created_height. This design ensures the hash is deterministic based only on user input, not network state like block height.

Applied to files:

  • internal/migrations/028-transaction-input-actions.sql
🧬 Code graph analysis (1)
tests/streams/transaction_input_data_test.go (5)
tests/streams/utils/runner.go (1)
  • RunSchemaTest (37-116)
internal/migrations/migration.go (1)
  • GetSeedScriptStatements (60-109)
tests/streams/utils/utils.go (1)
  • GetTestOptionsWithCache (75-88)
tests/streams/utils/setup/roles.go (1)
  • AddMemberToRoleBypass (73-98)
tests/streams/utils/setup/common.go (4)
  • CreateDataProvider (173-204)
  • CreateStream (41-43)
  • StreamInfo (22-25)
  • ContractTypePrimitive (18-18)
⏰ 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: acceptance-test
🔇 Additional comments (8)
tests/streams/transaction_input_data_test.go (2)

1-31: LGTM! Test setup follows established patterns.

The test entry point is well-structured, using the standard kwiltest build tag and schema test harness. The setup correctly seeds with migration statements and configures cache options.


179-203: LGTM! Helper function is clean and handles errors correctly.

The callViewAction helper properly constructs the transaction context and propagates both execution errors and result errors. The caller address lowercasing on line 190 aligns with the SQL actions' case normalization.

internal/migrations/028-transaction-input-actions.sql (6)

1-26: LGTM! Excellent documentation.

The header provides clear context on design philosophy, related tables, and related actions. This will be valuable for future maintainers understanding how transaction input data retrieval works.


28-62: LGTM! Action is well-implemented.

The get_transaction_streams action properly validates input, normalizes tx_id format (handling both 0x-prefixed and non-prefixed values), and returns ordered results. The query is simple and should perform well with proper indexing on the tx_id column.


64-103: LGTM! JOIN and ordering are correct.

The action properly joins primitive_events with streams using the stream_ref foreign key. The multi-column ORDER BY ensures deterministic results for batch insertions. The NUMERIC(36, 18) precision matches the Decimal type used in the test.


105-151: LGTM! Double JOIN correctly retrieves parent and child stream details.

The action properly joins taxonomies with both the parent stream (s) and child stream (cs) to provide complete taxonomy relationship information. The ORDER BY clause including group_sequence helps group related taxonomy entries together.


153-200: LGTM! Metadata value columns are correctly structured.

The action properly returns all typed value columns (value_i, value_f, value_b, value_s, value_ref) with the understanding that only one will be non-null per row. This matches the metadata table's design for storing different data types.


236-247: LGTM! Query is correct for attestation retrieval.

The action properly queries the attestations table using the normalized request_tx_id. Since request_tx_id is the PRIMARY KEY, no ORDER BY clause is needed—the query will return at most one row.

Comment thread internal/migrations/028-transaction-input-actions.sql Outdated
@williamrusdyputra williamrusdyputra merged commit e1bbdf4 into main Nov 21, 2025
7 checks passed
@williamrusdyputra williamrusdyputra deleted the transacAction branch November 21, 2025 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants