pub trait Network {
    type Address;
    type RecipientIdentifier: RecipientIdentifier;
    type Error;
    type Encoder: AddressEncoder<Address = Self::Address, Error = Self::Error, RecipientIdentifier = Self::RecipientIdentifier>;
    type TxIn: Input + ByteFormat;
    type TxOut: Output<RecipientIdentifier = Self::RecipientIdentifier> + ByteFormat;
    type Tx: Transaction<TxIn = Self::TxIn, TxOut = Self::TxOut>;
    type Builder: TxBuilder<Encoder = Self::Encoder, Transaction = Self::Tx>;

    fn tx_builder() -> Self::Builder { ... }
    fn builder_from_tx_ref(tx: &Self::Tx) -> Self::Builder { ... }
    fn builder_from_tx(tx: Self::Tx) -> Self::Builder { ... }
    fn builder_from_hex(
        hex_tx: &str
    ) -> Result<Self::Builder, <Self::Tx as Transaction>::TxError> { ... } fn encode_address(
        a: &Self::RecipientIdentifier
    ) -> Result<Self::Address, Self::Error> { ... } fn decode_address(addr: &Self::Address) -> Self::RecipientIdentifier { ... } fn string_to_address(s: &str) -> Result<Self::Address, Self::Error> { ... } }
Expand description

A Network describes a possible UTXO network. It is primarily a collection of types with enforced relationships, but also provides convenient access the the transaction builder, the address encoder, and other network-associated functionality.

Because we separate some commonly conflated functionality (e.g. output scripts and addresses) we provide Networks to enforce relationships between them. This is why the Network trait’s associated types are complex. It exists to guarantee consistency of associated types across a large number of disparate elements.

Required Associated Types

A type handling the network’s address semantics. This will typically represent some predicate on the transaction. It is used by both the Encoder and the Builder.

A type representing the in-protocol recipient. This is usually different from the Address type.

An error type that will be used by the Encoder, and returned by the passthrough encode_address and decode_address functions

An Encoder that uses the Address and Error types above. This Encoder must implement AddressEncoder. It handles translating the Address type to the networks RecipientIdentifier type.

A transaction Input type. This type is used within the Transaction and specificies UTXOs being spent by the transaction.

A transaction Output type. This type is used within the Transaction and specificies UTXOs being consumed by the transaction.

A Transaction type that uses the TxIn and TxOut.

A transaction Builder that uses the Encoder and Transaction types defined earlier. The builder is returned by Network::tx_builder(), and provides a convenient interface for transaction construction.

Provided Methods

Returns a new instance of the associated transaction builder.

Instantiate a builder from a tx object

Instantiate a builder from a tx object

Instantiate a builder from a hex-serialized transaction

Encode an address using the network’s Address semantics

Decode an address using the network’s Address semantics

Attempt to convert a string into an Address.

Implementors