Trait coins_core::nets::Network
source · [−]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
type Encoder: AddressEncoder<Address = Self::Address, Error = Self::Error, RecipientIdentifier = Self::RecipientIdentifier>
type Encoder: AddressEncoder<Address = Self::Address, Error = Self::Error, 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<RecipientIdentifier = Self::RecipientIdentifier> + ByteFormat
type TxOut: Output<RecipientIdentifier = Self::RecipientIdentifier> + ByteFormat
A transaction Output type. This type is used within the Transaction
and specificies
UTXOs being consumed by the transaction.
type Tx: Transaction<TxIn = Self::TxIn, TxOut = Self::TxOut>
type Tx: Transaction<TxIn = Self::TxIn, TxOut = Self::TxOut>
A Transaction type that uses the TxIn
and TxOut
.
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