Add getSignatureFromTransactionIfPresent - #1894
Conversation
🦋 Changeset detectedLatest commit: 43733d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 48 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
BundleMonFiles updated (4)
Unchanged files (146)
Total files change +138B +0.02% Final result: ✅ View report in BundleMon website ➡️ |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
This PR adds getSignatureFromTransactionIfPresent, a non-throwing variant of getSignatureFromTransaction that returns undefined when the fee payer hasn't signed the transaction. The existing throwing function is refactored to delegate to the new one, so there's a single source of truth for the "first signature is the fee payer" extraction logic.
The change is clean and well-scoped:
- Refactor is sound —
getSignatureFromTransactionkeeps its exact behavior (sameSOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSINGerror) and the existing tests for it are untouched, which confirms no behavioral drift. - Tests cover the right cases — signed fee payer, no signatures at all, and the important edge case where a non-fee-payer has signed but the fee payer slot is still
null. That last one verifies the function keys off the first entry in the orderedSignaturesMaprather than "any signature present". - Docs are thorough — README, TSDoc with cross-
@seelinks in both directions, and a changeset. Theminorbump for a new exported function is correct. - Since
signatures.tsis re-exported viaexport * from './signatures', the new function flows through to@solana/kitautomatically.
Notes for subsequent reviewers
- The
!transactionSignaturefalsy check in the throwing wrapper is safe: the base58 decoding of 64 signature bytes can never produce an empty string, so the only falsy value isundefined. - Nothing else in the monorepo needed updating — existing callers of
getSignatureFromTransactionare unaffected.
LGTM. (Submitting as a comment since I don't have approve permissions on this repo.)
|
Documentation Preview: https://kit-docs-jpq5lklwq-anza-tech.vercel.app |
689f04c to
43733d1
Compare
|
Falsy check is changed to |
Asking whether a transaction has been signed by its fee payer currently requires either catching `SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING` from `getSignatureFromTransaction` or reaching into `transaction.signatures` and reimplementing the knowledge that the fee payer occupies the first slot. Neither is something a consumer should have to do, and the first turns an ordinary branch into exception-driven control flow that allocates and formats an error only to discard it. This adds `getSignatureFromTransactionIfPresent`, which returns `undefined` in that case, and reimplements `getSignatureFromTransaction` on top of it so the two cannot drift and the "first signature is the fee payer" comment lives in exactly one place. Behaviour is unchanged: the throwing variant still raises the same error under the same condition. The motivating case is a transaction partially signed by an authority and handed to a relayer that will pay for it. Such a transaction has a perfectly valid set of signatures and simply does not have an identifier yet, so callers that hold one need a way to ask without treating the answer as exceptional.
43733d1 to
108e5fe
Compare

Summary of Changes
This PR adds a new function
getSignatureFromTransactionIfPresent, a non-throwing variant ofgetSignatureFromTransactionIf the transaction has a fee-payer signature then it is returned, otherwise
undefinedThis allows apps to avoid dealing with the details of a transaction signature, while handling the case where the transaction may not be signed yet.
This is primarily added for use in #1893 , but exported from
@solana/transactionsbecause it's useful functionality for apps.