pub trait Network {
type Address;
type RecipientIdentifier: RecipientIdentifier;
type Error;
type Encoder: AddressEncoder
where
<Self::Encoder as AddressEncoder>::Address == Self::Address,
<Self::Encoder as AddressEncoder>::Error == Self::Error,
<Self::Encoder as AddressEncoder>::RecipientIdentifier == Self::RecipientIdentifier;
type TxIn: Input + ByteFormat;
type TxOut: Output + ByteFormat
where
<Self::TxOut as Output>::RecipientIdentifier == Self::RecipientIdentifier;
type Tx: Transaction
where
<Self::Tx as Transaction>::TxIn == Self::TxIn,
<Self::Tx as Transaction>::TxOut == Self::TxOut;
type Builder: TxBuilder
where
<Self::Builder as TxBuilder>::Encoder == Self::Encoder,
<Self::Builder as TxBuilder>::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
type Encoder: AddressEncoder
where
<Self::Encoder as AddressEncoder>::Address == Self::Address,
<Self::Encoder as AddressEncoder>::Error == Self::Error,
<Self::Encoder as AddressEncoder>::RecipientIdentifier == Self::RecipientIdentifier
type Encoder: AddressEncoder
where
<Self::Encoder as AddressEncoder>::Address == Self::Address,
<Self::Encoder as AddressEncoder>::Error == Self::Error,
<Self::Encoder as AddressEncoder>::RecipientIdentifier == Self::RecipientIdentifier
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.
type TxIn: Input + ByteFormat
type TxIn: Input + ByteFormat
A transaction Input type. This type is used within the Transaction
and specificies UTXOs
being spent by the transaction.
type TxOut: Output + ByteFormat
where
<Self::TxOut as Output>::RecipientIdentifier == Self::RecipientIdentifier
type TxOut: Output + ByteFormat
where
<Self::TxOut as Output>::RecipientIdentifier == Self::RecipientIdentifier
A transaction Output type. This type is used within the Transaction
and specificies
UTXOs being consumed by the transaction.
type Tx: Transaction
where
<Self::Tx as Transaction>::TxIn == Self::TxIn,
<Self::Tx as Transaction>::TxOut == Self::TxOut
type Tx: Transaction
where
<Self::Tx as Transaction>::TxIn == Self::TxIn,
<Self::Tx as Transaction>::TxOut == Self::TxOut
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
fn tx_builder() -> Self::Builder
fn tx_builder() -> Self::Builder
Returns a new instance of the associated transaction builder.
fn builder_from_tx_ref(tx: &Self::Tx) -> Self::Builder
fn builder_from_tx_ref(tx: &Self::Tx) -> Self::Builder
Instantiate a builder from a tx object
fn builder_from_tx(tx: Self::Tx) -> Self::Builder
fn builder_from_tx(tx: Self::Tx) -> Self::Builder
Instantiate a builder from a tx object
fn builder_from_hex(
hex_tx: &str
) -> Result<Self::Builder, <Self::Tx as Transaction>::TxError>
fn builder_from_hex(
hex_tx: &str
) -> Result<Self::Builder, <Self::Tx as Transaction>::TxError>
Instantiate a builder from a hex-serialized transaction
fn encode_address(
a: &Self::RecipientIdentifier
) -> Result<Self::Address, Self::Error>
fn encode_address(
a: &Self::RecipientIdentifier
) -> Result<Self::Address, Self::Error>
Encode an address using the network’s Address
semantics
fn decode_address(addr: &Self::Address) -> Self::RecipientIdentifier
fn decode_address(addr: &Self::Address) -> Self::RecipientIdentifier
Decode an address using the network’s Address
semantics