feat: show transaction input data on-demand#1261
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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 |
Time Submission Status
|
There was a problem hiding this comment.
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_streamsandget_transaction_recordsare 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_taxonomiesget_transaction_metadataget_transaction_attestationConsider 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
⛔ Files ignored due to path filters (1)
go.sumis 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
callViewActionhelper 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_streamsaction 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.
resolves: https://github.com/trufnetwork/trufscan/issues/134
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.