Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dash-spv-ffi/include/dash_spv_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef DASH_SPV_FFI_H
#define DASH_SPV_FFI_H

/* Generated with cbindgen:0.29.0 */
/* Generated with cbindgen:0.29.2 */

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

Expand All @@ -16,11 +16,6 @@
namespace dash_spv_ffi {
#endif // __cplusplus

typedef enum FFIMempoolStrategy {
FetchAll = 0,
BloomFilter = 1,
} FFIMempoolStrategy;

typedef enum FFISyncStage {
Connecting = 0,
QueryingHeight = 1,
Expand All @@ -34,6 +29,11 @@ typedef enum FFISyncStage {
Failed = 9,
} FFISyncStage;

typedef enum FFIMempoolStrategy {
FetchAll = 0,
BloomFilter = 1,
} FFIMempoolStrategy;

typedef enum DashSpvValidationMode {
None = 0,
Basic = 1,
Expand Down
78 changes: 73 additions & 5 deletions key-wallet-ffi/FFI_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document provides a comprehensive reference for all FFI (Foreign Function I

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

**Total Functions**: 238
**Total Functions**: 242

## Table of Contents

Expand Down Expand Up @@ -68,7 +68,7 @@ Functions: 19

### Wallet Operations

Functions: 58
Functions: 62

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

```c
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
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
```

**Description:**
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`
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`

**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`
- `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`

**Module:** `transaction_checking`

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

---

#### `managed_wallet_get_dashpay_external_account`

```c
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
```

**Description:**
Get a managed DashPay external account by composite key # Safety - Pointers must be valid

**Safety:**
- Pointers must be valid

**Module:** `managed_account`

---

#### `managed_wallet_get_dashpay_receiving_account`

```c
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
```

**Description:**
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

**Safety:**
- `manager`, `wallet_id` must be valid - `user_identity_id` and `friend_identity_id` must each point to 32 bytes

**Module:** `managed_account`

---

#### `managed_wallet_get_next_bip44_change_address`

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

---

#### `wallet_add_dashpay_external_account_with_xpub_bytes`

```c
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
```

**Description:**
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

**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

**Module:** `wallet`

---

#### `wallet_add_dashpay_receiving_account`

```c
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
```

**Description:**
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

**Safety:**
- `wallet` must be a valid pointer - `user_identity_id` and `friend_identity_id` must each point to 32 bytes

**Module:** `wallet`

---

#### `wallet_build_and_sign_transaction`

```c
Expand Down
69 changes: 67 additions & 2 deletions key-wallet-ffi/include/key_wallet_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ typedef enum {
Provider platform P2P keys (DIP-3, ED25519) - Path: m/9'/5'/3'/4'/[key_index]
*/
PROVIDER_PLATFORM_KEYS = 10,
DASHPAY_RECEIVING_FUNDS = 11,
DASHPAY_EXTERNAL_ACCOUNT = 12,
} FFIAccountType;

/*
Expand Down Expand Up @@ -2418,6 +2420,37 @@ FFIManagedAccountResult managed_wallet_get_top_up_account_with_registration_inde
unsigned int registration_index)
;

/*
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
*/

FFIManagedAccountResult managed_wallet_get_dashpay_receiving_account(const FFIWalletManager *manager,
const uint8_t *wallet_id,
FFINetwork network,
unsigned int account_index,
const uint8_t *user_identity_id,
const uint8_t *friend_identity_id)
;

/*
Get a managed DashPay external account by composite key

# Safety
- Pointers must be valid
*/

FFIManagedAccountResult managed_wallet_get_dashpay_external_account(const FFIWalletManager *manager,
const uint8_t *wallet_id,
FFINetwork network,
unsigned int account_index,
const uint8_t *user_identity_id,
const uint8_t *friend_identity_id)
;

/*
Get the network of a managed account

Expand Down Expand Up @@ -3495,15 +3528,15 @@ FFIManagedWalletInfo *wallet_create_managed_wallet(const FFIWallet *wallet,
# Safety

- `managed_wallet` must be a valid pointer to an FFIManagedWalletInfo
- `wallet` must be a valid pointer to an FFIWallet (needed for address generation)
- `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`
*/

bool managed_wallet_check_transaction(FFIManagedWalletInfo *managed_wallet,
const FFIWallet *wallet,
FFIWallet *wallet,
FFINetwork network,
const uint8_t *tx_bytes,
size_t tx_len,
Expand Down Expand Up @@ -3802,6 +3835,38 @@ FFIAccountResult wallet_add_account(FFIWallet *wallet,
unsigned int account_index)
;

/*
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
*/

FFIAccountResult wallet_add_dashpay_receiving_account(FFIWallet *wallet,
FFINetwork network,
unsigned int account_index,
const uint8_t *user_identity_id,
const uint8_t *friend_identity_id)
;

/*
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
*/

FFIAccountResult wallet_add_dashpay_external_account_with_xpub_bytes(FFIWallet *wallet,
FFINetwork network,
unsigned int account_index,
const uint8_t *user_identity_id,
const uint8_t *friend_identity_id,
const uint8_t *xpub_bytes,
size_t xpub_len)
;

/*
Add an account to the wallet with xpub as byte array

Expand Down
34 changes: 34 additions & 0 deletions key-wallet-ffi/src/address_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ fn get_managed_account_by_type<'a>(
AccountType::ProviderOwnerKeys => collection.provider_owner_keys.as_ref(),
AccountType::ProviderOperatorKeys => collection.provider_operator_keys.as_ref(),
AccountType::ProviderPlatformKeys => collection.provider_platform_keys.as_ref(),
AccountType::DashpayReceivingFunds {
..
}
| AccountType::DashpayExternalAccount {
..
} => {
// DashPay managed accounts are not currently persisted in ManagedAccountCollection
None
}
}
}

Expand Down Expand Up @@ -84,6 +93,15 @@ fn get_managed_account_by_type_mut<'a>(
AccountType::ProviderOwnerKeys => collection.provider_owner_keys.as_mut(),
AccountType::ProviderOperatorKeys => collection.provider_operator_keys.as_mut(),
AccountType::ProviderPlatformKeys => collection.provider_platform_keys.as_mut(),
AccountType::DashpayReceivingFunds {
..
}
| AccountType::DashpayExternalAccount {
..
} => {
// DashPay managed accounts are not currently persisted in ManagedAccountCollection
None
}
}
}

Expand Down Expand Up @@ -783,6 +801,22 @@ pub unsafe extern "C" fn managed_wallet_mark_address_used(
}
}
}
if !found {
for account in collection.dashpay_receival_accounts.values_mut() {
if account.mark_address_used(&address) {
found = true;
break;
}
}
}
if !found {
for account in collection.dashpay_external_accounts.values_mut() {
if account.mark_address_used(&address) {
found = true;
break;
}
}
}
found
};

Expand Down
Loading
Loading