[WIP] Add get new address API to Wallet
This commit is contained in:
parent
cdb90aa35c
commit
84d28a0476
@ -44,15 +44,15 @@ open class RustBuffer : Structure() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal fun alloc(size: Int = 0) = rustCall() { status ->
|
internal fun alloc(size: Int = 0) = rustCall() { status ->
|
||||||
_UniFFILib.INSTANCE.ffi_bdk_ed55_rustbuffer_alloc(size, status)
|
_UniFFILib.INSTANCE.ffi_bdk_75ce_rustbuffer_alloc(size, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun free(buf: RustBuffer.ByValue) = rustCall() { status ->
|
internal fun free(buf: RustBuffer.ByValue) = rustCall() { status ->
|
||||||
_UniFFILib.INSTANCE.ffi_bdk_ed55_rustbuffer_free(buf, status)
|
_UniFFILib.INSTANCE.ffi_bdk_75ce_rustbuffer_free(buf, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun reserve(buf: RustBuffer.ByValue, additional: Int) = rustCall() { status ->
|
internal fun reserve(buf: RustBuffer.ByValue, additional: Int) = rustCall() { status ->
|
||||||
_UniFFILib.INSTANCE.ffi_bdk_ed55_rustbuffer_reserve(buf, additional, status)
|
_UniFFILib.INSTANCE.ffi_bdk_75ce_rustbuffer_reserve(buf, additional, status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,27 +276,31 @@ internal interface _UniFFILib : Library {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ffi_bdk_ed55_OfflineWallet_object_free(ptr: Pointer,
|
fun ffi_bdk_75ce_OfflineWallet_object_free(ptr: Pointer,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): Unit
|
): Unit
|
||||||
|
|
||||||
fun bdk_ed55_OfflineWallet_new(descriptor: RustBuffer.ByValue,
|
fun bdk_75ce_OfflineWallet_new(descriptor: RustBuffer.ByValue,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): Pointer
|
): Pointer
|
||||||
|
|
||||||
fun ffi_bdk_ed55_rustbuffer_alloc(size: Int,
|
fun bdk_75ce_OfflineWallet_get_new_address(ptr: Pointer,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
|
||||||
fun ffi_bdk_ed55_rustbuffer_from_bytes(bytes: ForeignBytes.ByValue,
|
fun ffi_bdk_75ce_rustbuffer_alloc(size: Int,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
|
||||||
fun ffi_bdk_ed55_rustbuffer_free(buf: RustBuffer.ByValue,
|
fun ffi_bdk_75ce_rustbuffer_from_bytes(bytes: ForeignBytes.ByValue,
|
||||||
|
uniffi_out_err: RustCallStatus
|
||||||
|
): RustBuffer.ByValue
|
||||||
|
|
||||||
|
fun ffi_bdk_75ce_rustbuffer_free(buf: RustBuffer.ByValue,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): Unit
|
): Unit
|
||||||
|
|
||||||
fun ffi_bdk_ed55_rustbuffer_reserve(buf: RustBuffer.ByValue,additional: Int,
|
fun ffi_bdk_75ce_rustbuffer_reserve(buf: RustBuffer.ByValue,additional: Int,
|
||||||
uniffi_out_err: RustCallStatus
|
uniffi_out_err: RustCallStatus
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
|
||||||
@ -544,6 +548,7 @@ private inline fun <U> rustCall(callback: (RustCallStatus) -> U): U {
|
|||||||
|
|
||||||
|
|
||||||
public interface OfflineWalletInterface {
|
public interface OfflineWalletInterface {
|
||||||
|
fun getNewAddress(): String
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +559,7 @@ class OfflineWallet(
|
|||||||
constructor(descriptor: String ) :
|
constructor(descriptor: String ) :
|
||||||
this(
|
this(
|
||||||
rustCall() { status ->
|
rustCall() { status ->
|
||||||
_UniFFILib.INSTANCE.bdk_ed55_OfflineWallet_new(descriptor.lower() ,status)
|
_UniFFILib.INSTANCE.bdk_75ce_OfflineWallet_new(descriptor.lower() ,status)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -567,7 +572,7 @@ class OfflineWallet(
|
|||||||
*/
|
*/
|
||||||
override protected fun freeRustArcPtr() {
|
override protected fun freeRustArcPtr() {
|
||||||
rustCall() { status ->
|
rustCall() { status ->
|
||||||
_UniFFILib.INSTANCE.ffi_bdk_ed55_OfflineWallet_object_free(this.pointer, status)
|
_UniFFILib.INSTANCE.ffi_bdk_75ce_OfflineWallet_object_free(this.pointer, status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,6 +584,15 @@ class OfflineWallet(
|
|||||||
buf.putLong(Pointer.nativeValue(this.lower()))
|
buf.putLong(Pointer.nativeValue(this.lower()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getNewAddress(): String =
|
||||||
|
callWithPointer {
|
||||||
|
rustCall() { status ->
|
||||||
|
_UniFFILib.INSTANCE.bdk_75ce_OfflineWallet_get_new_address(it, status)
|
||||||
|
}
|
||||||
|
}.let {
|
||||||
|
String.lift(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -4,4 +4,5 @@ namespace bdk {
|
|||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
constructor(string descriptor);
|
constructor(string descriptor);
|
||||||
|
string get_new_address();
|
||||||
};
|
};
|
14
src/lib.rs
14
src/lib.rs
@ -1,14 +1,13 @@
|
|||||||
use bdk::Wallet;
|
use bdk::Wallet;
|
||||||
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::database::MemoryDatabase;
|
use bdk::database::MemoryDatabase;
|
||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
// use crate::error::FfiError;
|
// use crate::error::FfiError;
|
||||||
use std::sync::{RwLock, Mutex};
|
use std::sync::{RwLock, Mutex};
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
use bdk::database::BatchDatabase;
|
use bdk::database::BatchDatabase;
|
||||||
use bdk::sled;
|
use bdk::sled;
|
||||||
use bdk::sled::Tree;
|
use bdk::sled::Tree;
|
||||||
|
|
||||||
//mod error;
|
//mod error;
|
||||||
//mod types;
|
//mod types;
|
||||||
//mod wallet;
|
//mod wallet;
|
||||||
@ -40,6 +39,17 @@ impl OfflineWallet {
|
|||||||
// wallet: RwLock::new(Vec::new())
|
// wallet: RwLock::new(Vec::new())
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_new_address(&self) -> String {
|
||||||
|
self
|
||||||
|
.wallet
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.get_address(AddressIndex::New)
|
||||||
|
.unwrap()
|
||||||
|
.address
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uniffi::deps::static_assertions::assert_impl_all!(OfflineWallet: Sync, Send);
|
uniffi::deps::static_assertions::assert_impl_all!(OfflineWallet: Sync, Send);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user