JniConverter.getVerifiedBalance()

This commit is contained in:
Jack Grigg 2019-02-19 01:45:38 +00:00
parent 2a091a1da1
commit 870283c8ea
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
2 changed files with 27 additions and 2 deletions

View File

@ -19,6 +19,8 @@ class JniConverter {
external fun getBalance(dbData: String, account: Int): Long
external fun getVerifiedBalance(dbData: String, account: Int): Long
external fun getReceivedMemoAsUtf8(dbData: String, idNote: Long): String
external fun getSentMemoAsUtf8(dbData: String, idNote: Long): String

View File

@ -31,8 +31,8 @@ use zip32::ExtendedFullViewingKey;
use crate::{
sql::{
get_address, get_balance, init_accounts_table, init_blocks_table, init_data_database,
scan_cached_blocks, send_to_address,
get_address, get_balance, get_verified_balance, init_accounts_table, init_blocks_table,
init_data_database, scan_cached_blocks, send_to_address,
},
utils::exception::unwrap_exc_or,
};
@ -187,6 +187,29 @@ pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_JniConverter_getBalance(
unwrap_exc_or(&env, res, -1)
}
#[no_mangle]
pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_JniConverter_getVerifiedBalance(
env: JNIEnv<'_>,
_: JClass<'_>,
db_data: JString<'_>,
account: jint,
) -> jlong {
let res = panic::catch_unwind(|| {
let db_data = utils::java_string_to_rust(&env, db_data);
let account = if account >= 0 {
account as u32
} else {
return Err(format_err!("account argument must be positive"));
};
match get_verified_balance(&db_data, account) {
Ok(balance) => Ok(balance.0),
Err(e) => Err(format_err!("Error while fetching verified balance: {}", e)),
}
});
unwrap_exc_or(&env, res, -1)
}
#[no_mangle]
pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_JniConverter_getReceivedMemoAsUtf8(
env: JNIEnv<'_>,