bdk_chain::bitcoin::bech32::primitives::encode

Struct Encoder

pub struct Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,
{ /* private fields */ }
Expand description

The Encoder builds iterators that can be used to encode field elements into a bech32 address.

Construct the encoder by calling Fe32IterExt::with_checksum on an iterator of field elements, optionally prefix the data with a witness version, and then get the encoding as either a stream of characters (Encoder::chars) or a stream of field elements (Encoder::fes).

§Examples

use bech32::{Bech32, ByteIterExt, Fe32IterExt, Hrp};

let data = [0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4];

let hrp = Hrp::parse("abc").expect("bc is valid hrp string");
let chars = data
    .iter()
    .copied()
    .bytes_to_fes()
    .with_checksum::<Bech32>(&hrp)
    .chars();

Implementations§

§

impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,

pub fn new(data: I, hrp: &'hrp Hrp) -> Encoder<'hrp, I, Ck>

Constructs a new bech32 encoder.

pub fn with_witness_version(self, witness_version: Fe32) -> Encoder<'hrp, I, Ck>

Adds witness_version to the encoder (as first byte of encoded data).

Note, caller to guarantee that witness version is within valid range (0-16).

pub fn chars(self) -> CharIter<'hrp, I, Ck>

Returns an iterator that yields the bech32 encoded address as field ASCII characters.

pub fn bytes(self) -> ByteIter<'hrp, I, Ck>

Returns an iterator that yields the bech32 encoded address as field ASCII characters, as byte values.

pub fn fes(self) -> Fe32Iter<'hrp, I, Ck>

Returns an iterator that yields the field elements that go into the checksum, as well as the checksum at the end.

Each field element yielded has been input into the checksum algorithm (including the HRP as it is fed into the algorithm).

Trait Implementations§

§

impl<'hrp, I, Ck> Clone for Encoder<'hrp, I, Ck>
where I: Clone + Iterator<Item = Fe32>, Ck: Clone + Checksum,

§

fn clone(&self) -> Encoder<'hrp, I, Ck>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'hrp, I, Ck> PartialEq for Encoder<'hrp, I, Ck>
where I: PartialEq + Iterator<Item = Fe32>, Ck: PartialEq + Checksum,

§

fn eq(&self, other: &Encoder<'hrp, I, Ck>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'hrp, I, Ck> Eq for Encoder<'hrp, I, Ck>
where I: Eq + Iterator<Item = Fe32>, Ck: Eq + Checksum,

§

impl<'hrp, I, Ck> StructuralPartialEq for Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,

Auto Trait Implementations§

§

impl<'hrp, I, Ck> Freeze for Encoder<'hrp, I, Ck>
where I: Freeze,

§

impl<'hrp, I, Ck> RefUnwindSafe for Encoder<'hrp, I, Ck>

§

impl<'hrp, I, Ck> Send for Encoder<'hrp, I, Ck>
where I: Send, Ck: Send,

§

impl<'hrp, I, Ck> Sync for Encoder<'hrp, I, Ck>
where I: Sync, Ck: Sync,

§

impl<'hrp, I, Ck> Unpin for Encoder<'hrp, I, Ck>
where I: Unpin, Ck: Unpin,

§

impl<'hrp, I, Ck> UnwindSafe for Encoder<'hrp, I, Ck>
where I: UnwindSafe, Ck: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V