Package org.ldk.batteries
Class ChannelManagerConstructor
- java.lang.Object
-
- org.ldk.batteries.ChannelManagerConstructor
-
public class ChannelManagerConstructor extends Object
A simple utility class which assists in constructing a fresh or deserializing from disk a ChannelManager and one or more ChannelMonitors. Also constructs a PeerManager and spawns a background thread to monitor for and notify you of relevant Events. Note that you must ensure you hold a reference to any constructed ChannelManagerConstructor objects to ensure you continue to receive events generated by the background thread which will be stopped if this object is garbage collected.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceChannelManagerConstructor.EventHandlerAbstract interface which should handle Events and persist the ChannelManager.static classChannelManagerConstructor.InvalidSerializedDataExceptionAn Exception that indicates the serialized data is invalid and has been corrupted on disk.
-
Field Summary
Fields Modifier and Type Field Description ChannelManagerchannel_managerThe ChannelManager either deserialized or newly-constructed.byte[]channel_manager_latest_block_hashThe latest block has the channel manager saw.TwoTuple_BlockHashChannelMonitorZ[]channel_monitorsA list of ChannelMonitors and the last block they each saw.NetworkGraphnet_graphThe `NetworkGraph` deserialized from the byte given to the constructor when deserializing or the `NetworkGraph` given explicitly to the new-object constructor.NioPeerHandlernio_peer_handlerA NioPeerHandler which manages a background thread to handle socket events and pass them to the peer_manager.InvoicePayerpayerIf a `NetworkGraph` is provided to the constructor *and* a `LockableScore` is provided to `chain_sync_completed`, this will be non-null after `chain_sync_completed` returns.PeerManagerpeer_managerA PeerManager which is constructed to pass messages and handle connections to peers.
-
Constructor Summary
Constructors Constructor Description ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, Filter filter, byte[] net_graph_serialized, BroadcasterInterface tx_broadcaster, Logger logger)Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementationsChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, NetworkGraph net_graph, BroadcasterInterface tx_broadcaster, Logger logger)Constructs a channel manager from the given interface implementations
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchain_sync_completed(ChannelManagerConstructor.EventHandler event_handler, MultiThreadedLockableScore scorer)Utility which adds all of the deserialized ChannelMonitors to the chain watch so that further updates from the ChannelManager are processed as normal.voidinterrupt()Interrupt the background thread, stopping the background handling of events.
-
-
-
Field Detail
-
channel_manager
public final ChannelManager channel_manager
The ChannelManager either deserialized or newly-constructed.
-
channel_manager_latest_block_hash
public final byte[] channel_manager_latest_block_hash
The latest block has the channel manager saw. If this is non-null it is a 32-byte block hash. You should sync the blockchain starting with the block that builds on this block.
-
channel_monitors
public final TwoTuple_BlockHashChannelMonitorZ[] channel_monitors
A list of ChannelMonitors and the last block they each saw. You should sync the blockchain on each individually starting with the block that builds on the hash given. After doing so (and syncing the blockchain on the channel manager as well), you should call chain_sync_completed() and then continue to normal application operation.
-
peer_manager
public final PeerManager peer_manager
A PeerManager which is constructed to pass messages and handle connections to peers.
-
nio_peer_handler
public final NioPeerHandler nio_peer_handler
A NioPeerHandler which manages a background thread to handle socket events and pass them to the peer_manager.
-
payer
@Nullable public InvoicePayer payer
If a `NetworkGraph` is provided to the constructor *and* a `LockableScore` is provided to `chain_sync_completed`, this will be non-null after `chain_sync_completed` returns. It should be used to send payments instead of doing so directly via the `channel_manager`. When payments are made through this, they are automatically retried and the provided Scorer will be updated with payment failure data.
-
net_graph
@Nullable public final NetworkGraph net_graph
The `NetworkGraph` deserialized from the byte given to the constructor when deserializing or the `NetworkGraph` given explicitly to the new-object constructor.
-
-
Constructor Detail
-
ChannelManagerConstructor
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable Filter filter, @Nullable byte[] net_graph_serialized, BroadcasterInterface tx_broadcaster, Logger logger) throws ChannelManagerConstructor.InvalidSerializedDataExceptionDeserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations- Parameters:
filter- If provided, the outputs which were previously registered to be monitored for will be loaded into the filter. Note that if the provided Watch is a ChainWatch and has an associated filter, the previously registered outputs will be loaded when chain_sync_completed is called.- Throws:
ChannelManagerConstructor.InvalidSerializedDataException
-
ChannelManagerConstructor
public ChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable NetworkGraph net_graph, BroadcasterInterface tx_broadcaster, Logger logger)
Constructs a channel manager from the given interface implementations
-
-
Method Detail
-
chain_sync_completed
public void chain_sync_completed(ChannelManagerConstructor.EventHandler event_handler, @Nullable MultiThreadedLockableScore scorer)
Utility which adds all of the deserialized ChannelMonitors to the chain watch so that further updates from the ChannelManager are processed as normal. This also spawns a background thread which will call the appropriate methods on the provided EventHandler as required.
-
interrupt
public void interrupt()
Interrupt the background thread, stopping the background handling of events.
-
-