Reorganized code into wallet mod/package
This commit is contained in:
parent
060e54a718
commit
a056c0dd59
@ -1,7 +1,5 @@
|
||||
#![deny(unsafe_code)] /* No `unsafe` needed! */
|
||||
|
||||
mod blockchain;
|
||||
mod database;
|
||||
mod error;
|
||||
mod types;
|
||||
mod wallet;
|
||||
|
@ -27,7 +27,7 @@ fn free_void_result(void_result: FfiResult<()>) {
|
||||
}
|
||||
|
||||
// TODO do we need this? remove?
|
||||
/// Frees a Rust-allocated string
|
||||
/// Free a Rust-allocated string
|
||||
#[ffi_export]
|
||||
fn free_string(string: Option<char_p_boxed>) {
|
||||
drop(string)
|
||||
|
@ -9,11 +9,17 @@ use bdk::{Error, Wallet};
|
||||
use safer_ffi::boxed::Box;
|
||||
use safer_ffi::char_p::{char_p_boxed, char_p_ref};
|
||||
|
||||
use crate::blockchain::BlockchainConfig;
|
||||
use crate::database::DatabaseConfig;
|
||||
use blockchain::BlockchainConfig;
|
||||
use database::DatabaseConfig;
|
||||
|
||||
use crate::error::get_name;
|
||||
use crate::types::{FfiResult, FfiResultVec};
|
||||
|
||||
mod blockchain;
|
||||
mod database;
|
||||
|
||||
// create a new wallet
|
||||
|
||||
#[derive_ReprC]
|
||||
#[ReprC::opaque]
|
||||
pub struct OpaqueWallet {
|
||||
@ -45,15 +51,29 @@ fn new_wallet_result(
|
||||
}
|
||||
}
|
||||
|
||||
fn new_wallet(
|
||||
descriptor: String,
|
||||
change_descriptor: Option<String>,
|
||||
blockchain_config: &AnyBlockchainConfig,
|
||||
database_config: &AnyDatabaseConfig,
|
||||
) -> Result<Wallet<AnyBlockchain, AnyDatabase>, Error> {
|
||||
let network = Testnet;
|
||||
|
||||
let client = AnyBlockchain::from_config(blockchain_config)?;
|
||||
let database = AnyDatabase::from_config(database_config)?;
|
||||
|
||||
let descriptor: &str = descriptor.as_str();
|
||||
let change_descriptor: Option<&str> = change_descriptor.as_deref();
|
||||
|
||||
Wallet::new(descriptor, change_descriptor, network, database, client)
|
||||
}
|
||||
|
||||
#[ffi_export]
|
||||
fn free_wallet_result(wallet_result: FfiResult<OpaqueWallet>) {
|
||||
drop(wallet_result);
|
||||
}
|
||||
|
||||
#[ffi_export]
|
||||
fn free_unspent_result(unspent_result: FfiResultVec<LocalUtxo>) {
|
||||
drop(unspent_result)
|
||||
}
|
||||
// wallet operations
|
||||
|
||||
#[ffi_export]
|
||||
fn sync_wallet(opaque_wallet: &OpaqueWallet) -> FfiResult<()> {
|
||||
@ -105,24 +125,12 @@ fn list_unspent(opaque_wallet: &OpaqueWallet) -> FfiResultVec<LocalUtxo> {
|
||||
}
|
||||
}
|
||||
|
||||
fn new_wallet(
|
||||
descriptor: String,
|
||||
change_descriptor: Option<String>,
|
||||
blockchain_config: &AnyBlockchainConfig,
|
||||
database_config: &AnyDatabaseConfig,
|
||||
) -> Result<Wallet<AnyBlockchain, AnyDatabase>, Error> {
|
||||
let network = Testnet;
|
||||
|
||||
let client = AnyBlockchain::from_config(blockchain_config)?;
|
||||
let database = AnyDatabase::from_config(database_config)?;
|
||||
|
||||
let descriptor: &str = descriptor.as_str();
|
||||
let change_descriptor: Option<&str> = change_descriptor.as_deref();
|
||||
|
||||
Wallet::new(descriptor, change_descriptor, network, database, client)
|
||||
#[ffi_export]
|
||||
fn free_unspent_result(unspent_result: FfiResultVec<LocalUtxo>) {
|
||||
drop(unspent_result)
|
||||
}
|
||||
|
||||
// Non-opaque returned structs
|
||||
// Non-opaque returned values
|
||||
|
||||
#[derive_ReprC]
|
||||
#[repr(C)]
|
Loading…
x
Reference in New Issue
Block a user