Skip to content

Commit 46af7c5

Browse files
committed
Expose Network as enum type rather than via string
1 parent 8248e2e commit 46af7c5

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class LibraryTest {
6161
@Test fun fullCycle() {
6262
setup()
6363

64-
val network: Network = "regtest"
65-
assertEquals(network, "regtest")
64+
val network = Network.REGTEST
6665

6766
val tmpDir1 = createTempDirectory("ldk_node").toString()
6867
println("Random dir 1: $tmpDir1")

bindings/ldk_node.udl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ enum PaymentStatus {
121121
"Failed",
122122
};
123123

124+
enum Network {
125+
"Bitcoin",
126+
"Testnet",
127+
"Signet",
128+
"Regtest",
129+
};
130+
124131
dictionary PaymentDetails {
125132
PaymentHash hash;
126133
PaymentPreimage? preimage;
@@ -190,8 +197,5 @@ typedef string ChannelId;
190197
[Custom]
191198
typedef string UserChannelId;
192199

193-
[Custom]
194-
typedef string Network;
195-
196200
[Custom]
197201
typedef string Mnemonic;

src/types.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use lightning_transaction_sync::EsploraSyncClient;
2222
use bitcoin::hashes::sha256::Hash as Sha256;
2323
use bitcoin::hashes::Hash;
2424
use bitcoin::secp256k1::PublicKey;
25-
use bitcoin::{Address, Network, OutPoint, Txid};
25+
use bitcoin::{Address, OutPoint, Txid};
2626

2727
use bip39::Mnemonic;
2828

@@ -285,18 +285,6 @@ impl Readable for UserChannelId {
285285
}
286286
}
287287

288-
impl UniffiCustomTypeConverter for Network {
289-
type Builtin = String;
290-
291-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
292-
Ok(Network::from_str(&val).map_err(|_| Error::InvalidNetwork)?)
293-
}
294-
295-
fn from_custom(obj: Self) -> Self::Builtin {
296-
obj.to_string()
297-
}
298-
}
299-
300288
impl UniffiCustomTypeConverter for Txid {
301289
type Builtin = String;
302290
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {

0 commit comments

Comments
 (0)