Skip to content

Commit 0f1e7ed

Browse files
committed
Expose Network as enum type rather than via string
1 parent b05d04f commit 0f1e7ed

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
@@ -118,6 +118,13 @@ enum PaymentStatus {
118118
"Failed",
119119
};
120120

121+
enum Network {
122+
"Bitcoin",
123+
"Testnet",
124+
"Signet",
125+
"Regtest",
126+
};
127+
121128
dictionary PaymentDetails {
122129
PaymentHash hash;
123130
PaymentPreimage? preimage;
@@ -187,8 +194,5 @@ typedef string ChannelId;
187194
[Custom]
188195
typedef string UserChannelId;
189196

190-
[Custom]
191-
typedef string Network;
192-
193197
[Custom]
194198
typedef string Mnemonic;

src/types.rs

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

2828
use bip39::Mnemonic;
2929

@@ -271,18 +271,6 @@ impl Readable for UserChannelId {
271271
}
272272
}
273273

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

0 commit comments

Comments
 (0)