Skip to content

Commit 36ab19f

Browse files
author
Conor Okus
committed
Temporarily removes java snippets + adds notes on using segwit inputs
1 parent 3e18d3f commit 36ab19f

File tree

3 files changed

+65
-76
lines changed

3 files changed

+65
-76
lines changed

docs/tutorials/building-a-node-with-ldk/opening-a-channel.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ val createChannelResult = channelManager.create_channel(
5555

5656
# FundingGenerationReady Event Handling
5757

58-
At this point, an outbound channel has been initiated with your peer and it will appear in `ChannelManager::list_channels`. However, the channel is not yet funded. Once your peer accepts the channel, you will be notified with a `FundingGenerationReady` event. It's then your responsibility to construct the funding transaction and pass it to ChannelManager, which will broadcast it once it receives your channel counterparty's signature.
58+
At this point, an outbound channel has been initiated with your peer and it will appear in `ChannelManager::list_channels`. However, the channel is not yet funded. Once your peer accepts the channel, you will be notified with a `FundingGenerationReady` event. It's then your responsibility to construct the funding transaction and pass it to ChannelManager, which will broadcast it once it receives your channel counterparty's signature.
5959

60+
::: tip Note
61+
62+
Remember that the funding transaction must only spend SegWit inputs.
63+
64+
:::
6065

6166
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin'}">
6267
<template v-slot:rust>

docs/tutorials/building-a-node-with-ldk/setting-up-a-channel-manager.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To add a `ChannelManager` to your application, run:
2626

2727
<template v-slot:kotlin>
2828

29-
```kotlin
29+
```java
3030
import org.ldk.batteries.ChannelManagerConstructor
3131

3232
val channelManagerConstructor = ChannelManagerConstructor(
@@ -77,7 +77,7 @@ There are a few dependencies needed to get this working. Let's walk through sett
7777

7878
<template v-slot:kotlin>
7979

80-
```kotlin
80+
```java
8181
object YourFeeEstimator : FeeEstimatorInterface {
8282
override fun get_est_sat_per_1000_weight(confirmationTarget: ConfirmationTarget?): Int {
8383
if (confirmationTarget == ConfirmationTarget.LDKConfirmationTarget_Background) {
@@ -142,7 +142,7 @@ retrieving fresh ones every time
142142

143143
<template v-slot:kotlin>
144144

145-
```kotlin
145+
```java
146146
object YourLogger : LoggerInterface {
147147
override fun log(record: Record?) {
148148
// <insert code to print this log and/or write this log to a file>
@@ -183,7 +183,7 @@ retrieving fresh ones every time
183183

184184
<template v-slot:kotlin>
185185

186-
```kotlin
186+
```java
187187
object YourTxBroadcaster: BroadcasterInterface.BroadcasterInterfaceInterface {
188188
override fun broadcast_transaction(tx: ByteArray?) {
189189
// <insert code to broadcast the given transaction here>
@@ -235,7 +235,7 @@ retrieving fresh ones every time
235235

236236
<template v-slot:kotlin>
237237

238-
```kotlin
238+
```java
239239
object YourPersister: Persist.PersistInterface {
240240
override fun persist_new_channel(
241241
id: OutPoint?, data: ChannelMonitor?, updateId: MonitorUpdateId?
@@ -318,7 +318,7 @@ inform LDK about these transactions/outputs in Step 14.
318318

319319
<template v-slot:kotlin>
320320

321-
```kotlin
321+
```java
322322
object YourTxFilter : Filter.FilterInterface {
323323
override fun register_tx(txid: ByteArray, script_pubkey: ByteArray) {
324324
// <insert code for you to watch for this transaction on-chain>
@@ -356,7 +356,7 @@ inform LDK about these transactions/outputs in Step 14.
356356

357357
<template v-slot:kotlin>
358358

359-
```kotlin
359+
```java
360360
val filter : Filter = // leave this as `null` or insert the Filter object.
361361

362362
val chainMonitor = ChainMonitor.of(filter, txBroadcaster, logger, feeEstimator, persister)
@@ -416,7 +416,7 @@ inform LDK about these transactions/outputs in Step 14.
416416

417417
<template v-slot:kotlin>
418418

419-
```kotlin
419+
```java
420420
val keySeed = ByteArray(32)
421421
// <insert code to fill key_seed with random bytes OR if restarting, reload the
422422
// seed from disk>
@@ -466,7 +466,7 @@ generation is unique across restarts.
466466

467467
<template v-slot:kotlin>
468468

469-
```kotlin
469+
```java
470470
// Initialize the hashmap where we'll store the `ChannelMonitor`s read from disk.
471471
// This hashmap will later be given to the `ChannelManager` on initialization.
472472
var channelMonitors = arrayOf<ByteArray>();
@@ -542,7 +542,7 @@ generation is unique across restarts.
542542

543543
<template v-slot:kotlin>
544544

545-
```kotlin
545+
```java
546546
if (serializedChannelManager != "") {
547547
// loading from disk (restarting)
548548
channelManagerConstructor = ChannelManagerConstructor(
@@ -589,10 +589,12 @@ generation is unique across restarts.
589589

590590
**Example:**
591591

592-
<CodeSwitcher :languages="{full_blocks_rust:'Rust Full Blocks or BIP 157/158', electrum_java:'Java Electrum'}">
593-
<template v-slot:full_blocks_rust>
594-
592+
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin'}">
593+
<template v-slot:rust>
594+
595595
```rust
596+
// Full Blocks or BIP 157/158
597+
596598
use lightning_block_sync::init;
597599
use lightning_block_sync::poll;
598600
use lightning_block_sync::UnboundedCache;
@@ -648,7 +650,7 @@ generation is unique across restarts.
648650
));
649651
}
650652

651-
// Save the chain tip to be used in Step 14.
653+
// Save the chain tip to be used in future steps
652654
chain_tip = Some(
653655
init::synchronize_listeners(
654656
&mut block_source,
@@ -663,47 +665,49 @@ generation is unique across restarts.
663665

664666
</template>
665667

666-
<template v-slot:electrum_java>
668+
<template v-slot:kotlin>
667669

668670
```java
671+
// Electrum/Esplora
672+
669673
// Retrieve transaction IDs to check the chain for un-confirmation.
670-
byte[][] relevant_txids_1 = channel_manager.as_Confirm().get_relevant_txids();
671-
byte[][] relevant_txids_2 = chain_monitor.as_Confirm().get_relevant_txids();
672-
byte[][] relevant_txids = ArrayUtils.addAll(relevant_txids_1, relevant_txids_2);
674+
val relevantTxIdsFromChannelManager: Array<ByteArray> = channelManager .as_Confirm().get_relevant_txids()
675+
val relevantTxIdsFromChannelManager: Array<ByteArray> = chainMonitor.as_Confirm().get_relevant_txids()
676+
val relevantTxIds = relevantTxIdsFromChannelManager + relevantTxIdsFromChainMonitor
673677

674-
byte[][] unconfirmed_txids = // <insert code to find out from your chain source
675-
// if any of relevant_txids have been reorged out
676-
// of the chain>
678+
val unconfirmedTxs: Array<ByteArray> = // <insert code to find out from your chain source
679+
// if any of relevant_txids have been reorged out
680+
// of the chain>
677681

678-
for (byte[] txid : unconfirmed_txids) {
679-
channel_manager.transaction_unconfirmed(txid);
680-
chain_monitor.transaction_unconfirmed(txid);
682+
for (txid in unconfirmedTxs) {
683+
channelManager .transaction_unconfirmed(txid)
684+
chainMonitor.transaction_unconfirmed(txid)
681685
}
682686

683687
// Retrieve transactions and outputs that were registered through the `Filter`
684688
// interface.
685689

686690
// If any of these txs/outputs were confirmed on-chain, then:
687-
byte[] header = // insert block header from the block with confirmed tx/output
688-
int height = // insert block height of `header`
689-
Long tx_index = // insert tx index in block
690-
byte[] serialized_tx = // insert tx hex as byte array
691-
TwoTuple_usizeTransactionZ tx = TwoTuple_usizeTransactionZ.of(tx_index, serialized_tx);
691+
val header: Array<ByteArray> = // insert block header from the block with confirmed tx/output
692+
val height: Int = // insert block height of `header`
693+
val txIndex: Long = // insert tx index in block
694+
val serializedTx: Array<ByteArray> = // insert tx hex as byte array
695+
val tx: TwoTuple_usizeTransactionZ = TwoTuple_usizeTransactionZ.of(txIndex, serializedTx);
692696

693697
// Marshall all TwoTuples you built right above into an array
694-
TwoTuple_usizeTransactionZ[] tx_list = new TwoTuple_usizeTransactionZ[]{tx, .. };
698+
val txList = arrayOf<TwoTuple_usizeTransactionZ>(TwoTuple_usizeTransactionZ.of(tx.., ..));
695699

696-
channel_manager.transactions_confirmed(header, height, tx_list);
697-
chain_monitor.transactions_confirmed(header, height, tx_list);
700+
channelManager.transactions_confirmed(header, height, txList);
701+
chainMonitor.transactions_confirmed(header, height, txList);
698702

699-
byte[] best_header = // <insert code to get your best known header>
700-
int best_height = // <insert code to get your best known block height>
701-
channel_manager.update_best_block(best_header, best_height);
702-
chain_monitor.update_best_block(best_header, best_height);
703+
val bestHeader: Array<ByteArray> = // <insert code to get your best known header>
704+
val bestHeight: Int = // <insert code to get your best known block height>
705+
channelManager.update_best_block(bestHeader, bestHeight);
706+
chainMonitor.update_best_block(bestHeader, bestHeight);
703707

704708
// Finally, tell LDK that chain sync is complete. This will also spawn several
705709
// background threads to handle networking and event processing.
706-
channel_manager_constructor.chain_sync_completed(customEventHandler);
710+
channelManagerConstructor.chain_sync_completed(customEventHandler);
707711
```
708712

709713
</template>
@@ -719,28 +723,30 @@ If you are connecting full blocks or using BIP 157/158, then it is recommended t
719723
LDK's `lightning_block_sync` sample module as in the example above: the high-level steps that must be done for both `ChannelManager` and each `ChannelMonitor` are as follows:
720724

721725
1. Get the last blockhash that each object saw.
722-
* `ChannelManager`'s is in `channel_manager_constructor.channel_manager_latest_block_hash`
723-
* Each `ChannelMonitor`'s is in `channel_manager_constructor.channel_monitors`, as the 2nd element in each tuple
726+
* Receive the latest block hash when through [deserializtion](https://docs.rs/lightning/*/lightning/ln/channelmanager/struct.ChannelManagerReadArgs.html) of the `ChannelManager` via `read()`
727+
* Each `ChannelMonitor`'s is in `channel_manager.channel_monitors`, as the 2nd element in each tuple
724728
2. For each object, if its latest known blockhash has been reorged out of the chain, then disconnect blocks using `channel_manager.as_Listen().block_disconnected(..)` or `channel_monitor.block_disconnected(..)` until you reach the last common ancestor with the main chain.
725729
3. For each object, reconnect blocks starting from the common ancestor until it gets to your best known chain tip using `channel_manager.as_Listen().block_connected(..)` and/or `channel_monitor.block_connected(..)`.
726-
4. Call `channel_manager_constructor.chain_sync_completed(..)` to complete the initial sync process.
730+
4. Call `channel_manager.chain_sync_completed(..)` to complete the initial sync process.
727731

732+
**Esplora**
728733

734+
Alternatively, you can use LDK's `lightning-block-sync` crate. This provides utilities for syncing LDK via the transaction-based Confirm interface.
729735

730-
**Electrum**
736+
**Electrum/Esplora**
731737

732-
Otherwise, you can use LDK's `Confirm` interface as in the examples above. The high-level steps are as follows:
738+
Otherwise, you can use LDK's `Confirm` interface directly as in the examples above. The high-level steps are as follows:
733739
1. Tell LDK about relevant confirmed and unconfirmed transactions.
734740
2. Tell LDK what your best known block header and height is.
735741
3. Call `channel_manager_constructor.chain_sync_completed(..)` to complete the initial sync process.
736742

737-
**References:** [Rust `Confirm` docs](https://docs.rs/lightning/*/lightning/chain/trait.Confirm.html), [Rust `Listen` docs](https://docs.rs/lightning/*/lightning/chain/trait.Listen.html), [Rust `lightning_block_sync` module docs](https://docs.rs/lightning-block-sync/*/lightning_block_sync/)
743+
**References:** [Rust `Confirm` docs](https://docs.rs/lightning/*/lightning/chain/trait.Confirm.html), [Rust `Listen` docs](https://docs.rs/lightning/*/lightning/chain/trait.Listen.html), [Rust `lightning_block_sync` module docs](https://docs.rs/lightning-block-sync/*/lightning_block_sync/), [Rust `lightning_transaction_sync` module docs](https://docs.rs/lightning-transaction-sync/*/lightning_transaction_sync/)
738744

739745
**Dependencies:** `ChannelManager`, `ChainMonitor`, `ChannelMonitor`s
740746
* If providing providing full blocks or BIP 157/158: set of `ChannelMonitor`s
741747
* If using Electrum: `ChainMonitor`
742748

743-
### Optional: Initialize the `P2PGossipSync`
749+
### Optional: Initialize `P2PGossipSync or RapidGossipSync`
744750

745751
**You must follow this step if:** you need LDK to provide routes for sending payments (i.e. you are *not* providing your own routes)
746752

@@ -765,7 +771,7 @@ let gossip_sync = Arc::new(P2PGossipSync::new(
765771

766772
<template v-slot:kotlin>
767773

768-
```kotlin
774+
```java
769775
val genesisBlock : BestBlock = BestBlock.from_genesis(Network.LDKNetwork_Testnet)
770776
val genesisBlockHash : String = byteArrayToHex(genesisBlock.block_hash())
771777

@@ -786,4 +792,5 @@ val p2pGossip : P2PGossipSync = P2PGossipSync.of(networkGraph, Option_AccessZ.no
786792

787793
**Optional dependency:** `Access`, a source of chain information. Recommended to be able to verify channels before adding them to the internal network graph.
788794

789-
**References:** [Rust `P2PGossipSync` docs](https://docs.rs/lightning/*/lightning/routing/gossip/struct.P2PGossipSync.html), [`Access` docs](https://docs.rs/lightning/*/lightning/chain/trait.Access.html), [Java `P2PGossipSync` docs](https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/P2PGossipSync.java)
795+
**References:** [Rust `P2PGossipSync` docs](https://docs.rs/lightning/*/lightning/routing/gossip/struct.P2PGossipSync.html), [`Access` docs](https://docs.rs/lightning/*/lightning/chain/trait.Access.html), [Java `P2PGossipSync` docs](https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/P2PGossipSync.java), [Rust `RapidGossipSync` docs](https://docs.rs/lightning-rapid-gossip-sync/*/lightning_rapid_gossip_sync/), [Java `RapidGossipSync` docs](https://github.com/lightningdevkit/ldk-garbagecollected/blob/main/src/main/java/org/ldk/structs/RapidGossipSync.java)
796+

docs/tutorials/getting-started.md

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MacOS, Windows and Linux are supported.
99
## Installation
1010
To add LDK to a project, run:
1111

12-
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin', javascript:'JavaScript'}">
12+
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin', javascript:'JavaScript'}">
1313
<template v-slot:rust>
1414

1515
```toml
@@ -26,22 +26,9 @@ To add LDK to a project, run:
2626
```
2727

2828
</template>
29-
<template v-slot:java>
30-
31-
```xml
32-
<!--
33-
For Maven, add the following dependency to your POM and replace {VERSION} with the
34-
version number you want to use.
35-
-->
36-
37-
<dependency>
38-
<groupId>org.lightningdevkit</groupId>
39-
<artifactId>ldk-java</artifactId>
40-
<version>{VERSION}</version>
41-
</dependency>
42-
```
29+
<template v-slot:kotlin>
4330

44-
```kotlin
31+
```java
4532
/*
4633
For Gradle, add the following dependency to your build.gradle and replace {VERSION} with
4734
the version number you want to use.
@@ -52,12 +39,7 @@ To add LDK to a project, run:
5239
implementation 'org.lightningdevkit:ldk-java:{VERSION}'
5340
// ...
5441
}
55-
```
56-
57-
</template>
58-
<template v-slot:kotlin>
5942

60-
```kotlin
6143
/* To include the LDK Kotlin bindings in an Android project download the latest binary from https://github.com/lightningdevkit/ldk-garbagecollected/releases and place it in your libs directory.
6244
Then add to your build.gradle file:
6345
*/
@@ -70,6 +52,7 @@ To add LDK to a project, run:
7052
```
7153

7254
</template>
55+
7356
<template v-slot:javascript>
7457

7558
```javascript
@@ -81,24 +64,18 @@ To add LDK to a project, run:
8164

8265
Example usage after installation is complete:
8366

84-
<CodeSwitcher :languages="{rust:'Rust', java:'Java', kotlin:'Kotlin', javascript:'JavaScript'}">
67+
<CodeSwitcher :languages="{rust:'Rust', kotlin:'Kotlin', javascript:'JavaScript'}">
8568
<template v-slot:rust>
8669

8770
```rust
8871
use lightning::chain::chaininterface::FeeEstimator;
8972
```
9073

9174
</template>
92-
<template v-slot:java>
9375

94-
```java
95-
import org.ldk.structs.FeeEstimator
96-
```
97-
98-
</template>
9976
<template v-slot:kotlin>
10077

101-
```kotlin
78+
```java
10279
import org.ldk.structs.FeeEstimator
10380
```
10481

0 commit comments

Comments
 (0)