#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate num_traits;
#[macro_use]
extern crate num_derive;
#[macro_use]
mod macros;
pub mod anoncreds;
pub mod blob_storage;
pub mod crypto;
pub mod did;
pub mod ledger;
pub mod payments;
pub mod pairwise;
pub mod pool;
pub mod wallet;
pub mod utils;
pub mod native;
use std::sync::mpsc;
pub type IndyHandle = i32;
#[derive(Debug, PartialEq, Copy, Clone, FromPrimitive, ToPrimitive)]
#[repr(i32)]
#[allow(dead_code)]
pub enum ErrorCode
{
Success = 0,
CommonInvalidParam1 = 100,
CommonInvalidParam2 = 101,
CommonInvalidParam3 = 102,
CommonInvalidParam4 = 103,
CommonInvalidParam5 = 104,
CommonInvalidParam6 = 105,
CommonInvalidParam7 = 106,
CommonInvalidParam8 = 107,
CommonInvalidParam9 = 108,
CommonInvalidParam10 = 109,
CommonInvalidParam11 = 110,
CommonInvalidParam12 = 111,
CommonInvalidState = 112,
CommonInvalidStructure = 113,
CommonIOError = 114,
CommonInvalidParam13 = 115,
CommonInvalidParam14 = 116,
CommonInvalidParam15 = 117,
CommonInvalidParam16 = 118,
CommonInvalidParam17 = 119,
CommonInvalidParam18 = 120,
CommonInvalidParam19 = 121,
CommonInvalidParam20 = 122,
CommonInvalidParam21 = 123,
CommonInvalidParam22 = 124,
CommonInvalidParam23 = 125,
CommonInvalidParam24 = 126,
CommonInvalidParam25 = 127,
CommonInvalidParam26 = 128,
CommonInvalidParam27 = 129,
WalletInvalidHandle = 200,
WalletUnknownTypeError = 201,
WalletTypeAlreadyRegisteredError = 202,
WalletAlreadyExistsError = 203,
WalletNotFoundError = 204,
WalletIncompatiblePoolError = 205,
WalletAlreadyOpenedError = 206,
WalletAccessFailed = 207,
WalletInputError = 208,
WalletDecodingError = 209,
WalletStorageError = 210,
WalletEncryptionError = 211,
WalletItemNotFound = 212,
WalletItemAlreadyExists = 213,
WalletQueryError = 214,
PoolLedgerNotCreatedError = 300,
PoolLedgerInvalidPoolHandle = 301,
PoolLedgerTerminated = 302,
LedgerNoConsensusError = 303,
LedgerInvalidTransaction = 304,
LedgerSecurityError = 305,
PoolLedgerConfigAlreadyExistsError = 306,
PoolLedgerTimeout = 307,
PoolIncompatibleProtocolVersion = 308,
AnoncredsRevocationRegistryFullError = 400,
AnoncredsInvalidUserRevocIndex = 401,
AnoncredsMasterSecretDuplicateNameError = 404,
AnoncredsProofRejected = 405,
AnoncredsCredentialRevoked = 406,
AnoncredsCredDefAlreadyExistsError = 407,
UnknownCryptoTypeError = 500,
DidAlreadyExistsError = 600,
UnknownPaymentMethod = 700,
IncompatiblePaymentError = 701,
PaymentInsufficientFundsError = 702,
PaymentSourceDoesNotExistError = 703,
PaymentExtraFundsError = 705,
}
impl ErrorCode {
#[allow(non_snake_case)]
#[allow(dead_code)]
#[allow(unused)]
pub fn description(&self) -> &'static str {
match self {
CommonInvalidParam1 => "Caller passed invalid value as param 1",
CommonInvalidParam2 => "Caller passed invalid value as param 2",
CommonInvalidParam3 => "Caller passed invalid value as param 3",
CommonInvalidParam4 => "Caller passed invalid value as param 4",
CommonInvalidParam5 => "Caller passed invalid value as param 5",
CommonInvalidParam6 => "Caller passed invalid value as param 6",
CommonInvalidParam7 => "Caller passed invalid value as param 7",
CommonInvalidParam8 => "Caller passed invalid value as param 8",
CommonInvalidParam9 => "Caller passed invalid value as param 9",
CommonInvalidParam10 => "Caller passed invalid value as param 10",
CommonInvalidParam11 => "Caller passed invalid value as param 11",
CommonInvalidParam12 => "Caller passed invalid value as param 12",
CommonInvalidParam13 => "Caller passed invalid value as param 13",
CommonInvalidParam14 => "Caller passed invalid value as param 14",
CommonInvalidParam15 => "Caller passed invalid value as param 15",
CommonInvalidParam16 => "Caller passed invalid value as param 16",
CommonInvalidParam17 => "Caller passed invalid value as param 17",
CommonInvalidParam18 => "Caller passed invalid value as param 18",
CommonInvalidParam19 => "Caller passed invalid value as param 19",
CommonInvalidParam20 => "Caller passed invalid value as param 20",
CommonInvalidParam21 => "Caller passed invalid value as param 21",
CommonInvalidParam22 => "Caller passed invalid value as param 22",
CommonInvalidParam23 => "Caller passed invalid value as param 23",
CommonInvalidParam24 => "Caller passed invalid value as param 24",
CommonInvalidParam25 => "Caller passed invalid value as param 25",
CommonInvalidParam26 => "Caller passed invalid value as param 26",
CommonInvalidParam27 => "Caller passed invalid value as param 27",
CommonInvalidState => "Invalid library state was detected in runtime. It signals library bug",
CommonInvalidStructure => "Object (json, config, key, credential and etc...) passed by library caller has invalid structure",
CommonIOError => "IO Error",
WalletInvalidHandle => "Caller passed invalid wallet handle",
WalletUnknownTypeError => "Caller passed invalid wallet handle",
WalletTypeAlreadyRegisteredError => "Attempt to register already existing wallet type",
WalletAlreadyExistsError => "Attempt to create wallet with name used for another exists wallet",
WalletNotFoundError => "Requested entity id isn't present in wallet",
WalletIncompatiblePoolError => "Trying to use wallet with pool that has different name",
WalletAccessFailed => "Trying to open wallet encrypted wallet with invalid credentials",
WalletAlreadyOpenedError => "Trying to open wallet that was opened already",
WalletInputError => "Input provided to wallet operations is considered not valid",
WalletDecodingError => "Decoding of wallet data during input/output failed",
WalletStorageError => "Storage error occurred during wallet operation",
WalletEncryptionError => "Error during encryption-related operations",
WalletItemNotFound => "Requested wallet item not found",
WalletItemAlreadyExists => "Returned if wallet's add_record operation is used with record name that already exists",
WalletQueryError => "Returned if provided wallet query is invalid",
PoolLedgerNotCreatedError => "Trying to open pool ledger that wasn't created before",
PoolLedgerInvalidPoolHandle => "Caller passed invalid pool ledger handle",
PoolLedgerTerminated => "Pool ledger terminated",
LedgerNoConsensusError => "No concensus during ledger operation",
LedgerInvalidTransaction => "Attempt to send unknown or incomplete transaction message",
LedgerSecurityError => "Attempt to send transaction without the necessary privileges",
PoolLedgerConfigAlreadyExistsError => "Attempt to create pool ledger config with name used for another existing pool",
PoolLedgerTimeout => "Timeout for action",
PoolIncompatibleProtocolVersion => "Attempt to open Pool for witch Genesis Transactions are not compatible with set Protocol version. Set the correct Protocol version first.",
AnoncredsRevocationRegistryFullError => "Revocation registry is full and creation of new registry is necessary",
AnoncredsInvalidUserRevocIndex => "Invalid user revocation index",
AnoncredsMasterSecretDuplicateNameError => "Attempt to generate master secret with duplicated name",
AnoncredsProofRejected => "Proof rejected",
AnoncredsCredentialRevoked => "Credential revoked",
AnoncredsCredDefAlreadyExistsError => "Credential definition already exists",
UnknownCryptoTypeError => "Unknown format of DID entity keys",
DidAlreadyExistsError => "Did already exists",
UnknownPaymentMethod => "Unknown payment method was given",
IncompatiblePaymentError => "Multiple different payment methods were specified",
PaymentInsufficientFundsError => "Payment cannot be processed because there was insufficient funds",
PaymentSourceDoesNotExistError => "No such source on a ledger.",
PaymentExtraFundsError => "Payment cannot be processed because there were more funds than required",
}
}
pub fn is_ok(&self) -> bool {
*self == ErrorCode::Success
}
pub fn is_err(&self) -> bool {
*self != ErrorCode::Success
}
pub fn try_err(&self) -> Result<(), ErrorCode> {
if self.is_err() {
return Err(*self)
}
Ok(())
}
}
impl From<i32> for ErrorCode {
fn from(i: i32) -> Self {
let conversion = num_traits::FromPrimitive::from_i32(i);
if conversion.is_some() {
conversion.unwrap()
} else {
panic!("Unable to convert from {}, unknown error code", i)
}
}
}
impl Into<i32> for ErrorCode {
fn into(self) -> i32 {
num_traits::ToPrimitive::to_i32(&self).unwrap()
}
}
impl From<mpsc::RecvTimeoutError> for ErrorCode {
fn from(err: mpsc::RecvTimeoutError) -> Self {
match err {
mpsc::RecvTimeoutError::Timeout => {
warn!("Timed out waiting for libindy to call back");
ErrorCode::CommonIOError
},
mpsc::RecvTimeoutError::Disconnected => {
warn!("Channel to libindy was disconnected unexpectedly");
ErrorCode::CommonIOError
}
}
}
}
impl From<mpsc::RecvError> for ErrorCode {
fn from(e: mpsc::RecvError) -> Self {
warn!("Channel returned an error - {:?}", e);
ErrorCode::CommonIOError
}
}