Skip to content

Commit 68a5086

Browse files
authored
Merge pull request #114 from tnull/2023-05-get-bindings-release-ready
Get binding generation & publishing ready for 0.1 release
2 parents 59a425e + 7de04b7 commit 68a5086

File tree

29 files changed

+316
-184
lines changed

29 files changed

+316
-184
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ jobs:
66
build:
77
strategy:
88
matrix:
9-
toolchain: [ stable, beta ]
9+
toolchain: [
10+
stable,
11+
beta,
12+
1.60.0, # Our MSRV
13+
]
1014
include:
1115
- toolchain: stable
1216
check-fmt: true
17+
build-uniffi: true
18+
- toolchain: 1.60.0
19+
msrv: true
1320
runs-on: ubuntu-latest
1421
steps:
1522
- name: Checkout source code
@@ -20,17 +27,27 @@ jobs:
2027
toolchain: ${{ matrix.toolchain }}
2128
override: true
2229
profile: minimal
30+
- name: Pin packages to allow for MSRV
31+
if: matrix.msrv
32+
run: cargo update -p hashlink --precise "0.8.1" --verbose # hashlink 0.8.2 requires hashbrown 0.13, requiring 1.61.0
2333
- name: Build on Rust ${{ matrix.toolchain }}
2434
run: cargo build --verbose --color always
2535
- name: Build with UniFFI support on Rust ${{ matrix.toolchain }}
36+
if: matrix.build-uniffi
2637
run: cargo build --features uniffi --verbose --color always
38+
- name: Build documentation on Rust ${{ matrix.toolchain }}
39+
run: |
40+
cargo doc --release --verbose --color always
41+
cargo doc --document-private-items --verbose --color always
2742
- name: Check release build on Rust ${{ matrix.toolchain }}
2843
run: cargo check --release --verbose --color always
2944
- name: Check release build with UniFFI support on Rust ${{ matrix.toolchain }}
45+
if: matrix.build-uniffi
3046
run: cargo check --release --features uniffi --verbose --color always
3147
- name: Test on Rust ${{ matrix.toolchain }}
3248
run: cargo test
3349
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
50+
if: matrix.build-uniffi
3451
run: cargo test --features uniffi
3552
- name: Check formatting on Rust ${{ matrix.toolchain }}
3653
if: matrix.check-fmt

Package.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// swift-tools-version:5.5
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let tag = "0.1-alpha.1"
7+
let checksum = "d91403566498f01cdaaafc07a9360ef661151e64075c6d83bbce4c9b5bfa7cee"
8+
let url = "https://github.com/lightningdevkit/ldk-node/releases/download/\(tag)/LDKNodeFFI.xcframework.zip"
9+
10+
let package = Package(
11+
name: "ldk-node",
12+
platforms: [
13+
.iOS(.v15),
14+
.macOS(.v12),
15+
],
16+
products: [
17+
// Products define the executables and libraries a package produces, and make them visible to other packages.
18+
.library(
19+
name: "LDKNode",
20+
targets: ["LDKNodeFFI", "LDKNode"]),
21+
],
22+
targets: [
23+
.target(
24+
name: "LDKNode",
25+
dependencies: ["LDKNodeFFI"],
26+
path: "./bindings/swift/Sources",
27+
swiftSettings: [.unsafeFlags(["-suppress-warnings"])]
28+
),
29+
.binaryTarget(
30+
name: "LDKNodeFFI",
31+
url: url,
32+
checksum: checksum
33+
)
34+
]
35+
)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727

2828
node.start().unwrap();
2929

30-
let funding_address = node.new_funding_address();
30+
let funding_address = node.new_onchain_address();
3131

3232
// .. fund address ..
3333

