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

add standard build methods for easier discovery #244

Closed
wants to merge 1 commit into from
Closed

add standard build methods for easier discovery #244

wants to merge 1 commit into from

Conversation

w3irdrobot
Copy link
Contributor

Description

Add standard builder and build methods for easier crate discovery for new developers.

Notes to the reviewers

Completely unasked for. Just something I happen to run into while writing some documentation and thought it'd be a nice addition. Purely for quality of life. No underlying functionality changes. Actually these just delegate the calls to existing methods. If this is wanted, we could discuss deprecating existing methods for new ones if you want to prevent confusion with multiple methods doing the same thing.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Copy link
Member

@yukibtc yukibtc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced about this change.

Since this is a builder, maybe the building methods can all be renamed with build name/prefix, like:

// Build an event
.build(keys)?;

// Build an unsigned event
.build_unsigned(public_key);

// Build POW event
.build_pow(keys, diffculty)?;

But I'm not convinced of this change either.

IMO the current names (to_event, to_pow_event and to_unsigned_event) are more readable, easy to understand what they do when reading/writing the code.

What do you think? @benthecarman @rustedmoon

@benthecarman
Copy link
Contributor

I always use to_event, I think @yukibtc's function names makes the most sense if more we're added.

@yukibtc
Copy link
Member

yukibtc commented Jan 16, 2024

@w3irdrobot a solution that you can apply locally, if you prefer those names, is to create a trait and implement it for EventBuilder:

pub trait Wrapper {
    fn sign(self, keys: &Keys) -> Result<Event, Error>;

    fn build(self, pubkey: XOnlyPublicKey) -> UnsignedEvent;
}

impl Wrapper for EventBuilder {
    fn sign(self, keys: &Keys) -> Result<Event, Error> {
        self.to_event(keys)
    }

    fn build(self, pubkey: XOnlyPublicKey) -> UnsignedEvent {
        self.to_unsigned_event(pubkey)
    }
}

@yukibtc yukibtc closed this Jan 16, 2024
@w3irdrobot w3irdrobot deleted the add-builder-methods branch January 16, 2024 14:51
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