Struct Channel

Source
pub struct Channel<N>
where N: Nomenclature, N::State: State,
{ /* private fields */ }
Expand description

Channel operates as a three sets of extensions, where each set is applied to construct the transaction graph and the state in a strict order one after other. The order of the extensions within each set is defined by the concrete type implementing extension::Nomenclature marker trait, provided as a type parameter N

Implementations§

Source§

impl Channel<BoltExt>

Source

pub fn with( temp_channel_id: TempChannelId, chain_hash: Slice32, policy: Policy, common_params: CommonParams, local_params: PeerParams, local_keys: LocalKeyset, ) -> Self

Constructs the new channel which will check the negotiation process against the provided policy and will use given parameters for constructing open_channel (for outbound channels) and accept_channel (for inbound channels) request sent to the remote node.

Source

pub fn set_policy(&mut self, policy: Policy)

Sets channel policy.

Can be used for changing the policy on the fly to enable accepting new open_channel - or follow-up accept_channel requests.

Source

pub fn set_common_params(&mut self, params: CommonParams)

Sets common parameters for the chanel.

Can be used for changing prospective channel parameters on the fly to enable accepting new open_channel - or follow-up accept_channel requests.

Source

pub fn set_local_params(&mut self, params: PeerParams)

Sets local parameters for the channel.

Can be used for changing prospective channel parameters on the fly to enable accepting new open_channel - or follow-up accept_channel requests.

Source

pub fn active_channel_id(&self) -> ActiveChannelId

Returns active channel id, covering both temporary and final channel ids

Source

pub fn channel_id(&self) -> Option<ChannelId>

Returns ChannelId, if the channel already assigned it

Source

pub fn try_channel_id(&self) -> Result<ChannelId, Error>

Returns ChannelId, if the channel already assigned it – or errors otherwise.

Source

pub fn temp_channel_id(&self) -> Option<TempChannelId>

Before the channel is assigned a final ChannelId returns TempChannelId, and None after

Source

pub fn compose_open_channel( &mut self, funding_sat: u64, push_msat: u64, policy: Policy, common_params: CommonParams, local_params: PeerParams, local_keys: LocalKeyset, ) -> Result<OpenChannel, Error>

Composes open_channel message used for proposing channel opening to a remote peer. The message is composed basing on the local channel parameters set with Channel::with or Channel::set_local_params (see super::BoltChannel::local_params for details on local parameters).

Fails if the node is not in Lifecycle::Initial or Lifecycle::Reestablishing state.

Source

pub fn compose_accept_channel(&mut self) -> Result<AcceptChannel, Error>

Composes accept_channel message used for accepting channel opening from a remote peer. The message is composed basing on the local channel parameters set with Channel::with or Channel::set_local_params (see super::BoltChannel::local_params for details on local parameters).

Fails if the node is not in Lifecycle::Initial or Lifecycle::Reestablishing state.

Source

pub fn compose_funding_locked(&mut self) -> FundingLocked

Source

pub fn compose_reestablish_channel( &mut self, remote_channel_reestablish: &ChannelReestablish, ) -> Result<ChannelReestablish, Error>

Source

pub fn compose_add_update_htlc( &mut self, amount_msat: u64, payment_hash: HashLock, cltv_expiry: u32, route: Vec<Hop<PaymentOnion>>, ) -> Result<Messages, Error>

Source

pub fn chain_hash(&self) -> Slice32

Source

pub fn network(&self) -> Option<Network>

Tries to identify bitcoin network which channel is based on. Returns None if the channel is using non-bitcoin chain.

Source

pub fn channel_info(&self, remote_node: NodeId) -> LocalChannelInfo

Source

pub fn funding_pubkey(&self) -> PublicKey

Source

pub fn funding_script_pubkey(&self) -> PubkeyScript

Source

pub fn feerate_per_kw(&self) -> u32

Source

pub fn local_amount_msat(&self) -> u64

Source

pub fn remote_amount_msat(&self) -> u64

Source§

impl<N> Channel<N>
where N: Nomenclature, N::State: State,

Source

pub fn funding(&self) -> &Funding

Method borrowing Channel::funding field. This is a state that is shared / can be accessed by all channel

Source

pub fn constructor(&self) -> &N::Constructor

Method borrowing Channel::constructor field. Constructor extensions constructs base transaction graph. There could

Source

pub fn constructor_mut(&mut self) -> &mut N::Constructor

Method returning mutable borrow of Channel::constructor field. Constructor extensions constructs base transaction graph. There could

Source

pub fn extenders(&self) -> &ExtensionQueue<N>

Method borrowing Channel::extenders field. Extender extensions adds additional outputs to the transaction graph

Source

pub fn modifiers(&self) -> &ExtensionQueue<N>

Method borrowing Channel::modifiers field. Modifier extensions do not change number of outputs, but may change

Source§

impl<N> Channel<N>
where N: 'static + Nomenclature, N::State: State,

Source

