Skip to content

Commit 53a3305

Browse files
authored
refactor: drop FFINetworks and use FFINetwork only (#294)
This drops the `FFINetworks` enum which was supposed to be used by the FFI layer to provide multiple networks via bitflag combinations. Since im working away from having multi network support in the wallet this PR removes it and uses `FFINetwork` instead.
1 parent cf751cd commit 53a3305

31 files changed

+201
-390
lines changed

dash-spv-ffi/examples/wallet_manager_usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() {
5151
let affected = wallet_manager_process_transaction(
5252
wallet_manager,
5353
tx_hex.as_ptr() as *const i8,
54-
FFINetworks::TestnetFlag,
54+
FFINetwork::Testnet,
5555
100000, // block height
5656
&mut error
5757
);

key-wallet-ffi/FFI_API.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Free a managed account result's error message (if any) Note: This does NOT free
418418
#### `wallet_manager_add_wallet_from_mnemonic`
419419

420420
```c
421-
wallet_manager_add_wallet_from_mnemonic(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetworks, error: *mut FFIError,) -> bool
421+
wallet_manager_add_wallet_from_mnemonic(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetwork, error: *mut FFIError,) -> bool
422422
```
423423

424424
**Description:**
@@ -434,7 +434,7 @@ Add a wallet from mnemonic to the manager (backward compatibility) # Safety -
434434
#### `wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes`
435435

436436
```c
437-
wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetworks, birth_height: c_uint, account_options: *const crate::types::FFIWalletAccountCreationOptions, downgrade_to_pubkey_wallet: bool, allow_external_signing: bool, wallet_bytes_out: *mut *mut u8, wallet_bytes_len_out: *mut usize, wallet_id_out: *mut u8, error: *mut FFIError,) -> bool
437+
wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetwork, birth_height: c_uint, account_options: *const crate::types::FFIWalletAccountCreationOptions, downgrade_to_pubkey_wallet: bool, allow_external_signing: bool, wallet_bytes_out: *mut *mut u8, wallet_bytes_len_out: *mut usize, wallet_id_out: *mut u8, error: *mut FFIError,) -> bool
438438
```
439439

440440
**Module:** `wallet_manager`
@@ -444,7 +444,7 @@ wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes(manager: *mut FF
444444
#### `wallet_manager_add_wallet_from_mnemonic_with_options`
445445

446446
```c
447-
wallet_manager_add_wallet_from_mnemonic_with_options(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetworks, account_options: *const crate::types::FFIWalletAccountCreationOptions, error: *mut FFIError,) -> bool
447+
wallet_manager_add_wallet_from_mnemonic_with_options(manager: *mut FFIWalletManager, mnemonic: *const c_char, passphrase: *const c_char, network: FFINetwork, account_options: *const crate::types::FFIWalletAccountCreationOptions, error: *mut FFIError,) -> bool
448448
```
449449

450450
**Description:**
@@ -1219,7 +1219,7 @@ Build and sign a transaction using the wallet's managed info This is the recomm
12191219
#### `wallet_build_transaction`
12201220

12211221
```c
1222-
wallet_build_transaction(wallet: *mut FFIWallet, _network: FFINetworks, account_index: c_uint, outputs: *const FFITxOutput, outputs_count: usize, fee_per_kb: u64, tx_bytes_out: *mut *mut u8, tx_len_out: *mut usize, error: *mut FFIError,) -> bool
1222+
wallet_build_transaction(wallet: *mut FFIWallet, account_index: c_uint, outputs: *const FFITxOutput, outputs_count: usize, fee_per_kb: u64, tx_bytes_out: *mut *mut u8, tx_len_out: *mut usize, error: *mut FFIError,) -> bool
12231223
```
12241224

12251225
**Description:**
@@ -1251,7 +1251,7 @@ Check if a transaction belongs to the wallet using ManagedWalletInfo # Safety
12511251
#### `wallet_create_from_mnemonic`
12521252

12531253
```c
1254-
wallet_create_from_mnemonic(mnemonic: *const c_char, passphrase: *const c_char, network: FFINetworks, error: *mut FFIError,) -> *mut FFIWallet
1254+
wallet_create_from_mnemonic(mnemonic: *const c_char, passphrase: *const c_char, network: FFINetwork, error: *mut FFIError,) -> *mut FFIWallet
12551255
```
12561256

12571257
**Description:**
@@ -1267,7 +1267,7 @@ Create a new wallet from mnemonic (backward compatibility - single network) # S
12671267
#### `wallet_create_from_mnemonic_with_options`
12681268

12691269
```c
1270-
wallet_create_from_mnemonic_with_options(mnemonic: *const c_char, passphrase: *const c_char, networks: FFINetworks, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
1270+
wallet_create_from_mnemonic_with_options(mnemonic: *const c_char, passphrase: *const c_char, network: FFINetwork, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
12711271
```
12721272

12731273
**Description:**
@@ -1283,7 +1283,7 @@ Create a new wallet from mnemonic with options # Safety - `mnemonic` must be a
12831283
#### `wallet_create_from_seed`
12841284

12851285
```c
1286-
wallet_create_from_seed(seed: *const u8, seed_len: usize, network: FFINetworks, error: *mut FFIError,) -> *mut FFIWallet
1286+
wallet_create_from_seed(seed: *const u8, seed_len: usize, network: FFINetwork, error: *mut FFIError,) -> *mut FFIWallet
12871287
```
12881288

12891289
**Description:**
@@ -1299,7 +1299,7 @@ Create a new wallet from seed (backward compatibility) # Safety - `seed` must
12991299
#### `wallet_create_from_seed_with_options`
13001300

13011301
```c
1302-
wallet_create_from_seed_with_options(seed: *const u8, seed_len: usize, networks: FFINetworks, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
1302+
wallet_create_from_seed_with_options(seed: *const u8, seed_len: usize, network: FFINetwork, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
13031303
```
13041304

13051305
**Description:**
@@ -1331,7 +1331,7 @@ Create a managed wallet from a regular wallet This creates a ManagedWalletInfo
13311331
#### `wallet_create_random`
13321332

13331333
```c
1334-
wallet_create_random(network: FFINetworks, error: *mut FFIError,) -> *mut FFIWallet
1334+
wallet_create_random(network: FFINetwork, error: *mut FFIError,) -> *mut FFIWallet
13351335
```
13361336

13371337
**Description:**
@@ -1347,7 +1347,7 @@ Create a new random wallet (backward compatibility) # Safety - `error` must be
13471347
#### `wallet_create_random_with_options`
13481348

13491349
```c
1350-
wallet_create_random_with_options(networks: FFINetworks, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
1350+
wallet_create_random_with_options(network: FFINetwork, account_options: *const FFIWalletAccountCreationOptions, error: *mut FFIError,) -> *mut FFIWallet
13511351
```
13521352

13531353
**Description:**
@@ -1603,7 +1603,7 @@ Get an IdentityTopUp account handle with a specific registration index This is u
16031603
#### `wallet_get_utxos`
16041604

16051605
```c
1606-
wallet_get_utxos(_wallet: *const crate::types::FFIWallet, _network: FFINetworks, utxos_out: *mut *mut FFIUTXO, count_out: *mut usize, error: *mut FFIError,) -> bool
1606+
wallet_get_utxos(_wallet: *const crate::types::FFIWallet, utxos_out: *mut *mut FFIUTXO, count_out: *mut usize, error: *mut FFIError,) -> bool
16071607
```
16081608

16091609
**Description:**
@@ -1667,7 +1667,7 @@ Check if wallet is watch-only # Safety - `wallet` must be a valid pointer to a
16671667
#### `wallet_sign_transaction`
16681668

16691669
```c
1670-
wallet_sign_transaction(wallet: *const FFIWallet, _network: FFINetworks, tx_bytes: *const u8, tx_len: usize, signed_tx_out: *mut *mut u8, signed_len_out: *mut usize, error: *mut FFIError,) -> bool
1670+
wallet_sign_transaction(wallet: *const FFIWallet, tx_bytes: *const u8, tx_len: usize, signed_tx_out: *mut *mut u8, signed_len_out: *mut usize, error: *mut FFIError,) -> bool
16711671
```
16721672

16731673
**Description:**
@@ -2293,14 +2293,14 @@ Check if an account is watch-only # Safety - `account` must be a valid pointer
22932293
#### `account_get_network`
22942294

22952295
```c
2296-
account_get_network(account: *const FFIAccount) -> FFINetworks
2296+
account_get_network(account: *const FFIAccount) -> FFINetwork
22972297
```
22982298

22992299
**Description:**
2300-
Get the network of an account # Safety - `account` must be a valid pointer to an FFIAccount instance - Returns FFINetwork::NoNetworks if the account is null
2300+
Get the network of an account # Safety - `account` must be a valid pointer to an FFIAccount instance - Returns `FFINetwork::Dash` if the account is null
23012301

23022302
**Safety:**
2303-
- `account` must be a valid pointer to an FFIAccount instance - Returns FFINetwork::NoNetworks if the account is null
2303+
- `account` must be a valid pointer to an FFIAccount instance - Returns `FFINetwork::Dash` if the account is null
23042304

23052305
**Module:** `account`
23062306

@@ -2369,7 +2369,7 @@ bls_account_get_is_watch_only(account: *const FFIBLSAccount) -> bool
23692369
#### `bls_account_get_network`
23702370

23712371
```c
2372-
bls_account_get_network(account: *const FFIBLSAccount) -> FFINetworks
2372+
bls_account_get_network(account: *const FFIBLSAccount) -> FFINetwork
23732373
```
23742374

23752375
**Module:** `account`
@@ -2452,7 +2452,7 @@ eddsa_account_get_is_watch_only(account: *const FFIEdDSAAccount) -> bool
24522452
#### `eddsa_account_get_network`
24532453

24542454
```c
2455-
eddsa_account_get_network(account: *const FFIEdDSAAccount) -> FFINetworks
2455+
eddsa_account_get_network(account: *const FFIEdDSAAccount) -> FFINetwork
24562456
```
24572457

24582458
**Module:** `account`
@@ -3042,10 +3042,10 @@ managed_account_get_network(account: *const FFIManagedAccount,) -> FFINetwork
30423042
```
30433043

30443044
**Description:**
3045-
Get the network of a managed account # Safety - `account` must be a valid pointer to an FFIManagedAccount instance
3045+
Get the network of a managed account # Safety - `account` must be a valid pointer to an FFIManagedAccount instance - Returns `FFINetwork::Dash` if the account is null
30463046

30473047
**Safety:**
3048-
- `account` must be a valid pointer to an FFIManagedAccount instance
3048+
- `account` must be a valid pointer to an FFIManagedAccount instance - Returns `FFINetwork::Dash` if the account is null
30493049

30503050
**Module:** `managed_account`
30513051

@@ -3505,7 +3505,7 @@ This function is unsafe because it dereferences raw pointers: - `encrypted_key`
35053505
#### `bip38_encrypt_private_key`
35063506

35073507
```c
3508-
bip38_encrypt_private_key(private_key: *const c_char, passphrase: *const c_char, _network: FFINetworks, error: *mut FFIError,) -> *mut c_char
3508+
bip38_encrypt_private_key(private_key: *const c_char, passphrase: *const c_char, error: *mut FFIError,) -> *mut c_char
35093509
```
35103510

35113511
**Description:**
@@ -4080,7 +4080,7 @@ Free a string # Safety - `s` must be a valid pointer created by C string creat
40804080
- `FFIWalletManager` - Wallet manager handle
40814081
- `FFIBalance` - Balance information
40824082
- `FFIUTXO` - Unspent transaction output
4083-
- `FFINetworks` - Network enumeration
4083+
- `FFINetwork` - Network enumeration
40844084

40854085
## Memory Management
40864086

key-wallet-ffi/include/key_wallet_ffi.h

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,14 @@ typedef enum {
8989
} FFIAccountType;
9090

9191
/*
92-
FFI Network type (bit flags for multiple networks)
92+
FFI Network type (single network)
9393
*/
9494
typedef enum {
95-
NO_NETWORKS = 0,
96-
DASH_FLAG = 1,
97-
TESTNET_FLAG = 2,
98-
REGTEST_FLAG = 4,
99-
DEVNET_FLAG = 8,
100-
ALL_NETWORKS = 15,
101-
} FFINetworks;
95+
DASH = 0,
96+
TESTNET = 1,
97+
REGTEST = 2,
98+
DEVNET = 3,
99+
} FFINetwork;
102100

103101
/*
104102
FFI Error code
@@ -119,16 +117,6 @@ typedef enum {
119117
INTERNAL_ERROR = 12,
120118
} FFIErrorCode;
121119

122-
/*
123-
FFI Network type (single network)
124-
*/
125-
typedef enum {
126-
DASH = 0,
127-
TESTNET = 1,
128-
REGTEST = 2,
129-
DEVNET = 3,
130-
} FFINetwork;
131-
132120
/*
133121
Address pool type
134122
*/
@@ -897,9 +885,9 @@ FFIAccountResult wallet_get_top_up_account_with_registration_index(const FFIWall
897885
# Safety
898886
899887
- `account` must be a valid pointer to an FFIAccount instance
900-
- Returns FFINetwork::NoNetworks if the account is null
888+
- Returns `FFINetwork::Dash` if the account is null
901889
*/
902-
FFINetworks account_get_network(const FFIAccount *account) ;
890+
FFINetwork account_get_network(const FFIAccount *account) ;
903891

904892
/*
905893
Get the parent wallet ID of an account
@@ -951,9 +939,9 @@ FFIAccountResult wallet_get_top_up_account_with_registration_index(const FFIWall
951939
# Safety
952940
953941
- `account` must be a valid pointer to an FFIBLSAccount instance
954-
- Returns FFINetwork::NoNetworks if the account is null
942+
- Returns `FFINetwork::Dash` if the account is null
955943
*/
956-
FFINetworks bls_account_get_network(const FFIBLSAccount *account) ;
944+
FFINetwork bls_account_get_network(const FFIBLSAccount *account) ;
957945

958946
/*
959947
Get the parent wallet ID of a BLS account
@@ -1008,9 +996,9 @@ FFIAccountType bls_account_get_account_type(const FFIBLSAccount *account,
1008996
# Safety
1009997
1010998
- `account` must be a valid pointer to an FFIEdDSAAccount instance
1011-
- Returns FFINetwork::NoNetworks if the account is null
999+
- Returns `FFINetwork::Dash` if the account is null
10121000
*/
1013-
FFINetworks eddsa_account_get_network(const FFIEdDSAAccount *account) ;
1001+
FFINetwork eddsa_account_get_network(const FFIEdDSAAccount *account) ;
10141002

10151003
/*
10161004
Get the parent wallet ID of an EdDSA account
@@ -2433,6 +2421,7 @@ FFIManagedAccountResult managed_wallet_get_dashpay_external_account(const FFIWal
24332421
# Safety
24342422
24352423
- `account` must be a valid pointer to an FFIManagedAccount instance
2424+
- Returns `FFINetwork::Dash` if the account is null
24362425
*/
24372426
FFINetwork managed_account_get_network(const FFIManagedAccount *account) ;
24382427

@@ -3200,7 +3189,6 @@ bool mnemonic_to_seed(const char *mnemonic,
32003189
*/
32013190

32023191
bool wallet_build_transaction(FFIWallet *wallet,
3203-
FFINetworks _network,
32043192
unsigned int account_index,
32053193
const FFITxOutput *outputs,
32063194
size_t outputs_count,
@@ -3224,7 +3212,6 @@ bool wallet_build_transaction(FFIWallet *wallet,
32243212
*/
32253213

32263214
bool wallet_sign_transaction(const FFIWallet *wallet,
3227-
FFINetworks _network,
32283215
const uint8_t *tx_bytes,
32293216
size_t tx_len,
32303217
uint8_t **signed_tx_out,
@@ -3589,7 +3576,6 @@ bool managed_wallet_get_utxos(const FFIManagedWalletInfo *managed_info,
35893576
*/
35903577

35913578
bool wallet_get_utxos(const FFIWallet *_wallet,
3592-
FFINetworks _network,
35933579
FFIUTXO **utxos_out,
35943580
size_t *count_out,
35953581
FFIError *error)
@@ -3622,7 +3608,7 @@ bool wallet_get_utxos(const FFIWallet *_wallet,
36223608

36233609
FFIWallet *wallet_create_from_mnemonic_with_options(const char *mnemonic,
36243610
const char *passphrase,
3625-
FFINetworks networks,
3611+
FFINetwork network,
36263612
const FFIWalletAccountCreationOptions *account_options,
36273613
FFIError *error)
36283614
;
@@ -3641,7 +3627,7 @@ FFIWallet *wallet_create_from_mnemonic_with_options(const char *mnemonic,
36413627

36423628
FFIWallet *wallet_create_from_mnemonic(const char *mnemonic,
36433629
const char *passphrase,
3644-
FFINetworks network,
3630+
FFINetwork network,
36453631
FFIError *error)
36463632
;
36473633

@@ -3658,7 +3644,7 @@ FFIWallet *wallet_create_from_mnemonic(const char *mnemonic,
36583644

36593645
FFIWallet *wallet_create_from_seed_with_options(const uint8_t *seed,
36603646
size_t seed_len,
3661-
FFINetworks networks,
3647+
FFINetwork network,
36623648
const FFIWalletAccountCreationOptions *account_options,
36633649
FFIError *error)
36643650
;
@@ -3675,7 +3661,7 @@ FFIWallet *wallet_create_from_seed_with_options(const uint8_t *seed,
36753661

36763662
FFIWallet *wallet_create_from_seed(const uint8_t *seed,
36773663
size_t seed_len,
3678-
FFINetworks network,
3664+
FFINetwork network,
36793665
FFIError *error)
36803666
;
36813667

@@ -3689,7 +3675,7 @@ FFIWallet *wallet_create_from_seed(const uint8_t *seed,
36893675
- The caller must ensure all pointers remain valid for the duration of this call
36903676
*/
36913677

3692-
FFIWallet *wallet_create_random_with_options(FFINetworks networks,
3678+
FFIWallet *wallet_create_random_with_options(FFINetwork network,
36933679
const FFIWalletAccountCreationOptions *account_options,
36943680
FFIError *error)
36953681
;
@@ -3702,7 +3688,7 @@ FFIWallet *wallet_create_random_with_options(FFINetworks networks,
37023688
- `error` must be a valid pointer to an FFIError structure or null
37033689
- The caller must ensure the pointer remains valid for the duration of this call
37043690
*/
3705-
FFIWallet *wallet_create_random(FFINetworks network, FFIError *error) ;
3691+
FFIWallet *wallet_create_random(FFINetwork network, FFIError *error) ;
37063692

37073693
/*
37083694
Get wallet ID (32-byte hash)
@@ -3906,7 +3892,7 @@ char *wallet_manager_describe(const FFIWalletManager *manager,
39063892
bool wallet_manager_add_wallet_from_mnemonic_with_options(FFIWalletManager *manager,
39073893
const char *mnemonic,
39083894
const char *passphrase,
3909-
FFINetworks network,
3895+
FFINetwork network,
39103896
const FFIWalletAccountCreationOptions *account_options,
39113897
FFIError *error)
39123898
;
@@ -3926,7 +3912,7 @@ bool wallet_manager_add_wallet_from_mnemonic_with_options(FFIWalletManager *mana
39263912
bool wallet_manager_add_wallet_from_mnemonic(FFIWalletManager *manager,
39273913
const char *mnemonic,
39283914
const char *passphrase,
3929-
FFINetworks network,
3915+
FFINetwork network,
39303916
FFIError *error)
39313917
;
39323918

@@ -3956,7 +3942,7 @@ bool wallet_manager_add_wallet_from_mnemonic(FFIWalletManager *manager,
39563942
bool wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes(FFIWalletManager *manager,
39573943
const char *mnemonic,
39583944
const char *passphrase,
3959-
FFINetworks network,
3945+
FFINetwork network,
39603946
unsigned int birth_height,
39613947
const FFIWalletAccountCreationOptions *account_options,
39623948
bool downgrade_to_pubkey_wallet,
@@ -4201,12 +4187,7 @@ void wallet_manager_free_addresses(char **addresses,
42014187
- `passphrase` must be a valid, null-terminated C string
42024188
- `error` must be a valid pointer to an FFIError or null
42034189
*/
4204-
4205-
char *bip38_encrypt_private_key(const char *private_key,
4206-
const char *passphrase,
4207-
FFINetworks _network,
4208-
FFIError *error)
4209-
;
4190+
char *bip38_encrypt_private_key(const char *private_key, const char *passphrase, FFIError *error) ;
42104191

42114192
/*
42124193
Decrypt a BIP38 encrypted private key

key-wallet-ffi/scripts/generate_ffi_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def generate_markdown(functions: List[FFIFunction]) -> str:
257257
md.append("- `FFIWalletManager` - Wallet manager handle")
258258
md.append("- `FFIBalance` - Balance information")
259259
md.append("- `FFIUTXO` - Unspent transaction output")
260-
md.append("- `FFINetworks` - Network enumeration")
260+
md.append("- `FFINetwork` - Network enumeration")
261261
md.append("")
262262

263263
# Memory Management

0 commit comments

Comments
 (0)