Skip to content

Commit 6a82cbb

Browse files
committed
refactor(sdk): define FFINetwork in rs-sdk-ffi
`FFINetwork` came from rust-dashcore's `dash-network` crate behind its `ffi` feature, which dashpay/rust-dashcore#776 removes together with `key-wallet-ffi`. `rs-sdk-ffi` now defines the enum and its `Network` conversions itself, and every other FFI crate takes it from there. The generated C definition is unchanged (`FFINetwork_Mainnet` and so on), so Swift and Kotlin need no code change. `build_ios.sh` stops shipping `dash-network.h`, and nothing enables `dash-network`'s `ffi` feature any more. Its unused `dashcore_network_get_name` export goes with it.
1 parent f16a556 commit 6a82cbb

16 files changed

Lines changed: 69 additions & 48 deletions

File tree

‎Cargo.lock‎

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/Network.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package org.dashfoundation.dashsdk
33
/**
44
* The Dash network the SDK is operating on.
55
*
6-
* Kotlin mirror of `dash-network`'s `FFINetwork` C-ABI enum — the single
6+
* Kotlin mirror of `rs-sdk-ffi`'s `FFINetwork` C-ABI enum — the single
77
* network type every Rust FFI surface takes/returns. Port of
88
* `SwiftDashSDK/DashNetwork.swift`; [ffiValue] ordinals must stay in sync
9-
* with `dash-network/src/ffi.rs`.
9+
* with `rs-sdk-ffi/src/types.rs`.
1010
*/
1111
enum class Network(val ffiValue: Int) {
1212
MAINNET(0),

‎packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/NetworkTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NetworkTest {
99

1010
@Test
1111
fun ffiOrdinalsMatchDashNetworkFfiEnum() {
12-
// Must stay in sync with dash-network/src/ffi.rs.
12+
// Must stay in sync with rs-sdk-ffi/src/types.rs.
1313
assertEquals(0, Network.MAINNET.ffiValue)
1414
assertEquals(1, Network.TESTNET.ffiValue)
1515
assertEquals(2, Network.DEVNET.ffiValue)

‎packages/rs-platform-wallet-ffi/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ tokio-metrics = { workspace = true, optional = true }
3232
# Core dependencies (for Network type)
3333
dashcore = { workspace = true }
3434
key-wallet = { workspace = true, features = ["bincode"] }
35-
dash-network = { workspace = true, features = ["ffi"] }
3635

3736
# For the glue impl of platform-wallet's async `DrainCryptoProvider` trait over
3837
# the resolver-backed signer (deferred-crypto drain FFI).

‎packages/rs-platform-wallet-ffi/src/types.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::os::raw::c_char;
55
// `FFINetwork` is the `#[repr(C)]` mirror cbindgen emits for callers.
66
// Every FFI entry point in this crate takes / returns `FFINetwork`;
77
// internal Rust code converts via `Network::from(ffi)` / `ffi.into()`.
8-
pub use dash_network::ffi::FFINetwork;
9-
pub use dash_network::Network;
8+
pub use rs_sdk_ffi::{FFINetwork, Network};
109

1110
/// Block time structure
1211
#[repr(C)]

‎packages/rs-sdk-ffi/Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ key-wallet = { workspace = true }
4343
# FFI. Single source of truth — reused, not re-implemented.
4444
platform-encryption = { path = "../rs-platform-encryption" }
4545

46-
# Single source of truth for the Network enum and its `#[repr(C)]`
47-
# FFI variant, both used directly across this crate's FFI surface.
48-
dash-network = { workspace = true, features = ["ffi"] }
46+
# Single source of truth for the Network enum. `FFINetwork` in
47+
# `src/types.rs` is its `#[repr(C)]` mirror.
48+
dash-network = { workspace = true }
4949

5050
# FFI and serialization
5151
serde = { version = "1.0", features = ["derive"] }

‎packages/rs-sdk-ffi/src/types.rs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,42 @@ pub type DashSDKPublicKeyHandle = IdentityPublicKeyHandle;
4040
// is the `#[repr(C)]` mirror cbindgen emits for callers. Every FFI
4141
// entry point in this crate takes / returns `FFINetwork`; internal
4242
// Rust code converts via `Network::from(ffi)` / `ffi.into()`.
43-
pub use dash_network::ffi::FFINetwork;
4443
pub use dash_network::Network;
4544

45+
/// C-ABI mirror of [`Network`].
46+
///
47+
/// cbindgen:prefix-with-name
48+
#[repr(C)]
49+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50+
pub enum FFINetwork {
51+
Mainnet = 0,
52+
Testnet = 1,
53+
Devnet = 2,
54+
Regtest = 3,
55+
}
56+
57+
impl From<Network> for FFINetwork {
58+
fn from(network: Network) -> Self {
59+
match network {
60+
Network::Mainnet => FFINetwork::Mainnet,
61+
Network::Testnet => FFINetwork::Testnet,
62+
Network::Devnet => FFINetwork::Devnet,
63+
Network::Regtest => FFINetwork::Regtest,
64+
}
65+
}
66+
}
67+
68+
impl From<FFINetwork> for Network {
69+
fn from(network: FFINetwork) -> Self {
70+
match network {
71+
FFINetwork::Mainnet => Network::Mainnet,
72+
FFINetwork::Testnet => Network::Testnet,
73+
FFINetwork::Devnet => Network::Devnet,
74+
FFINetwork::Regtest => Network::Regtest,
75+
}
76+
}
77+
}
78+
4679
/// SDK configuration passed from C callers.
4780
///
4881
/// # Pointer lifetime

‎packages/rs-unified-sdk-ffi/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ crate-type = ["staticlib", "cdylib"]
1010
[dependencies]
1111
platform-wallet-ffi = { path = "../rs-platform-wallet-ffi" }
1212
rs-sdk-ffi = { path = "../rs-sdk-ffi" }
13-
dash-network = { workspace = true, features = ["ffi"] }
1413

1514
[features]
1615
default = []
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
pub use dash_network;
21
pub use platform_wallet_ffi;
32
pub use rs_sdk_ffi;

‎packages/rs-unified-sdk-jni/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ crate-type = ["cdylib"]
1515
jni = "0.21"
1616
rs-sdk-ffi = { path = "../rs-sdk-ffi" }
1717
platform-wallet-ffi = { path = "../rs-platform-wallet-ffi" }
18-
dash-network = { workspace = true, features = ["ffi"] }
1918
log = "0.4"
2019
zeroize = "1"
2120

0 commit comments

Comments
 (0)