New: Add logic for deleting UTXOs above a given height.
This commit is contained in:
parent
cde327a0f8
commit
77b2ac5bae
|
@ -138,6 +138,11 @@ class RustBackend private constructor() : RustBackendWelding {
|
|||
height: Int
|
||||
): Boolean = putUtxo(pathDataDb, tAddress, txId, index, script, value, height)
|
||||
|
||||
override fun clearUtxos(
|
||||
tAddress: String,
|
||||
aboveHeight: Int,
|
||||
): Boolean = clearUtxos(pathDataDb, tAddress, aboveHeight)
|
||||
|
||||
override fun getDownloadedUtxoBalance(address: String): CompactBlockProcessor.WalletBalance {
|
||||
val verified = getVerifiedTransparentBalance(pathDataDb, address)
|
||||
val total = getTotalTransparentBalance(pathDataDb, address)
|
||||
|
@ -306,6 +311,12 @@ class RustBackend private constructor() : RustBackendWelding {
|
|||
height: Int
|
||||
): Boolean
|
||||
|
||||
@JvmStatic private external fun clearUtxos(
|
||||
dbDataPath: String,
|
||||
tAddress: String,
|
||||
aboveHeight: Int,
|
||||
): Boolean
|
||||
|
||||
@JvmStatic private external fun getVerifiedTransparentBalance(
|
||||
pathDataDb: String,
|
||||
taddr: String
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cash.z.ecc.android.sdk.jni
|
||||
|
||||
import cash.z.ecc.android.sdk.block.CompactBlockProcessor
|
||||
import cash.z.ecc.android.sdk.ext.ZcashSdk
|
||||
|
||||
/**
|
||||
* Contract defining the exposed capabilities of the Rust backend.
|
||||
|
@ -70,6 +71,8 @@ interface RustBackendWelding {
|
|||
height: Int
|
||||
): Boolean
|
||||
|
||||
fun clearUtxos(tAddress: String, aboveHeight: Int = ZcashSdk.SAPLING_ACTIVATION_HEIGHT - 1): Boolean
|
||||
|
||||
fun getDownloadedUtxoBalance(address: String): CompactBlockProcessor.WalletBalance
|
||||
|
||||
// Implemented by `DerivationTool`
|
||||
|
|
|
@ -38,7 +38,10 @@ use zcash_client_sqlite::{
|
|||
BlockDB,
|
||||
error::SqliteClientError,
|
||||
NoteId,
|
||||
wallet::init::{init_accounts_table, init_blocks_table, init_wallet_db}, wallet::put_received_transparent_utxo, WalletDB,
|
||||
wallet::init::{init_accounts_table, init_blocks_table, init_wallet_db},
|
||||
wallet::{put_received_transparent_utxo, delete_utxos_above},
|
||||
wallet::rewind_to_height,
|
||||
WalletDB,
|
||||
};
|
||||
use zcash_primitives::{
|
||||
block::BlockHash,
|
||||
|
@ -776,6 +779,31 @@ pub unsafe extern "C" fn Java_cash_z_ecc_android_sdk_jni_RustBackend_putUtxo(
|
|||
unwrap_exc_or(&env, res, JNI_FALSE)
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_cash_z_ecc_android_sdk_jni_RustBackend_clearUtxos(
|
||||
env: JNIEnv<'_>,
|
||||
_: JClass<'_>,
|
||||
db_data: JString<'_>,
|
||||
taddress: JString<'_>,
|
||||
above_height: jint,
|
||||
) -> jint {
|
||||
let res = panic::catch_unwind(|| {
|
||||
let db_data = wallet_db(&env, NETWORK, db_data)?;
|
||||
let mut db_data = db_data.get_update_ops()?;
|
||||
let addr = utils::java_string_to_rust(&env, taddress);
|
||||
let taddress = TransparentAddress::decode(&NETWORK, &addr).unwrap();
|
||||
let height = BlockHeight::from(above_height as u32);
|
||||
|
||||
debug!("clearing UTXOs that were found above height: {}", above_height);
|
||||
match delete_utxos_above(&mut db_data, &taddress, height) {
|
||||
Ok(rows) => Ok(rows as i32),
|
||||
Err(e) => Err(format_err!("Error while clearing UTXOs: {}", e)),
|
||||
}
|
||||
});
|
||||
unwrap_exc_or(&env, res, -1)
|
||||
}
|
||||
|
||||
// ADDED BY ANDROID
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_cash_z_ecc_android_sdk_jni_RustBackend_scanBlockBatch(
|
||||
|
|
Loading…
Reference in New Issue