Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chary/multisig sign update #1464

Merged
merged 13 commits into from
Nov 12, 2024
Merged

Chary/multisig sign update #1464

merged 13 commits into from
Nov 12, 2024

Conversation

charymalloju
Copy link
Contributor

@charymalloju charymalloju commented Nov 12, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced transaction management with the addition of a signed_at timestamp to track when transactions are signed.
    • Improved error handling for transaction creation, ensuring invalid inputs return appropriate error messages.
  • Bug Fixes

    • Fixed issues with transaction deletion by ensuring proper handling of signed transactions and returning appropriate error responses.
  • Documentation

    • Updated JSON serialization options for transaction fields to improve flexibility in data representation.

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
resolute 🛑 Canceled (Inspect) Nov 12, 2024 5:30am

Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes introduce several enhancements to the transaction handling in the server's handler and schema components. Key modifications include the addition of a signed_at timestamp field to transaction-related methods and structures, improved error handling in transaction creation, and updates to SQL queries to accommodate the new field. The database schema is also updated to ensure the signed_at column exists in the transactions table. Overall, these updates aim to improve transaction management and tracking.

Changes

File Change Summary
server/handler/transactions.go Modified methods: CreateTransaction, GetTransactions, GetAllMultisigTxns, SignTransaction, UpdateTransactionInfo, DeleteTransaction. Added error handling for JSON marshaling, included signed_at in SQL queries, and updated transaction status handling.
server/schema/transactions.go Added SignedAt field to Transaction and AllTransactionResult structs. Updated JSON tags for certain fields to include omitempty.
server/schema/update_schema.sql Added SQL block to check for and create signed_at column in transactions table if it does not exist.

Poem

In the burrow deep where transactions play,
A new timestamp joins the fray. 🐇
With signed_at now in our sight,
We track each deal both day and night.
Errors handled, fields refined,
A smoother path for all aligned! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

🧹 Outside diff range and nitpick comments (5)
server/schema/update_schema.sql (1)

24-25: Consider adding an index if signed_at will be frequently queried.

If this column will be used in WHERE clauses or ORDER BY statements (e.g., filtering or sorting by signing time), consider adding an index to improve query performance.

Example index creation:

CREATE INDEX IF NOT EXISTS idx_transactions_signed_at ON transactions(signed_at);
server/handler/transactions.go (4)

148-153: Refactor: Handle NULL 'signed_at' using sql.NullTime

Currently, you're using COALESCE in your SQL queries to replace NULL signed_at values with a default timestamp '0001-01-01 00:00:00'. This can be confusing and may lead to incorrect time comparisons. Instead, consider allowing signed_at to be NULL in your queries and handle it using sql.NullTime in Go. This approach is more idiomatic and makes the nullability explicit.

Apply the following changes:

- rows, err = h.DB.Query(`SELECT t.id, COALESCE(t.signed_at, '0001-01-01 00:00:00'::timestamp) AS signed_at, t.multisig_address, t.status, ...`, ...)
+ rows, err = h.DB.Query(`SELECT t.id, t.signed_at, t.multisig_address, t.status, ...`, ...)

In your Go code:

- var signedAt time.Time
+ var signedAt sql.NullTime

And adjust the assignment:

- if signedAt.IsZero() {
-     transaction.SignedAt = time.Time{} // Set it to zero time if not set
- } else {
-     transaction.SignedAt = signedAt // Otherwise, set the actual signed time
- }
+ if signedAt.Valid {
+     transaction.SignedAt = signedAt.Time
+ } else {
+     // Handle NULL value as appropriate, e.g., leave as zero value or set to `nil` if using pointer
+ }

Line range hint 176-206: Simplify signedAt handling with sql.NullTime

By using sql.NullTime for signedAt, you can eliminate the manual checks for zero values and directly assign the timestamp if it's valid. This enhances code readability and reduces potential errors.

After updating signedAt to sql.NullTime, adjust the assignment as shown above.


249-253: Consistent handling of signed_at in GetAllMultisigTxns

Ensure that you apply the same sql.NullTime handling in the GetAllMultisigTxns method. Remove the COALESCE from your SQL queries and handle NULL values in Go.

Modify your SQL queries:

- rows, err = h.DB.Query(`SELECT t.id, COALESCE(t.signed_at, '0001-01-01 00:00:00'::timestamp) AS signed_at, t.multisig_address, t.status, ...`, ...)
+ rows, err = h.DB.Query(`SELECT t.id, t.signed_at, t.multisig_address, t.status, ...`, ...)

And use sql.NullTime as previously described.


Line range hint 275-303: Apply sql.NullTime handling in transaction scanning

In the loop where you scan transaction data, update the signedAt variable to use sql.NullTime and adjust the assignment accordingly. This maintains consistency across your codebase.

Adjust your variable declaration and assignment:

- var signedAt time.Time
+ var signedAt sql.NullTime

And after scanning:

+ if signedAt.Valid {
+     transaction.SignedAt = signedAt.Time
+ } else {
+     // Handle NULL value appropriately
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc0a410 and 4182e14.

📒 Files selected for processing (3)
  • server/handler/transactions.go (8 hunks)
  • server/schema/transactions.go (2 hunks)
  • server/schema/update_schema.sql (1 hunks)
🔇 Additional comments (4)
server/schema/update_schema.sql (1)

16-27: LGTM! Safe and consistent schema update implementation.

The implementation follows PostgreSQL best practices by:

  • Using IF NOT EXISTS to prevent errors on repeated runs
  • Following the same pattern as existing code
  • Using appropriate data type for timestamp tracking
server/schema/transactions.go (1)

20-20: LGTM! Field addition looks good.

The new SignedAt field in the Transaction struct is well-structured with appropriate tags and consistent with the existing timestamp fields.

server/handler/transactions.go (2)

457-457: Ensure consistent timezone usage when updating signed_at

When updating the signed_at field in the database, you're using time.Now().UTC(). Confirm that all timestamps across your application are stored and compared using UTC to prevent timezone-related bugs.

To verify consistency, you can check other instances where timestamps are set or compared.


552-562: Verify the logic for clearing signatures after deletion

Ensure that the logic to clear signatures for transactions with a signed_at greater than the deleted transaction's signed_at aligns with the intended business rules. There might be edge cases where transactions have the same signed_at timestamp or where signed_at is NULL.

Consider adding tests to cover these scenarios or reviewing the transaction flow to confirm correctness.

server/schema/transactions.go Show resolved Hide resolved
server/handler/transactions.go Show resolved Hide resolved
@charymalloju charymalloju merged commit ae90850 into master Nov 12, 2024
10 checks passed
@charymalloju charymalloju deleted the chary/multisig-sign-update branch November 12, 2024 05:54
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