Skip to content

feat: expand utility methods on Psbt, Transaction, Address, TxOut, and TxIn#40

Draft
darioAnongba wants to merge 2 commits intomainfrom
feat/expand-utility-methods
Draft

feat: expand utility methods on Psbt, Transaction, Address, TxOut, and TxIn#40
darioAnongba wants to merge 2 commits intomainfrom
feat/expand-utility-methods

Conversation

@darioAnongba
Copy link
Collaborator

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 storage
  • n_inputs() / n_outputs() — count of PSBT inputs/outputs

Transaction

  • weight getter — transaction weight in Weight Units (WU)
  • version getter — protocol version number (1, 2, or 3)
  • lock_time getter — raw nLockTime value (block height or timestamp)

TxIn

  • sequence getter — nSequence value, important for RBF signaling and relative timelocks

Address

  • address_type getter — retrieve the address type directly from an Address (P2PKH, P2SH, P2WPKH, P2WSH, P2TR). Previously only available on AddressInfo
  • is_related_to_pubkey() — check if an address matches a given script_pubkey

TxOut

  • new(value, script_pubkey) constructor — create transaction outputs from components, useful for building custom outputs without going through TxBuilder

Tests

Comprehensive Node.js integration tests for all new methods, including:

  • Address type detection for P2PKH, P2SH, P2WPKH, and P2TR addresses
  • TxOut construction and field access
  • Transaction deserialization from raw bytes with getter validation
  • PSBT binary round-trip serialization
  • PSBT input/output counts and error handling

Checklist

  • CHANGELOG.md updated
  • cargo check --all-features passes
  • cargo clippy --all-features --all-targets -- -D warnings passes
  • cargo fmt --check passes
  • Node.js tests added

Toshi and others added 2 commits March 16, 2026 16:25
…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
/// 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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why add a function that doesn't exist in the underlying library? We just want to expose the same API.

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.

feat: expand API surface coverage

1 participant