feat: expand utility methods on Psbt, Transaction, Address, TxOut, and TxIn#40
Draft
darioAnongba wants to merge 2 commits intomainfrom
Draft
feat: expand utility methods on Psbt, Transaction, Address, TxOut, and TxIn#40darioAnongba wants to merge 2 commits intomainfrom
darioAnongba wants to merge 2 commits intomainfrom
Conversation
…d TxIn Add commonly needed utility methods across multiple wrapper types: Psbt: - to_bytes()/from_bytes() for BIP-174 binary serialization - n_inputs()/n_outputs() for PSBT input/output counts Transaction: - weight getter (Weight Units) - version getter (protocol version) - lock_time getter (consensus locktime) TxIn: - sequence getter (nSequence value) Address: - address_type getter (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) - is_related_to_pubkey() for script matching TxOut: - new(value, script_pubkey) constructor Includes comprehensive Node.js integration tests for all additions. Closes #21
darioAnongba
commented
Mar 17, 2026
| /// Returns `true` if the address creates a particular script. | ||
| /// This will return `true` even if the address has not been checked against | ||
| /// the current network. | ||
| pub fn is_related_to_pubkey(&self, script: ScriptBuf) -> bool { |
Collaborator
Author
There was a problem hiding this comment.
why add a function that doesn't exist in the underlying library? We want to expose the same API.
|
|
||
| /// Serialize the PSBT to a string in base64 format | ||
| /// The number of PSBT inputs. | ||
| pub fn n_inputs(&self) -> usize { |
Collaborator
Author
There was a problem hiding this comment.
why add a function that doesn't exist in the underlying library? We just want to expose the same API.
| } | ||
|
|
||
| /// The number of PSBT outputs. | ||
| pub fn n_outputs(&self) -> usize { |
Collaborator
Author
There was a problem hiding this comment.
why add a function that doesn't exist in the underlying library? We just want to expose the same API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expand the API surface coverage for commonly needed utility methods across multiple wrapper types.
Closes #21 (partial — covers PSBT utilities, transaction introspection, address utilities, and type constructors)
Changes
Psbt
to_bytes()/from_bytes()— BIP-174 binary serialization, useful for hardware wallet communication, WASM module interop, and IndexedDB storagen_inputs()/n_outputs()— count of PSBT inputs/outputsTransaction
weightgetter — transaction weight in Weight Units (WU)versiongetter — protocol version number (1, 2, or 3)lock_timegetter — raw nLockTime value (block height or timestamp)TxIn
sequencegetter — nSequence value, important for RBF signaling and relative timelocksAddress
address_typegetter — retrieve the address type directly from an Address (P2PKH, P2SH, P2WPKH, P2WSH, P2TR). Previously only available on AddressInfois_related_to_pubkey()— check if an address matches a given script_pubkeyTxOut
new(value, script_pubkey)constructor — create transaction outputs from components, useful for building custom outputs without going through TxBuilderTests
Comprehensive Node.js integration tests for all new methods, including:
Checklist
cargo check --all-featurespassescargo clippy --all-features --all-targets -- -D warningspassescargo fmt --checkpasses