use {ErrorCode, IndyError};
use std::ffi::CString;
use std::ptr::null;
use futures::Future;
use ffi::payments;
use ffi::{ResponseStringCB,
ResponseStringStringCB,
ResponseStringI64CB,
ResponseSliceCB,
ResponseBoolCB,
WalletHandle,
CommandHandle
};
use utils::callbacks::{ClosureHandler, ResultHandler};
use futures::IntoFuture;
pub fn create_payment_address(wallet_handle: WalletHandle, payment_method: &str, config: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _create_payment_address(command_handle, wallet_handle, payment_method, config, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _create_payment_address(command_handle: CommandHandle, wallet_handle: WalletHandle, payment_method: &str, config: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let config = c_str!(config);
ErrorCode::from(unsafe { payments::indy_create_payment_address(command_handle, wallet_handle, payment_method.as_ptr(), config.as_ptr(), cb) })
}
pub fn list_payment_addresses(wallet_handle: WalletHandle) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _list_payment_addresses(command_handle, wallet_handle, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _list_payment_addresses(command_handle: CommandHandle, wallet_handle: WalletHandle, cb: Option<ResponseStringCB>) -> ErrorCode {
ErrorCode::from(unsafe { payments::indy_list_payment_addresses(command_handle, wallet_handle, cb) })
}
pub fn add_request_fees(wallet_handle: WalletHandle,
submitter_did: Option<&str>,
req_json: &str,
inputs_json: &str,
outputs_json: &str,
extra: Option<&str>) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
let err = _add_request_fees(command_handle, wallet_handle, submitter_did, req_json, inputs_json, outputs_json, extra, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _add_request_fees(command_handle: CommandHandle,
wallet_handle: WalletHandle,
submitter_did: Option<&str>,
req_json: &str,
inputs_json: &str,
outputs_json: &str,
extra: Option<&str>,
cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let req_json = c_str!(req_json);
let inputs_json = c_str!(inputs_json);
let outputs_json = c_str!(outputs_json);
let extra_str = opt_c_str!(extra);
ErrorCode::from(unsafe {
payments::indy_add_request_fees(command_handle,
wallet_handle,
opt_c_ptr!(submitter_did, submitter_did_str),
req_json.as_ptr(),
inputs_json.as_ptr(),
outputs_json.as_ptr(),
opt_c_ptr!(extra, extra_str),
cb)
})
}
pub fn parse_response_with_fees(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _parse_response_with_fees(command_handle, payment_method, resp_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _parse_response_with_fees(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe { payments::indy_parse_response_with_fees(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
}
#[deprecated(since="2.0.0", note="please use `parse_get_payment_sources_with_from_response` instead")]
pub fn build_get_payment_sources_request(wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_address: &str) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) =
ClosureHandler::cb_ec_string_string();
let err = _build_get_payment_sources_request(command_handle, wallet_handle, submitter_did, payment_address, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _build_get_payment_sources_request(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_address: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let payment_address = c_str!(payment_address);
ErrorCode::from(unsafe { payments::indy_build_get_payment_sources_request(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), payment_address.as_ptr(), cb) })
}
pub fn build_get_payment_sources_with_from_request(wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_address: &str, from: Option<i64>) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) =
ClosureHandler::cb_ec_string_string();
let err = _build_get_payment_sources_with_from_request(command_handle, wallet_handle, submitter_did, payment_address, from, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _build_get_payment_sources_with_from_request(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_address: &str, from: Option<i64>, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let payment_address = c_str!(payment_address);
ErrorCode::from(unsafe { payments::indy_build_get_payment_sources_with_from_request(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), payment_address.as_ptr(), from.unwrap_or(-1), cb) })
}
#[deprecated(since="2.0.0", note="please use `parse_get_payment_sources_with_from_response` instead")]
pub fn parse_get_payment_sources_response(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _parse_get_payment_sources_response(command_handle, payment_method, resp_json, cb);
Box::new(ResultHandler::str(command_handle, err, receiver))
}
fn _parse_get_payment_sources_response(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe { payments::indy_parse_get_payment_sources_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
}
pub fn parse_get_payment_sources_with_from_response(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=(String, Option<i64>), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_i64();
let err = _parse_get_payment_sources_with_from_response(command_handle, payment_method, resp_json, cb);
Box::new(ResultHandler::str_i64(command_handle, err, receiver).map(|(s, i)| (s, if i >= 0 {Some(i)} else {None})).into_future())
}
fn _parse_get_payment_sources_with_from_response(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringI64CB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe { payments::indy_parse_get_payment_sources_with_from_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
}
pub fn build_payment_req(wallet_handle: WalletHandle, submitter_did: Option<&str>, inputs: &str, outputs: &str, extra: Option<&str>) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
let err = _build_payment_req(command_handle, wallet_handle, submitter_did, inputs, outputs, extra, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _build_payment_req(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, inputs: &str, outputs: &str, extra: Option<&str>, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let inputs = c_str!(inputs);
let outputs = c_str!(outputs);
let extra_str = opt_c_str!(extra);
ErrorCode::from(unsafe {
payments::indy_build_payment_req(command_handle,
wallet_handle,
opt_c_ptr!(submitter_did, submitter_did_str),
inputs.as_ptr(),
outputs.as_ptr(),
opt_c_ptr!(extra, extra_str),
cb)
})
}
pub fn parse_payment_response(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _parse_payment_response(command_handle, payment_method, resp_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _parse_payment_response(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe { payments::indy_parse_payment_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
}
pub fn prepare_extra_with_acceptance_data(extra_json: Option<&str>,
text: Option<&str>,
version: Option<&str>,
taa_digest: Option<&str>,
mechanism: &str,
time: u64) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _prepare_extra_with_acceptance_data(command_handle, extra_json, text, version, taa_digest, mechanism, time, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _prepare_extra_with_acceptance_data(command_handle: CommandHandle,
extra_json: Option<&str>,
text: Option<&str>,
version: Option<&str>,
taa_digest: Option<&str>,
mechanism: &str,
time: u64,
cb: Option<ResponseStringCB>) -> ErrorCode {
let extra_str = opt_c_str!(extra_json);
let text_str = opt_c_str!(text);
let version_str = opt_c_str!(version);
let taa_digest_str = opt_c_str!(taa_digest);
let mechanism = c_str!(mechanism);
ErrorCode::from(unsafe {
payments::indy_prepare_payment_extra_with_acceptance_data(command_handle,
opt_c_ptr!(extra_json, extra_str),
opt_c_ptr!(text, text_str),
opt_c_ptr!(version, version_str),
opt_c_ptr!(taa_digest, taa_digest_str),
mechanism.as_ptr(),
time,
cb)
})
}
pub fn build_mint_req(wallet_handle: WalletHandle, submitter_did: Option<&str>, outputs_json: &str, extra: Option<&str>) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
let err = _build_mint_req(command_handle, wallet_handle, submitter_did, outputs_json, extra, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _build_mint_req(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, outputs_json: &str, extra: Option<&str>, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let outputs_json = c_str!(outputs_json);
let extra_str = opt_c_str!(extra);
ErrorCode::from(unsafe { payments::indy_build_mint_req(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), outputs_json.as_ptr(), opt_c_ptr!(extra, extra_str), cb) })
}
pub fn build_set_txn_fees_req(wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_method: &str, fees_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _build_set_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, fees_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _build_set_txn_fees_req(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_method: &str, fees_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let payment_method = c_str!(payment_method);
let fees_json = c_str!(fees_json);
ErrorCode::from(unsafe { payments::indy_build_set_txn_fees_req(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), payment_method.as_ptr(), fees_json.as_ptr(), cb) })
}
pub fn build_get_txn_fees_req(wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_method: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _build_get_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _build_get_txn_fees_req(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, payment_method: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let payment_method = c_str!(payment_method);
ErrorCode::from(unsafe { payments::indy_build_get_txn_fees_req(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), payment_method.as_ptr(), cb) })
}
pub fn parse_get_txn_fees_response(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _parse_get_txn_fees_response(command_handle, payment_method, resp_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _parse_get_txn_fees_response(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe { payments::indy_parse_get_txn_fees_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
}
pub fn build_verify_payment_req(wallet_handle: WalletHandle, submitter_did: Option<&str>, receipt: &str) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
let err = _build_verify_req(command_handle, wallet_handle, submitter_did, receipt, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _build_verify_req(command_handle: CommandHandle, wallet_handle: WalletHandle, submitter_did: Option<&str>, receipt: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let submitter_did_str = opt_c_str!(submitter_did);
let receipt = c_str!(receipt);
ErrorCode::from(unsafe {
payments::indy_build_verify_payment_req(command_handle, wallet_handle, opt_c_ptr!(submitter_did, submitter_did_str), receipt.as_ptr(), cb)
})
}
pub fn parse_verify_payment_response(payment_method: &str, resp_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _parse_verify_response(command_handle, payment_method, resp_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _parse_verify_response(command_handle: CommandHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let payment_method = c_str!(payment_method);
let resp_json = c_str!(resp_json);
ErrorCode::from(unsafe {
payments::indy_parse_verify_payment_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb)
})
}
pub fn get_request_info(get_auth_rule_resp_json: &str, requester_info_json: &str, fees_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _get_request_info(command_handle, get_auth_rule_resp_json, requester_info_json, fees_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _get_request_info(command_handle: CommandHandle, get_auth_rule_resp_json: &str, requester_info_json: &str, fees_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let get_auth_rule_resp_json = c_str!(get_auth_rule_resp_json);
let requester_info_json = c_str!(requester_info_json);
let fees_json = c_str!(fees_json);
ErrorCode::from(unsafe {
payments::indy_get_request_info(command_handle, get_auth_rule_resp_json.as_ptr(), requester_info_json.as_ptr(), fees_json.as_ptr(), cb)
})
}
pub fn sign_with_address(wallet_handle: WalletHandle, address: &str, message: &[u8]) -> Box<dyn Future<Item=Vec<u8>, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_slice();
let err = _sign_with_address(command_handle, wallet_handle, address, message, cb);
ResultHandler::slice(command_handle, err, receiver)
}
fn _sign_with_address(command_handle: CommandHandle, wallet_handle: WalletHandle, address: &str, message: &[u8], cb: Option<ResponseSliceCB>) -> ErrorCode {
let address = c_str!(address);
ErrorCode::from(unsafe {
payments::indy_sign_with_address(command_handle, wallet_handle, address.as_ptr(),
message.as_ptr() as *const u8,
message.len() as u32,
cb)
})
}
pub fn verify_with_address(address: &str, message: &[u8], signature: &[u8]) -> Box<dyn Future<Item=bool, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_bool();
let err = _verify_with_address(command_handle, address, message, signature, cb);
ResultHandler::bool(command_handle, err, receiver)
}
fn _verify_with_address(command_handle: CommandHandle, address: &str, message: &[u8], signature: &[u8], cb: Option<ResponseBoolCB>) -> ErrorCode {
let address = c_str!(address);
ErrorCode::from(unsafe {
payments::indy_verify_with_address(command_handle, address.as_ptr(),
message.as_ptr() as *const u8, message.len() as u32,
signature.as_ptr() as *const u8, signature.len() as u32,
cb)
})
}