Skip to content

Commit 88c2a6e

Browse files
feat: dashpay support (#177)
* partial dashpay support * fixed immature transactions * docs: update FFI API documentation * fixes * fixes * fixes * fixes
1 parent 618213d commit 88c2a6e

File tree

27 files changed

+1713
-239
lines changed

27 files changed

+1713
-239
lines changed

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef DASH_SPV_FFI_H
44
#define DASH_SPV_FFI_H
55

6-
/* Generated with cbindgen:0.29.0 */
6+
/* Generated with cbindgen:0.29.2 */
77

88
/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */
99

@@ -16,11 +16,6 @@
1616
namespace dash_spv_ffi {
1717
#endif // __cplusplus
1818

19-
typedef enum FFIMempoolStrategy {
20-
FetchAll = 0,
21-
BloomFilter = 1,
22-
} FFIMempoolStrategy;
23-
2419
typedef enum FFISyncStage {
2520
Connecting = 0,
2621
QueryingHeight = 1,
@@ -34,6 +29,11 @@ typedef enum FFISyncStage {
3429
Failed = 9,
3530
} FFISyncStage;
3631

32+
typedef enum FFIMempoolStrategy {
33+
FetchAll = 0,
34+
BloomFilter = 1,
35+
} FFIMempoolStrategy;
36+
3737
typedef enum DashSpvValidationMode {
3838
None = 0,
3939
Basic = 1,

key-wallet-ffi/FFI_API.md

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document provides a comprehensive reference for all FFI (Foreign Function I
44

55
**Auto-generated**: This documentation is automatically generated from the source code. Do not edit manually.
66

7-
**Total Functions**: 238
7+
**Total Functions**: 242
88

99
## Table of Contents
1010

@@ -68,7 +68,7 @@ Functions: 19
6868

6969
### Wallet Operations
7070

71-
Functions: 58
71+
Functions: 62
7272

7373
| Function | Description | Module |
7474
|----------|-------------|--------|
@@ -90,6 +90,8 @@ Functions: 58
9090
| `managed_wallet_get_balance` | Get wallet balance from managed wallet info Returns the balance breakdown in... | managed_wallet |
9191
| `managed_wallet_get_bip_44_external_address_range` | Get BIP44 external (receive) addresses in the specified range Returns extern... | managed_wallet |
9292
| `managed_wallet_get_bip_44_internal_address_range` | Get BIP44 internal (change) addresses in the specified range Returns interna... | managed_wallet |
93+
| `managed_wallet_get_dashpay_external_account` | Get a managed DashPay external account by composite key # Safety - Pointers ... | managed_account |
94+
| `managed_wallet_get_dashpay_receiving_account` | Get a managed DashPay receiving funds account by composite key # Safety - `m... | managed_account |
9395
| `managed_wallet_get_next_bip44_change_address` | Get the next unused change address Generates the next unused change address ... | managed_wallet |
9496
| `managed_wallet_get_next_bip44_receive_address` | Get the next unused receive address Generates the next unused receive addres... | managed_wallet |
9597
| `managed_wallet_get_top_up_account_with_registration_index` | Get a managed IdentityTopUp account with a specific registration index This ... | managed_account |
@@ -100,6 +102,8 @@ Functions: 58
100102
| `wallet_add_account` | Add an account to the wallet without xpub # Safety This function dereferenc... | wallet |
101103
| `wallet_add_account_with_string_xpub` | Add an account to the wallet with xpub as string # Safety This function der... | wallet |
102104
| `wallet_add_account_with_xpub_bytes` | Add an account to the wallet with xpub as byte array # Safety This function... | wallet |
105+
| `wallet_add_dashpay_external_account_with_xpub_bytes` | Add a DashPay external (watch-only) account with xpub bytes # Safety - `wall... | wallet |
106+
| `wallet_add_dashpay_receiving_account` | Add a DashPay receiving funds account # Safety - `wallet` must be a valid po... | wallet |
103107
| `wallet_build_and_sign_transaction` | Build and sign a transaction using the wallet's managed info This is the rec... | transaction |
104108
| `wallet_build_transaction` | Build a transaction (unsigned) This creates an unsigned transaction | transaction |
105109
| `wallet_check_transaction` | Check if a transaction belongs to the wallet using ManagedWalletInfo # Safet... | transaction |
@@ -815,14 +819,14 @@ Get the parent wallet ID of a managed account Note: ManagedAccount doesn't stor
815819
#### `managed_wallet_check_transaction`
816820

817821
```c
818-
managed_wallet_check_transaction(managed_wallet: *mut FFIManagedWalletInfo, wallet: *const FFIWallet, network: FFINetwork, tx_bytes: *const u8, tx_len: usize, context_type: FFITransactionContext, block_height: c_uint, block_hash: *const u8, // 32 bytes if not null timestamp: u64, update_state: bool, result_out: *mut FFITransactionCheckResult, error: *mut FFIError,) -> bool
822+
managed_wallet_check_transaction(managed_wallet: *mut FFIManagedWalletInfo, wallet: *mut FFIWallet, network: FFINetwork, tx_bytes: *const u8, tx_len: usize, context_type: FFITransactionContext, block_height: c_uint, block_hash: *const u8, // 32 bytes if not null timestamp: u64, update_state: bool, result_out: *mut FFITransactionCheckResult, error: *mut FFIError,) -> bool
819823
```
820824

821825
**Description:**
822-
Check if a transaction belongs to the wallet This function checks a transaction against all relevant account types in the wallet and returns detailed information about which accounts are affected. # Safety - `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo - `wallet` must be a valid pointer to an FFIWallet (needed for address generation) - `tx_bytes` must be a valid pointer to transaction bytes with at least `tx_len` bytes - `result_out` must be a valid pointer to store the result - `error` must be a valid pointer to an FFIError - The affected_accounts array in the result must be freed with `transaction_check_result_free`
826+
Check if a transaction belongs to the wallet This function checks a transaction against all relevant account types in the wallet and returns detailed information about which accounts are affected. # Safety - `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo - `wallet` must be a valid pointer to an FFIWallet (needed for address generation and DashPay queries) - `tx_bytes` must be a valid pointer to transaction bytes with at least `tx_len` bytes - `result_out` must be a valid pointer to store the result - `error` must be a valid pointer to an FFIError - The affected_accounts array in the result must be freed with `transaction_check_result_free`
823827

824828
**Safety:**
825-
- `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo - `wallet` must be a valid pointer to an FFIWallet (needed for address generation) - `tx_bytes` must be a valid pointer to transaction bytes with at least `tx_len` bytes - `result_out` must be a valid pointer to store the result - `error` must be a valid pointer to an FFIError - The affected_accounts array in the result must be freed with `transaction_check_result_free`
829+
- `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo - `wallet` must be a valid pointer to an FFIWallet (needed for address generation and DashPay queries) - `tx_bytes` must be a valid pointer to transaction bytes with at least `tx_len` bytes - `result_out` must be a valid pointer to store the result - `error` must be a valid pointer to an FFIError - The affected_accounts array in the result must be freed with `transaction_check_result_free`
826830

827831
**Module:** `transaction_checking`
828832

@@ -972,6 +976,38 @@ Get BIP44 internal (change) addresses in the specified range Returns internal a
972976

973977
---
974978

979+
#### `managed_wallet_get_dashpay_external_account`
980+
981+
```c
982+
managed_wallet_get_dashpay_external_account(manager: *const FFIWalletManager, wallet_id: *const u8, network: FFINetwork, account_index: c_uint, user_identity_id: *const u8, friend_identity_id: *const u8,) -> FFIManagedAccountResult
983+
```
984+
985+
**Description:**
986+
Get a managed DashPay external account by composite key # Safety - Pointers must be valid
987+
988+
**Safety:**
989+
- Pointers must be valid
990+
991+
**Module:** `managed_account`
992+
993+
---
994+
995+
#### `managed_wallet_get_dashpay_receiving_account`
996+
997+
```c
998+
managed_wallet_get_dashpay_receiving_account(manager: *const FFIWalletManager, wallet_id: *const u8, network: FFINetwork, account_index: c_uint, user_identity_id: *const u8, friend_identity_id: *const u8,) -> FFIManagedAccountResult
999+
```
1000+
1001+
**Description:**
1002+
Get a managed DashPay receiving funds account by composite key # Safety - `manager`, `wallet_id` must be valid - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1003+
1004+
**Safety:**
1005+
- `manager`, `wallet_id` must be valid - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1006+
1007+
**Module:** `managed_account`
1008+
1009+
---
1010+
9751011
#### `managed_wallet_get_next_bip44_change_address`
9761012

9771013
```c
@@ -1132,6 +1168,38 @@ This function dereferences raw pointers. The caller must ensure that: - The wall
11321168

11331169
---
11341170

1171+
#### `wallet_add_dashpay_external_account_with_xpub_bytes`
1172+
1173+
```c
1174+
wallet_add_dashpay_external_account_with_xpub_bytes(wallet: *mut FFIWallet, network: FFINetwork, account_index: c_uint, user_identity_id: *const u8, friend_identity_id: *const u8, xpub_bytes: *const u8, xpub_len: usize,) -> FFIAccountResult
1175+
```
1176+
1177+
**Description:**
1178+
Add a DashPay external (watch-only) account with xpub bytes # Safety - `wallet` must be valid, `xpub_bytes` must point to `xpub_len` bytes - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1179+
1180+
**Safety:**
1181+
- `wallet` must be valid, `xpub_bytes` must point to `xpub_len` bytes - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1182+
1183+
**Module:** `wallet`
1184+
1185+
---
1186+
1187+
#### `wallet_add_dashpay_receiving_account`
1188+
1189+
```c
1190+
wallet_add_dashpay_receiving_account(wallet: *mut FFIWallet, network: FFINetwork, account_index: c_uint, user_identity_id: *const u8, friend_identity_id: *const u8,) -> FFIAccountResult
1191+
```
1192+
1193+
**Description:**
1194+
Add a DashPay receiving funds account # Safety - `wallet` must be a valid pointer - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1195+
1196+
**Safety:**
1197+
- `wallet` must be a valid pointer - `user_identity_id` and `friend_identity_id` must each point to 32 bytes
1198+
1199+
**Module:** `wallet`
1200+
1201+
---
1202+
11351203
#### `wallet_build_and_sign_transaction`
11361204

11371205
```c

key-wallet-ffi/include/key_wallet_ffi.h

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ typedef enum {
106106
Provider platform P2P keys (DIP-3, ED25519) - Path: m/9'/5'/3'/4'/[key_index]
107107
*/
108108
PROVIDER_PLATFORM_KEYS = 10,
109+
DASHPAY_RECEIVING_FUNDS = 11,
110+
DASHPAY_EXTERNAL_ACCOUNT = 12,
109111
} FFIAccountType;
110112

111113
/*
@@ -2418,6 +2420,37 @@ FFIManagedAccountResult managed_wallet_get_top_up_account_with_registration_inde
24182420
unsigned int registration_index)
24192421
;
24202422

2423+
/*
2424+
Get a managed DashPay receiving funds account by composite key
2425+
2426+
# Safety
2427+
- `manager`, `wallet_id` must be valid
2428+
- `user_identity_id` and `friend_identity_id` must each point to 32 bytes
2429+
*/
2430+
2431+
FFIManagedAccountResult managed_wallet_get_dashpay_receiving_account(const FFIWalletManager *manager,
2432+
const uint8_t *wallet_id,
2433+
FFINetwork network,
2434+
unsigned int account_index,
2435+
const uint8_t *user_identity_id,
2436+
const uint8_t *friend_identity_id)
2437+
;
2438+
2439+
/*
2440+
Get a managed DashPay external account by composite key
2441+
2442+
# Safety
2443+
- Pointers must be valid
2444+
*/
2445+
2446+
FFIManagedAccountResult managed_wallet_get_dashpay_external_account(const FFIWalletManager *manager,
2447+
const uint8_t *wallet_id,
2448+
FFINetwork network,
2449+
unsigned int account_index,
2450+
const uint8_t *user_identity_id,
2451+
const uint8_t *friend_identity_id)
2452+
;
2453+
24212454
/*
24222455
Get the network of a managed account
24232456
@@ -3495,15 +3528,15 @@ FFIManagedWalletInfo *wallet_create_managed_wallet(const FFIWallet *wallet,
34953528
# Safety
34963529
34973530
- `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo
3498-
- `wallet` must be a valid pointer to an FFIWallet (needed for address generation)
3531+
- `wallet` must be a valid pointer to an FFIWallet (needed for address generation and DashPay queries)
34993532
- `tx_bytes` must be a valid pointer to transaction bytes with at least `tx_len` bytes
35003533
- `result_out` must be a valid pointer to store the result
35013534
- `error` must be a valid pointer to an FFIError
35023535
- The affected_accounts array in the result must be freed with `transaction_check_result_free`
35033536
*/
35043537

35053538
bool managed_wallet_check_transaction(FFIManagedWalletInfo *managed_wallet,
3506-
const FFIWallet *wallet,
3539+
FFIWallet *wallet,
35073540
FFINetwork network,
35083541
const uint8_t *tx_bytes,
35093542
size_t tx_len,
@@ -3802,6 +3835,38 @@ FFIAccountResult wallet_add_account(FFIWallet *wallet,
38023835
unsigned int account_index)
38033836
;
38043837

3838+
/*
3839+
Add a DashPay receiving funds account
3840+
3841+
# Safety
3842+
- `wallet` must be a valid pointer
3843+
- `user_identity_id` and `friend_identity_id` must each point to 32 bytes
3844+
*/
3845+
3846+
FFIAccountResult wallet_add_dashpay_receiving_account(FFIWallet *wallet,
3847+
FFINetwork network,
3848+
unsigned int account_index,
3849+
const uint8_t *user_identity_id,
3850+
const uint8_t *friend_identity_id)
3851+
;
3852+
3853+
/*
3854+
Add a DashPay external (watch-only) account with xpub bytes
3855+
3856+
# Safety
3857+
- `wallet` must be valid, `xpub_bytes` must point to `xpub_len` bytes
3858+
- `user_identity_id` and `friend_identity_id` must each point to 32 bytes
3859+
*/
3860+
3861+
FFIAccountResult wallet_add_dashpay_external_account_with_xpub_bytes(FFIWallet *wallet,
3862+
FFINetwork network,
3863+
unsigned int account_index,
3864+
const uint8_t *user_identity_id,
3865+
const uint8_t *friend_identity_id,
3866+
const uint8_t *xpub_bytes,
3867+
size_t xpub_len)
3868+
;
3869+
38053870
/*
38063871
Add an account to the wallet with xpub as byte array
38073872

key-wallet-ffi/src/address_pool.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ fn get_managed_account_by_type<'a>(
5050
AccountType::ProviderOwnerKeys => collection.provider_owner_keys.as_ref(),
5151
AccountType::ProviderOperatorKeys => collection.provider_operator_keys.as_ref(),
5252
AccountType::ProviderPlatformKeys => collection.provider_platform_keys.as_ref(),
53+
AccountType::DashpayReceivingFunds {
54+
..
55+
}
56+
| AccountType::DashpayExternalAccount {
57+
..
58+
} => {
59+
// DashPay managed accounts are not currently persisted in ManagedAccountCollection
60+
None
61+
}
5362
}
5463
}
5564

@@ -84,6 +93,15 @@ fn get_managed_account_by_type_mut<'a>(
8493
AccountType::ProviderOwnerKeys => collection.provider_owner_keys.as_mut(),
8594
AccountType::ProviderOperatorKeys => collection.provider_operator_keys.as_mut(),
8695
AccountType::ProviderPlatformKeys => collection.provider_platform_keys.as_mut(),
96+
AccountType::DashpayReceivingFunds {
97+
..
98+
}
99+
| AccountType::DashpayExternalAccount {
100+
..
101+
} => {
102+
// DashPay managed accounts are not currently persisted in ManagedAccountCollection
103+
None
104+
}
87105
}
88106
}
89107

@@ -783,6 +801,22 @@ pub unsafe extern "C" fn managed_wallet_mark_address_used(
783801
}
784802
}
785803
}
804+
if !found {
805+
for account in collection.dashpay_receival_accounts.values_mut() {
806+
if account.mark_address_used(&address) {
807+
found = true;
808+
break;
809+
}
810+
}
811+
}
812+
if !found {
813+
for account in collection.dashpay_external_accounts.values_mut() {
814+
if account.mark_address_used(&address) {
815+
found = true;
816+
break;
817+
}
818+
}
819+
}
786820
found
787821
};
788822

0 commit comments

Comments
 (0)