Skip to content

Commit acfcd7c

Browse files
committed
Expose Network as enum type rather than via string
1 parent e0cc6f8 commit acfcd7c

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
@@ -116,6 +116,13 @@ enum PaymentStatus {
116116
"Failed",
117117
};
118118

119+
enum Network {
120+
"Bitcoin",
121+
"Testnet",
122+
"Signet",
123+
"Regtest",
124+
};
125+
119126
dictionary PaymentDetails {
120127
PaymentHash hash;
121128
PaymentPreimage? preimage;
@@ -160,8 +167,5 @@ typedef string ChannelId;
160167
[Custom]
161168
typedef string UserChannelId;
162169

163-
[Custom]
164-
typedef string Network;
165-
166170
[Custom]
167171
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, Txid};
25+
use bitcoin::{Address, Txid};
2626

2727
use bip39::Mnemonic;
2828

@@ -270,18 +270,6 @@ impl Readable for UserChannelId {
270270
}
271271
}
272272

273-
impl UniffiCustomTypeConverter for Network {
274-
type Builtin = String;
275-
276-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
277-
Ok(Network::from_str(&val).map_err(|_| Error::InvalidNetwork)?)
278-
}
279-
280-
fn from_custom(obj: Self) -> Self::Builtin {
281-
obj.to_string()
282-
}
283-
}
284-
285273
impl UniffiCustomTypeConverter for Txid {
286274
type Builtin = String;
287275
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {

0 commit comments

Comments
 (0)