use {ErrorCode, IndyError};
use std::ffi::CString;
use futures::Future;
use ffi::did;
use ffi::{ResponseEmptyCB,
ResponseStringCB,
ResponseStringStringCB};
use utils::callbacks::{ClosureHandler, ResultHandler};
use {CommandHandle, WalletHandle, PoolHandle};
pub fn create_and_store_my_did(wallet_handle: WalletHandle, did_json: &str) -> Box<dyn Future<Item=(String, String), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
let err = _create_and_store_my_did(command_handle, wallet_handle, did_json, cb);
ResultHandler::str_str(command_handle, err, receiver)
}
fn _create_and_store_my_did(command_handle: CommandHandle, wallet_handle: WalletHandle, did_json: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let did_json = c_str!(did_json);
ErrorCode::from(unsafe { did::indy_create_and_store_my_did(command_handle, wallet_handle, did_json.as_ptr(), cb) })
}
pub fn replace_keys_start(wallet_handle: WalletHandle, tgt_did: &str, identity_json: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _replace_keys_start(command_handle, wallet_handle, tgt_did, identity_json, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _replace_keys_start(command_handle: CommandHandle, wallet_handle: WalletHandle, tgt_did: &str, identity_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let tgt_did = c_str!(tgt_did);
let identity_json = c_str!(identity_json);
ErrorCode::from(unsafe { did::indy_replace_keys_start(command_handle, wallet_handle, tgt_did.as_ptr(), identity_json.as_ptr(), cb) })
}
pub fn replace_keys_apply(wallet_handle: WalletHandle, tgt_did: &str) -> Box<dyn Future<Item=(), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
let err = _replace_keys_apply(command_handle, wallet_handle, tgt_did, cb);
ResultHandler::empty(command_handle, err, receiver)
}
fn _replace_keys_apply(command_handle: CommandHandle, wallet_handle: WalletHandle, tgt_did: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
let tgt_did = c_str!(tgt_did);
ErrorCode::from(unsafe { did::indy_replace_keys_apply(command_handle, wallet_handle, tgt_did.as_ptr(), cb) })
}
pub fn store_their_did(wallet_handle: WalletHandle, identity_json: &str) -> Box<dyn Future<Item=(), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
let err = _store_their_did(command_handle, wallet_handle, identity_json, cb);
ResultHandler::empty(command_handle, err, receiver)
}
fn _store_their_did(command_handle: CommandHandle, wallet_handle: WalletHandle, identity_json: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
let identity_json = c_str!(identity_json);
ErrorCode::from(unsafe { did::indy_store_their_did(command_handle, wallet_handle, identity_json.as_ptr(), cb) })
}
pub fn key_for_did(pool_handle: PoolHandle, wallet_handle: WalletHandle, did: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _key_for_did(command_handle, pool_handle, wallet_handle, did, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _key_for_did(command_handle: CommandHandle, pool_handle: PoolHandle, wallet_handle: WalletHandle, did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let did = c_str!(did);
ErrorCode::from(unsafe { did::indy_key_for_did(command_handle, pool_handle, wallet_handle, did.as_ptr(), cb) })
}
pub fn key_for_local_did(wallet_handle: WalletHandle, did: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _key_for_local_did(command_handle, wallet_handle, did, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _key_for_local_did(command_handle: CommandHandle, wallet_handle: WalletHandle, did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let did = c_str!(did);
ErrorCode::from(unsafe { did::indy_key_for_local_did(command_handle, wallet_handle, did.as_ptr(), cb) })
}
pub fn set_endpoint_for_did(wallet_handle: WalletHandle, did: &str, address: &str, transport_key: &str) -> Box<dyn Future<Item=(), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
let err = _set_endpoint_for_did(command_handle, wallet_handle, did, address, transport_key, cb);
ResultHandler::empty(command_handle, err, receiver)
}
fn _set_endpoint_for_did(command_handle: CommandHandle, wallet_handle: WalletHandle, did: &str, address: &str, transport_key: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
let did = c_str!(did);
let address = c_str!(address);
let transport_key = c_str!(transport_key);
ErrorCode::from(unsafe { did::indy_set_endpoint_for_did(command_handle, wallet_handle, did.as_ptr(), address.as_ptr(), transport_key.as_ptr(), cb) })
}
pub fn get_endpoint_for_did(wallet_handle: WalletHandle, pool_handle: PoolHandle, did: &str) -> Box<dyn Future<Item=(String, Option<String>), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_opt_string();
let err = _get_endpoint_for_did(command_handle, wallet_handle, pool_handle, did, cb);
ResultHandler::str_optstr(command_handle, err, receiver)
}
fn _get_endpoint_for_did(command_handle: CommandHandle, wallet_handle: WalletHandle, pool_handle: PoolHandle, did: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
let did = c_str!(did);
ErrorCode::from(unsafe { did::indy_get_endpoint_for_did(command_handle, wallet_handle, pool_handle, did.as_ptr(), cb) })
}
pub fn set_did_metadata(wallet_handle: WalletHandle, tgt_did: &str, metadata: &str) -> Box<dyn Future<Item=(), Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
let err = _set_did_metadata(command_handle, wallet_handle, tgt_did, metadata, cb);
ResultHandler::empty(command_handle, err, receiver)
}
fn _set_did_metadata(command_handle: CommandHandle, wallet_handle: WalletHandle, tgt_did: &str, metadata: &str, cb: Option<ResponseEmptyCB>) -> ErrorCode {
let tgt_did = c_str!(tgt_did);
let metadata = c_str!(metadata);
ErrorCode::from(unsafe { did::indy_set_did_metadata(command_handle, wallet_handle, tgt_did.as_ptr(), metadata.as_ptr(), cb) })
}
pub fn get_did_metadata(wallet_handle: WalletHandle, tgt_did: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _get_did_metadata(command_handle, wallet_handle, tgt_did, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _get_did_metadata(command_handle: CommandHandle, wallet_handle: WalletHandle, tgt_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let tgt_did = c_str!(tgt_did);
ErrorCode::from(unsafe { did::indy_get_did_metadata(command_handle, wallet_handle, tgt_did.as_ptr(), cb) })
}
pub fn get_my_did_with_metadata(wallet_handle: WalletHandle, my_did: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _get_my_did_with_metadata(command_handle, wallet_handle, my_did, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _get_my_did_with_metadata(command_handle: CommandHandle, wallet_handle: WalletHandle, my_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let my_did = c_str!(my_did);
ErrorCode::from(unsafe { did::indy_get_my_did_with_meta(command_handle, wallet_handle, my_did.as_ptr(), cb) })
}
pub fn list_my_dids_with_metadata(wallet_handle: WalletHandle) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _list_my_dids_with_metadata(command_handle, wallet_handle, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _list_my_dids_with_metadata(command_handle: CommandHandle, wallet_handle: WalletHandle, cb: Option<ResponseStringCB>) -> ErrorCode {
ErrorCode::from(unsafe { did::indy_list_my_dids_with_meta(command_handle, wallet_handle, cb) })
}
pub fn abbreviate_verkey(tgt_did: &str, verkey: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _abbreviate_verkey(command_handle, tgt_did, verkey, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _abbreviate_verkey(command_handle: CommandHandle, tgt_did: &str, verkey: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let tgt_did = c_str!(tgt_did);
let verkey = c_str!(verkey);
ErrorCode::from(unsafe { did::indy_abbreviate_verkey(command_handle, tgt_did.as_ptr(), verkey.as_ptr(), cb) })
}
pub fn qualify_did(wallet_handle: WalletHandle, did: &str, method: &str) -> Box<dyn Future<Item=String, Error=IndyError>> {
let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
let err = _qualify_did(command_handle, wallet_handle, did, method, cb);
ResultHandler::str(command_handle, err, receiver)
}
fn _qualify_did(command_handle: CommandHandle, wallet_handle: WalletHandle, did: &str, method: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
let did = c_str!(did);
let method = c_str!(method);
ErrorCode::from(unsafe { did::indy_qualify_did(command_handle, wallet_handle, did.as_ptr(), method.as_ptr(), cb) })
}