Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tx_input, tx_output, tx_hash for Android
- Loading branch information
1 parent
0b87dde
commit 80db929
Showing
11 changed files
with
432 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::ptr_j::*; | ||
use super::result::ToJniResult; | ||
use crate::panic::{handle_exception_result, ToResult}; | ||
use crate::ptr::RPtrRepresentable; | ||
use jni::objects::{JObject}; | ||
use jni::sys::{jbyteArray, jobject}; | ||
use jni::JNIEnv; | ||
use wasm_bindgen::JsValue; | ||
|
||
pub trait HashType { | ||
fn to_bytes(&self) -> Vec<u8>; | ||
fn from_bytes(bytes: Vec<u8>) -> Result<Self, JsValue> where Self: Sized; | ||
} | ||
|
||
pub unsafe fn hash_to_bytes<T: RPtrRepresentable + HashType>( | ||
env: JNIEnv, hash: JRPtr | ||
) -> jobject { | ||
handle_exception_result(|| { | ||
let hash = hash.rptr(&env)?; | ||
hash | ||
.typed_ref::<T>() | ||
.map(|hash| hash.to_bytes()) | ||
.and_then(|bytes| env.byte_array_from_slice(&bytes).into_result()) | ||
.map(|arr| JObject::from(arr)) | ||
}) | ||
.jresult(&env) | ||
} | ||
|
||
pub unsafe fn hash_from_bytes<T: RPtrRepresentable + HashType>( | ||
env: JNIEnv, bytes: jbyteArray, | ||
) -> jobject { | ||
handle_exception_result(|| { | ||
env | ||
.convert_byte_array(bytes) | ||
.into_result() | ||
.and_then(|bytes| T::from_bytes(bytes).into_result()) | ||
.and_then(|hash| hash.rptr().jptr(&env)) | ||
}) | ||
.jresult(&env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.