Skip to content

Commit

Permalink
Merge rust-bitcoin#129: segwit: Inline functions
Browse files Browse the repository at this point in the history
a774bc1 segwit: Inline functions (Tobin C. Harding)

Pull request description:

  As we do, inline "small" public functions in the `segwit` module.

ACKs for top commit:
  apoelstra:
    ACK a774bc1

Tree-SHA512: 42b0bf1a2ba5235d01a370d275679800dcb5c02b3a851fa74a28df0dbd7eeb2051a031e0c075f258f68e3285294f40d19a425f33f3454cb33a376ca95f6228da
  • Loading branch information
apoelstra committed Sep 12, 2023
2 parents 1867dcf + a774bc1 commit ea16371
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use crate::write_err;
/// let (_hrp, _witness_version, _witness_program) = segwit::decode(address).expect("failed to decode address");
/// ```
#[cfg(feature = "alloc")]
#[inline]
pub fn decode(s: &str) -> Result<(Hrp, Fe32, Vec<u8>), SegwitHrpstringError> {
let segwit = SegwitHrpstring::new(s)?;
Ok((segwit.hrp(), segwit.witness_version(), segwit.byte_iter().collect::<Vec<u8>>()))
Expand All @@ -85,6 +86,7 @@ pub fn decode(s: &str) -> Result<(Hrp, Fe32, Vec<u8>), SegwitHrpstringError> {
/// [BIP-173]: <https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki>
/// [BIP-350]: <https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki>
#[cfg(feature = "alloc")]
#[inline]
pub fn encode(
hrp: &Hrp,
witness_version: Fe32,
Expand All @@ -100,12 +102,14 @@ pub fn encode(

/// Encodes a segwit version 0 address.
#[cfg(feature = "alloc")]
#[inline]
pub fn encode_v0(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeError> {
encode(hrp, VERSION_0, witness_program)
}

/// Encodes a segwit version 1 address.
#[cfg(feature = "alloc")]
#[inline]
pub fn encode_v1(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeError> {
encode(hrp, VERSION_1, witness_program)
}
Expand All @@ -114,6 +118,7 @@ pub fn encode_v1(hrp: &Hrp, witness_program: &[u8]) -> Result<String, EncodeErro
///
/// Does not check the validity of the witness version and witness program lengths (see
/// the [`crate::primitives::segwit`] module for validation functions).
#[inline]
pub fn encode_to_fmt_unchecked<W: fmt::Write>(
fmt: &mut W,
hrp: &Hrp,
Expand Down Expand Up @@ -142,6 +147,7 @@ pub fn encode_to_fmt_unchecked<W: fmt::Write>(
///
/// Does not check the validity of the witness version and witness program lengths (see
/// the [`crate::primitives::segwit`] module for validation functions).
#[inline]
pub fn encode_to_fmt_unchecked_uppercase<W: fmt::Write>(
fmt: &mut W,
hrp: &Hrp,
Expand Down

0 comments on commit ea16371

Please sign in to comment.