pub struct Channel<N>{ /* 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>
impl Channel<BoltExt>
Sourcepub fn with(
temp_channel_id: TempChannelId,
chain_hash: Slice32,
policy: Policy,
common_params: CommonParams,
local_params: PeerParams,
local_keys: LocalKeyset,
) -> Self
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.
Sourcepub fn set_policy(&mut self, policy: Policy)
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.
Sourcepub fn set_common_params(&mut self, params: CommonParams)
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.
Sourcepub fn set_local_params(&mut self, params: PeerParams)
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.
Sourcepub fn active_channel_id(&self) -> ActiveChannelId
pub fn active_channel_id(&self) -> ActiveChannelId
Returns active channel id, covering both temporary and final channel ids
Sourcepub fn channel_id(&self) -> Option<ChannelId>
pub fn channel_id(&self) -> Option<ChannelId>
Returns ChannelId
, if the channel already assigned it
Sourcepub fn try_channel_id(&self) -> Result<ChannelId, Error>
pub fn try_channel_id(&self) -> Result<ChannelId, Error>
Returns ChannelId
, if the channel already assigned it – or errors
otherwise.
Sourcepub fn temp_channel_id(&self) -> Option<TempChannelId>
pub fn temp_channel_id(&self) -> Option<TempChannelId>
Before the channel is assigned a final ChannelId
returns
TempChannelId
, and None
after
Sourcepub 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>
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.
Sourcepub fn compose_accept_channel(&mut self) -> Result<AcceptChannel, Error>
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.
pub fn compose_funding_locked(&mut self) -> FundingLocked
pub fn compose_reestablish_channel( &mut self, remote_channel_reestablish: &ChannelReestablish, ) -> Result<ChannelReestablish, Error>
pub fn compose_add_update_htlc( &mut self, amount_msat: u64, payment_hash: HashLock, cltv_expiry: u32, route: Vec<Hop<PaymentOnion>>, ) -> Result<Messages, Error>
pub fn chain_hash(&self) -> Slice32
Sourcepub fn network(&self) -> Option<Network>
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.
pub fn channel_info(&self, remote_node: NodeId) -> LocalChannelInfo
pub fn funding_pubkey(&self) -> PublicKey
pub fn funding_script_pubkey(&self) -> PubkeyScript
pub fn feerate_per_kw(&self) -> u32
pub fn local_amount_msat(&self) -> u64
pub fn remote_amount_msat(&self) -> u64
Source§impl<N> Channel<N>
impl<N> Channel<N>
Sourcepub fn funding(&self) -> &Funding
pub fn funding(&self) -> &Funding
Method borrowing Channel::funding
field.
This is a state that is shared / can be accessed by all channel
Sourcepub fn constructor(&self) -> &N::Constructor
pub fn constructor(&self) -> &N::Constructor
Method borrowing Channel::constructor
field.
Constructor extensions constructs base transaction graph. There could
Sourcepub fn constructor_mut(&mut self) -> &mut N::Constructor
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
Sourcepub fn extenders(&self) -> &ExtensionQueue<N>
pub fn extenders(&self) -> &ExtensionQueue<N>
Method borrowing Channel::extenders
field.
Extender extensions adds additional outputs to the transaction graph
Sourcepub fn modifiers(&self) -> &ExtensionQueue<N>
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>
impl<N> Channel<N>
Sourcepub fn new(
constructor: N::Constructor,
extenders: impl IntoIterator<Item = Box<dyn ChannelExtension<N>>>,
modifiers: impl IntoIterator<Item = Box<dyn ChannelExtension<N>>>,
) -> Self
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
pub fn extension<E>(&'static self, id: N) -> Option<&E>
pub fn extension_mut<E>(&'static mut self, id: N) -> Option<&mut E>
Sourcepub fn extender(&self, id: N) -> Option<&dyn ChannelExtension<N>>
pub fn extender(&self, id: N) -> Option<&dyn ChannelExtension<N>>
Gets extender by extension identifier
Sourcepub fn modifier(&self, id: N) -> Option<&dyn ChannelExtension<N>>
pub fn modifier(&self, id: N) -> Option<&dyn ChannelExtension<N>>
Gets modifier by extension identifier
Sourcepub fn extender_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>
pub fn extender_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>
Gets mutable extender by extension identifier
Sourcepub fn modifier_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>
pub fn modifier_mut(&mut self, id: N) -> Option<&mut dyn ChannelExtension<N>>
Gets mutable modifier by extension identifier
Sourcepub fn add_extender(&mut self, extension: Box<dyn ChannelExtension<N>>)
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.
Sourcepub fn add_modifier(&mut self, modifier: Box<dyn ChannelExtension<N>>)
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.
Sourcepub fn commitment_tx(
&mut self,
remote: bool,
) -> Result<Psbt, <N as Nomenclature>::Error>
pub fn commitment_tx( &mut self, remote: bool, ) -> Result<Psbt, <N as Nomenclature>::Error>
Constructs current version of commitment transaction
pub fn set_funding_amount(&mut self, amount: u64)
Source§impl<N> Channel<N>
impl<N> Channel<N>
Sourcepub fn refund_tx(
&mut self,
funding_psbt: Psbt,
remote: bool,
) -> Result<Psbt, <N as Nomenclature>::Error>
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.
pub fn set_funding( &mut self, psbt: Psbt, ) -> Result<(), <N as Nomenclature>::Error>
Trait Implementations§
Source§impl<N> ChannelExtension<N> for Channel<N>
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.
impl<N> ChannelExtension<N> for Channel<N>
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>>
fn new() -> Box<dyn ChannelExtension<N>>
Source§fn build_graph(
&self,
tx_graph: &mut TxGraph<'_>,
as_remote_node: bool,
) -> Result<(), <N as Nomenclature>::Error>
fn build_graph( &self, tx_graph: &mut TxGraph<'_>, as_remote_node: bool, ) -> Result<(), <N as Nomenclature>::Error>
Source§impl<N> Extension<N> for Channel<N>
Channel is the extension to itself :) so it receives the same input as any
other extension and just forwards it to them
impl<N> Extension<N> for Channel<N>
Channel is the extension to itself :) so it receives the same input as any other extension and just forwards it to them
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>
fn state_change( &mut self, request: &<N as Nomenclature>::UpdateRequest, message: &mut <N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>
Source§fn update_from_local(
&mut self,
message: &<N as Nomenclature>::UpdateMessage,
) -> Result<(), <N as Nomenclature>::Error>
fn update_from_local( &mut self, message: &<N as Nomenclature>::UpdateMessage, ) -> Result<(), <N as Nomenclature>::Error>
Source§fn update_from_peer(
&mut self,
message: &<N as Nomenclature>::PeerMessage,
) -> Result<(), <N as Nomenclature>::Error>
fn update_from_peer( &mut self, message: &<N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>
fn load_state(&mut self, state: &N::State)
fn store_state(&self, state: &mut N::State)
Source§impl<N> StrictDecode for Channel<N>
impl<N> StrictDecode for Channel<N>
Source§fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
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>
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
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>
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
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>
impl<N> StrictEncode for Channel<N>
Source§fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
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>
fn strict_serialize(&self) -> Result<Vec<u8>, Error>
StrictEncode::strict_encode
function