Skip to content

Commit

Permalink
mobile add prism param (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaorongqiang authored May 6, 2023
1 parent 54efd20 commit 10d5744
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
3 changes: 1 addition & 2 deletions container/Dockerfile-wallet_mobile-lib_android
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ FROM rust:1.66.0-slim
RUN apt update -y && apt upgrade -y && apt install -y unzip wget make pkg-config
RUN wget -nc -P /opt/ https://www.openssl.org/source/openssl-1.1.1s.tar.gz
RUN wget -nc -P /opt/ https://dl.google.com/android/repository/android-ndk-r25c-linux.zip && unzip /opt/android-ndk-r25c-linux.zip -d /opt/
ENV PATH="/opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATHTMP"

ENV PATHTMP="$PATH"
ENV PATH="/opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
ENV WORK_DIR /platform

ENV ANDROID_NDK_HOME /opt/android-ndk-r25c/
Expand Down
35 changes: 31 additions & 4 deletions src/components/wallet_mobile/src/android/tx_builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::parseU64;
use crate::rust::*;
use jni::objects::{JClass, JString};
use jni::sys::{jboolean, jint, jlong, jstring, JNI_TRUE};
use jni::JNIEnv;
use ledger::data_model::AssetTypeCode;
use zei::xfr::sig::XfrKeyPair;

use super::parseU64;

#[no_mangle]
/// # Safety
/// @param kp: owner's XfrKeyPair
Expand Down Expand Up @@ -341,6 +340,8 @@ pub unsafe extern "system" fn Java_com_findora_JniApi_transactionBuilderAddOpera
amount: JString,
keypair: jlong,
address: JString,
asset: JString,
lowlevel_data: JString,
) -> jlong {
let builder = &*(builder as *mut TransactionBuilder);
let addr: String = env
Expand All @@ -349,10 +350,36 @@ pub unsafe extern "system" fn Java_com_findora_JniApi_transactionBuilderAddOpera
.into();

let fra_kp = &*(keypair as *mut XfrKeyPair);
let asset_str: String = env
.get_string(asset)
.expect("Couldn't get java string!")
.into();

let asset = if asset_str.is_empty() {
None
} else {
Some(AssetTypeCode::new_from_base64(&asset_str).unwrap())
};

let lowlevel_data_str: String = env
.get_string(lowlevel_data)
.expect("Couldn't get java string!")
.into();

let lowlevel_data = if lowlevel_data_str.is_empty() {
None
} else {
Some(hex::decode(lowlevel_data_str).unwrap())
};
builder
.clone()
.add_transfer_to_account_operation(parseU64(env, amount), Some(addr), fra_kp)
.add_transfer_to_account_operation(
parseU64(env, amount),
Some(addr),
fra_kp,
asset,
lowlevel_data,
)
.unwrap();
Box::into_raw(Box::new(builder)) as jlong
}
Expand Down
33 changes: 26 additions & 7 deletions src/components/wallet_mobile/src/ios/tx_builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::os::raw::c_char;
use zei::xfr::sig::XfrKeyPair;

use super::parse_u64;
use crate::rust::{
c_char_to_string, string_to_c_char, AssetRules, ClientAssetRecord, FeeInputs,
OwnerMemo, PublicParams, TransactionBuilder,
};
use ledger::data_model::AssetTypeCode;
use std::os::raw::c_char;
use zei::xfr::sig::XfrKeyPair;

#[no_mangle]
/// @param kp: owner's XfrKeyPair
Expand Down Expand Up @@ -263,6 +263,8 @@ pub extern "C" fn findora_ffi_transaction_builder_add_operation_convert_account(
address: *const c_char,
amount: *const c_char,
kp: &XfrKeyPair,
asset: *const c_char,
lowlevel_data: *const c_char,
) -> *mut TransactionBuilder {
let amount = parse_u64(amount);
let addr_stirng = c_char_to_string(address);
Expand All @@ -271,10 +273,27 @@ pub extern "C" fn findora_ffi_transaction_builder_add_operation_convert_account(
} else {
Some(addr_stirng)
};
if let Ok(builder) = builder
.clone()
.add_transfer_to_account_operation(amount, addr, kp)
{
let asset_str = c_char_to_string(asset);
let asset = if asset_str.is_empty() {
None
} else {
Some(AssetTypeCode::new_from_base64(&asset_str).unwrap())
};

let lowlevel_data_str = c_char_to_string(lowlevel_data);
let lowlevel_data = if lowlevel_data_str.is_empty() {
None
} else {
Some(hex::decode(lowlevel_data_str).unwrap())
};

if let Ok(builder) = builder.clone().add_transfer_to_account_operation(
amount,
addr,
kp,
asset,
lowlevel_data,
) {
Box::into_raw(Box::new(builder))
} else {
std::ptr::null_mut()
Expand Down
12 changes: 10 additions & 2 deletions src/components/wallet_mobile/src/rust/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::str::FromStr;
use ledger::data_model::ASSET_TYPE_FRA;
use ledger::data_model::{AssetTypeCode, ASSET_TYPE_FRA};
use ruc::{d, Result, RucResult};
use zei::xfr::sig::{XfrKeyPair, XfrPublicKey};

Expand Down Expand Up @@ -42,14 +42,22 @@ impl TransactionBuilder {
amount: u64,
address: Option<String>,
keypair: &XfrKeyPair,
asset: Option<AssetTypeCode>,
lowlevel_data: Option<Vec<u8>>,
) -> Result<Self> {
let target_address = match address {
Some(s) => MultiSigner::from_str(&s)?,
None => MultiSigner::Xfr(keypair.get_pk()),
};

self.get_builder_mut()
.add_operation_convert_account(keypair, target_address, amount, None, None)?
.add_operation_convert_account(
keypair,
target_address,
amount,
asset,
lowlevel_data,
)?
.sign(keypair);

Ok(self)
Expand Down

0 comments on commit 10d5744

Please sign in to comment.