@@ -59,6 +59,9 @@ LDK Node currently comes with a decidedly opinionated set of design choices:
5959
## Language Support
6060
LDK Node itself is written in [Rust][rust] and may therefore be natively added as a library dependency to any `std` Rust program. However, beyond its Rust API it also offers language bindings for [Swift][swift], [Kotlin][kotlin], and [Python][python] based on the [UniFFI](https://github.com/mozilla/uniffi-rs/). Moreover, [Flutter bindings][flutter_bindings] are also available.
6161

62+
## MSRV
63+
The Minimum Supported Rust Version (MSRV) is currently 1.60.0.
64+
6265
[api_docs]: https://docs.rs/ldk-node/*/ldk_node/
6366
[api_docs_node]: https://docs.rs/ldk-node/*/ldk_node/struct.Node.html
6467
[api_docs_builder]: https://docs.rs/ldk-node/*/ldk_node/struct.Builder.html

bindings/kotlin/ldk-node-android/lib/build.gradle.kts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ afterEvaluate {
6868
pom {
6969
name.set("ldk-node-android")
7070
description.set(
71-
"LDK Node, a ready-to-go node implementation built using LDK."
71+
"LDK Node, a ready-to-go Lightning node library built using LDK and BDK."
7272
)
7373
url.set("https://lightningdevkit.org")
7474
licenses {
@@ -85,12 +85,7 @@ afterEvaluate {
8585
developer {
8686
id.set("tnull")
8787
name.set("Elias Rohrer")
88-
email.set("tnull@noreply.github.org")
89-
}
90-
developer {
91-
id.set("jurvis")
92-
name.set("Jurvis Tan")
93-
email.set("jurvis@noreply.github.org")
88+
email.set("dev@tnull.de")
9489
}
9590
}
9691
scm {
@@ -111,23 +106,3 @@ signing {
111106
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
112107
sign(publishing.publications)
113108
}
114-
115-
//tasks.named<Test>("test") {
116-
// // Use JUnit Platform for unit tests.
117-
// useJUnitPlatform()
118-
//
119-
// testLogging {
120-
// events(PASSED, SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
121-
// exceptionFormat = FULL
122-
// showExceptions = true
123-
// showCauses = true
124-
// showStackTraces = true
125-
// showStandardStreams = true
126-
// }
127-
//}
128-
129-
//// This task dependency ensures that we build the bindings
130-
//// binaries before running the tests
131-
//tasks.withType<KotlinCompile> {
132-
// dependsOn("buildAndroidLib")
133-
//}

bindings/kotlin/ldk-node-android/lib/src/androidTest/kotlin/org/lightningdevkit/ldknode/AndroidLibTest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
1616
@RunWith(AndroidJUnit4::class)
1717
class AndroidLibTest {
1818
@Test fun node_start_stop() {
19-
val network: Network = "regtest"
20-
assertEquals(network, "regtest")
19+
val network = Network.REGTEST
2120

2221
val tmpDir1 = createTempDirectory("ldk_node").toString()
2322
println("Random dir 1: $tmpDir1")
@@ -27,8 +26,8 @@ class AndroidLibTest {
2726
val listenAddress1 = "127.0.0.1:2323"
2827
val listenAddress2 = "127.0.0.1:2324"
2928

30-
val config1 = Config(tmpDir1, "http://127.0.0.1:3002", network, listenAddress1, 2048u)
31-
val config2 = Config(tmpDir2, "http://127.0.0.1:3002", network, listenAddress2, 2048u)
29+
val config1 = Config(tmpDir1, network, listenAddress1, 2048u)
30+
val config2 = Config(tmpDir2, network, listenAddress2, 2048u)
3231

3332
val builder1 = Builder.fromConfig(config1)
3433
val builder2 = Builder.fromConfig(config2)
@@ -45,10 +44,10 @@ class AndroidLibTest {
4544
val nodeId2 = node2.nodeId()
4645
println("Node Id 2: $nodeId2")
4746

48-
val address1 = node1.newFundingAddress()
47+
val address1 = node1.newOnchainAddress()
4948
println("Funding address 1: $address1")
5049

51-
val address2 = node2.newFundingAddress()
50+
val address2 = node2.newOnchainAddress()
5251
println("Funding address 2: $address2")
5352

5453
node1.stop()

bindings/kotlin/ldk-node-jvm/lib/build.gradle.kts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ afterEvaluate {
6666
pom {
6767
name.set("ldk-node-jvm")
6868
description.set(
69-
"LDK Node, a ready-to-go node implementation built using LDK."
69+
"LDK Node, a ready-to-go Lightning node library built using LDK and BDK."
7070
)
7171
url.set("https://lightningdevkit.org")
7272
licenses {
@@ -80,15 +80,12 @@ afterEvaluate {
8080
}
8181
}
8282
developers {
83-
developer {
84-
id.set("tnull")
85-
name.set("Elias Rohrer")
86-
email.set("tnull@noreply.github.org")
87-
}
88-
developer {
89-
id.set("jurvis")
90-
name.set("Jurvis Tan")
91-
email.set("jurvis@noreply.github.org")
83+
developers {
84+
developer {
85+
id.set("tnull")
86+
name.set("Elias Rohrer")
87+
email.set("dev@tnull.de")
88+
}
9289
}
9390
}
9491
scm {

bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ fun runCommandAndWait(cmd: String): String {
2323
return stdout + stderr
2424
}
2525

26-
fun mine(blocks: UInt) {
26+
fun mine(blocks: UInt): String {
2727
val address = runCommandAndWait("bitcoin-cli -regtest getnewaddress")
2828
val output = runCommandAndWait("bitcoin-cli -regtest generatetoaddress $blocks $address")
2929
println("Mining output: $output")
30+
val re = Regex("\n.+\n\\]$")
31+
val lastBlock = re.find(output)!!.value.replace("]","").replace("\"", "").replace("\n","").trim()
32+
println("Last block: $lastBlock")
33+
return lastBlock
34+
}
35+
36+
fun mineAndWait(esploraEndpoint: String, blocks: UInt) {
37+
val lastBlockHash = mine(blocks)
38+
waitForBlock(esploraEndpoint, lastBlockHash)
3039
}
3140

3241
fun sendToAddress(address: String, amountSats: UInt): String {
@@ -39,6 +48,7 @@ fun setup() {
3948
runCommandAndWait("bitcoin-cli -regtest createwallet ldk_node_test")
4049
runCommandAndWait("bitcoin-cli -regtest loadwallet ldk_node_test true")
4150
mine(101u)
51+
Thread.sleep(5_000)
4252
}
4353

4454
fun waitForTx(esploraEndpoint: String, txid: String) {
@@ -53,16 +63,32 @@ fun waitForTx(esploraEndpoint: String, txid: String) {
5363
val response = client.send(request, HttpResponse.BodyHandlers.ofString());
5464

5565
esploraPickedUpTx = re.containsMatchIn(response.body());
56-
Thread.sleep(1_000)
66+
Thread.sleep(500)
67+
}
68+
}
69+
70+
fun waitForBlock(esploraEndpoint: String, blockHash: String) {
71+
var esploraPickedUpBlock = false
72+
val re = Regex("\"in_best_chain\":true");
73+
while (!esploraPickedUpBlock) {
74+
val client = HttpClient.newBuilder().build()
75+
val request = HttpRequest.newBuilder()
76+
.uri(URI.create(esploraEndpoint + "/block/" + blockHash + "/status"))
77+
.build();
78+
79+
val response = client.send(request, HttpResponse.BodyHandlers.ofString());
80+
val body = response.body()
81+
82+
esploraPickedUpBlock = re.containsMatchIn(response.body());
83+
Thread.sleep(500)
5784
}
5885
}
5986

6087
class LibraryTest {
6188
@Test fun fullCycle() {
89+
val esploraEndpoint = "http://127.0.0.1:3002"
6290
setup()
6391

64-
val network = Network.REGTEST
65-
6692
val tmpDir1 = createTempDirectory("ldk_node").toString()
6793
println("Random dir 1: $tmpDir1")
6894
val tmpDir2 = createTempDirectory("ldk_node").toString()
@@ -71,13 +97,27 @@ class LibraryTest {
7197
val listenAddress1 = "127.0.0.1:2323"
7298
val listenAddress2 = "127.0.0.1:2324"
7399

74-
val esploraEndpoint = "http://127.0.0.1:3002"
100+
val logLevel = LogLevel.TRACE;
101+
102+
val config1 = Config()
103+
config1.storageDirPath = tmpDir1
104+
config1.listeningAddress = listenAddress1
105+
config1.network = Network.REGTEST
106+
config1.logLevel = LogLevel.TRACE
75107

76-
val config1 = Config(tmpDir1, esploraEndpoint, network, listenAddress1, 2048u)
77-
val config2 = Config(tmpDir2, esploraEndpoint, network, listenAddress2, 2048u)
108+
println("Config 1: $config1")
109+
110+
val config2 = Config()
111+
config2.storageDirPath = tmpDir2
112+
config2.listeningAddress = listenAddress2
113+
config2.network = Network.REGTEST
114+
config2.logLevel = LogLevel.TRACE
115+
println("Config 2: $config2")
78116

79117
val builder1 = Builder.fromConfig(config1)
118+
builder1.setEsploraServer(esploraEndpoint)
80119
val builder2 = Builder.fromConfig(config2)
120+
builder2.setEsploraServer(esploraEndpoint)
81121

82122
val node1 = builder1.build()
83123
val node2 = builder2.build()
@@ -91,15 +131,15 @@ class LibraryTest {
91131
val nodeId2 = node2.nodeId()
92132
println("Node Id 2: $nodeId2")
93133

94-
val address1 = node1.newFundingAddress()
134+
val address1 = node1.newOnchainAddress()
95135
println("Funding address 1: $address1")
96136

97-
val address2 = node2.newFundingAddress()
137+
val address2 = node2.newOnchainAddress()
98138
println("Funding address 2: $address2")
99139

100140
val txid1 = sendToAddress(address1, 100000u)
101141
val txid2 = sendToAddress(address2, 100000u)
102-
mine(6u)
142+
mineAndWait(esploraEndpoint, 6u)
103143

104144
waitForTx(esploraEndpoint, txid1)
105145
waitForTx(esploraEndpoint, txid2)
@@ -139,7 +179,7 @@ class LibraryTest {
139179

140180
waitForTx(esploraEndpoint, fundingTxid)
141181

142-
mine(6u)
182+
mineAndWait(esploraEndpoint, 6u)
143183

144184
node1.syncWallets()
145185
node2.syncWallets()
@@ -196,10 +236,7 @@ class LibraryTest {
196236
assert(channelClosedEvent2 is Event.ChannelClosed)
197237
node2.eventHandled()
198238

199-
mine(1u)
200-
201-
// Sleep a bit to allow for the block to propagate to esplora
202-
Thread.sleep(5_000)
239+
mineAndWait(esploraEndpoint, 1u)
203240

204241
node1.syncWallets()
205242
node2.syncWallets()

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface LDKNode {
4343
PublicKey node_id();
4444
NetAddress? listening_address();
4545
[Throws=NodeError]
46-
Address new_funding_address();
46+
Address new_onchain_address();
4747
[Throws=NodeError]
4848
Txid send_to_onchain_address([ByRef]Address address, u64 amount_msat);
4949
[Throws=NodeError]

bindings/swift/ldk_nodeFFI.xcframework/Info.plist renamed to bindings/swift/LDKNodeFFI.xcframework/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<key>LibraryIdentifier</key>
99
<string>macos-arm64_x86_64</string>
1010
<key>LibraryPath</key>
11-
<string>ldk_nodeFFI.framework</string>
11+
<string>LDKNodeFFI.framework</string>
1212
<key>SupportedArchitectures</key>
1313
<array>
1414
<string>arm64</string>
@@ -21,7 +21,7 @@
2121
<key>LibraryIdentifier</key>
2222
<string>ios-arm64_x86_64-simulator</string>
2323
<key>LibraryPath</key>
24-
<string>ldk_nodeFFI.framework</string>
24+
<string>LDKNodeFFI.framework</string>
2525
<key>SupportedArchitectures</key>
2626
<array>
2727
<string>arm64</string>
@@ -36,7 +36,7 @@
3636
<key>LibraryIdentifier</key>
3737
<string>ios-arm64</string>
3838
<key>LibraryPath</key>
39-
<string>ldk_nodeFFI.framework</string>
39+
<string>LDKNodeFFI.framework</string>
4040
<key>SupportedArchitectures</key>
4141
<array>
4242
<string>arm64</string>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// This is the "umbrella header" for our combined Rust code library.
22
// It needs to import all of the individual headers.
33

4-
#import "ldk_nodeFFI.h"
4+
#import "LDKNodeFFI.h"

0 commit comments

Comments
 (0)