pub fn new( constructor: N::Constructor, extenders: impl IntoIterator<Item = Box<dyn ChannelExtension<N>>>, modifiers: impl IntoIterator<Item = Box<dyn ChannelExtension<N>>>, ) -> Self

Constructs channel with all used extensions

Source

pub fn extension<E>(&'static self, id: N) -> Option<&E>

Source

pub fn extension_mut<E>(&'static mut self, id: N) -> Option<&mut E>

Source

pub fn extender(&self, id: N) -> Option<&dyn ChannelExtension<N>>

Gets extender by extension identifier

Source

pub fn modifier(&self, id: N) -> Option<&dyn ChannelExtension<N>>

Gets modifier by extension identifier

Source

pub fn extender_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>

Gets mutable extender by extension identifier

Source

pub fn modifier_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>

Gets mutable modifier by extension identifier

Source

pub fn add_extender(&mut self, extension: Box<dyn ChannelExtension<N>>)

Adds new extension to the channel.

Will be effective onl upon next channel state update.

Source

pub fn add_modifier(&mut self, modifier: Box<dyn ChannelExtension<N>>)

Adds new modifier to the channel.

Will be effective onl upon next channel state update.

Source

pub fn commitment_tx( &mut self, remote: bool, ) -> Result<Psbt, <N as Nomenclature>::Error>

Constructs current version of commitment transaction

Source

pub fn set_funding_amount(&mut self, amount: u64)

Source§

impl<N> Channel<N>
where N: 'static + Nomenclature, N::State: State, <N as Nomenclature>::Error: From<FundingError>,

Source

pub fn refund_tx( &mut self, funding_psbt: Psbt, remote: bool, ) -> Result<Psbt, <N as Nomenclature>::Error>

Constructs the first commitment transaction (called “refund transaction”) taking given funding outpoint.

Source

pub fn set_funding( &mut self, psbt: Psbt, ) -> Result<(), <N as Nomenclature>::Error>

Trait Implementations§

Source§

impl<N> ChannelExtension<N> for Channel<N>
where N: 'static + Nomenclature, N::State: State,

Channel is the extension to itself :) so it receives the same input as any other extension and just forwards it to them. This is required for channel composebility.

Source§

fn new() -> Box<dyn ChannelExtension<N>>

Constructs boxed extension objects which can be inserted into channel extension pipeline
Source§

fn build_graph( &self, tx_graph: &mut TxGraph<'_>, as_remote_node: bool, ) -> Result<(), <N as Nomenclature>::Error>

Applies state to the channel transaction graph
Source§

impl<N> Default for Channel<N>
where N: 'static + Nomenclature + Default, N::State: State,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<N> Extension<N> for Channel<N>
where N: 'static + Nomenclature, N::State: State,

Channel is the extension to itself :) so it receives the same input as any other extension and just forwards it to them

Source§

fn identity(&self) -> N

Source§

fn state_change( &mut self, request: &<N as Nomenclature>::UpdateRequest, message: &mut <N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>

Perform a sate change and produce a message which should be communicated to peers notifying them about the state change
Source§

fn update_from_local( &mut self, message: &<N as Nomenclature>::UpdateMessage, ) -> Result<(), <N as Nomenclature>::Error>

Updates extension state from some local data
Source§

fn update_from_peer( &mut self, message: &<N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>

Updates extension state from the data taken from the message received from the remote peer
Source§

fn load_state(&mut self, state: &N::State)

Source§

fn store_state(&self, state: &mut N::State)

Source§

impl<N> StrictDecode for Channel<N>
where N: 'static + Nomenclature, N::State: State,

Source§

fn strict_decode<D: Read>(d: D) -> Result<Self, Error>

Decode with the given std::io::Read instance; must either construct an instance or return implementation-specific error type.
Source§

fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>

Tries to deserialize byte array into the current type using StrictDecode::strict_decode. If there are some data remains in the buffer once deserialization is completed, fails with Error::DataNotEntirelyConsumed. Use io::Cursor over the buffer and StrictDecode::strict_decode to avoid such failures.
Source§

fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>

Reads data from file at path and reconstructs object from it. Fails with Error::DataNotEntirelyConsumed if file contains remaining data after the object reconstruction.
Source§

impl<N> StrictEncode for Channel<N>
where N: 'static + Nomenclature, N::State: State,

Source§

fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>

Encode with the given std::io::Write instance; must return result with either amount of bytes encoded – or implementation-specific error type.
Source§

fn strict_serialize(&self) -> Result<Vec<u8>, Error>

Serializes data as a byte array using StrictEncode::strict_encode function
Source§

fn strict_file_save(&self, path: impl AsRef<Path>) -> Result<usize, Error>

Saves data to a file at a given path. If the file does not exists, attempts to create the file. If the file already exists, it gets truncated.

Auto Trait Implementations§

§

impl<N> Freeze for Channel<N>

§

impl<N> !RefUnwindSafe for Channel<N>

§

impl<N> !Send for Channel<N>

§

impl<N> !Sync for Channel<N>

§

impl<N> Unpin for Channel<N>

§

impl<N> !UnwindSafe for Channel<N>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V