Skip to content

Commit

Permalink
Temp 6: add network type
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Sep 25, 2023
1 parent e50f8be commit 6e5be6c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
namespace bdk {
string hello_world();
};

enum Network {
"Bitcoin",
"Testnet",
"Signet",
"Regtest",
};
38 changes: 37 additions & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,49 @@ mod wallet;
// use std::io::Cursor;
// use std::str::FromStr;
// use std::sync::Arc;
//

use bdk::bitcoin::Network as BdkNetwork;

uniffi::include_scaffolding!("bdk");

pub fn hello_world() -> String {
String::from("Hello World")
}

pub enum Network {
/// Mainnet Bitcoin.
Bitcoin,
/// Bitcoin's testnet network.
Testnet,
/// Bitcoin's signet network.
Signet,
/// Bitcoin's regtest network.
Regtest,
}

impl From<Network> for BdkNetwork {
fn from(network: Network) -> Self {
match network {
Network::Bitcoin => BdkNetwork::Bitcoin,
Network::Testnet => BdkNetwork::Testnet,
Network::Signet => BdkNetwork::Signet,
Network::Regtest => BdkNetwork::Regtest,
}
}
}

impl From<BdkNetwork> for Network {
fn from(network: BdkNetwork) -> Self {
match network {
BdkNetwork::Bitcoin => Network::Bitcoin,
BdkNetwork::Testnet => Network::Testnet,
BdkNetwork::Signet => Network::Signet,
BdkNetwork::Regtest => Network::Regtest,
_ => panic!("Network {} not supported", network),
}
}
}

// /// A output script and an amount of satoshis.
// pub struct ScriptAmount {
// pub script: Arc<Script>,
Expand Down
5 changes: 5 additions & 0 deletions bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class JvmLibTest {
val message = helloWorld()
assertEquals("Hello World", message)
}

@Test
fun testNetwork() {
val signetNetwork = Network.SIGNET
}
}
/**
* Library test, which will execute on linux host.
Expand Down

0 comments on commit 6e5be6c

Please sign in to comment.