Add Wallet.balance()
This commit is contained in:
98
cc/bdk_ffi.h
98
cc/bdk_ffi.h
@@ -14,6 +14,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct BlockchainConfig BlockchainConfig_t;
|
||||
|
||||
typedef struct DatabaseConfig DatabaseConfig_t;
|
||||
|
||||
typedef struct OpaqueWallet OpaqueWallet_t;
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -107,47 +113,6 @@ FfiError_t
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef struct {
|
||||
|
||||
char * ok;
|
||||
|
||||
FfiError_t err;
|
||||
|
||||
} FfiResult_char_ptr_t;
|
||||
|
||||
void free_string_result (
|
||||
FfiResult_char_ptr_t string_result);
|
||||
|
||||
typedef struct {
|
||||
|
||||
FfiError_t err;
|
||||
|
||||
} FfiResultVoid_t;
|
||||
|
||||
void free_void_result (
|
||||
FfiResultVoid_t void_result);
|
||||
|
||||
/** \brief
|
||||
* Free a Rust-allocated string
|
||||
*/
|
||||
void free_string (
|
||||
char * string);
|
||||
|
||||
typedef struct BlockchainConfig BlockchainConfig_t;
|
||||
|
||||
BlockchainConfig_t * new_electrum_config (
|
||||
char const * url,
|
||||
char const * socks5,
|
||||
int16_t retry,
|
||||
int16_t timeout);
|
||||
|
||||
void free_blockchain_config (
|
||||
BlockchainConfig_t * blockchain_config);
|
||||
|
||||
typedef struct DatabaseConfig DatabaseConfig_t;
|
||||
|
||||
typedef struct OpaqueWallet OpaqueWallet_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
OpaqueWallet_t * ok;
|
||||
@@ -165,9 +130,23 @@ FfiResult_OpaqueWallet_ptr_t new_wallet_result (
|
||||
void free_wallet_result (
|
||||
FfiResult_OpaqueWallet_ptr_t wallet_result);
|
||||
|
||||
typedef struct {
|
||||
|
||||
FfiError_t err;
|
||||
|
||||
} FfiResultVoid_t;
|
||||
|
||||
FfiResultVoid_t sync_wallet (
|
||||
OpaqueWallet_t const * opaque_wallet);
|
||||
|
||||
typedef struct {
|
||||
|
||||
char * ok;
|
||||
|
||||
FfiError_t err;
|
||||
|
||||
} FfiResult_char_ptr_t;
|
||||
|
||||
FfiResult_char_ptr_t new_address (
|
||||
OpaqueWallet_t const * opaque_wallet);
|
||||
|
||||
@@ -221,9 +200,44 @@ typedef struct {
|
||||
FfiResult_Vec_LocalUtxo_t list_unspent (
|
||||
OpaqueWallet_t const * opaque_wallet);
|
||||
|
||||
void free_unspent_result (
|
||||
void free_veclocalutxo_result (
|
||||
FfiResult_Vec_LocalUtxo_t unspent_result);
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint64_t ok;
|
||||
|
||||
FfiError_t err;
|
||||
|
||||
} FfiResult_uint64_t;
|
||||
|
||||
FfiResult_uint64_t balance (
|
||||
OpaqueWallet_t const * opaque_wallet);
|
||||
|
||||
BlockchainConfig_t * new_electrum_config (
|
||||
char const * url,
|
||||
char const * socks5,
|
||||
int16_t retry,
|
||||
int16_t timeout);
|
||||
|
||||
void free_blockchain_config (
|
||||
BlockchainConfig_t * blockchain_config);
|
||||
|
||||
void free_string_result (
|
||||
FfiResult_char_ptr_t string_result);
|
||||
|
||||
void free_void_result (
|
||||
FfiResultVoid_t void_result);
|
||||
|
||||
void free_uint64_result (
|
||||
FfiResult_uint64_t void_result);
|
||||
|
||||
/** \brief
|
||||
* Free a Rust-allocated string
|
||||
*/
|
||||
void free_string (
|
||||
char * string);
|
||||
|
||||
DatabaseConfig_t * new_memory_config (void);
|
||||
|
||||
DatabaseConfig_t * new_sled_config (
|
||||
|
||||
@@ -114,12 +114,12 @@ int main (int argc, char const * const argv[])
|
||||
assert(unspent_ptr[i].keychain >= 0);
|
||||
}
|
||||
|
||||
free_unspent_result(unspent_result);
|
||||
free_veclocalutxo_result(unspent_result);
|
||||
free_wallet_result(wallet_result);
|
||||
}
|
||||
|
||||
// test balance
|
||||
/*{
|
||||
{
|
||||
char const *desc = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)";
|
||||
char const *change = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)";
|
||||
|
||||
@@ -128,7 +128,7 @@ int main (int argc, char const * const argv[])
|
||||
|
||||
// new wallet
|
||||
FfiResult_OpaqueWallet_ptr_t wallet_result = new_wallet_result(desc,change,bc_config,db_config);
|
||||
assert(wallet_result.err == NULL);
|
||||
assert(wallet_result.err == FFI_ERROR_NONE);
|
||||
assert(wallet_result.ok != NULL);
|
||||
|
||||
free_blockchain_config(bc_config);
|
||||
@@ -138,19 +138,20 @@ int main (int argc, char const * const argv[])
|
||||
|
||||
// sync wallet
|
||||
FfiResultVoid_t sync_result = sync_wallet(wallet);
|
||||
assert(sync_result.err == NULL);
|
||||
assert(sync_result.err == FFI_ERROR_NONE);
|
||||
free_void_result(sync_result);
|
||||
|
||||
// get balance
|
||||
FfiResultT_uint64_t balance_result = balance(wallet);
|
||||
assert(balance_result.err == NULL);
|
||||
printf("balance = %lu\n", balance_result.ok);
|
||||
FfiResult_uint64_t balance_result = balance(wallet);
|
||||
//printf("balance.err = %d\n", (balance_result.err));
|
||||
assert(balance_result.err == FFI_ERROR_NONE);
|
||||
//printf("balance.ok = %ld\n", balance_result.ok);
|
||||
assert(balance_result.ok > 0);
|
||||
|
||||
// free balance and wallet results
|
||||
free_u64_result(balance_result);
|
||||
free_uint64_result(balance_result);
|
||||
free_wallet_result(wallet_result);
|
||||
}*/
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user