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

fixes #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fixes #1

wants to merge 1 commit into from

Conversation

nahss
Copy link

@nahss nahss commented Aug 1, 2024

Hey skaunov, lovely submission I went through your dapp and noticed a few issues and optimizations. Below are some of the changes I made:

Key Concepts and Components:

LockObject Struct:

This is the core structure representing the HTLC. It includes fields like the creation timestamp, deadline, hashed secret, refund and target addresses, and the coin being locked.

Events:

The module defines several events to signal state changes in the HTLC:

  • NewLockEvent: Emitted when a new lock is created.
  • LockClaimedEvent: Emitted when a lock is redeemed using the correct secret.
  • LockRefundedEvent: Emitted when a lock is refunded after the deadline.

Error Codes:

Constants to represent various error conditions:

  • ESecretPreimageWrong: Thrown when the provided secret does not match the hashed value.
  • ESecretLengthWrong: Thrown when the length of the provided secret is incorrect.
  • ERefund3rdParty: Thrown when a third party tries to refund the lock.
  • ERefundEarly: Thrown when a refund is attempted before the deadline.

Functions:

  • create_lock_object: Creates a new HTLC with a specified duration.
  • create_lock_object_48: Convenience function to create an HTLC with a default duration of 48 hours.
  • create_lock_object_24: Convenience function to create an HTLC with a default duration of 24 hours.
  • redeem: Redeems the locked coin by providing the correct secret.
  • refund: Refunds the locked coin after the deadline, ensuring only authorized addresses can perform the refund.

Summary of Improvements:

Detailed Documentation:

Enhanced comments and documentation for structs, functions, and events.

Convenience Functions:

Added functions for creating locks with default durations.

Error Handling:

Clearer and more descriptive error handling.

Events:

Detailed event structures to capture important actions and state changes.

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.

1 participant