2021-01-04 15:18:51 +01:00
|
|
|
// Copyright (C) 2020 Éloïs SANCHEZ.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#![allow(clippy::missing_safety_doc, clippy::not_unsafe_ptr_arg_deref)]
|
|
|
|
|
2021-01-09 21:12:52 +01:00
|
|
|
mod r#async;
|
2021-01-04 15:18:51 +01:00
|
|
|
mod dewif;
|
2021-01-09 21:12:52 +01:00
|
|
|
mod error;
|
2021-01-09 23:39:04 +01:00
|
|
|
mod inputs;
|
2021-01-10 22:08:54 +01:00
|
|
|
mod legacy;
|
2021-01-04 15:18:51 +01:00
|
|
|
mod mnemonic;
|
2021-03-27 23:36:39 +01:00
|
|
|
mod payment;
|
2021-03-08 01:26:22 +01:00
|
|
|
mod pubkey;
|
2021-01-09 23:39:04 +01:00
|
|
|
mod secret_code;
|
2021-01-04 15:18:51 +01:00
|
|
|
|
2021-01-09 21:12:52 +01:00
|
|
|
use crate::error::{DartRes, DubpError};
|
2021-01-09 23:39:04 +01:00
|
|
|
use crate::inputs::*;
|
2021-01-09 21:12:52 +01:00
|
|
|
use crate::r#async::exec_async;
|
2021-01-09 23:39:04 +01:00
|
|
|
use crate::secret_code::gen_secret_code;
|
2021-01-08 01:49:54 +01:00
|
|
|
use allo_isolate::{IntoDart, Isolate};
|
2021-03-27 23:36:39 +01:00
|
|
|
use dubp_client::crypto::{
|
2021-01-04 15:18:51 +01:00
|
|
|
bases::b58::ToBase58,
|
2021-04-04 14:11:12 +02:00
|
|
|
dewif::{
|
|
|
|
Currency, DewifContent, DewifPayload, DewifReadError, ExpectedCurrency, G1_CURRENCY,
|
|
|
|
G1_TEST_CURRENCY,
|
|
|
|
},
|
2021-01-04 15:18:51 +01:00
|
|
|
keys::{
|
2021-02-28 03:09:01 +01:00
|
|
|
ed25519::bip32::{
|
|
|
|
ChainCode, InvalidAccountIndex, KeyPair, PrivateDerivationPath, PublicKeyWithChainCode,
|
|
|
|
},
|
2021-03-08 01:26:22 +01:00
|
|
|
ed25519::{KeyPairFromSeed32Generator, PublicKey, PublicKeyFromStrErr},
|
2021-04-04 14:11:12 +02:00
|
|
|
KeyPair as _, KeyPairEnum, KeysAlgo, PublicKey as _, Signator as _, Signature as _,
|
2021-01-04 15:18:51 +01:00
|
|
|
},
|
|
|
|
mnemonic::{Language, Mnemonic, MnemonicType},
|
2021-02-28 03:09:01 +01:00
|
|
|
utils::{U31Error, U31},
|
2021-01-04 15:18:51 +01:00
|
|
|
};
|
2021-01-09 21:12:52 +01:00
|
|
|
use fast_threadpool::{ThreadPool, ThreadPoolConfig, ThreadPoolSyncHandler};
|
|
|
|
use once_cell::sync::Lazy;
|
2021-02-28 03:09:01 +01:00
|
|
|
use parking_lot::Mutex;
|
|
|
|
use std::{collections::HashMap, ffi::CStr, io, os::raw, sync::Arc};
|
2021-01-04 15:18:51 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[no_mangle]
|
2021-01-09 23:39:04 +01:00
|
|
|
pub extern "C" fn change_dewif_secret_code(
|
2021-01-04 15:18:51 +01:00
|
|
|
port: i64,
|
|
|
|
dewif: *const raw::c_char,
|
2021-02-14 17:14:35 +01:00
|
|
|
old_secret_code: *const raw::c_char,
|
2021-01-09 22:03:19 +01:00
|
|
|
member_wallet: u32,
|
2021-01-09 23:39:04 +01:00
|
|
|
secret_code_type: u32,
|
2021-01-10 15:45:55 +01:00
|
|
|
system_memory: i64,
|
2021-01-08 01:49:54 +01:00
|
|
|
) {
|
2021-01-09 21:12:52 +01:00
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
2021-02-14 17:14:35 +01:00
|
|
|
let old_secret_code = char_ptr_to_str(old_secret_code)?;
|
2021-01-09 22:03:19 +01:00
|
|
|
let member_wallet = member_wallet != 0;
|
2021-01-09 23:39:04 +01:00
|
|
|
let secret_code_type = SecretCodeType::from(secret_code_type);
|
2021-01-10 15:45:55 +01:00
|
|
|
Ok((
|
|
|
|
dewif,
|
2021-02-14 17:14:35 +01:00
|
|
|
old_secret_code,
|
2021-01-10 15:45:55 +01:00
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
|
|
|
system_memory,
|
|
|
|
))
|
2021-01-09 22:03:19 +01:00
|
|
|
},
|
2021-02-14 17:14:35 +01:00
|
|
|
|(dewif, old_secret_code, member_wallet, secret_code_type, system_memory)| {
|
2021-01-10 15:45:55 +01:00
|
|
|
dewif::change_secret_code(
|
|
|
|
dewif,
|
2021-02-14 17:14:35 +01:00
|
|
|
old_secret_code,
|
2021-01-10 15:45:55 +01:00
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
|
|
|
system_memory,
|
|
|
|
)
|
2021-01-09 21:12:52 +01:00
|
|
|
},
|
|
|
|
)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 01:26:22 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn check_pubkey(port: i64, pubkey: *const raw::c_char) {
|
2021-04-04 14:11:12 +02:00
|
|
|
exec_async(port, || char_ptr_to_str(pubkey), pubkey::check_pubkey)
|
2021-03-08 01:26:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn compute_checksum(port: i64, pubkey: *const raw::c_char) {
|
2021-04-04 14:11:12 +02:00
|
|
|
exec_async(port, || char_ptr_to_str(pubkey), pubkey::compute_checksum)
|
2021-03-08 01:26:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 15:18:51 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn gen_dewif(
|
|
|
|
port: i64,
|
|
|
|
currency: *const raw::c_char,
|
|
|
|
language: u32,
|
|
|
|
mnemonic: *const raw::c_char,
|
2021-01-09 22:03:19 +01:00
|
|
|
member_wallet: u32,
|
2021-01-09 23:39:04 +01:00
|
|
|
secret_code_type: u32,
|
2021-01-10 15:45:55 +01:00
|
|
|
system_memory: i64,
|
2021-01-08 01:49:54 +01:00
|
|
|
) {
|
2021-01-09 21:12:52 +01:00
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let currency = char_ptr_to_str(currency)?;
|
2021-01-09 23:39:04 +01:00
|
|
|
let language = u32_to_language(language)?;
|
2021-01-09 21:12:52 +01:00
|
|
|
let mnemonic = char_ptr_to_str(mnemonic)?;
|
2021-01-09 22:03:19 +01:00
|
|
|
let member_wallet = member_wallet != 0;
|
2021-01-09 23:39:04 +01:00
|
|
|
let secret_code_type = SecretCodeType::from(secret_code_type);
|
|
|
|
Ok((
|
|
|
|
currency,
|
|
|
|
language,
|
|
|
|
mnemonic,
|
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
2021-01-10 15:45:55 +01:00
|
|
|
system_memory,
|
2021-01-09 23:39:04 +01:00
|
|
|
))
|
2021-01-09 22:03:19 +01:00
|
|
|
},
|
2021-02-27 22:26:30 +01:00
|
|
|
|(currency, language, mnemonic, member_wallet, secret_code_type, system_memory)| {
|
2021-01-09 23:39:04 +01:00
|
|
|
dewif::gen_dewif(
|
|
|
|
currency,
|
|
|
|
language,
|
|
|
|
mnemonic,
|
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
2021-01-10 15:45:55 +01:00
|
|
|
system_memory,
|
2021-01-09 23:39:04 +01:00
|
|
|
)
|
2021-01-09 21:12:52 +01:00
|
|
|
},
|
|
|
|
)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-06 19:52:42 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn gen_dewif_from_legacy(
|
|
|
|
port: i64,
|
|
|
|
currency: *const raw::c_char,
|
|
|
|
salt: *const raw::c_char,
|
|
|
|
password: *const raw::c_char,
|
|
|
|
member_wallet: u32,
|
|
|
|
secret_code_type: u32,
|
|
|
|
system_memory: i64,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let currency = char_ptr_to_str(currency)?;
|
|
|
|
let salt = char_ptr_to_str(salt)?.to_owned();
|
|
|
|
let password = char_ptr_to_str(password)?.to_owned();
|
|
|
|
let member_wallet = member_wallet != 0;
|
|
|
|
let secret_code_type = SecretCodeType::from(secret_code_type);
|
|
|
|
Ok((
|
|
|
|
currency,
|
|
|
|
salt,
|
|
|
|
password,
|
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
|
|
|
system_memory,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|(currency, salt, password, member_wallet, secret_code_type, system_memory)| {
|
|
|
|
legacy::gen_dewif_from_legacy(
|
|
|
|
currency,
|
|
|
|
salt,
|
|
|
|
password,
|
|
|
|
member_wallet,
|
|
|
|
secret_code_type,
|
|
|
|
system_memory,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-04 15:18:51 +01:00
|
|
|
#[no_mangle]
|
2021-01-08 01:49:54 +01:00
|
|
|
pub extern "C" fn gen_mnemonic(port: i64, language: u32) {
|
2021-01-10 10:27:31 +01:00
|
|
|
exec_async(port, || u32_to_language(language), mnemonic::gen_mnemonic)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 03:09:01 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_bip32_dewif_accounts_pubkeys(
|
|
|
|
port: i64,
|
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
secret_code: *const raw::c_char,
|
|
|
|
accounts_indexs_len: u32,
|
|
|
|
accounts_indexs: *const u32,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
|
|
|
let accounts_indexs = char_ptr_prt_to_vec_u31(accounts_indexs, accounts_indexs_len)?;
|
|
|
|
Ok((currency, dewif, secret_code, accounts_indexs))
|
|
|
|
},
|
|
|
|
|(currency, dewif, secret_code, accounts_indexs)| {
|
|
|
|
dewif::bip32::get_accounts_pubkeys(currency, dewif, secret_code, accounts_indexs)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-04 14:11:12 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_bip32_dewif_mnemonic(
|
|
|
|
port: i64,
|
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
secret_code: *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
|
|
|
Ok((currency, dewif, secret_code))
|
|
|
|
},
|
|
|
|
|(currency, dewif, secret_code)| dewif::bip32::get_mnemonic(currency, dewif, secret_code),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:36:44 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_dewif_meta(
|
|
|
|
port: i64,
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
member_wallet: u32,
|
|
|
|
secret_code_type: u32,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
|
|
|
let member_wallet = member_wallet != 0;
|
|
|
|
let secret_code_type = SecretCodeType::from(secret_code_type);
|
|
|
|
Ok((dewif, member_wallet, secret_code_type))
|
|
|
|
},
|
|
|
|
|(dewif, member_wallet, secret_code_type)| {
|
|
|
|
dewif::get_dewif_meta(dewif, member_wallet, secret_code_type)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-08 18:26:30 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_dewif_secret_code_len(
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
member_wallet: u32,
|
|
|
|
secret_code_type: u32,
|
2021-02-09 02:12:01 +01:00
|
|
|
) -> i32 {
|
|
|
|
if let Ok(secret_code_len) = dewif::get_secret_code_len(dewif, member_wallet, secret_code_type)
|
|
|
|
{
|
|
|
|
secret_code_len as i32
|
|
|
|
} else {
|
|
|
|
-1
|
|
|
|
}
|
2021-02-08 18:26:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 15:18:51 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_dewif_pubkey(
|
|
|
|
port: i64,
|
2021-02-28 03:09:01 +01:00
|
|
|
account_index: i32,
|
|
|
|
address_index: i32,
|
2021-01-04 15:18:51 +01:00
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
2021-02-28 03:09:01 +01:00
|
|
|
external_opt: i32,
|
2021-01-04 15:18:51 +01:00
|
|
|
pin: *const raw::c_char,
|
2021-01-08 01:49:54 +01:00
|
|
|
) {
|
2021-01-09 21:12:52 +01:00
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
2021-02-28 03:09:01 +01:00
|
|
|
let account_index_opt = i32_to_opt_u32(account_index);
|
|
|
|
let address_index_opt = i32_to_opt_u31(address_index)?;
|
2021-01-09 22:03:19 +01:00
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
2021-01-09 21:12:52 +01:00
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
let external_opt = i32_to_opt_bool(external_opt);
|
2021-01-09 21:12:52 +01:00
|
|
|
let pin = char_ptr_to_str(pin)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
Ok((
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
pin,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|(account_index_opt, address_index_opt, currency, dewif, external_opt, pin)| {
|
|
|
|
dewif::get_pubkey(
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
pin,
|
|
|
|
)
|
2021-01-09 21:12:52 +01:00
|
|
|
},
|
|
|
|
)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 01:58:03 +01:00
|
|
|
#[no_mangle]
|
2021-02-28 03:09:01 +01:00
|
|
|
pub extern "C" fn get_opaque_account_next_external_address(port: i64, account_index: u32) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let account_index = U31::new(account_index)?;
|
|
|
|
Ok(account_index)
|
|
|
|
},
|
|
|
|
dewif::bip32::get_opaque_account_next_external_address,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn load_opaque_bip32_accounts(
|
2021-02-09 01:58:03 +01:00
|
|
|
port: i64,
|
2021-02-28 03:09:01 +01:00
|
|
|
accounts_indexs_len: u32,
|
|
|
|
accounts_indexs: *const u32,
|
2021-02-09 01:58:03 +01:00
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
secret_code: *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
2021-02-28 03:09:01 +01:00
|
|
|
let accounts_indexs = char_ptr_prt_to_vec_u31(accounts_indexs, accounts_indexs_len)?;
|
2021-02-09 01:58:03 +01:00
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
Ok((accounts_indexs, currency, dewif, secret_code))
|
2021-02-09 01:58:03 +01:00
|
|
|
},
|
2021-02-28 03:09:01 +01:00
|
|
|
|(accounts_indexs, currency, dewif, secret_code)| {
|
|
|
|
dewif::bip32::load_opaque_bip32_accounts(accounts_indexs, currency, dewif, secret_code)
|
2021-02-09 01:58:03 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-10 22:08:54 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn get_legacy_pubkey(
|
|
|
|
port: i64,
|
|
|
|
salt: *const raw::c_char,
|
|
|
|
password: *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let salt = char_ptr_to_str(salt)?;
|
|
|
|
let password = char_ptr_to_str(password)?;
|
|
|
|
Ok((salt, password))
|
|
|
|
},
|
|
|
|
|(salt, password)| Ok::<_, DubpError>(legacy::get_pubkey(salt, password)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-04 15:18:51 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn mnemonic_to_pubkey(
|
|
|
|
port: i64,
|
|
|
|
language: u32,
|
|
|
|
mnemonic_phrase: *const raw::c_char,
|
2021-01-08 01:49:54 +01:00
|
|
|
) {
|
2021-01-09 21:12:52 +01:00
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
2021-01-10 10:27:31 +01:00
|
|
|
let language = u32_to_language(language)?;
|
2021-01-09 21:12:52 +01:00
|
|
|
let mnemonic_phrase = char_ptr_to_str(mnemonic_phrase)?;
|
|
|
|
Ok((language, mnemonic_phrase))
|
|
|
|
},
|
|
|
|
|(language, mnemonic_phrase)| mnemonic::mnemonic_to_pubkey(language, mnemonic_phrase),
|
|
|
|
)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn sign(
|
|
|
|
port: i64,
|
2021-02-28 03:09:01 +01:00
|
|
|
account_index: i32,
|
|
|
|
address_index: i32,
|
2021-01-04 15:18:51 +01:00
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
2021-02-28 03:09:01 +01:00
|
|
|
external_opt: i32,
|
2021-02-09 01:58:03 +01:00
|
|
|
secret_code: *const raw::c_char,
|
|
|
|
msg: *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
2021-02-28 03:09:01 +01:00
|
|
|
let account_index_opt = i32_to_opt_u32(account_index);
|
|
|
|
let address_index_opt = i32_to_opt_u31(address_index)?;
|
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
2021-02-09 01:58:03 +01:00
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
let external_opt = i32_to_opt_bool(external_opt);
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
2021-02-09 01:58:03 +01:00
|
|
|
let msg = char_ptr_to_str(msg)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
Ok((
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
msg,
|
|
|
|
))
|
2021-02-09 01:58:03 +01:00
|
|
|
},
|
2021-02-28 03:09:01 +01:00
|
|
|
|(
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
msg,
|
|
|
|
)| {
|
|
|
|
dewif::sign(
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
msg,
|
|
|
|
)
|
2021-01-10 22:08:54 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-04 15:18:51 +01:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn sign_several(
|
|
|
|
port: i64,
|
2021-02-28 03:09:01 +01:00
|
|
|
account_index: i32,
|
|
|
|
address_index: i32,
|
2021-01-04 15:18:51 +01:00
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
2021-02-28 03:09:01 +01:00
|
|
|
external_opt: i32,
|
|
|
|
secret_code: *const raw::c_char,
|
2021-02-09 01:58:03 +01:00
|
|
|
msgs_len: u32,
|
|
|
|
msgs: *const *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
2021-02-28 03:09:01 +01:00
|
|
|
let account_index_opt = i32_to_opt_u32(account_index);
|
|
|
|
let address_index_opt = i32_to_opt_u31(address_index)?;
|
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
2021-02-09 01:58:03 +01:00
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
let external_opt = i32_to_opt_bool(external_opt);
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
2021-02-09 01:58:03 +01:00
|
|
|
let msgs = char_ptr_prt_to_vec_str(msgs, msgs_len)?;
|
2021-02-28 03:09:01 +01:00
|
|
|
Ok((
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
msgs,
|
|
|
|
))
|
2021-02-09 01:58:03 +01:00
|
|
|
},
|
2021-02-28 03:09:01 +01:00
|
|
|
|(
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
msgs,
|
|
|
|
)| {
|
|
|
|
dewif::sign_several(
|
|
|
|
account_index_opt,
|
|
|
|
address_index_opt,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
external_opt,
|
|
|
|
secret_code,
|
|
|
|
&msgs,
|
|
|
|
)
|
2021-02-09 01:58:03 +01:00
|
|
|
},
|
2021-01-09 21:12:52 +01:00
|
|
|
)
|
2021-01-04 15:18:51 +01:00
|
|
|
}
|
2021-03-27 23:36:39 +01:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn simple_payment_bip32(
|
|
|
|
port: i64,
|
|
|
|
account_index: u32,
|
|
|
|
amount: f64,
|
|
|
|
currency: *const raw::c_char,
|
|
|
|
dewif: *const raw::c_char,
|
|
|
|
gva_endpoint: *const raw::c_char,
|
|
|
|
recipient: *const raw::c_char,
|
|
|
|
secret_code: *const raw::c_char,
|
|
|
|
tx_comment: *const raw::c_char,
|
|
|
|
) {
|
|
|
|
exec_async(
|
|
|
|
port,
|
|
|
|
|| {
|
|
|
|
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
|
|
|
let dewif = char_ptr_to_str(dewif)?;
|
|
|
|
let gva_endpoint = char_ptr_to_str(gva_endpoint)?;
|
|
|
|
let recipient = char_ptr_to_str(recipient)?;
|
|
|
|
let secret_code = char_ptr_to_str(secret_code)?;
|
|
|
|
let tx_comment = char_ptr_to_opt_string(tx_comment)?;
|
|
|
|
Ok((
|
|
|
|
account_index,
|
|
|
|
amount,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
gva_endpoint,
|
|
|
|
secret_code,
|
|
|
|
recipient,
|
|
|
|
tx_comment,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|(
|
|
|
|
account_index,
|
|
|
|
amount,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
gva_endpoint,
|
|
|
|
secret_code,
|
|
|
|
recipient,
|
|
|
|
tx_comment,
|
|
|
|
)| {
|
|
|
|
payment::simple_payment(
|
|
|
|
account_index,
|
|
|
|
amount,
|
|
|
|
currency,
|
|
|
|
dewif,
|
|
|
|
gva_endpoint,
|
|
|
|
secret_code,
|
|
|
|
recipient,
|
|
|
|
tx_comment,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|