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 TransactionBuilderOptions to set default settings & deprecate TransactionProcessor usage #39

Merged
merged 4 commits into from
Apr 23, 2023

Conversation

odcheung
Copy link
Collaborator

@odcheung odcheung commented Apr 17, 2023

  • Allow users to define default settings for TransactionBuilder
  • User can still override certain settings with input params on builder functions
  • Deprecate TransactionProcessor and use the regular Solana path for legacy messages
  • Legacy messages now also support custom send options

Verification

  • Ran the whirlpools test suite with both legacy and v0 mode. Both passed

Copy link
Contributor

@terranmoccasin terranmoccasin left a comment

Choose a reason for hiding this comment

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

Looks good, just a comment re: setting partial default options

this.instructions = [];
this.signers = [];
this.opts = defaultOpts ?? defaultTransactionBuilderOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be nicer for users of this class to only be able to pass in partial default options? For example, I don't think the following is possible:

const builder = new TransactionBuilder(connection, wallet, {
  defaultBuildOption: {
    blockhashCommitment: "confirmed"
  }
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah i've been attempting to do that but it's quite difficult to wrestle typescript to have nested partials while having intersection types like we have for BuildOptions.

For now, users would have to build their own by spreading the nested properties in their custom options.

...defaultBuildOptions,
...options,
};
async txnSize(userOptions?: Partial<BuildOptions>): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also - unrelated to this PR, but I was thinking it would be nice to make txnSize a synchronous function. It looks like the only async invocation is for getting the latest blockhash when calling build() to create the transaction.

Since the size of the blockhash never changes, what do you think about using a hardcoded blockhash value for transaction size calculations? We can make sure to get the latest blockhash when actually preparing the transaction send.

This is especially nice for a MultiTransactionBuilder I'm working on where it uses txnSize to determine if the current transaction is full, but the async messes up the fluent interface for working w/ the builder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed that would be nice. can we add it as part of the multi-tx initiative though? the effort would be to separate out the blockhash code from build and create a second "buildSync" method or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, sounds good! Working on it right now actually - I'll open a separate PR

const msg = txnMsg.compileToV0Message(lookupTableAccounts);
txnMsg.compileToLegacyMessage
Copy link
Contributor

@terranmoccasin terranmoccasin Apr 21, 2023

Choose a reason for hiding this comment

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

Should this line be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yis. removed!

@odcheung odcheung merged commit d656b9f into main Apr 23, 2023
@odcheung odcheung deleted the meep/tx-builder-opts branch April 23, 2023 23:44
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