Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OT_API Class Reference

#include <OpenTransactions.hpp>

Classes

class  Pid
 

Public Member Functions

EXPORT OT_API ()
 
EXPORT ~OT_API ()
 
EXPORT bool IsInitialized () const
 
EXPORT bool SetTransportCallback (TransportCallback *pTransportCallback)
 
EXPORT TransportCallbackGetTransportCallback () const
 
EXPORT bool TransportFunction (const OTServerContract &theServerContract, const OTEnvelope &theEnvelope) const
 
EXPORT bool GetWalletFilename (OTString &strPath) const
 
EXPORT bool SetWalletFilename (const OTString &strPath)
 
EXPORT OTWalletGetWallet (const char *szFuncName=nullptr) const
 
OTClientGetClient () const
 
EXPORT bool LoadConfigFile ()
 
EXPORT bool SetWallet (const OTString &strFilename)
 
EXPORT bool WalletExists () const
 
EXPORT bool LoadWallet () const
 
EXPORT time64_t GetTime () const
 
EXPORT bool NumList_Add (OTNumList &theList, const OTNumList &theNewNumbers) const
 
EXPORT bool NumList_Remove (OTNumList &theList, const OTNumList &theOldNumbers) const
 
EXPORT bool NumList_VerifyQuery (const OTNumList &theList, const OTNumList &theQueryNumbers) const
 
EXPORT bool NumList_VerifyAll (const OTNumList &theList, const OTNumList &theQueryNumbers) const
 
EXPORT int32_t NumList_Count (const OTNumList &theList) const
 
EXPORT int32_t GetNymCount () const
 
EXPORT int32_t GetServerCount () const
 
EXPORT int32_t GetAssetTypeCount () const
 
EXPORT int32_t GetAccountCount () const
 
EXPORT bool GetNym (int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
 
EXPORT bool GetServer (int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
 
EXPORT bool GetAssetType (int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
 
EXPORT bool GetAccount (int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
 
EXPORT OTPseudonymGetNym (const OTIdentifier &NYM_ID, const char *szFuncName=nullptr) const
 
EXPORT OTServerContractGetServer (const OTIdentifier &THE_ID, const char *szFuncName=nullptr) const
 
EXPORT OTAssetContractGetAssetType (const OTIdentifier &THE_ID, const char *szFuncName=nullptr) const
 
EXPORT OTAccountGetAccount (const OTIdentifier &THE_ID, const char *szFuncName=nullptr) const
 
EXPORT OTPseudonymGetNymByIDPartialMatch (const std::string PARTIAL_ID, const char *szFuncName=nullptr) const
 
EXPORT OTServerContractGetServerContractPartialMatch (const std::string PARTIAL_ID, const char *szFuncName=nullptr) const
 
EXPORT OTAssetContractGetAssetContractPartialMatch (const std::string PARTIAL_ID, const char *szFuncName=nullptr) const
 
EXPORT OTAccountGetAccountPartialMatch (const std::string PARTIAL_ID, const char *szFuncName=nullptr) const
 
EXPORT OTPseudonymGetOrLoadPublicNym (const OTIdentifier &NYM_ID, const char *szFuncName=nullptr) const
 
EXPORT OTPseudonymGetOrLoadPrivateNym (const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
 
EXPORT OTPseudonymGetOrLoadNym (const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
 
EXPORT OTAccountGetOrLoadAccount (const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
 
EXPORT OTAccountGetOrLoadAccount (const OTIdentifier &NYM_ID, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
 
EXPORT bool SetNym_Name (const OTIdentifier &NYM_ID, const OTIdentifier &SIGNER_NYM_ID, const OTString &NYM_NEW_NAME) const
 
EXPORT bool SetAccount_Name (const OTIdentifier &ACCT_ID, const OTIdentifier &SIGNER_NYM_ID, const OTString &ACCT_NEW_NAME) const
 
EXPORT bool SetAssetType_Name (const OTIdentifier &ASSET_ID, const OTString &STR_NEW_NAME) const
 
EXPORT bool SetServer_Name (const OTIdentifier &SERVER_ID, const OTString &STR_NEW_NAME) const
 
EXPORT OTPseudonymLoadPublicNym (const OTIdentifier &NYM_ID, const char *szFuncName=nullptr) const
 
EXPORT OTPseudonymLoadPrivateNym (const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
 
EXPORT OTPseudonymCreateNym (int32_t nKeySize=1024, const std::string str_id_source="", const std::string str_alt_location="") const
 
EXPORT bool IsNym_RegisteredAtServer (const OTIdentifier &NYM_ID, const OTIdentifier &SERVER_ID) const
 
EXPORT bool Wallet_ChangePassphrase () const
 
EXPORT bool Wallet_CanRemoveServer (const OTIdentifier &SERVER_ID) const
 
EXPORT bool Wallet_CanRemoveAssetType (const OTIdentifier &ASSET_ID) const
 
EXPORT bool Wallet_CanRemoveNym (const OTIdentifier &NYM_ID) const
 
EXPORT bool Wallet_CanRemoveAccount (const OTIdentifier &ACCOUNT_ID) const
 
EXPORT bool Wallet_RemoveServer (const OTIdentifier &SERVER_ID) const
 
EXPORT bool Wallet_RemoveAssetType (const OTIdentifier &ASSET_ID) const
 
EXPORT bool Wallet_RemoveNym (const OTIdentifier &NYM_ID) const
 
EXPORT bool Wallet_ExportNym (const OTIdentifier &NYM_ID, OTString &strOutput) const
 
EXPORT bool Wallet_ImportNym (const OTString &FILE_CONTENTS, OTIdentifier *pNymID=nullptr) const
 
EXPORT bool Wallet_ImportCert (const OTString &DISPLAY_NAME, const OTString &FILE_CONTENTS, OTIdentifier *pNymID=nullptr) const
 
EXPORT bool Wallet_ExportCert (const OTIdentifier &NYM_ID, OTString &strOutput) const
 
bool Wallet_ImportPurse (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTIdentifier &SIGNER_ID, const OTString &THE_PURSE, const OTString *pstrDisplay=nullptr)
 
EXPORT bool Encode (const OTString &strPlaintext, OTString &strOutput, bool bLineBreaks=true) const
 
EXPORT bool Decode (const OTString &strEncoded, OTString &strOutput, bool bLineBreaks=true) const
 
EXPORT bool Encrypt (const OTIdentifier &theRecipientNymID, const OTString &strPlaintext, OTString &strOutput) const
 
EXPORT bool Decrypt (const OTIdentifier &theRecipientNymID, const OTString &strCiphertext, OTString &strOutput) const
 
bool FlatSign (const OTIdentifier &theSignerNymID, const OTString &strInput, const OTString &strContractType, OTString &strOutput) const
 
EXPORT bool SignContract (const OTIdentifier &theSignerNymID, const OTString &strContract, OTString &strOutput) const
 
EXPORT bool AddSignature (const OTIdentifier &theSignerNymID, const OTString &strContract, OTString &strOutput) const
 
EXPORT bool VerifySignature (const OTString &strContract, const OTIdentifier &theSignerNymID, OTContract **ppContract=nullptr) const
 
EXPORT bool VerifyAndRetrieveXMLContents (const OTString &strContract, const OTIdentifier &theSignerNymID, OTString &strOutput)
 Verify and Retrieve XML Contents. More...
 
EXPORT bool VerifyAccountReceipt (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTChequeWriteCheque (const OTIdentifier &SERVER_ID, const int64_t &CHEQUE_AMOUNT, const time64_t &VALID_FROM, const time64_t &VALID_TO, const OTIdentifier &SENDER_ACCT_ID, const OTIdentifier &SENDER_USER_ID, const OTString &CHEQUE_MEMO, const OTIdentifier *pRECIPIENT_USER_ID=nullptr) const
 
EXPORT bool DiscardCheque (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const OTString &THE_CHEQUE) const
 
EXPORT OTPaymentPlanProposePaymentPlan (const OTIdentifier &SERVER_ID, const time64_t &VALID_FROM, const time64_t &VALID_TO, const OTIdentifier &SENDER_ACCT_ID, const OTIdentifier &SENDER_USER_ID, const OTString &PLAN_CONSIDERATION, const OTIdentifier &RECIPIENT_ACCT_ID, const OTIdentifier &RECIPIENT_USER_ID, const int64_t &INITIAL_PAYMENT_AMOUNT, const time64_t &INITIAL_PAYMENT_DELAY, const int64_t &PAYMENT_PLAN_AMOUNT, const time64_t &PAYMENT_PLAN_DELAY, const time64_t &PAYMENT_PLAN_PERIOD, time64_t PAYMENT_PLAN_LENGTH=OT_TIME_ZERO, int32_t PAYMENT_PLAN_MAX_PAYMENTS=0) const
 
EXPORT bool ConfirmPaymentPlan (const OTIdentifier &SERVER_ID, const OTIdentifier &SENDER_USER_ID, const OTIdentifier &SENDER_ACCT_ID, const OTIdentifier &RECIPIENT_USER_ID, OTPaymentPlan &thePlan) const
 
EXPORT PurseLoadPurse (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &USER_ID, const OTString *pstrDisplay=nullptr) const
 
EXPORT bool SavePurse (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &USER_ID, Purse &THE_PURSE) const
 
EXPORT PurseCreatePurse (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &OWNER_ID) const
 
EXPORT PurseCreatePurse_Passphrase (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID) const
 
EXPORT OTNym_or_SymmetricKeyLoadPurseAndOwnerFromString (const OTIdentifier &theServerID, const OTIdentifier &theAssetTypeID, const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bForEncrypting=true, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay1=nullptr, const OTString *pstrDisplay2=nullptr) const
 
EXPORT OTNym_or_SymmetricKeyLoadPurseAndOwnerForMerge (const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bCanBePublic=false, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
 
EXPORT TokenPurse_Peek (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTString &THE_PURSE, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
 
EXPORT PursePurse_Pop (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTString &THE_PURSE, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
 
EXPORT PursePurse_Empty (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTString &THE_PURSE, const OTString *pstrDisplay=nullptr) const
 
EXPORT PursePurse_Push (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTString &THE_PURSE, const OTString &THE_TOKEN, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
 
EXPORT TokenToken_ChangeOwner (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTString &THE_TOKEN, const OTIdentifier &SIGNER_NYM_ID, const OTString &OLD_OWNER, const OTString &NEW_OWNER, const OTString *pstrDisplay=nullptr) const
 
EXPORT MintLoadMint (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID) const
 
EXPORT OTAssetContractLoadAssetContract (const OTIdentifier &ASSET_ID) const
 
EXPORT OTServerContractLoadServerContract (const OTIdentifier &SERVER_ID) const
 
EXPORT bool IsBasketCurrency (const OTIdentifier &BASKET_ASSET_TYPE_ID) const
 
EXPORT int64_t GetBasketMinimumTransferAmount (const OTIdentifier &BASKET_ASSET_TYPE_ID) const
 
EXPORT int32_t GetBasketMemberCount (const OTIdentifier &BASKET_ASSET_TYPE_ID) const
 
EXPORT bool GetBasketMemberType (const OTIdentifier &BASKET_ASSET_TYPE_ID, int32_t nIndex, OTIdentifier &theOutputMemberType) const
 
EXPORT int64_t GetBasketMemberMinimumTransferAmount (const OTIdentifier &BASKET_ASSET_TYPE_ID, int32_t nIndex) const
 
EXPORT OTAccountLoadAssetAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadNymbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT OTLedgerLoadNymboxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT OTLedgerLoadInbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadInboxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadOutbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadOutboxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadPaymentInbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT OTLedgerLoadPaymentInboxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT OTLedgerLoadRecordBox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT OTLedgerLoadRecordBoxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT bool ClearRecord (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, int32_t nIndex, bool bClearAll=false) const
 
EXPORT OTLedgerLoadExpiredBox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT OTLedgerLoadExpiredBoxNoVerify (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT bool ClearExpired (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, int32_t nIndex, bool bClearAll=false) const
 
EXPORT bool RecordPayment (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, bool bIsInbox, int32_t nIndex, bool bSaveCopy) const
 
EXPORT bool DoesBoxReceiptExist (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, int32_t nBoxType, const int64_t &lTransactionNum) const
 
EXPORT OTMessagePopMessageBuffer (const int64_t &lRequestNumber, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
void FlushMessageBuffer ()
 
EXPORT OTMessageGetSentMessage (const int64_t &lRequestNumber, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT bool RemoveSentMessage (const int64_t &lRequestNumber, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT void FlushSentMessages (bool bHarvestingForRetry, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTLedger &THE_NYMBOX) const
 
EXPORT bool HaveAlreadySeenReply (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const int64_t &lRequestNumber) const
 
EXPORT bool ResyncNymWithServer (OTPseudonym &theNym, const OTLedger &theNymbox, const OTPseudonym &theMessageNym) const
 
EXPORT int32_t checkServerID (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t createUserAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t deleteUserAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t checkUser (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &USER_ID_CHECK) const
 
EXPORT int32_t usageCredits (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &USER_ID_CHECK, int64_t lAdjustment=0) const
 
EXPORT int32_t getRequest (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t sendUserMessage (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &USER_ID_RECIPIENT, const OTString &RECIPIENT_PUBKEY, const OTString &THE_MESSAGE) const
 
EXPORT int32_t sendUserInstrument (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &USER_ID_RECIPIENT, const OTString &RECIPIENT_PUBKEY, const OTPayment &THE_INSTRUMENT, const OTPayment *pINSTRUMENT_FOR_SENDER=nullptr) const
 
EXPORT int32_t issueAssetType (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTString &THE_CONTRACT) const
 
EXPORT int32_t getContract (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ASSET_ID) const
 
EXPORT int32_t getMint (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ASSET_ID) const
 
EXPORT int32_t getBoxReceipt (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, int32_t nBoxType, const int64_t &lTransactionNum) const
 
EXPORT int32_t queryAssetTypes (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTASCIIArmor &ENCODED_MAP) const
 
EXPORT int32_t createAssetAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ASSET_ID) const
 
EXPORT int32_t deleteAssetAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
 
EXPORT int32_t getAccount (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID) const
 
EXPORT int32_t getAccountFiles (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID) const
 
EXPORT BasketGenerateBasketCreation (const OTIdentifier &USER_ID, int64_t MINIMUM_TRANSFER) const
 
EXPORT bool AddBasketCreationItem (const OTIdentifier &USER_ID, Basket &theBasket, const OTIdentifier &ASSET_TYPE_ID, int64_t MINIMUM_TRANSFER) const
 
EXPORT int32_t issueBasket (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTString &BASKET_INFO) const
 
EXPORT BasketGenerateBasketExchange (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &BASKET_ASSET_TYPE_ID, const OTIdentifier &BASKET_ASSET_ACCT_ID, int32_t TRANSFER_MULTIPLE) const
 
EXPORT bool AddBasketExchangeItem (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, Basket &theBasket, const OTIdentifier &ASSET_TYPE_ID, const OTIdentifier &ASSET_ACCT_ID) const
 
EXPORT int32_t exchangeBasket (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &BASKET_ASSET_ID, const OTString &BASKET_INFO, bool bExchangeInOrOut) const
 
EXPORT int32_t getTransactionNumber (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t notarizeWithdrawal (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const int64_t &AMOUNT) const
 
EXPORT int32_t notarizeDeposit (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const OTString &THE_PURSE) const
 
EXPORT int32_t notarizeTransfer (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_FROM, const OTIdentifier &ACCT_TO, const int64_t &AMOUNT, const OTString &NOTE) const
 
EXPORT int32_t getNymbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t getInbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID) const
 
EXPORT int32_t getOutbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID) const
 
EXPORT int32_t processNymbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t processInbox (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const OTString &ACCT_LEDGER) const
 
EXPORT int32_t withdrawVoucher (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const OTIdentifier &RECIPIENT_USER_ID, const OTString &CHEQUE_MEMO, const int64_t &AMOUNT) const
 
EXPORT int32_t payDividend (const OTIdentifier &SERVER_ID, const OTIdentifier &ISSUER_USER_ID, const OTIdentifier &DIVIDEND_FROM_ACCT_ID, const OTIdentifier &SHARES_ASSET_TYPE_ID, const OTString &DIVIDEND_MEMO, const int64_t &AMOUNT_PER_SHARE) const
 
EXPORT int32_t depositCheque (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCT_ID, const OTString &THE_CHEQUE) const
 
EXPORT int32_t triggerClause (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const int64_t &lTransactionNum, const OTString &strClauseName, const OTString *pStrParam=nullptr) const
 
EXPORT bool Create_SmartContract (const OTIdentifier &SIGNER_NYM_ID, time64_t VALID_FROM, time64_t VALID_TO, OTString &strOutput) const
 
EXPORT bool SmartContract_AddBylaw (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &BYLAW_NAME, OTString &strOutput) const
 
EXPORT bool SmartContract_AddClause (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &BYLAW_NAME, const OTString &CLAUSE_NAME, const OTString &SOURCE_CODE, OTString &strOutput) const
 
EXPORT bool SmartContract_AddVariable (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &BYLAW_NAME, const OTString &VAR_NAME, const OTString &VAR_ACCESS, const OTString &VAR_TYPE, const OTString &VAR_VALUE, OTString &strOutput) const
 
EXPORT bool SmartContract_AddCallback (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &BYLAW_NAME, const OTString &CALLBACK_NAME, const OTString &CLAUSE_NAME, OTString &strOutput) const
 
EXPORT bool SmartContract_AddHook (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &BYLAW_NAME, const OTString &HOOK_NAME, const OTString &CLAUSE_NAME, OTString &strOutput) const
 
EXPORT bool SmartContract_AddParty (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &PARTY_NAME, const OTString &AGENT_NAME, OTString &strOutput) const
 
EXPORT bool SmartContract_AddAccount (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &PARTY_NAME, const OTString &ACCT_NAME, const OTString &ASSET_TYPE_ID, OTString &strOutput) const
 
EXPORT int32_t SmartContract_CountNumsNeeded (const OTString &THE_CONTRACT, const OTString &AGENT_NAME) const
 
EXPORT bool SmartContract_ConfirmAccount (const OTString &THE_CONTRACT, const OTIdentifier &SIGNER_NYM_ID, const OTString &PARTY_NAME, const OTString &ACCT_NAME, const OTString &AGENT_NAME, const OTString &ACCT_ID, OTString &strOutput) const
 
EXPORT bool SmartContract_ConfirmParty (const OTString &THE_CONTRACT, const OTString &PARTY_NAME, const OTIdentifier &NYM_ID, OTString &strOutput) const
 
EXPORT bool Msg_HarvestTransactionNumbers (const OTMessage &theMsg, const OTIdentifier &USER_ID, bool bHarvestingForRetry, bool bReplyWasSuccess, bool bReplyWasFailure, bool bTransactionWasSuccess, bool bTransactionWasFailure) const
 
EXPORT bool HarvestClosingNumbers (const OTIdentifier &SERVER_ID, const OTIdentifier &NYM_ID, const OTString &THE_CRON_ITEM) const
 
EXPORT bool HarvestAllNumbers (const OTIdentifier &SERVER_ID, const OTIdentifier &NYM_ID, const OTString &THE_CRON_ITEM) const
 
EXPORT int32_t activateSmartContract (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTString &THE_SMART_CONTRACT) const
 
EXPORT int32_t depositPaymentPlan (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTString &THE_PAYMENT_PLAN) const
 
EXPORT int32_t issueMarketOffer (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ASSET_ACCT_ID, const OTIdentifier &CURRENCY_ACCT_ID, const int64_t &MARKET_SCALE, const int64_t &MINIMUM_INCREMENT, const int64_t &TOTAL_ASSETS_ON_OFFER, const int64_t &PRICE_LIMIT, bool bBuyingOrSelling, time64_t tLifespanInSeconds=OT_TIME_DAY_IN_SECONDS, char STOP_SIGN=0, int64_t ACTIVATION_PRICE=0) const
 
EXPORT int32_t getMarketList (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t getMarketOffers (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &MARKET_ID, const int64_t &lDepth) const
 
EXPORT int32_t getMarketRecentTrades (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &MARKET_ID) const
 
EXPORT int32_t getNym_MarketOffers (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
 
EXPORT int32_t cancelCronItem (const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ASSET_ACCT_ID, const int64_t &lTransactionNum) const
 
EXPORT void AddServerContract (const OTServerContract &pContract) const
 
EXPORT void AddAssetContract (const OTAssetContract &theContract) const
 

Static Public Member Functions

static EXPORT bool InitOTApp ()
 
static EXPORT bool CleanupOTApp ()
 

Detailed Description

Definition at line 179 of file OpenTransactions.hpp.

Constructor & Destructor Documentation

opentxs::OT_API::OT_API ( )

Definition at line 626 of file OpenTransactions.cpp.

627  : m_pPid(new Pid())
628  , m_bInitialized(false)
629  , m_pTransportCallback(nullptr)
630  , m_pSocket(new OTSocket_ZMQ_4())
631  , m_strDataPath("")
632  , m_strWalletFilename("")
633  , m_strWalletFilePath("")
634  , m_strConfigFilename("")
635  , m_strConfigFilePath("")
636  , m_pWallet(nullptr)
637  , m_pClient(nullptr)
638 
639 {
640  if (!Init()) {
641  Cleanup();
642  }
643 }
opentxs::OT_API::~OT_API ( )

Definition at line 645 of file OpenTransactions.cpp.

646 {
647  // DELETE AND SET nullptr
648  //
649  if (nullptr != m_pSocket) delete m_pSocket;
650  m_pSocket = nullptr;
651 
652  if (nullptr != m_pTransportCallback) delete m_pTransportCallback;
653  m_pTransportCallback = nullptr;
654  if (nullptr != m_pWallet) delete m_pWallet;
655  m_pWallet = nullptr;
656  if (nullptr != m_pClient) delete m_pClient;
657  m_pClient = nullptr;
658 
659  if (m_bInitialized)
660  if (!(Cleanup())) // we only cleanup if we need to
661  {
662  OT_FAIL;
663  }
664 
665  // this must be last!
666  if (nullptr != m_pPid) delete m_pPid;
667 }
#define OT_FAIL
Definition: Assert.hpp:139

Member Function Documentation

int32_t opentxs::OT_API::activateSmartContract ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTString THE_SMART_CONTRACT 
) const

Definition at line 11142 of file OpenTransactions.cpp.

11145 {
11146  OTPseudonym* pNym = GetOrLoadPrivateNym(
11147  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
11148  if (nullptr == pNym) return (-1);
11149  // By this point, pNym is a good pointer, and is on the wallet.
11150  // (No need to cleanup.)
11151  OTServerContract* pServer =
11152  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
11153  if (nullptr == pServer) return (-1);
11154  // By this point, pServer is a good pointer. (No need to cleanup.)
11155  OTSmartContract theContract(SERVER_ID);
11156  OTMessage theMessage;
11157  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
11158 
11159  if (theContract.LoadContractFromString(THE_SMART_CONTRACT)) {
11160  int64_t lRequestNumber = 0;
11161  OTAgent* pAgent = nullptr;
11162  OTParty* pParty =
11163  theContract.FindPartyBasedOnNymAsAuthAgent(*pNym, &pAgent);
11164  if (nullptr == pParty) {
11165  otOut << __FUNCTION__
11166  << ": Failure: USER_ID *IS* a valid Nym, but that "
11167  "Nym is not the authorizing agent for any "
11168  "of the parties on this contract. Try calling "
11169  "ConfirmParty() first.\n";
11170  return (-1);
11171  }
11172  OT_ASSERT(nullptr != pAgent);
11173  //
11174  // BELOW THIS POINT, pAgent and pParty are both valid, and no need to
11175  // clean them up.
11176  // Note: Usually, payment plan or market offer will load up the Nym and
11177  // accounts,
11178  // and verify ownership, etc.
11179  // But in this case, the Nym who actually activates the smart contract
11180  // is merely
11181  // the authorizing agent for a single party, where there may be a dozen
11182  // parties listed
11183  // on the actual contract.
11184  //
11185  // It would be unreasonable to expect a party to have EVERY nym and
11186  // EVERY account
11187  // to the entire contract. As long as the Nym is legitimately the
11188  // authorizing agent
11189  // for one of the parties, then we allow him to send the activation
11190  // message to the server.
11191  //
11192  // (Let the server sort out the trouble of loading all the nyms, loading
11193  // all the accounts,
11194  // verifying all the asset type IDs, verifying all the agent names,
11195  // making sure there
11196  // are no stashes already created, ETC ETC.)
11197  //
11198  // ONE THING I should verify, is that all of the parties are confirmed.
11199  // I mean, it's not
11200  // even worth the bother to send the damn thing until then, right? And
11201  // the Server ID.
11202  //
11203 
11204  if (false ==
11205  theContract.AllPartiesHaveSupposedlyConfirmed()) // all parties are
11206  // NOT confirmed.
11207  {
11208  // otOut << __FUNCTION__ << ": Failed. EACH PARTY to this
11209  // smart contract needs to CONFIRM IT FIRST, before one of them "
11210  // "then activates it at the server. (But
11211  // THIS smart contract has NOT yet been confirmed, at least, "
11212  // "not by all of its parties.)\n";
11213  // return -1;
11214 
11215  // UPDATE: This is now how we will trigger the "cancel smart
11216  // contract" functionality, which can
11217  // only be performed BEFORE the contract has been activated.
11218 
11219  otOut << "Not all parties to smart contract are "
11220  "confirmed. Treating this as a request for "
11221  "cancelation...\n";
11222 
11223  if (theContract.IsCanceled()) {
11224  otErr << __FUNCTION__
11225  << ": Error: attempted to cancel (pre-emptively, "
11226  "before activation) a smart contract "
11227  "that was already set as canceled.\n";
11228  return (-1);
11229  }
11230  else if (!theContract.CancelBeforeActivation(
11231  *pNym)) // sets as canceler, releases signatures,
11232  // signs, saves.
11233  {
11234  otErr << __FUNCTION__
11235  << ": Error: attempted to cancel (pre-emptively, "
11236  "before activation) a smart contract, "
11237  "but the attempt somehow failed.\n";
11238  return (-1);
11239  }
11240  }
11241  if (SERVER_ID != theContract.GetServerID()) {
11242  otOut << __FUNCTION__
11243  << ": Failed. The server ID passed in doesn't "
11244  "match the one on the contract itself.\n";
11245  return -1;
11246  }
11247  if (!(pParty->GetAccountCount() > 0)) {
11248  otOut << __FUNCTION__
11249  << ": Failed. The activating Nym must not only be "
11250  "the authorizing agent for one of the parties, "
11251  "but must also be the authorized agent for one of "
11252  "that party's asset accounts. That party must have "
11253  "at least one asset account "
11254  "for this reason. (See code comment below this "
11255  "message, in the code.)\n";
11256  return -1;
11257  }
11258  //
11259  // REQUIREMENT: The ACTIVATOR aka the Originator Nym (the party who
11260  // activates the smart
11261  // contract on the server) must have at least one asset account as part
11262  // of the smart contract,
11263  // for which the authorizing agent for that party is also the authorized
11264  // agent for that account.
11265  // This is in order to make sure that the smart contracts will work with
11266  // the existing infrastructure,
11267  // so that functions like "GetOpeningNumber()" and "GetClosingNumber()"
11268  // will continue to work the way
11269  // they are expected to, and so that there is always at least ONE
11270  // closing transaction number supplied
11271  // for the smart contract (at least ONE finalReceipt will actually have
11272  // to be signed for once it is
11273  // deactivated) and so we can know who the owner of that account, and
11274  // what acct # it will be.
11275  //
11276  // This is also a requirement because the existing infrastructure uses
11277  // the transaction system for
11278  // activating cron items. It was simply not anticipated in the past that
11279  // cron items, based on valid
11280  // transactions, wouldn't also therefore be associated with at least one
11281  // asset account. In fact,
11282  // the original difference between transactions (vs normal messages) was
11283  // that transactions dealt
11284  // with asset accounts, whereas normal messages did not. (Such as,
11285  // "checkUser" or "getRequest".)
11286  //
11287  // A big piece of this is the BALANCE AGREEMENT. Obviously it wasn't
11288  // anticipated that "balance
11289  // agreements" would ever be needed for transactions, yet asset accounts
11290  // wouldn't be. So the below
11291  // TRANSACTION STATEMENT, for example, expects an asset account, as does
11292  // the verification code
11293  // associated with it. Even transaction statements were originally made
11294  // for situations where the balance
11295  // wasn't actually changing, (and so a balance agreement wasn't needed),
11296  // but where a signature on
11297  // the transaction numbers was still necessary, since one had to be
11298  // burned in order to prove that
11299  // the instrument was valid.
11300  //
11301  // Unfortunately, transaction statements still expected an asset account
11302  // to at least EXIST, since
11303  // they involved market offers (which do not immediately change the
11304  // balance) or payment plans
11305  // (which also do not immediately change the balance.) Yet the account's
11306  // ID was still at least
11307  // present in the receipt, and a transaction # was still used.
11308  //
11309  // In the case of smart contracts, I will probably someday lift this
11310  // restriction (that the activating
11311  // nym must also be the authorized agent on one of the asset accounts on
11312  // the smart contract). But I
11313  // will have to go over all the plumbing first and deal with that. In
11314  // the meantime:
11315  //
11316  // --- THE ACTIVATING NYM *MUST* ALSO BE THE AUTHORIZED AGENT
11317  // FOR AT LEAST ONE ASSET ACCOUNT, FOR THAT PARTY. ---
11318  //
11319 
11320  const std::string str_agent_name(pAgent->GetName().Get());
11321  OTPartyAccount* pAcct = pParty->GetAccountByAgent(str_agent_name);
11322 
11323  if (nullptr == pAcct) {
11324  otOut << __FUNCTION__
11325  << ": Failed. The activating Nym must not only be "
11326  "the authorizing agent for one of the parties, "
11327  "but must also be the authorized agent for one of "
11328  "that party's asset accounts. That party must have "
11329  "at least one asset account "
11330  "for this reason. (See code comment above this "
11331  "message, in the code.)\n";
11332  return -1;
11333  }
11334  const OTString& strAcctID = pAcct->GetAcctID();
11335 
11336  if (!strAcctID.Exists()) {
11337  otOut << __FUNCTION__
11338  << ": Failed. The Account ID is blank for asset acct ("
11339  << pAcct->GetName() << ") for party ("
11340  << pParty->GetPartyName()
11341  << "). Did you confirm this account, before trying to "
11342  "activate this contract?\n";
11343  return -1;
11344  }
11345  OTIdentifier theAcctID(strAcctID);
11346  const int64_t lOpeningTransNo = pParty->GetOpeningTransNo();
11347  const int64_t lClosingTransNo = pAcct->GetClosingTransNo();
11348 
11349  if ((lOpeningTransNo <= 0) || (lClosingTransNo <= 0)) {
11350  otOut << __FUNCTION__ << ": Failed. Opening Transaction # ("
11351  << lOpeningTransNo << ") or "
11352  "Closing # (" << lClosingTransNo
11353  << ") were invalid "
11354  "for asset acct (" << pAcct->GetName() << ") for party ("
11355  << pParty->GetPartyName()
11356  << "). Did you "
11357  "confirm this account and party, before trying to "
11358  "activate this contract?\n";
11359  return -1;
11360  }
11361  if (!pNym->VerifyIssuedNum(strServerID, lOpeningTransNo)) {
11362  otOut << __FUNCTION__ << ": Failed. Opening Transaction # ("
11363  << lOpeningTransNo << ") wasn't "
11364  "valid/issued to this Nym, "
11365  "for asset acct (" << pAcct->GetName()
11366  << ") for party (" << pParty->GetPartyName() << ") on server "
11367  "("
11368  << strServerID
11369  << "). Did you confirm this account and party, "
11370  "before trying to activate this contract?\n";
11371  return -1;
11372  }
11373  if (!pNym->VerifyIssuedNum(strServerID, lClosingTransNo)) {
11374  otOut << __FUNCTION__ << ": Failed. Closing Transaction # ("
11375  << lClosingTransNo << ") wasn't "
11376  "issued to this Nym, "
11377  "for asset acct (" << pAcct->GetName()
11378  << ") for party (" << pParty->GetPartyName()
11379  << "). Did you "
11380  "confirm this account and party, "
11381  "before trying to activate this contract?\n";
11382  return -1;
11383  }
11384  // These numbers (the opening and closing transaction #s) were already
11385  // available on
11386  // the smart contract -- specifically an opening number is stored for
11387  // each party,
11388  // taken from the authorizing agent for that party, and a closing number
11389  // is stored for
11390  // each asset account, taken from the authorized agent for that asset
11391  // account.
11392  //
11393  // Now we set the appropriate opening/closing number onto the smart
11394  // contract, in the way
11395  // of the existing CronItem system, so that it will work properly within
11396  // that infrastructure.
11397  // (This is what makes the activating Nym slightly different / more than
11398  // the other authorizing
11399  // agent nyms for each party to the contract. Not only does it have
11400  // opening/closing numbers
11401  // on its party like all the others, but its numbers are also those used
11402  // for the cron item itself.)
11403  //
11404  theContract.PrepareToActivate(lOpeningTransNo, lClosingTransNo, USER_ID,
11405  theAcctID);
11406  // This call changes the contract slightly, so it must be re-signed (in
11407  // order to save changes.)
11408  theContract.ReleaseSignatures();
11409 
11410  if (!pAgent->SignContract(theContract)) // RE-SIGN HERE.
11411  {
11412  otErr << __FUNCTION__
11413  << ": Failed re-signing contract, after calling "
11414  "PrepareToActivate().\n";
11415  return -1;
11416  }
11417 
11418  theContract.SaveContract();
11419  const OTString strContract(theContract); // Grab a string version of the
11420  // latest signed contract.
11421  // Create a transaction
11422  //
11423  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
11424  USER_ID, theAcctID, SERVER_ID, OTTransaction::smartContract,
11425  theContract.GetTransactionNum());
11426 
11427  // set up the transaction item (each transaction may have multiple
11428  // items...)
11429  OTItem* pItem = OTItem::CreateItemFromTransaction(
11430  *pTransaction, OTItem::smartContract);
11431 
11432  // Add the smart contract string as the attachment on the transaction
11433  // item.
11434  pItem->SetAttachment(strContract);
11435 
11436  // sign the item
11437  pItem->SignContract(*pNym);
11438  pItem->SaveContract();
11439 
11440  // the Transaction "owns" the item now and will handle cleaning it up.
11441  pTransaction->AddItem(*pItem); // the Transaction's destructor will
11442  // cleanup the item. It "owns" it now.
11443  // TRANSACTION AGREEMENT
11444 
11445  // pStatementItem is signed and saved within this call. No need to do
11446  // that again.
11447  OTItem* pStatementItem =
11448  pNym->GenerateTransactionStatement(*pTransaction);
11449 
11450  if (nullptr !=
11451  pStatementItem) // Will never be nullptr. Will assert above
11452  // before it gets here.
11453  pTransaction->AddItem(*pStatementItem); // Better not be nullptr...
11454  // message will fail... But
11455  // better check anyway.
11456  // sign the transaction
11457  pTransaction->SignContract(*pNym);
11458  pTransaction->SaveContract();
11459  // set up the ledger
11460  OTLedger theLedger(USER_ID, theAcctID, SERVER_ID);
11461 
11462  theLedger.GenerateLedger(theAcctID, SERVER_ID,
11463  OTLedger::message); // bGenerateLedger defaults
11464  // to false, which is
11465  // correct.
11466  theLedger.AddTransaction(*pTransaction); // now the ledger "owns" and
11467  // will handle cleaning up the
11468  // transaction.
11469  // sign the ledger
11470  theLedger.SignContract(*pNym);
11471  theLedger.SaveContract();
11472  // extract the ledger in ascii-armored form... encoding...
11473  OTString strLedger(theLedger);
11474  OTASCIIArmor ascLedger(strLedger);
11475  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
11476  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
11477  theMessage.m_strRequestNum.Format(
11478  "%ld", lRequestNumber); // Always have to send this.
11479  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
11480  // server request, I have
11481  // to increment it
11482  // (1) Set up member variables
11483  theMessage.m_strCommand = "notarizeTransactions";
11484  theMessage.m_strNymID = strNymID;
11485  theMessage.m_strServerID = strServerID;
11486  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
11487  // theMessage.m_strServerID is
11488  // already set. (It uses it.)
11489  theAcctID.GetString(theMessage.m_strAcctID);
11490  theMessage.m_ascPayload = ascLedger;
11491  OTIdentifier NYMBOX_HASH;
11492  const std::string str_server(strServerID.Get());
11493  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
11494  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11495  if (!bNymboxHash)
11496  otErr << __FUNCTION__
11497  << ": Failed getting NymboxHash from Nym for server: "
11498  << str_server << "\n";
11499  // (2) Sign the Message
11500  theMessage.SignContract(*pNym);
11501 
11502  // (3) Save the Message (with signatures and all, back to its internal
11503  // member m_strRawFile.)
11504  theMessage.SaveContract();
11505 
11506  // (Send it)
11507  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
11508  m_pTransportCallback);
11509  m_pClient->ProcessMessageOut(theMessage);
11510  return m_pClient->CalcReturnVal(lRequestNumber);
11511 
11512  } // theContract.LoadContractFromString()
11513  else
11514  otOut << __FUNCTION__
11515  << ": Unable to load smart contract from string:\n\n"
11516  << THE_SMART_CONTRACT << "\n\n";
11517 
11518  return (-1);
11519 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
void opentxs::OT_API::AddAssetContract ( const OTAssetContract theContract) const

Definition at line 14063 of file OpenTransactions.cpp.

14064 {
14065  m_pWallet->AddAssetContract(theContract);
14066 }
EXPORT void AddAssetContract(const OTAssetContract &theContract)
Definition: OTWallet.cpp:752
bool opentxs::OT_API::AddBasketCreationItem ( const OTIdentifier USER_ID,
Basket theBasket,
const OTIdentifier ASSET_TYPE_ID,
int64_t  MINIMUM_TRANSFER 
) const

Definition at line 8739 of file OpenTransactions.cpp.

8744 {
8745  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
8746  if (nullptr == pNym) return false;
8747  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8748  // cleanup.)
8749  // There is an OT_ASSERT_MSG in here for memory failure,
8750  // but it still might return nullptr if various verification fails.
8751  OTAssetContract* pContract = GetAssetType(ASSET_TYPE_ID, __FUNCTION__);
8752  if (nullptr == pContract) return false;
8753  // No need to cleanup pContract.
8754 
8755  theBasket.AddSubContract(ASSET_TYPE_ID, MINIMUM_TRANSFER);
8756 
8757  theBasket.IncrementSubCount();
8758 
8759  theBasket.ReleaseSignatures();
8760  theBasket.SignContract(*pNym);
8761  theBasket.SaveContract();
8762 
8763  return true;
8764 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::AddBasketExchangeItem ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
Basket theBasket,
const OTIdentifier ASSET_TYPE_ID,
const OTIdentifier ASSET_ACCT_ID 
) const

Definition at line 8916 of file OpenTransactions.cpp.

8921 {
8922  OTPseudonym* pNym = GetOrLoadPrivateNym(
8923  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
8924  if (nullptr == pNym) return false;
8925  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8926  // cleanup.)
8927  OTAssetContract* pContract = GetAssetType(ASSET_TYPE_ID, __FUNCTION__);
8928  if (nullptr == pContract) return false;
8929  // By this point, pContract is a good pointer, and is on the wallet. (No
8930  // need to cleanup.)
8931  OTAccount* pAccount =
8932  GetOrLoadAccount(*pNym, ASSET_ACCT_ID, SERVER_ID, __FUNCTION__);
8933  if (nullptr == pAccount) return false;
8934  // By this point, pAccount is a good pointer, and is on the wallet. (No need
8935  // to cleanup.)
8936  if (pNym->GetTransactionNumCount(SERVER_ID) < 1) {
8937  otOut << "OT_API::AddBasketExchangeItem: you need at least one "
8938  "transaction number to add this exchange item.\n";
8939  return false;
8940  }
8941  if (ASSET_TYPE_ID != pAccount->GetAssetTypeID()) {
8942  const OTString strAssetTypeID(ASSET_TYPE_ID), strAcctID(ASSET_ACCT_ID);
8943  otOut << "OT_API::AddBasketExchangeItem: Wrong asset type ID "
8944  "on account " << strAcctID << " (expected to find asset type "
8945  << strAssetTypeID << ")\n";
8946  return false;
8947  }
8948  // By this point, I know that everything checks out. Signature and Account
8949  // ID.
8950  // pAccount is good, and no need to clean it up.
8951  const OTString strServerID(SERVER_ID);
8952 
8953  int64_t lSubClosingTransactionNo = 0; // For the basketReceipt (closing
8954  // transaction num) for the sub
8955  // account.
8956 
8957  if (pNym->GetNextTransactionNum(*pNym, strServerID,
8958  lSubClosingTransactionNo)) // this saves
8959  {
8960  theBasket.AddRequestSubContract(ASSET_TYPE_ID, ASSET_ACCT_ID,
8961  lSubClosingTransactionNo);
8962 
8963  theBasket.ReleaseSignatures();
8964  theBasket.SignContract(*pNym);
8965  theBasket.SaveContract();
8966 
8967  return true;
8968  }
8969  else
8970  otErr << "OT_API::AddBasketExchangeItem: Failed getting next "
8971  "transaction number. \n";
8972 
8973  return false;
8974 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
void opentxs::OT_API::AddServerContract ( const OTServerContract pContract) const

Definition at line 14058 of file OpenTransactions.cpp.

14059 {
14060  m_pWallet->AddServerContract(pContract);
14061 }
EXPORT void AddServerContract(const OTServerContract &theContract)
Definition: OTWallet.cpp:725
bool opentxs::OT_API::AddSignature ( const OTIdentifier theSignerNymID,
const OTString strContract,
OTString strOutput 
) const
OT-Sign a CONTRACT.  (Add a signature)

Tries to instantiate the contract object, based on the string passed in. Signs the contract, WITHOUT releasing any signatures that are already there. Returns the signed contract, or nullptr if failure.

OT-Sign a CONTRACT. (Add a signature)

const char * OT_API_AddSignature(const char * SIGNER_NYM_ID, const char * THE_CONTRACT);

Tries to instantiate the contract object, based on the string passed in. Signs the contract, without releasing any signatures that are already there. Returns the signed contract, or nullptr if failure.

NOTE: The actual OT functionality (Use Cases) NEVER requires you to sign via this function. Why not? because, anytime a signature is needed on something, the relevant OT API call will require you to pass in the Nym, and the API already signs internally wherever it deems appropriate. Thus, this function is only for advanced uses, for OT-Scripts, server operators, etc.

Definition at line 3462 of file OpenTransactions.cpp.

3465 {
3466  OTPseudonym* pNym = GetOrLoadPrivateNym(
3467  theSignerNymID, false, __FUNCTION__); // This logs and ASSERTs already.
3468  if (nullptr == pNym) return false;
3469  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3470  // cleanup.)
3471  if (!strContract.Exists()) {
3472  otOut << __FUNCTION__
3473  << ": Empty contract passed in. (Returning false.)\n";
3474  return false;
3475  }
3476  //
3477  std::unique_ptr<OTContract> pContract(
3479 
3480  if (nullptr == pContract)
3481  pContract.reset(OTScriptable::InstantiateScriptable(strContract));
3482 
3483  if (nullptr == pContract)
3484  pContract.reset(::InstantiateContract(strContract));
3485 
3486  if (nullptr == pContract) {
3487  otOut << __FUNCTION__
3488  << ": I tried my best. Unable to instantiate contract "
3489  "passed in:\n\n" << strContract << "\n\n";
3490  return false;
3491  }
3492 
3493  // pContract->ReleaseSignatures(); // Other than this line, this
3494  // function is identical to
3495  // OT_API::SignContract(). (This one adds signatures without removing
3496  // existing ones.)
3497  pContract->SignContract(*pNym);
3498  pContract->SaveContract();
3499  strOutput.Release();
3500  pContract->SaveContractRaw(strOutput);
3501  return true;
3502 }
static EXPORT OTTransactionType * TransactionFactory(OTString strInput)
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int32_t opentxs::OT_API::cancelCronItem ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ASSET_ACCT_ID,
const int64_t &  lTransactionNum 
) const

CANCEL A SPECIFIC OFFER (THAT SAME NYM PLACED PREVIOUSLY ON SAME SERVER.) By transaction number as key.

Definition at line 11573 of file OpenTransactions.cpp.

11580 {
11581  OTPseudonym* pNym = GetOrLoadPrivateNym(
11582  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
11583  if (nullptr == pNym) return (-1);
11584  // By this point, pNym is a good pointer, and is on the wallet.
11585  // (No need to cleanup.)
11586  OTServerContract* pServer =
11587  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
11588  if (nullptr == pServer) return (-1);
11589  // By this point, pServer is a good pointer. (No need to cleanup.)
11590  OTMessage theMessage;
11591 
11592  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
11593 
11594  if (pNym->GetTransactionNumCount(strServerID) < 1) {
11595  otOut << "OT_API::cancelCronItem: At least 1 Transaction Number is "
11596  "necessary to cancel any cron item. "
11597  "Try requesting the server for more numbers (you are low.)\n";
11598  return (-1);
11599  }
11600  int64_t lStoredTransactionNumber = 0;
11601  bool bGotTransNum = pNym->GetNextTransactionNum(
11602  *pNym, strServerID, lStoredTransactionNumber, true); // bSave=false
11603 
11604  if (!bGotTransNum)
11605  otErr << "OT_API::cancelCronItem: Supposedly there was a "
11606  "transaction number available, but the call\n"
11607  "still failed.\n";
11608  else {
11609  int64_t lRequestNumber = 0;
11610 
11611  OTString str_ASSET_ACCT_ID(ASSET_ACCT_ID);
11612 
11613  // Create a transaction
11614  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
11615  USER_ID, ASSET_ACCT_ID, SERVER_ID, OTTransaction::cancelCronItem,
11616  lStoredTransactionNumber);
11617  // set up the transaction item (each transaction may have multiple
11618  // items...)
11619  OTItem* pItem = OTItem::CreateItemFromTransaction(
11620  *pTransaction, OTItem::cancelCronItem);
11621  OT_ASSERT_MSG(nullptr != pItem,
11622  "Error allocating memory in the OT API");
11623 
11624  pItem->SetReferenceToNum(lTransactionNum); // This transaction is being
11625  // sent in order to cancel
11626  // another transaction.
11627  pTransaction->SetReferenceToNum(lTransactionNum); // This is where we
11628  // clearly show which
11629  // one is actually
11630  // being cancelled.
11631 
11632  // sign the item
11633  pItem->SignContract(*pNym);
11634  pItem->SaveContract();
11635 
11636  // the Transaction "owns" the item now and will handle cleaning it up.
11637  pTransaction->AddItem(*pItem); // the Transaction's destructor will
11638  // cleanup the item. It "owns" it now.
11639  // TRANSACTION AGREEMENT
11640 
11641  // pBalanceItem is signed and saved within this call. No need to do that
11642  // again.
11643  OTItem* pStatementItem =
11644  pNym->GenerateTransactionStatement(*pTransaction);
11645 
11646  if (nullptr !=
11647  pStatementItem) // will never be nullptr. Will assert above
11648  // before it gets here.
11649  pTransaction->AddItem(*pStatementItem); // Better not be nullptr...
11650  // message will fail... But
11651  // better check anyway.
11652  // sign the transaction
11653  pTransaction->SignContract(*pNym);
11654  pTransaction->SaveContract();
11655 
11656  // set up the ledger
11657  OTLedger theLedger(USER_ID, ASSET_ACCT_ID, SERVER_ID);
11658  theLedger.GenerateLedger(ASSET_ACCT_ID, SERVER_ID,
11659  OTLedger::message); // bGenerateLedger defaults
11660  // to false, which is
11661  // correct.
11662  theLedger.AddTransaction(*pTransaction); // now the ledger "owns" and
11663  // will handle cleaning up the
11664  // transaction.
11665 
11666  // sign the ledger
11667  theLedger.SignContract(*pNym);
11668  theLedger.SaveContract();
11669 
11670  // extract the ledger in ascii-armored form... encoding...
11671  OTString strLedger(theLedger);
11672  OTASCIIArmor ascLedger(strLedger);
11673 
11674  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
11675  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
11676  theMessage.m_strRequestNum.Format(
11677  "%ld", lRequestNumber); // Always have to send this.
11678  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
11679  // server request, I have
11680  // to increment it
11681 
11682  // (1) Set up member variables
11683  theMessage.m_strCommand = "notarizeTransactions";
11684  theMessage.m_strNymID = strNymID;
11685  theMessage.m_strServerID = strServerID;
11686  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
11687  // theMessage.m_strServerID is
11688  // already set. (It uses it.)
11689 
11690  theMessage.m_strAcctID = str_ASSET_ACCT_ID;
11691  theMessage.m_ascPayload = ascLedger;
11692 
11693  OTIdentifier NYMBOX_HASH;
11694  const std::string str_server(strServerID.Get());
11695  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
11696  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11697 
11698  if (!bNymboxHash)
11699  otErr << "Failed getting NymboxHash from Nym for server: "
11700  << str_server << "\n";
11701 
11702  // (2) Sign the Message
11703  theMessage.SignContract(*pNym);
11704 
11705  // (3) Save the Message (with signatures and all, back to its internal
11706  // member m_strRawFile.)
11707  theMessage.SaveContract();
11708 
11709  // (Send it)
11710  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
11711  m_pTransportCallback);
11712  m_pClient->ProcessMessageOut(theMessage);
11713 
11714  return m_pClient->CalcReturnVal(lRequestNumber);
11715  } // got transaction number.
11716 
11717  return (-1);
11718 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::checkServerID ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 14027 of file OpenTransactions.cpp.

14029 {
14030  OTPseudonym* pNym = GetOrLoadPrivateNym(
14031  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
14032  if (nullptr == pNym) return (-1);
14033  // By this point, pNym is a good pointer, and is on the wallet.
14034  // (No need to cleanup.)
14035  OTServerContract* pServer =
14036  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
14037  if (nullptr == pServer) return (-1);
14038  // By this point, pServer is a good pointer. (No need to cleanup.)
14039  OTMessage theMessage;
14040 
14041  int32_t nReturnValue = m_pClient->ProcessUserCommand(
14042  OTClient::checkServerID, theMessage, *pNym, *pServer,
14043  nullptr); // nullptr pAccount on this command.
14044  if (0 < nReturnValue) {
14045  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
14046  m_pTransportCallback);
14047  m_pClient->ProcessMessageOut(theMessage);
14048 
14049  return nReturnValue;
14050  }
14051  else
14052  otErr << "Error processing checkServerID command in "
14053  "OT_API::checkServerID\n";
14054 
14055  return -1;
14056 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::checkUser ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier USER_ID_CHECK 
) const

Definition at line 13587 of file OpenTransactions.cpp.

13590 {
13591  OTPseudonym* pNym = GetOrLoadPrivateNym(
13592  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13593  if (nullptr == pNym) return (-1);
13594  // By this point, pNym is a good pointer, and is on the wallet.
13595  // (No need to cleanup.)
13596  OTServerContract* pServer =
13597  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13598  if (nullptr == pServer) return (-1);
13599  // By this point, pServer is a good pointer. (No need to cleanup.)
13600  OTMessage theMessage;
13601  int64_t lRequestNumber = 0;
13602 
13603  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13604  strNymID2(USER_ID_CHECK);
13605 
13606  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13607  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13608  theMessage.m_strRequestNum.Format(
13609  "%ld", lRequestNumber); // Always have to send this.
13610  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13611  // server request, I have to
13612  // increment it
13613 
13614  // (1) set up member variables
13615  theMessage.m_strCommand = "checkUser";
13616  theMessage.m_strNymID = strNymID;
13617  theMessage.m_strNymID2 = strNymID2;
13618  theMessage.m_strServerID = strServerID;
13619  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13620  // theMessage.m_strServerID is already
13621  // set. (It uses it.)
13622 
13623  // (2) Sign the Message
13624  theMessage.SignContract(*pNym);
13625 
13626  // (3) Save the Message (with signatures and all, back to its internal
13627  // member m_strRawFile.)
13628  theMessage.SaveContract();
13629 
13630  // (Send it)
13631  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13632  m_pClient->ProcessMessageOut(theMessage);
13633 
13634  return m_pClient->CalcReturnVal(lRequestNumber);
13635 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool opentxs::OT_API::CleanupOTApp ( )
static

Definition at line 595 of file OpenTransactions.cpp.

596 {
597  if (!OT_API::bInitOTApp) {
598  otErr << __FUNCTION__ << ": WARNING: Never Successfully called: "
599  << "OT_API::InitCTX()"
600  << "\n";
601  OT_API::bInitOTApp = true;
602  return false;
603  }
604 
605  if (!OT_API::bCleanupOTApp) {
606  OTCachedKey::Cleanup(); // it has a static list of dynamically allocated
607  // master keys that need to be cleaned up, if
608  // the application is shutting down.
609 
610  // We clean these up in reverse order from the Init function, which just
611  // seems
612  // like the best default, in absence of any brighter ideas.
613  //
614  OTCrypto::It()->Cleanup(); // (OpenSSL gets cleaned up here.)
615 
616  return true;
617  }
618  else {
619  otErr << __FUNCTION__
620  << ": ERROR: This function can only be called once.\n";
621  return false;
622  }
623 }
static EXPORT OTCrypto * It()
Definition: OTCrypto.cpp:630
static EXPORT void Cleanup()
OTLOG_IMPORT OTLogStream otErr
EXPORT void Cleanup() const
Definition: OTCrypto.cpp:678
bool opentxs::OT_API::ClearExpired ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
int32_t  nIndex,
bool  bClearAll = false 
) const

Definition at line 6758 of file OpenTransactions.cpp.

6762 {
6763  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6764  if (nullptr == pNym) return false;
6765  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6766  // cleanup.)
6767  std::unique_ptr<OTLedger> pExpiredBox(LoadExpiredBox(SERVER_ID, USER_ID));
6768  if (nullptr == pExpiredBox) {
6769  pExpiredBox.reset(OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
6770  OTLedger::expiredBox, true));
6771 
6772  if (nullptr == pExpiredBox) {
6773  otErr << __FUNCTION__
6774  << ": Unable to load or create expired box (and thus "
6775  "unable to do anything with it.)\n";
6776  return false;
6777  }
6778  }
6779  if (bClearAll) {
6780  pExpiredBox->ReleaseTransactions();
6781  pExpiredBox->ReleaseSignatures();
6782  pExpiredBox->SignContract(*pNym);
6783  pExpiredBox->SaveContract();
6784  pExpiredBox->SaveExpiredBox();
6785  return true;
6786  }
6787  // Okay, it's not "clear all" but "clear at index" ...
6788  //
6789  const int32_t nTransCount = pExpiredBox->GetTransactionCount();
6790 
6791  if ((nIndex < 0) || (nIndex >= nTransCount)) {
6792  otErr << __FUNCTION__
6793  << ": Index out of bounds (highest allowed index for this "
6794  "expired box is " << nTransCount - 1 << ".)\n";
6795  return false;
6796  }
6797  OTTransaction* pTransaction = pExpiredBox->GetTransactionByIndex(nIndex);
6798  bool bRemoved = false;
6799 
6800  if (nullptr != pTransaction) {
6801  const int64_t lTransactionNum = pTransaction->GetTransactionNum();
6802 
6803  if (!pExpiredBox->DeleteBoxReceipt(lTransactionNum)) {
6804  otErr << __FUNCTION__
6805  << ": Failed trying to delete the box receipt for a "
6806  "transaction being removed from a expired box: "
6807  << lTransactionNum << "\n";
6808  }
6809  bRemoved = pExpiredBox->RemoveTransaction(lTransactionNum);
6810  }
6811  if (bRemoved) {
6812  pExpiredBox->ReleaseSignatures();
6813  pExpiredBox->SignContract(*pNym);
6814  pExpiredBox->SaveContract();
6815  pExpiredBox->SaveExpiredBox();
6816  return true;
6817  }
6818  else {
6819  const int32_t nTemp = static_cast<int32_t>(nIndex);
6820  otOut << __FUNCTION__
6821  << ": Failed trying to clear an expired record from "
6822  "the expired box at index: " << nTemp << "\n";
6823  }
6824  return false;
6825 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otErr
EXPORT OTLedger * LoadExpiredBox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
bool opentxs::OT_API::ClearRecord ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID,
int32_t  nIndex,
bool  bClearAll = false 
) const

Definition at line 8198 of file OpenTransactions.cpp.

8202 {
8203  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
8204  if (nullptr == pNym) return false;
8205  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8206  // cleanup.)
8207  std::unique_ptr<OTLedger> pRecordBox(
8208  LoadRecordBox(SERVER_ID, USER_ID, ACCOUNT_ID));
8209  if (nullptr == pRecordBox) {
8210  pRecordBox.reset(OTLedger::GenerateLedger(
8211  USER_ID, ACCOUNT_ID, SERVER_ID, OTLedger::recordBox, true));
8212 
8213  if (nullptr == pRecordBox) {
8214  otErr << __FUNCTION__
8215  << ": Unable to load or create record box "
8216  "(and thus unable to do anything with it.)\n";
8217  return false;
8218  }
8219  }
8220  if (bClearAll) {
8221  pRecordBox->ReleaseTransactions();
8222  pRecordBox->ReleaseSignatures();
8223  pRecordBox->SignContract(*pNym);
8224  pRecordBox->SaveContract();
8225  pRecordBox->SaveRecordBox();
8226  return true;
8227  }
8228  // Okay, it's not "clear all" but "clear at index" ...
8229  //
8230  const int32_t nTransCount = pRecordBox->GetTransactionCount();
8231 
8232  if ((nIndex < 0) || (nIndex >= nTransCount)) {
8233  otOut << __FUNCTION__
8234  << ": Index out of bounds (highest allowed index for "
8235  "this record box is " << nTransCount - 1 << ".)\n";
8236  return false;
8237  }
8238  OTTransaction* pTransaction = pRecordBox->GetTransactionByIndex(nIndex);
8239  bool bRemoved = false;
8240 
8241  if (nullptr != pTransaction) {
8242  const int64_t lTransactionNum = pTransaction->GetTransactionNum();
8243 
8244  if (!pRecordBox->DeleteBoxReceipt(lTransactionNum)) {
8245  otErr << __FUNCTION__
8246  << ": Failed trying to delete the box receipt for a "
8247  "transaction being removed from a record box: "
8248  << lTransactionNum << "\n";
8249  }
8250  bRemoved = pRecordBox->RemoveTransaction(lTransactionNum);
8251  }
8252  if (bRemoved) {
8253  pRecordBox->ReleaseSignatures();
8254  pRecordBox->SignContract(*pNym);
8255  pRecordBox->SaveContract();
8256  pRecordBox->SaveRecordBox();
8257  return true;
8258  }
8259  else {
8260  const int32_t nTemp = static_cast<int32_t>(nIndex);
8261  otOut << __FUNCTION__
8262  << ": Failed trying to clear a record from the record "
8263  "box at index: " << nTemp << "\n";
8264  }
8265  return false;
8266 }
EXPORT OTLedger * LoadRecordBox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::ConfirmPaymentPlan ( const OTIdentifier SERVER_ID,
const OTIdentifier SENDER_USER_ID,
const OTIdentifier SENDER_ACCT_ID,
const OTIdentifier RECIPIENT_USER_ID,
OTPaymentPlan thePlan 
) const

Definition at line 5170 of file OpenTransactions.cpp.

5175 {
5176  OTPseudonym* pNym = GetOrLoadPrivateNym(
5177  SENDER_USER_ID, false, __FUNCTION__); // This logs, ASSERTs, etc.
5178  if (nullptr == pNym) return false;
5179  // By this point, pNym is a good pointer, and is on the wallet. (No need to
5180  // cleanup.)
5181  OTAccount* pAccount =
5182  GetOrLoadAccount(*pNym, SENDER_ACCT_ID, SERVER_ID, __FUNCTION__);
5183  if (nullptr == pAccount) return false;
5184  // By this point, pAccount is a good pointer, and is on the wallet. (No need
5185  // to cleanup.)
5186  std::unique_ptr<OTPseudonym> pMerchantNym(
5187  LoadPublicNym(RECIPIENT_USER_ID, __FUNCTION__));
5188 
5189  // if (nullptr == pMerchantNym) // We don't have this Nym in our storage
5190  // already.
5191  // {
5192  // const OTString strRecipNymID(RECIPIENT_USER_ID);
5193  // otOut << __FUNCTION__ << ": There's no (Merchant) Nym with the
5194  // recipient's NymID in local storage: " << strRecipNymID << "\n";
5195  // return false;
5196  // }
5197  // pMerchantNym is also good, and has an angel. (No need to cleanup.)
5198  //
5199  // The "Creation Date" of the agreement is re-set here.
5200  //
5201  bool bConfirmed =
5202  thePlan.Confirm(*pNym, pMerchantNym.get(), &RECIPIENT_USER_ID);
5203  //
5204  // WARNING: The call to "Confirm()" uses TWO transaction numbers from pNym!
5205  // If you don't end up actually USING this payment plan, then you need to
5206  // retrieve
5207  // those numbers and Add them back to pNym again.
5208  // A nice client will store a copy of any payment plans until they are
5209  // closed out, or canceled,
5210  // or whatever.
5211  // ANY FAILURES BELOW THIS POINT need to be smart enough to retrieve those
5212  // numbers before returning.
5213  //
5214  const OTString strServerID(SERVER_ID);
5215 
5216  if (!bConfirmed) {
5217  otOut << __FUNCTION__ << ": Failed trying to confirm the agreement.\n";
5218  thePlan.HarvestOpeningNumber(*pNym);
5219  thePlan.HarvestClosingNumbers(*pNym);
5220  return false;
5221  }
5222  thePlan.SignContract(*pNym); // Here we have saved the CUSTOMER's version,
5223  thePlan.SaveContract(); // which contains a copy of the merchant's version.
5224  //
5225  // DROP A COPY into the Outpayments box...
5226  //
5227  // (Since we used a transaction number to confirm the plan, we
5228  // have to track it until it's deposited or until we cancel it.)
5229  //
5230  const OTString strInstrument(thePlan);
5231  OTMessage* pMessage = new OTMessage;
5232  OT_ASSERT(nullptr != pMessage);
5233 
5234  const OTString strNymID(SENDER_USER_ID), strNymID2(RECIPIENT_USER_ID);
5235 
5236  pMessage->m_strCommand = "outpaymentsMessage";
5237  pMessage->m_strNymID = strNymID;
5238  pMessage->m_strNymID2 = strNymID2;
5239  pMessage->m_strServerID = strServerID;
5240  pMessage->m_ascPayload.SetString(strInstrument);
5241 
5242  pMessage->SignContract(*pNym);
5243  pMessage->SaveContract();
5244 
5245  pNym->AddOutpayments(*pMessage); // Now the Nym is responsible to delete it.
5246  // It's in his "outpayments".
5247  OTPseudonym* pSignerNym = pNym;
5248  pNym->SaveSignedNymfile(*pSignerNym);
5249  return true;
5250 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * LoadPublicNym(const OTIdentifier &NYM_ID, const char *szFuncName=nullptr) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::Create_SmartContract ( const OTIdentifier SIGNER_NYM_ID,
time64_t  VALID_FROM,
time64_t  VALID_TO,
OTString strOutput 
) const

Definition at line 3653 of file OpenTransactions.cpp.

3660 {
3661  OTPseudonym* pNym = GetOrLoadPrivateNym(
3662  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
3663  if (nullptr == pNym) return false;
3664  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3665  // cleanup.)
3666  OTSmartContract* pContract = new OTSmartContract();
3667  OT_ASSERT_MSG(nullptr != pContract,
3668  "OT_API::Create_SmartContract: ASSERT "
3669  "while trying to instantiate blank smart "
3670  "contract.\n");
3671  if (!pContract->SetDateRange(VALID_FROM, VALID_TO)) {
3672  otOut << "OT_API::Create_SmartContract: Failed trying to set date "
3673  "range.\n";
3674  return false;
3675  }
3676  pContract->SignContract(*pNym);
3677  pContract->SaveContract();
3678  strOutput.Release();
3679  pContract->SaveContractRaw(strOutput);
3680  return true;
3681 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
int32_t opentxs::OT_API::createAssetAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ASSET_ID 
) const

Definition at line 13196 of file OpenTransactions.cpp.

13199 {
13200  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
13201  if (nullptr == pNym) return (-1);
13202  // By this point, pNym is a good pointer, and is on the wallet.
13203  // (No need to cleanup.)
13204  OTServerContract* pServer =
13205  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13206  if (nullptr == pServer) return (-1);
13207  // By this point, pServer is a good pointer. (No need to cleanup.)
13208  OTAssetContract* pAssetContract =
13209  GetAssetType(ASSET_ID, __FUNCTION__); // This ASSERTs and logs already.
13210  if (nullptr == pAssetContract) return (-1);
13211  // By this point, pAssetContract is a good pointer. (No need to cleanup.)
13212  OTMessage theMessage;
13213  int64_t lRequestNumber = 0;
13214 
13215  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13216  strAssetTypeID(ASSET_ID);
13217 
13218  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13219  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13220  theMessage.m_strRequestNum.Format(
13221  "%ld", lRequestNumber); // Always have to send this.
13222  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13223  // server request, I have to
13224  // increment it
13225 
13226  // (1) set up member variables
13227  theMessage.m_strCommand = "createAccount";
13228  theMessage.m_strNymID = strNymID;
13229  theMessage.m_strServerID = strServerID;
13230  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13231  // theMessage.m_strServerID is already
13232  // set. (It uses it.)
13233 
13234  theMessage.m_strAssetID = strAssetTypeID;
13235 
13236  // (2) Sign the Message
13237  theMessage.SignContract(*pNym);
13238 
13239  // (3) Save the Message (with signatures and all, back to its internal
13240  // member m_strRawFile.)
13241  theMessage.SaveContract();
13242 
13243  // (Send it)
13244  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13245  m_pClient->ProcessMessageOut(theMessage);
13246 
13247  return m_pClient->CalcReturnVal(lRequestNumber);
13248 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTPseudonym * opentxs::OT_API::CreateNym ( int32_t  nKeySize = 1024,
const std::string  str_id_source = "",
const std::string  str_alt_location = "" 
) const

Definition at line 1514 of file OpenTransactions.cpp.

1517 {
1518  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
1519  switch (nKeySize) {
1520  case 1024:
1521  case 2048:
1522  case 4096:
1523  case 8192:
1524  break;
1525  default:
1526  otErr << __FUNCTION__ << ": Failure: nKeySize must be one of: "
1527  "1024, 2048, 4096, 8192. (" << nKeySize
1528  << " was passed...)\n";
1529  return nullptr;
1530  }
1531  OTWallet* pWallet =
1532  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1533  if (nullptr == pWallet) return nullptr;
1534  // By this point, pWallet is a good pointer. (No need to cleanup.)
1535  OTPseudonym* pNym = new OTPseudonym;
1536  OT_ASSERT(nullptr != pNym);
1537  if (false ==
1538  pNym->GenerateNym(nKeySize, true, str_id_source, str_alt_location)) {
1539  otErr << __FUNCTION__ << ": Failed trying to generate Nym.\n";
1540  delete pNym;
1541  pNym = nullptr;
1542  return nullptr;
1543  }
1544  pWallet->AddNym(
1545  *pNym); // Add our new nym to the wallet, who "owns" it hereafter.
1546 
1547  // Note: It's already on the master key. To prevent that, we would have had
1548  // to PAUSE the master key before calling GenerateNym above. So the below
1549  // call
1550  // is less about the Nym's encryption, and more about the wallet KNOWING.
1551  // Because
1552  // OTWallet::ConvertNymToCachedKey is what adds this nym to the wallet's
1553  // list of
1554  // "master key nyms". Until that happens, the wallet has no idea.
1555  //
1556  if (!pWallet->ConvertNymToCachedKey(*pNym))
1557  otErr << __FUNCTION__
1558  << ": Error: Failed in pWallet->ConvertNymToCachedKey \n";
1559  pWallet->SaveWallet(); // Since it just changed.
1560  // By this point, pNym is a good pointer, and is on the wallet.
1561  // (No need to cleanup.)
1562  return pNym;
1563 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
Purse * opentxs::OT_API::CreatePurse ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID,
const OTIdentifier OWNER_ID 
) const

Definition at line 5333 of file OpenTransactions.cpp.

5336 {
5337  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5338  Purse* pPurse = new Purse(SERVER_ID, ASSET_ID, OWNER_ID);
5339  OT_ASSERT_MSG(nullptr != pPurse,
5340  "Error allocating memory in the OT API."); // responsible to
5341  // delete or return
5342  // pPurse below
5343  // this point.
5344 
5345  return pPurse;
5346 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
Purse * opentxs::OT_API::CreatePurse_Passphrase ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
) const

Definition at line 5354 of file OpenTransactions.cpp.

5356 {
5357  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5358  Purse* pPurse = new Purse(SERVER_ID, ASSET_ID);
5359  OT_ASSERT_MSG(nullptr != pPurse,
5360  "Error allocating memory in the OT API."); // responsible to
5361  // delete or return
5362  // pPurse below
5363  // this point.
5364  if (pPurse->GenerateInternalKey())
5365  return pPurse;
5366  else
5367  otErr << "OT_API::CreatePurse_Passphrase: "
5368  "pPurse->GenerateInternalKey() returned false. (Failure.)\n";
5369  delete pPurse;
5370  pPurse = nullptr;
5371  return nullptr;
5372 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::createUserAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 13965 of file OpenTransactions.cpp.

13967 {
13968  OTPseudonym* pNym = GetOrLoadPrivateNym(
13969  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13970  if (nullptr == pNym) return (-1);
13971  // By this point, pNym is a good pointer, and is on the wallet.
13972  // (No need to cleanup.)
13973  OTServerContract* pServer =
13974  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13975  if (nullptr == pServer) return (-1);
13976  // By this point, pServer is a good pointer. (No need to cleanup.)
13977  OTMessage theMessage;
13978 
13979  int32_t nReturnValue = m_pClient->ProcessUserCommand(
13980  OTClient::createUserAccount, theMessage, *pNym, *pServer,
13981  nullptr); // nullptr pAccount on this command.
13982  if (0 < nReturnValue) {
13983  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
13984  m_pTransportCallback);
13985  m_pClient->ProcessMessageOut(theMessage);
13986 
13987  return nReturnValue;
13988  }
13989  else
13990  otErr << "OT_API::createUserAccount: Error in "
13991  "m_pClient->ProcessUserCommand() \n";
13992 
13993  return -1;
13994 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Decode ( const OTString strEncoded,
OTString strOutput,
bool  bLineBreaks = true 
) const
Decode an OT-encoded string (back to plaintext.)

This will base64-decode, uncompress, and unpack an OT-encoded string. Returns the plaintext string, or nullptr.

Decode an OT-encoded string (back to plaintext.)

const char * OT_API_Decode(const char * szEncoded);

This will base64-decode, uncompress, and unpack an OT-encoded string. Returns the plaintext string, or nullptr.

Internally: OTASCIIArmor ascEncoded(szEncoded); OTString strPlain(ascEncoded); // strPlain now contains the decoded plaintext string. return strPlain.Get(); // We return it.

Definition at line 3257 of file OpenTransactions.cpp.

3259 {
3260  OTASCIIArmor ascArmor;
3261  const bool bLoadedArmor = OTASCIIArmor::LoadFromString(
3262  ascArmor, strEncoded); // str_bookend="-----BEGIN" by default
3263  if (!bLoadedArmor || !ascArmor.Exists()) {
3264  otErr << __FUNCTION__
3265  << ": Failure loading string into OTASCIIArmor object:\n\n"
3266  << strEncoded << "\n\n";
3267  return false;
3268  }
3269  strOutput.Release();
3270  const bool bSuccess = ascArmor.GetString(strOutput, bLineBreaks);
3271  return bSuccess;
3272 }
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Decrypt ( const OTIdentifier theRecipientNymID,
const OTString strCiphertext,
OTString strOutput 
) const
OT-DECRYPT an OT-encrypted string back to plaintext.

Decrypts the base64-encoded ciphertext back into a normal string plaintext. Returns the plaintext string, or nullptr.

OT-DECRYPT an OT-encrypted string back to plaintext.

const char * OT_API_Decrypt(const char * RECIPIENT_NYM_ID, const char * szCiphertext);

Decrypts the base64-encoded ciphertext back into a normal string plaintext. Returns the plaintext string, or nullptr.

Internally the C++ code is: OTEnvelope theEnvelope; // Here is the envelope object. (The ciphertext IS the data for an OTEnvelope.) OTASCIIArmor ascCiphertext(szCiphertext); // The base64-encoded ciphertext passed in. Next we'll try to attach it to envelope object... if (theEnvelope.SetAsciiArmoredData(ascCiphertext)) { // ...so that we can open it using the appropriate Nym, into a plain string object: OTString strServerReply; // This will contain the output when we're done. const bool bOpened = // Now we try to decrypt: theEnvelope.Open(RECIPIENT_NYM, strServerReply); if (bOpened) { return strServerReply.Get(); } }

Definition at line 3338 of file OpenTransactions.cpp.

3340 {
3341  OTPseudonym* pRecipientNym =
3342  GetOrLoadPrivateNym(theRecipientNymID, false,
3343  __FUNCTION__); // This logs and ASSERTs already.
3344  if (nullptr == pRecipientNym) return false;
3345  OTEnvelope theEnvelope;
3346  OTASCIIArmor ascCiphertext;
3347  const bool bLoadedArmor = OTASCIIArmor::LoadFromString(
3348  ascCiphertext, strCiphertext); // str_bookend="-----BEGIN" by default
3349  if (!bLoadedArmor || !ascCiphertext.Exists()) {
3350  otErr << __FUNCTION__
3351  << ": Failure loading string into OTASCIIArmor object:\n\n"
3352  << strCiphertext << "\n\n";
3353  return false;
3354  }
3355  if (theEnvelope.SetAsciiArmoredData(ascCiphertext)) {
3356  strOutput.Release();
3357  return theEnvelope.Open(*pRecipientNym, strOutput);
3358  }
3359  return false;
3360 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::deleteAssetAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 13250 of file OpenTransactions.cpp.

13253 {
13254  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
13255  if (nullptr == pNym) return (-1);
13256  // By this point, pNym is a good pointer, and is on the wallet.
13257  // (No need to cleanup.)
13258  OTServerContract* pServer =
13259  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13260  if (nullptr == pServer) return (-1);
13261  // By this point, pServer is a good pointer. (No need to cleanup.)
13262  OTAccount* pAccount =
13263  GetOrLoadAccount(*pNym, ACCOUNT_ID, SERVER_ID, __FUNCTION__);
13264  if (nullptr == pAccount) return (-1);
13265  // By this point, pAccount is a good pointer, and is on the wallet. (No need
13266  // to cleanup.)
13267  OTMessage theMessage;
13268  int64_t lRequestNumber = 0;
13269 
13270  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCOUNT_ID);
13271 
13272  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13273  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13274  theMessage.m_strRequestNum.Format(
13275  "%ld", lRequestNumber); // Always have to send this.
13276  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13277  // server request, I have to
13278  // increment it
13279 
13280  // (1) set up member variables
13281  theMessage.m_strCommand = "deleteAssetAccount";
13282  theMessage.m_strNymID = strNymID;
13283  theMessage.m_strServerID = strServerID;
13284  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13285  // theMessage.m_strServerID is already
13286  // set. (It uses it.)
13287 
13288  theMessage.m_strAcctID = strAcctID;
13289 
13290  // (2) Sign the Message
13291  theMessage.SignContract(*pNym);
13292 
13293  // (3) Save the Message (with signatures and all, back to its internal
13294  // member m_strRawFile.)
13295  theMessage.SaveContract();
13296 
13297  // (Send it)
13298  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13299  m_pClient->ProcessMessageOut(theMessage);
13300 
13301  return m_pClient->CalcReturnVal(lRequestNumber);
13302 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::deleteUserAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 13996 of file OpenTransactions.cpp.

13998 {
13999  OTPseudonym* pNym = GetOrLoadPrivateNym(
14000  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
14001  if (nullptr == pNym) return (-1);
14002  // By this point, pNym is a good pointer, and is on the wallet.
14003  // (No need to cleanup.)
14004  OTServerContract* pServer =
14005  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
14006  if (nullptr == pServer) return (-1);
14007  // By this point, pServer is a good pointer. (No need to cleanup.)
14008  OTMessage theMessage;
14009 
14010  int32_t nReturnValue = m_pClient->ProcessUserCommand(
14011  OTClient::deleteUserAccount, theMessage, *pNym, *pServer,
14012  nullptr); // nullptr pAccount on this command.
14013  if (0 < nReturnValue) {
14014  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
14015  m_pTransportCallback);
14016  m_pClient->ProcessMessageOut(theMessage);
14017 
14018  return nReturnValue;
14019  }
14020  else
14021  otErr << "Error processing deleteUserAccount command in "
14022  "OT_API::deleteUserAccount\n";
14023 
14024  return -1;
14025 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::depositCheque ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const OTString THE_CHEQUE 
) const

Definition at line 10590 of file OpenTransactions.cpp.

10594 {
10595  OTPseudonym* pNym = GetOrLoadPrivateNym(
10596  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
10597  if (nullptr == pNym) return (-1);
10598  // By this point, pNym is a good pointer, and is on the wallet. (No need to
10599  // cleanup.)
10600  OTServerContract* pServer =
10601  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
10602  if (nullptr == pServer) return (-1);
10603  // By this point, pServer is a good pointer. (No need to cleanup.)
10604  OTAccount* pAccount =
10605  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
10606  if (nullptr == pAccount) return (-1);
10607  // By this point, pAccount is a good pointer, and is on the wallet. (No need
10608  // to cleanup.)
10609  OTIdentifier CONTRACT_ID;
10610  OTString strContractID;
10611  CONTRACT_ID = pAccount->GetAssetTypeID();
10612  CONTRACT_ID.GetString(strContractID);
10613  OTMessage theMessage;
10614  int64_t lRequestNumber = 0;
10615 
10616  OTString strServerID(SERVER_ID), strNymID(USER_ID), strDepositAcct(ACCT_ID);
10617 
10618  OTCheque theCheque(SERVER_ID, CONTRACT_ID);
10619 
10620  int64_t lStoredTransactionNumber = 0;
10621  bool bGotTransNum = pNym->GetNextTransactionNum(*pNym, strServerID,
10622  lStoredTransactionNumber);
10623 
10624  if (!bGotTransNum)
10625  otOut << __FUNCTION__ << ": No transaction numbers were available. "
10626  "Try requesting the server for a new one.\n";
10627  else if (!theCheque.LoadContractFromString(THE_CHEQUE)) {
10628  otOut << __FUNCTION__
10629  << ": Unable to load cheque from string. Sorry. Contents:\n\n"
10630  << THE_CHEQUE << "\n\n";
10631  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
10632  pNym->AddTransactionNum(*pNym, strServerID, lStoredTransactionNumber,
10633  true); // bSave=true
10634  }
10635  else if (theCheque.GetServerID() != SERVER_ID) {
10636  const OTString strChequeServerID(theCheque.GetServerID());
10637  otOut << __FUNCTION__ << ": ServerID on cheque (" << strChequeServerID
10638  << ") doesn't "
10639  "match serverID where it's being deposited to (" << strServerID
10640  << ").";
10641  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
10642  pNym->AddTransactionNum(*pNym, strServerID, lStoredTransactionNumber,
10643  true); // bSave=true
10644  }
10645  else {
10646  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
10647 
10648  if (nullptr == pInbox) {
10649  otOut << __FUNCTION__ << ": Failed loading inbox for acct "
10650  << strDepositAcct << "\n";
10651  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10652  // NUMBERS.
10653  pNym->AddTransactionNum(*pNym, strServerID,
10654  lStoredTransactionNumber,
10655  true); // bSave=true
10656  return -1;
10657  }
10658  // If bCancellingCheque==true, we're actually cancelling the cheque by
10659  // "depositing"
10660  // it back into the same account it's drawn on.
10661  //
10662  bool bCancellingCheque = false;
10663 
10664  if (theCheque.HasRemitter())
10665  bCancellingCheque = ((theCheque.GetRemitterAcctID() == ACCT_ID) &&
10666  (theCheque.GetRemitterUserID() == USER_ID));
10667  else {
10668  bCancellingCheque = ((theCheque.GetSenderAcctID() == ACCT_ID) &&
10669  (theCheque.GetSenderUserID() == USER_ID));
10670  if (bCancellingCheque)
10671  bCancellingCheque = theCheque.VerifySignature(*pNym);
10672  }
10673  if (bCancellingCheque) // By this point he's definitely TRYING to cancel
10674  // the cheque.
10675  {
10676  bCancellingCheque = pNym->VerifyIssuedNum(
10677  strServerID, theCheque.GetTransactionNum());
10678 
10679  // If we TRIED to cancel the cheque (being in this block...) yet the
10680  // signature fails
10681  // to verify, or the transaction number isn't even issued, then our
10682  // attempt to cancel
10683  // the cheque is going to fail.
10684  if (!bCancellingCheque) {
10685  // This is the "tried and failed" block.
10686  //
10687  otOut << __FUNCTION__
10688  << ": Cannot cancel this cheque. Either the "
10689  "signature fails to verify,\n"
10690  "or the transaction number is already closed "
10691  "out. (Failure.) Cheque contents:\n\n" << THE_CHEQUE
10692  << "\n\n";
10693 
10694  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10695  // NUMBERS.
10696  pNym->AddTransactionNum(*pNym, strServerID,
10697  lStoredTransactionNumber,
10698  true); // bSave=true
10699  return (-1);
10700  }
10701  // Else we succeeded in verifying signature and issued num.
10702  // Let's just make sure there isn't a chequeReceipt or
10703  // voucherReceipt
10704  // already sitting in the inbox, for this same cheque.
10705  //
10706  OTTransaction* pChequeReceipt =
10707  pInbox->GetChequeReceipt(theCheque.GetTransactionNum());
10708 
10709  if (nullptr != pChequeReceipt) // Hmm looks like there's ALREADY a
10710  // chequeReceipt in the inbox (so we
10711  // can't cancel it.)
10712  {
10713  otOut << __FUNCTION__
10714  << ": Cannot cancel this cheque. There is "
10715  "already a "
10716  << (theCheque.HasRemitter() ? "voucherReceipt"
10717  : "chequeReceipt")
10718  << " for it in the inbox. "
10719  "(Failure.) Cheque contents:\n\n" << THE_CHEQUE
10720  << "\n\n";
10721  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10722  // NUMBERS.
10723  pNym->AddTransactionNum(*pNym, strServerID,
10724  lStoredTransactionNumber,
10725  true); // bSave=true
10726  return (-1);
10727  }
10728  }
10729  // By this point, we're either NOT cancelling the cheque, or if we are,
10730  // we've already
10731  // verified the signature and transaction number on the cheque. (AND
10732  // we've already
10733  // verified that there aren't any chequeReceipts for this cheque, in the
10734  // inbox.)
10735  //
10736  if (bCancellingCheque && !theCheque.HasRemitter()) {
10737  theCheque.CancelCheque(); // Sets the amount to zero.
10738  theCheque.ReleaseSignatures(); // Usually when you deposit a cheque,
10739  // it's signed by someone else.
10740  theCheque.SignContract(*pNym); // But if we are CANCELING a cheque,
10741  // that means we wrote that cheque
10742  theCheque.SaveContract(); // originally, so we are the original
10743  // signer.
10744  } // cancelling cheque
10745  // Create a transaction
10746  std::unique_ptr<OTTransaction> pTransaction(
10747  OTTransaction::GenerateTransaction(USER_ID, ACCT_ID, SERVER_ID,
10749  lStoredTransactionNumber));
10750 
10751  // set up the transaction item (each transaction may have multiple
10752  // items...)
10753  OTItem* pItem = OTItem::CreateItemFromTransaction(
10754  *pTransaction, OTItem::depositCheque);
10755 
10756  OTString strNote(bCancellingCheque
10757  ? "Cancel this cheque, please!"
10758  : "Deposit this cheque, please!"); // todo
10759  pItem->SetNote(strNote);
10760 
10761  OTString strCheque(theCheque); // <===== THE CHEQUE
10762 
10763  // Add the cheque string as the attachment on the transaction item.
10764  pItem->SetAttachment(
10765  strCheque); // The cheque is contained in the reference string.
10766 
10767  // sign the item
10768  pItem->SignContract(*pNym);
10769  pItem->SaveContract();
10770 
10771  // the Transaction "owns" the item now and will handle cleaning it up.
10772  pTransaction->AddItem(*pItem); // the Transaction's destructor will
10773  // cleanup the item. It "owns" it now.
10774  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
10775 
10776  if (nullptr == pOutbox) {
10777  otOut << "OT_API::depositCheque: Failed loading outbox for acct "
10778  << strDepositAcct << "\n";
10779  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10780  // NUMBERS.
10781  pNym->AddTransactionNum(*pNym, strServerID,
10782  lStoredTransactionNumber,
10783  true); // bSave=true
10784  }
10785  else {
10786  // BALANCE AGREEMENT
10787  // pBalanceItem is signed and saved within this call. No need to do
10788  // that twice.
10789  //
10790  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
10791  theCheque.GetAmount(), *pTransaction, *pNym, *pAccount,
10792  *pOutbox);
10793 
10794  if (nullptr !=
10795  pBalanceItem) // will never be nullptr. Will assert above
10796  // before it gets here.
10797  pTransaction->AddItem(
10798  *pBalanceItem); // Better not be nullptr...
10799  // message will fail...
10800  // But better check
10801  // anyway.
10802  // else log
10803  // sign the transaction
10804  pTransaction->SignContract(*pNym);
10805  pTransaction->SaveContract();
10806 
10807  // set up the ledger
10808  OTLedger theLedger(USER_ID, ACCT_ID, SERVER_ID);
10809  theLedger.GenerateLedger(ACCT_ID, SERVER_ID,
10810  OTLedger::message); // bGenerateLedger
10811  // defaults to false,
10812  // which is correct.
10813  theLedger.AddTransaction(*pTransaction); // now the ledger "owns"
10814  // and will handle cleaning
10815  // up the transaction.
10816  pTransaction.release();
10817 
10818  // sign the ledger
10819  theLedger.SignContract(*pNym);
10820  theLedger.SaveContract();
10821 
10822  // extract the ledger in ascii-armored form... encoding...
10823  OTString strLedger(theLedger);
10824  OTASCIIArmor ascLedger(strLedger);
10825 
10826  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
10827  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
10828  theMessage.m_strRequestNum.Format(
10829  "%ld", lRequestNumber); // Always have to send this.
10830  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it
10831  // for a server
10832  // request, I have to
10833  // increment it
10834 
10835  // (1) Set up member variables
10836  theMessage.m_strCommand = "notarizeTransactions";
10837  theMessage.m_strNymID = strNymID;
10838  theMessage.m_strServerID = strServerID;
10839  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
10840  // theMessage.m_strServerID is
10841  // already set. (It uses it.)
10842 
10843  theMessage.m_strAcctID = strDepositAcct;
10844  theMessage.m_ascPayload = ascLedger;
10845 
10846  OTIdentifier NYMBOX_HASH;
10847  const std::string str_server(strServerID.Get());
10848  const bool bNymboxHash =
10849  pNym->GetNymboxHash(str_server, NYMBOX_HASH);
10850  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10851 
10852  if (!bNymboxHash)
10853  otErr << "Failed getting NymboxHash from Nym for server: "
10854  << str_server << "\n";
10855 
10856  // (2) Sign the Message
10857  theMessage.SignContract(*pNym);
10858 
10859  // (3) Save the Message (with signatures and all, back to its
10860  // internal member m_strRawFile.)
10861  theMessage.SaveContract();
10862 
10863  // (Send it)
10864  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
10865  m_pTransportCallback);
10866  m_pClient->ProcessMessageOut(theMessage);
10867 
10868  return m_pClient->CalcReturnVal(lRequestNumber);
10869  }
10870  } // bSuccess
10871 
10872  return -1;
10873 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::depositPaymentPlan ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTString THE_PAYMENT_PLAN 
) const

Definition at line 10885 of file OpenTransactions.cpp.

10888 {
10889  OTServerContract* pServer =
10890  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
10891  if (nullptr == pServer) return (-1);
10892  // By this point, pServer is a good pointer. (No need to cleanup.)
10893  OTPseudonym* pNym = GetOrLoadPrivateNym(
10894  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
10895  if (nullptr == pNym) return (-1);
10896  // By this point, pNym is a good pointer. (No need to cleanup.)
10897  OTPaymentPlan thePlan;
10898  OTMessage theMessage;
10899 
10900  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
10901 
10902  if (thePlan.LoadContractFromString(THE_PAYMENT_PLAN) &&
10903  thePlan.VerifySignature(*pNym)) {
10904  int64_t lRequestNumber = 0;
10905  const bool bCancelling = (thePlan.GetRecipientUserID() == USER_ID);
10906 
10907  if (bCancelling) {
10908  if (thePlan.IsCanceled()) {
10909  otErr << __FUNCTION__
10910  << ": Error: attempted to cancel (pre-emptively, "
10911  "before activation) a payment plan "
10912  "that was already set as canceled.\n";
10913  return (-1);
10914  }
10915  else if (!thePlan.CancelBeforeActivation(
10916  *pNym)) // releases signatures, signs, saves.
10917  {
10918  otErr << __FUNCTION__
10919  << ": Error: attempted to cancel (pre-emptively, "
10920  "before activation) a payment plan, "
10921  "but the attempt somehow failed.\n";
10922  return (-1);
10923  }
10924  }
10925 
10926  // The logic for DEPOSITOR_ACCT_ID comes about because normally the
10927  // sender is the one
10928  // who activates the payment plan. BUT the recipient might ALSO activate
10929  // it as a way
10930  // of CANCELLING it. So we check to see if the recipient user is the
10931  // same as USER_ID.
10932  // If so, then we use the RECIPIENT account here (it's being cancelled.)
10933  // Otherwise,
10934  // we use the sender account ID here as normal (it's being activated.)
10935  //
10936  const OTIdentifier DEPOSITOR_ACCT_ID(bCancelling
10937  ? thePlan.GetRecipientAcctID()
10938  : thePlan.GetSenderAcctID());
10939  const OTString strDepositAcct(DEPOSITOR_ACCT_ID);
10940  OTAccount* pAccount =
10941  GetOrLoadAccount(*pNym, DEPOSITOR_ACCT_ID, SERVER_ID, __FUNCTION__);
10942  if (nullptr == pAccount) return (-1);
10943  // By this point, pAccount is a good pointer and in the wallet.
10944  // (No need to cleanup.) I also know it has the right Server ID
10945  // and that the Nym owns it, and has signed it, etc.
10946  // If the depositor is the recipient, then it's not properly confirmed
10947  // yet, and he's
10948  // actually cancelling it here. The transaction number on the plan will
10949  // still be set to 0.
10950  // Therefore he needs to use a fresh transaction number to perform this
10951  // action.
10952  // Otherwise, if the depositor is the sender (as should normally be)
10953  // then the plan is
10954  // actually being activated, and has already been properly confirmed,
10955  // and will thus
10956  // already have its own transaction number set on it.
10957  //
10958  const int64_t lTransactionNum = thePlan.GetOpeningNumber(USER_ID);
10959  // Create a transaction
10960  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
10961  USER_ID, DEPOSITOR_ACCT_ID, SERVER_ID, OTTransaction::paymentPlan,
10962  lTransactionNum);
10963  // set up the transaction item (each transaction may have multiple
10964  // items...)
10965  OTItem* pItem = OTItem::CreateItemFromTransaction(*pTransaction,
10967 
10968  OTString strPlan(thePlan);
10969 
10970  // Add the payment plan string as the attachment on the transaction
10971  // item.
10972  pItem->SetAttachment(
10973  strPlan); // The payment plan is contained in the reference string.
10974 
10975  // sign the item
10976  pItem->SignContract(*pNym);
10977  pItem->SaveContract();
10978 
10979  // the Transaction "owns" the item now and will handle cleaning it up.
10980  pTransaction->AddItem(*pItem); // the Transaction's destructor will
10981  // cleanup the item. It "owns" it now.
10982 
10983  // TRANSACTION AGREEMENT
10984 
10985  // pBalanceItem is signed and saved within this call. No need to do that
10986  // again.
10987  OTItem* pStatementItem =
10988  pNym->GenerateTransactionStatement(*pTransaction);
10989 
10990  if (nullptr !=
10991  pStatementItem) // will never be nullptr. Will assert above
10992  // before it gets here.
10993  pTransaction->AddItem(*pStatementItem); // Better not be nullptr...
10994  // message will fail... But
10995  // better check anyway.
10996  // sign the transaction
10997  pTransaction->SignContract(*pNym);
10998  pTransaction->SaveContract();
10999 
11000  // set up the ledger
11001  OTLedger theLedger(USER_ID, DEPOSITOR_ACCT_ID, SERVER_ID);
11002  theLedger.GenerateLedger(DEPOSITOR_ACCT_ID, SERVER_ID,
11003  OTLedger::message); // bGenerateLedger defaults
11004  // to false, which is
11005  // correct.
11006  theLedger.AddTransaction(*pTransaction); // now the ledger "owns" and
11007  // will handle cleaning up the
11008  // transaction.
11009 
11010  // sign the ledger
11011  theLedger.SignContract(*pNym);
11012  theLedger.SaveContract();
11013 
11014  // extract the ledger in ascii-armored form... encoding...
11015  OTString strLedger(theLedger);
11016  OTASCIIArmor ascLedger(strLedger);
11017 
11018  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
11019  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
11020  theMessage.m_strRequestNum.Format(
11021  "%ld", lRequestNumber); // Always have to send this.
11022  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
11023  // server request, I have
11024  // to increment it
11025 
11026  // (1) Set up member variables
11027  theMessage.m_strCommand = "notarizeTransactions";
11028  theMessage.m_strNymID = strNymID;
11029  theMessage.m_strServerID = strServerID;
11030  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
11031  // theMessage.m_strServerID is
11032  // already set. (It uses it.)
11033 
11034  theMessage.m_strAcctID = strDepositAcct;
11035  theMessage.m_ascPayload = ascLedger;
11036 
11037  OTIdentifier NYMBOX_HASH;
11038  const std::string str_server(strServerID.Get());
11039  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
11040  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11041 
11042  if (!bNymboxHash)
11043  otErr << "Failed getting NymboxHash from Nym for server: "
11044  << str_server << "\n";
11045 
11046  // (2) Sign the Message
11047  theMessage.SignContract(*pNym);
11048 
11049  // (3) Save the Message (with signatures and all, back to its internal
11050  // member m_strRawFile.)
11051  theMessage.SaveContract();
11052 
11053  // (Send it)
11054  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
11055  m_pTransportCallback);
11056  m_pClient->ProcessMessageOut(theMessage);
11057 
11058  return m_pClient->CalcReturnVal(lRequestNumber);
11059  } // thePlan.LoadContractFromString()
11060  else {
11061  otOut << "Unable to load payment plan from string, or verify it. "
11062  "Sorry.\n";
11063  }
11064 
11065  return (-1);
11066 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::DiscardCheque ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const OTString THE_CHEQUE 
) const

Definition at line 10514 of file OpenTransactions.cpp.

10518 {
10519  OTPseudonym* pNym = GetOrLoadPrivateNym(
10520  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
10521  if (nullptr == pNym) return false;
10522  // By this point, pNym is a good pointer, and is on the wallet. (No need to
10523  // cleanup.)
10524  OTServerContract* pServer =
10525  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
10526  if (nullptr == pServer) return false;
10527  // By this point, pServer is a good pointer. (No need to cleanup.)
10528  OTAccount* pAccount =
10529  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
10530  if (nullptr == pAccount) return false;
10531  // By this point, pAccount is a good pointer, and is on the wallet. (No need
10532  // to cleanup.)
10533  OTIdentifier CONTRACT_ID;
10534  OTString strContractID;
10535 
10536  CONTRACT_ID = pAccount->GetAssetTypeID();
10537  CONTRACT_ID.GetString(strContractID);
10538  // By this point, pNym is a good pointer, and is on the wallet.
10539  // (No need to cleanup.) pServer and pAccount are also good.
10540  //
10541  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
10542 
10543  OTCheque theCheque(SERVER_ID, CONTRACT_ID);
10544 
10545  if (!theCheque.LoadContractFromString(THE_CHEQUE)) {
10546  otOut << __FUNCTION__ << ": Unable to load cheque from string. Sorry. "
10547  "Cheque contents:\n\n" << THE_CHEQUE << "\n\n";
10548  return false;
10549  }
10550  else if ((theCheque.GetServerID() == SERVER_ID) &&
10551  (theCheque.GetAssetID() == CONTRACT_ID) &&
10552  (theCheque.GetSenderUserID() == USER_ID) &&
10553  (theCheque.GetSenderAcctID() == ACCT_ID)) {
10554  if (pNym->VerifyIssuedNum(
10555  strServerID, theCheque.GetTransactionNum())) // we only "add it
10556  // back" if it was
10557  // really there in
10558  // the first place.
10559  {
10560  pNym->AddTransactionNum(*pNym, strServerID,
10561  theCheque.GetTransactionNum(),
10562  true); // bSave=true
10563  return true;
10564  }
10565  else // No point adding it back as available to use, if pNym doesn't
10566  // even have it signed out!
10567  {
10568  otOut << __FUNCTION__
10569  << ": Failed attempt to claw back a transaction number that "
10570  "wasn't signed out to pNym in the first place. "
10571  "Cheque contents:\n\n" << THE_CHEQUE << "\n\n";
10572  return false;
10573  }
10574  } // bSuccess
10575  else
10576  otOut << __FUNCTION__
10577  << ": Unable to verify cheque's server ID, asset type "
10578  "ID, user ID, or acct ID. Sorry. "
10579  "Cheque contents:\n\n" << THE_CHEQUE << "\n\n";
10580  return false;
10581 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::DoesBoxReceiptExist ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID,
int32_t  nBoxType,
const int64_t &  lTransactionNum 
) const

Definition at line 13304 of file OpenTransactions.cpp.

13311 {
13312  // static
13313  return VerifyBoxReceiptExists(
13314  SERVER_ID, USER_ID, // Unused here for now, but still convention.
13315  ACCOUNT_ID, // If for Nymbox (vs inbox/outbox) then pass USER_ID in this
13316  // field also.
13317  nBoxType, // 0/nymbox, 1/inbox, 2/outbox
13318  lTransactionNum);
13319 }
EXPORT bool VerifyBoxReceiptExists(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, int32_t nBoxType, const int64_t &lTransactionNum)
Definition: Helpers.cpp:358
bool opentxs::OT_API::Encode ( const OTString strPlaintext,
OTString strOutput,
bool  bLineBreaks = true 
) const

OT-encode a plaintext string. This will pack, compress, and base64-encode a plain string. Returns the base64-encoded string, or nullptr.

OT-encode a plaintext string.

const char * OT_API_Encode(const char * szPlaintext);

This will pack, compress, and base64-encode a plain string. Returns the base64-encoded string, or nullptr.

Internally: OTString strPlain(szPlaintext); OTASCIIArmor ascEncoded(thePlaintext); // ascEncoded now contains the OT-encoded string. return ascEncoded.Get(); // We return it.

Definition at line 3229 of file OpenTransactions.cpp.

3231 {
3232  OTASCIIArmor ascArmor;
3233  bool bSuccess = ascArmor.SetString(strPlaintext, bLineBreaks); // encodes.
3234 
3235  if (bSuccess) {
3236  strOutput.Release();
3237  bSuccess = ascArmor.WriteArmoredString(
3238  strOutput, "ENCODED TEXT" // -----BEGIN OT ENCODED TEXT-----
3239  ); // (bool bEscaped=false by default.)
3240  }
3241  return bSuccess;
3242 }
bool opentxs::OT_API::Encrypt ( const OTIdentifier theRecipientNymID,
const OTString strPlaintext,
OTString strOutput 
) const
OT-ENCRYPT a plaintext string.

This will encode, ENCRYPT, and encode a plain string. Returns the base64-encoded ciphertext, or nullptr.

OT-ENCRYPT a plaintext string.

const char * OT_API_Encrypt(const char * RECIPIENT_NYM_ID, const char * szPlaintext);

This will encode, ENCRYPT, and encode a plain string. Returns the base64-encoded ciphertext, or nullptr.

Internally the C++ code is: OTString strPlain(szPlaintext); OTEnvelope theEnvelope; if (theEnvelope.Seal(RECIPIENT_NYM, strPlain)) { // Now it's encrypted (in binary form, inside the envelope), to the recipient's nym. OTASCIIArmor ascCiphertext(theEnvelope); // ascCiphertext now contains the base64-encoded ciphertext (as a string.) return ascCiphertext.Get(); }

Definition at line 3292 of file OpenTransactions.cpp.

3294 {
3295  OTPasswordData thePWData(OT_PW_DISPLAY);
3296  OTPseudonym* pRecipientNym =
3297  GetOrLoadNym(theRecipientNymID, false, __FUNCTION__,
3298  &thePWData); // This logs and ASSERTs already.
3299  if (nullptr == pRecipientNym) return false;
3300  OTEnvelope theEnvelope;
3301  bool bSuccess = theEnvelope.Seal(*pRecipientNym, strPlaintext);
3302 
3303  if (bSuccess) {
3304  OTASCIIArmor ascCiphertext(theEnvelope);
3305  strOutput.Release();
3306 
3307  bSuccess = ascCiphertext.WriteArmoredString(
3308  strOutput, "ENCRYPTED TEXT" // -----BEGIN OT ENCRYPTED TEXT-----
3309  ); // (bool bEscaped=false by default.)
3310  }
3311  return bSuccess;
3312 }
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
int32_t opentxs::OT_API::exchangeBasket ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier BASKET_ASSET_ID,
const OTString BASKET_INFO,
bool  bExchangeInOrOut 
) const

Definition at line 9110 of file OpenTransactions.cpp.

9115 {
9116  OTPseudonym* pNym = GetOrLoadPrivateNym(
9117  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
9118  if (nullptr == pNym) return (-1);
9119  // By this point, pNym is a good pointer, and is on the wallet. (No need to
9120  // cleanup.)
9121  OTServerContract* pServer =
9122  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
9123  if (nullptr == pServer) return (-1);
9124  // By this point, pServer is a good pointer. (No need to cleanup.)
9125  OTAssetContract* pContract = GetAssetType(BASKET_ASSET_ID, __FUNCTION__);
9126  if (nullptr == pContract) return (-1);
9127  // By this point, pContract is a good pointer, and is on the wallet. (No
9128  // need to cleanup.)
9129  const OTString strServerID(SERVER_ID), strUserID(USER_ID);
9130 
9131  // Next load the Basket object out of that contract, and load the
9132  // RequestBasket object that was passed in.
9133  Basket theBasket, theRequestBasket;
9134 
9135  if (pContract->GetBasketInfo().GetLength() &&
9136  theBasket.LoadContractFromString(pContract->GetBasketInfo()) &&
9137  BASKET_INFO.GetLength() &&
9138  theRequestBasket.LoadContractFromString(BASKET_INFO)) {
9139  const OTIdentifier& BASKET_ASSET_ACCT_ID(
9140  theRequestBasket.GetRequestAccountID());
9141  OTAccount* pAccount = GetOrLoadAccount(*pNym, BASKET_ASSET_ACCT_ID,
9142  SERVER_ID, __FUNCTION__);
9143  if (nullptr == pAccount) return (-1);
9144 
9145  // By this point, pAccount is a good pointer, and is on the wallet. (No
9146  // need to cleanup.)
9147  // We need a transaction number just to send this thing. Plus, we need a
9148  // number for
9149  // each sub-account to the basket, as well as the basket's main account.
9150  // That is: 1 + theBasket.Count() + 1
9151  // Total of 2, since theBasket.Count() worth of numbers were already
9152  // added in the
9153  // calls to OT_API::AddBasketExchangeItem.
9154 
9155  if (pNym->GetTransactionNumCount(SERVER_ID) < 2) {
9156  otOut << "OT_API::exchangeBasket: you don't have enough "
9157  "transaction numbers to perform the exchange.\n";
9158  }
9159  else {
9160  int64_t lStoredTransactionNumber = 0;
9161  bool bGotTransNum = pNym->GetNextTransactionNum(
9162  *pNym, strServerID, lStoredTransactionNumber); // this saves
9163 
9164  if (bGotTransNum) {
9165  // LOAD the INBOX for the MAIN ACCOUNT
9166  //
9167  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
9168  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
9169 
9170  if (nullptr == pInbox) {
9171  otOut << "OT_API::exchangeBasket: Failed loading inbox!\n";
9172 
9173  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF
9174  // AVAILABLE NUMBERS.
9175  pNym->AddTransactionNum(*pNym, strServerID,
9176  lStoredTransactionNumber,
9177  true); // bSave=true
9178  }
9179  else if (nullptr == pOutbox) {
9180  otOut << "OT_API::exchangeBasket: Failed loading outbox!\n";
9181 
9182  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF
9183  // AVAILABLE NUMBERS.
9184  pNym->AddTransactionNum(*pNym, strServerID,
9185  lStoredTransactionNumber,
9186  true); // bSave=true
9187  }
9188  // Set up the Request Basket! ------------------------------
9189  else {
9190  // Create a transaction
9191  OTTransaction* pTransaction =
9193  USER_ID, BASKET_ASSET_ACCT_ID, SERVER_ID,
9195  lStoredTransactionNumber);
9196 
9197  // set up the transaction item (each transaction may have
9198  // multiple items...)
9199  OTItem* pItem = OTItem::CreateItemFromTransaction(
9200  *pTransaction, OTItem::exchangeBasket);
9201 
9202  // This pItem is where the Basket Info will be stored. (So
9203  // it ends up on receipts...)
9204  pTransaction->AddItem(*pItem); // the Transaction's
9205  // destructor will cleanup
9206  // the item. It "owns" it
9207  // now.
9208 
9209  // NOTE: I'm not checking this call for success...
9210  // But, I DID check the count beforehand, and I know there
9211  // are enough numbers.
9212  //
9213  int64_t lClosingTransactionNo =
9214  0; // for Main Basket Acct on the Request Basket.
9215  OT_ASSERT(pNym->GetNextTransactionNum(
9216  *pNym, strServerID,
9217  lClosingTransactionNo)); // this saves
9218 
9219  // This goes in the final API call.
9220  theRequestBasket.SetClosingNum(
9221  lClosingTransactionNo); // For the basketReceipt
9222  // (Closing Transaction Num) for
9223  // main account.
9224 
9225  // This goes in the final API call.
9226  theRequestBasket.SetExchangingIn(bExchangeInOrOut);
9227 
9228  theRequestBasket.ReleaseSignatures();
9229  theRequestBasket.SignContract(*pNym);
9230  theRequestBasket.SaveContract();
9231 
9232  // Export the Basket object into a string, add it as
9233  // a payload on my request, and send to server.
9234  OTString strBasketInfo;
9235  theRequestBasket.SaveContractRaw(strBasketInfo);
9236 
9237  pItem->SetAttachment(strBasketInfo);
9238 
9239  // sign the item. save it.
9240  //
9241  pItem->SignContract(*pNym);
9242  pItem->SaveContract();
9243 
9244  // BALANCE AGREEMENT!
9245  //
9246  // pBalanceItem is signed and saved within this call. No
9247  // need to do that again.
9248  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
9249  0, // Change in balance is 0. (The accounts will all be
9250  // changed,
9251  *pTransaction, *pNym, *pAccount,
9252  *pOutbox); // but basketReceipts will be used to account
9253  // for it.)
9254 
9255  if (nullptr !=
9256  pBalanceItem) // will never be nullptr. Will assert
9257  // above before it gets here.
9258  pTransaction->AddItem(*pBalanceItem); // Better not be
9259  // nullptr... message
9260  // will fail...
9261  // But better
9262  // check anyway.
9263 
9264  // sign the transaction
9265  pTransaction->SignContract(*pNym);
9266  pTransaction->SaveContract();
9267 
9268  // set up the ledger
9269  OTLedger theLedger(USER_ID, BASKET_ASSET_ACCT_ID,
9270  SERVER_ID);
9271  theLedger.GenerateLedger(
9272  BASKET_ASSET_ACCT_ID, SERVER_ID,
9273  OTLedger::message); // bGenerateLedger defaults to
9274  // false, which is correct.
9275  theLedger.AddTransaction(*pTransaction);
9276 
9277  // sign the ledger
9278  theLedger.SignContract(*pNym);
9279  theLedger.SaveContract();
9280 
9281  // extract the ledger in ascii-armored form
9282  OTString strLedger(theLedger);
9283  OTASCIIArmor ascLedger; // I can't pass strLedger into this
9284  // constructor because I want to
9285  // encode it
9286 
9287  // Encoding...
9288  ascLedger.SetString(strLedger);
9289 
9290  OTMessage theMessage;
9291 
9292  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
9293  int64_t lRequestNumber = 0;
9294  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
9295  theMessage.m_strRequestNum.Format(
9296  "%ld", lRequestNumber); // Always have to send this.
9297  pNym->IncrementRequestNum(
9298  *pNym, strServerID); // since I used it for a server
9299  // request, I have to increment it
9300 
9301  // (1) Set up member variables
9302  theMessage.m_strCommand = "notarizeTransactions";
9303  theMessage.m_strNymID = strUserID;
9304  theMessage.m_strServerID = strServerID;
9305  theMessage.SetAcknowledgments(
9306  *pNym); // Must be called AFTER theMessage.m_strServerID
9307  // is already set. (It uses it.)
9308 
9309  BASKET_ASSET_ACCT_ID.GetString(theMessage.m_strAcctID);
9310  theMessage.m_ascPayload = ascLedger;
9311 
9312  OTIdentifier NYMBOX_HASH;
9313  const std::string str_server(strServerID.Get());
9314  const bool bNymboxHash =
9315  pNym->GetNymboxHash(str_server, NYMBOX_HASH);
9316  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
9317 
9318  if (!bNymboxHash)
9319  otErr << "Failed getting NymboxHash from Nym for "
9320  "server: " << str_server << "\n";
9321 
9322  // (2) Sign the Message
9323  theMessage.SignContract(*pNym);
9324 
9325  // (3) Save the Message (with signatures and all, back to
9326  // its internal member m_strRawFile.)
9327  theMessage.SaveContract();
9328 
9329  // (Send it)
9330  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
9331  m_pTransportCallback);
9332  m_pClient->ProcessMessageOut(theMessage);
9333 
9334  return m_pClient->CalcReturnVal(lRequestNumber);
9335  } // Inbox loaded.
9336  } // successfully got first transaction number.
9337  }
9338  }
9339 
9340  return (-1);
9341 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::FlatSign ( const OTIdentifier theSignerNymID,
const OTString strInput,
const OTString strContractType,
OTString strOutput 
) const

OT-Sign a piece of flat text. (With no discernible bookends around it.) strType contains the OT type. For example, if you are trying to sign a ledger (which does not have any existing signatures on it) then you would pass LEDGER for strType, resulting in --—BEGIN OT SIGNED LEDGER--—

OT-Sign a piece of flat text. (With no discernible bookends around it.) strContractType contains, for example, if you are trying to sign a ledger (which does not have any existing signatures on it) then you would pass LEDGER for strContractType, resulting in --—BEGIN OT SIGNED LEDGER--—

Definition at line 3367 of file OpenTransactions.cpp.

3370 {
3371  OTPseudonym* pNym = GetOrLoadPrivateNym(
3372  theSignerNymID, false, __FUNCTION__); // This logs and ASSERTs already.
3373  if (nullptr == pNym) return false;
3374  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3375  // cleanup.)
3376  if (!strInput.Exists()) {
3377  otOut << __FUNCTION__
3378  << ": Empty contract passed in. (Returning false.)\n";
3379  return false;
3380  }
3381  if (!strContractType.Exists()) {
3382  otOut << __FUNCTION__
3383  << ": Empty contract type passed in. (Returning false.)\n";
3384  return false;
3385  }
3386  OTString strTemp(strInput);
3387  return OTContract::SignFlatText(strTemp, strContractType, *pNym, strOutput);
3388 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT bool SignFlatText(OTString &strFlatText, const OTString &strContractType, const OTPseudonym &theSigner, OTString &strOutput)
void opentxs::OT_API::FlushMessageBuffer ( )

Definition at line 8326 of file OpenTransactions.cpp.

8327 {
8328  OT_ASSERT_MSG(m_bInitialized && (m_pClient != nullptr),
8329  "Not initialized; call OT_API::Init first.");
8330 
8331  m_pClient->GetMessageBuffer().Clear();
8332 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTMessageBuffer & GetMessageBuffer()
Definition: OTClient.hpp:359
void opentxs::OT_API::FlushSentMessages ( bool  bHarvestingForRetry,
const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTLedger THE_NYMBOX 
) const

Definition at line 8440 of file OpenTransactions.cpp.

8444 {
8445  OT_ASSERT_MSG(m_bInitialized && (m_pClient != nullptr),
8446  "Not initialized; call OT_API::Init first.");
8447  OTPseudonym* pNym =
8448  GetNym(USER_ID, __FUNCTION__); // This logs and ASSERTs already.
8449  if (nullptr == pNym) return;
8450  // Below this point, pNym is a good ptr, and will be cleaned up
8451  // automatically.
8452  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
8453  if ((THE_NYMBOX.GetUserID() != USER_ID) ||
8454  (THE_NYMBOX.GetPurportedServerID() != SERVER_ID)) {
8455  const OTString strLedger(THE_NYMBOX);
8456  otErr << __FUNCTION__ << ": Failure, Bad input data: UserID ("
8457  << strNymID << ") or ServerID "
8458  "(" << strServerID
8459  << ") failed to match Nymbox:\n\n" << strLedger << "\n\n";
8460  return;
8461  }
8462  // Iterate through the nymbox receipts.
8463  // If ANY of them is a REPLY NOTICE, then see if the SENT MESSAGE for that
8464  // SAME
8465  // request number is in the sent queue.
8466  // If it IS, REMOVE IT from the sent queue. (Since Nymbox clearly already
8467  // contains
8468  // a reply to it, no need to queue it anymore.)
8469  // At the end of this loop, then FLUSH the sent queue. We KNOW only
8470  // important
8471  // (nymbox related) messages should be queued there, and once we see the
8472  // latest Nymbox,
8473  // then we KNOW which ones to remove before flushing.
8474  //
8475  for (auto& it : THE_NYMBOX.GetTransactionMap()) {
8476  const OTTransaction* pTransaction = it.second;
8477  OT_ASSERT(nullptr != pTransaction);
8478 
8479  if (OTTransaction::replyNotice == pTransaction->GetType()) {
8480  OTMessage* pMessage =
8481  m_pClient->GetMessageOutbuffer().GetSentMessage(*pTransaction);
8482 
8483  if (nullptr != pMessage) // It WAS there in my sent buffer!
8484  {
8485  // Since it IS in my Nymbox already as a replyNotice,
8486  // therefore I'm safe to erase it from my sent queue.
8487  //
8489  *pTransaction);
8490  }
8491  // else do nothing, must have already removed it.
8492  }
8493  }
8494  // Now that we've REMOVED the sent messages that already have a reply
8495  // in the Nymbox (and thus CLEARLY do not need harvesting...)
8496  //
8497  // Clear all "sent message" cached messages for this server and NymID.
8498  // (And harvest their transaction numbers back, since we know for a fact
8499  // the server hasn't replied to them (the reply would be in the Nymbox,
8500  // which
8501  // we just got.)
8502  //
8503  // UPDATE: We will have to rely on the Developer using the OT API to call
8504  // OT_API_FlushSentMessages IMMEDIATELY after calling getNymbox and
8505  // receiving
8506  // a successful reply. Why? Because that's the only way to give him the
8507  // chance
8508  // to see if certain replies are there or not (before they get removed.)
8509  // That way
8510  // he can do his own harvesting, do a re-try, etc and then finally when he
8511  // is done
8512  // with that, do the flush.
8513  //
8514  m_pClient->GetMessageOutbuffer().Clear(
8515  &strServerID, &strNymID, pNym,
8516  &bHarvestingForRetry); // FYI: This HARVESTS any sent messages that need
8517  // harvesting, before flushing them all.
8518 }
EXPORT OTMessage * GetSentMessage(const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
EXPORT bool RemoveSentMessage(const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
OTMessageOutbuffer & GetMessageOutbuffer()
Definition: OTClient.hpp:363
EXPORT void Clear(const OTString *serverId=nullptr, const OTString *nymId=nullptr, OTPseudonym *nym=nullptr, const bool *harvestingForRetry=nullptr)
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
Basket * opentxs::OT_API::GenerateBasketCreation ( const OTIdentifier USER_ID,
int64_t  MINIMUM_TRANSFER 
) const

Definition at line 8714 of file OpenTransactions.cpp.

8718 {
8719  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
8720  if (nullptr == pNym) return nullptr;
8721  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8722  // cleanup.)
8723  int64_t lMinimumTransferAmount = 10;
8724 
8725  if (MINIMUM_TRANSFER > 0) lMinimumTransferAmount = MINIMUM_TRANSFER;
8726  Basket* pBasket = new Basket(0, lMinimumTransferAmount);
8727  OT_ASSERT_MSG(nullptr != pBasket, "OT_API::GenerateBasketCreation: Error "
8728  "allocating memory in the OT API");
8729 
8730  pBasket->SignContract(*pNym);
8731  pBasket->SaveContract();
8732 
8733  return pBasket;
8734 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
Basket * opentxs::OT_API::GenerateBasketExchange ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier BASKET_ASSET_TYPE_ID,
const OTIdentifier BASKET_ASSET_ACCT_ID,
int32_t  TRANSFER_MULTIPLE 
) const

Definition at line 8825 of file OpenTransactions.cpp.

8830 {
8831  OTPseudonym* pNym = GetOrLoadPrivateNym(
8832  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
8833  if (nullptr == pNym) return nullptr;
8834  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8835  // cleanup.)
8836  OTAssetContract* pContract =
8837  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8838  if (nullptr == pContract) return nullptr;
8839  // By this point, pContract is a good pointer, and is on the wallet. (No
8840  // need to cleanup.)
8841  OTAccount* pAccount =
8842  GetOrLoadAccount(*pNym, BASKET_ASSET_ACCT_ID, SERVER_ID, __FUNCTION__);
8843  if (nullptr == pAccount) return nullptr;
8844  // By this point, pAccount is a good pointer, and is on the wallet. (No need
8845  // to cleanup.)
8846  if (BASKET_ASSET_TYPE_ID != pAccount->GetAssetTypeID()) {
8847  const OTString strAcctID(BASKET_ASSET_ACCT_ID),
8848  strAcctTypeID(BASKET_ASSET_TYPE_ID);
8849  otOut << "OT_API::GenerateBasketExchange: Wrong asset type ID "
8850  "on account " << strAcctID << " (expected type to be "
8851  << strAcctTypeID << ")\n";
8852  return nullptr;
8853  }
8854  // By this point, I know that everything checks out. Signature and Account
8855  // ID.
8856  // pAccount is good, and no need to clean it up.
8857  OTString strServerID(SERVER_ID);
8858 
8859  int32_t nTransferMultiple = 1;
8860 
8861  if (TRANSFER_MULTIPLE > 0) nTransferMultiple = TRANSFER_MULTIPLE;
8862 
8863  // Next load the Basket object out of that contract.
8864  Basket theBasket;
8865  Basket* pRequestBasket = nullptr;
8866 
8867  // todo perhaps verify the basket here, even though I already verified the
8868  // asset contract itself...
8869  // Can't never be too sure.
8870  if (pContract->GetBasketInfo().Exists() &&
8871  theBasket.LoadContractFromString(pContract->GetBasketInfo())) {
8872  // We need a transaction number just to send this thing. Plus, we need a
8873  // number for
8874  // each sub-account to the basket, as well as the basket's main account.
8875  // That is: 1 + theBasket.Count() + 1
8876  //
8877  if (pNym->GetTransactionNumCount(SERVER_ID) < (2 + theBasket.Count())) {
8878  otOut << "OT_API::GenerateBasketExchange: you don't have "
8879  "enough transaction numbers to perform the "
8880  "exchange.\n";
8881  }
8882  else {
8883  pRequestBasket =
8884  new Basket(theBasket.Count(), theBasket.GetMinimumTransfer());
8885  OT_ASSERT_MSG(nullptr != pRequestBasket,
8886  "OT_API::GenerateBasketExchange: Error allocating "
8887  "memory in the OT API");
8888 
8889  pRequestBasket->SetTransferMultiple(
8890  nTransferMultiple); // This stays in this function.
8891 
8892  // Make sure the server knows where to put my new basket currency
8893  // funds,
8894  // once the exchange is done.
8895  pRequestBasket->SetRequestAccountID(
8896  BASKET_ASSET_ACCT_ID); // This stays too
8897 
8898  // Export the Basket object into a string, add it as
8899  // a payload on my request, and send to server.
8900  pRequestBasket->SignContract(*pNym);
8901  pRequestBasket->SaveContract();
8902  } // *pNym apparently has enough transaction numbers to exchange the
8903  // basket.
8904  }
8905  else {
8906  otOut << "OT_API::GenerateBasketExchange: Error loading "
8907  "basket info from asset contract. "
8908  "Are you SURE this is a basket currency?\n";
8909  return nullptr;
8910  }
8911  return pRequestBasket;
8912 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::GetAccount ( int32_t  iIndex,
OTIdentifier THE_ID,
OTString THE_NAME 
) const

Definition at line 1366 of file OpenTransactions.cpp.

1368 {
1369  OTWallet* pWallet =
1370  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1371  if (nullptr != pWallet)
1372  return pWallet->GetAccount(iIndex, THE_ID, THE_NAME);
1373 
1374  return false;
1375 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTAccount * opentxs::OT_API::GetAccount ( const OTIdentifier THE_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1449 of file OpenTransactions.cpp.

1451 {
1452  OTWallet* pWallet = GetWallet(nullptr != szFunc ? szFunc : __FUNCTION__);
1453  if (nullptr != pWallet) {
1454  OTAccount* pAcct = pWallet->GetAccount(THE_ID);
1455  if ((nullptr == pAcct) &&
1456  (nullptr != szFunc)) // We only log if the caller asked us to.
1457  {
1458  const OTString strID(THE_ID);
1459  otWarn << __FUNCTION__ << " " << szFunc
1460  << ": No account found in "
1461  "wallet with ID: " << strID << "\n";
1462  }
1463  return pAcct;
1464  }
1465  return nullptr;
1466 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otWarn
int32_t opentxs::OT_API::getAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID 
) const

Definition at line 13392 of file OpenTransactions.cpp.

13395 {
13396  OTPseudonym* pNym = GetOrLoadPrivateNym(
13397  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13398  if (nullptr == pNym) return (-1);
13399  // By this point, pNym is a good pointer, and is on the wallet.
13400  // (No need to cleanup.)
13401  OTServerContract* pServer =
13402  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13403  if (nullptr == pServer) return (-1);
13404  // By this point, pServer is a good pointer. (No need to cleanup.)
13405  OTAccount* pAccount =
13406  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
13407  if (nullptr == pAccount) return (-1);
13408  // By this point, pAccount is a good pointer, and is on the wallet. (No need
13409  // to cleanup.)
13410  OTMessage theMessage;
13411  int64_t lRequestNumber = 0;
13412 
13413  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCT_ID);
13414 
13415  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13416  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13417  theMessage.m_strRequestNum.Format(
13418  "%ld", lRequestNumber); // Always have to send this.
13419  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13420  // server request, I have to
13421  // increment it
13422 
13423  // (1) set up member variables
13424  theMessage.m_strCommand = "getAccount";
13425  theMessage.m_strNymID = strNymID;
13426  theMessage.m_strServerID = strServerID;
13427  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13428  // theMessage.m_strServerID is already
13429  // set. (It uses it.)
13430 
13431  theMessage.m_strAcctID = strAcctID;
13432 
13433  // (2) Sign the Message
13434  theMessage.SignContract(*pNym);
13435 
13436  // (3) Save the Message (with signatures and all, back to its internal
13437  // member m_strRawFile.)
13438  theMessage.SaveContract();
13439 
13440  // (Send it)
13441  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13442  m_pClient->ProcessMessageOut(theMessage);
13443 
13444  return m_pClient->CalcReturnVal(lRequestNumber);
13445 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::GetAccountCount ( ) const

Definition at line 1326 of file OpenTransactions.cpp.

1327 {
1328  OTWallet* pWallet =
1329  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1330  if (nullptr != pWallet) return pWallet->GetAccountCount();
1331 
1332  return 0;
1333 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::getAccountFiles ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID 
) const

Definition at line 13447 of file OpenTransactions.cpp.

13450 {
13451  OTPseudonym* pNym = GetOrLoadPrivateNym(
13452  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13453  if (nullptr == pNym) return (-1);
13454  // By this point, pNym is a good pointer, and is on the wallet.
13455  // (No need to cleanup.)
13456  OTServerContract* pServer =
13457  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13458  if (nullptr == pServer) return (-1);
13459  // By this point, pServer is a good pointer. (No need to cleanup.)
13460  OTAccount* pAccount =
13461  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
13462  if (nullptr == pAccount) return (-1);
13463  // By this point, pAccount is a good pointer, and is on the wallet. (No need
13464  // to cleanup.)
13465  OTMessage theMessage;
13466  int64_t lRequestNumber = 0;
13467 
13468  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCT_ID);
13469 
13470  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13471  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13472  theMessage.m_strRequestNum.Format(
13473  "%ld", lRequestNumber); // Always have to send this.
13474  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13475  // server request, I have to
13476  // increment it
13477 
13478  // (1) set up member variables
13479  theMessage.m_strCommand = "getAccountFiles";
13480  theMessage.m_strNymID = strNymID;
13481  theMessage.m_strServerID = strServerID;
13482  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13483  // theMessage.m_strServerID is already
13484  // set. (It uses it.)
13485 
13486  theMessage.m_strAcctID = strAcctID;
13487 
13488  // (2) Sign the Message
13489  theMessage.SignContract(*pNym);
13490 
13491  // (3) Save the Message (with signatures and all, back to its internal
13492  // member m_strRawFile.)
13493  theMessage.SaveContract();
13494 
13495  // (Send it)
13496  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13497  m_pClient->ProcessMessageOut(theMessage);
13498 
13499  return m_pClient->CalcReturnVal(lRequestNumber);
13500 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTAccount * opentxs::OT_API::GetAccountPartialMatch ( const std::string  PARTIAL_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1500 of file OpenTransactions.cpp.

1502 {
1503  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
1504  OTWallet* pWallet = GetWallet(szFunc); // This logs and ASSERTs already.
1505  if (nullptr != pWallet) return pWallet->GetAccountPartialMatch(PARTIAL_ID);
1506 
1507  return nullptr;
1508 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTAssetContract * opentxs::OT_API::GetAssetContractPartialMatch ( const std::string  PARTIAL_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1489 of file OpenTransactions.cpp.

1491 {
1492  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
1493  OTWallet* pWallet = GetWallet(szFunc); // This logs and ASSERTs already.
1494  if (nullptr != pWallet)
1495  return pWallet->GetAssetContractPartialMatch(PARTIAL_ID);
1496 
1497  return nullptr;
1498 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
bool opentxs::OT_API::GetAssetType ( int32_t  iIndex,
OTIdentifier THE_ID,
OTString THE_NAME 
) const

Definition at line 1355 of file OpenTransactions.cpp.

1357 {
1358  OTWallet* pWallet =
1359  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1360  if (nullptr != pWallet)
1361  return pWallet->GetAssetType(iIndex, THE_ID, THE_NAME);
1362 
1363  return false;
1364 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTAssetContract * opentxs::OT_API::GetAssetType ( const OTIdentifier THE_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1430 of file OpenTransactions.cpp.

1432 {
1433  OTWallet* pWallet = GetWallet(nullptr != szFunc ? szFunc : __FUNCTION__);
1434  if (nullptr != pWallet) {
1435  OTAssetContract* pContract = pWallet->GetAssetContract(THE_ID);
1436  if ((nullptr == pContract) &&
1437  (nullptr != szFunc)) // We only log if the caller asked us to.
1438  {
1439  const OTString strID(THE_ID);
1440  otWarn << __FUNCTION__ << " " << szFunc
1441  << ": No asset contract "
1442  "found in wallet with ID: " << strID << "\n";
1443  }
1444  return pContract;
1445  }
1446  return nullptr;
1447 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otWarn
int32_t opentxs::OT_API::GetAssetTypeCount ( ) const

Definition at line 1317 of file OpenTransactions.cpp.

1318 {
1319  OTWallet* pWallet =
1320  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1321  if (nullptr != pWallet) return pWallet->GetAssetTypeCount();
1322 
1323  return 0;
1324 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::GetBasketMemberCount ( const OTIdentifier BASKET_ASSET_TYPE_ID) const

Definition at line 8570 of file OpenTransactions.cpp.

8572 {
8573  // There is an OT_ASSERT_MSG in here for memory failure,
8574  // but it still might return nullptr if various verification fails.
8575  OTAssetContract* pContract =
8576  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8577  if (nullptr == pContract) return 0;
8578  // No need to cleanup pContract.
8579  // Next load the Basket object out of that contract.
8580  Basket theBasket;
8581 
8582  // todo perhaps verify the basket here, even though I already verified the
8583  // asset contract itself...
8584  // Can't never be too sure...
8585  //
8586  if (pContract->GetBasketInfo().Exists() &&
8587  theBasket.LoadContractFromString(pContract->GetBasketInfo()))
8588  return theBasket.Count();
8589 
8590  return 0;
8591 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
int64_t opentxs::OT_API::GetBasketMemberMinimumTransferAmount ( const OTIdentifier BASKET_ASSET_TYPE_ID,
int32_t  nIndex 
) const

Definition at line 8640 of file OpenTransactions.cpp.

8642 {
8643  // There is an OT_ASSERT_MSG in here for memory failure,
8644  // but it still might return nullptr if various verification fails.
8645  OTAssetContract* pContract =
8646  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8647  if (nullptr == pContract) return 0;
8648  // No need to cleanup pContract.
8649  // Next load the Basket object out of that contract.
8650  Basket theBasket;
8651 
8652  // todo perhaps verify the basket here, even though I already verified the
8653  // asset contract itself...
8654  // Can't never be too sure.
8655  if (pContract->GetBasketInfo().GetLength() &&
8656  theBasket.LoadContractFromString(pContract->GetBasketInfo())) {
8657  if ((nIndex >= theBasket.Count()) || (nIndex < 0)) {
8658  otErr << "OT_API::GetBasketMemberMinimumTransferAmount: Index "
8659  "out of bounds: " << nIndex << "\n";
8660  return 0;
8661  }
8662 
8663  BasketItem* pItem = theBasket.At(nIndex);
8664 
8665  OT_ASSERT_MSG(
8666  nullptr != pItem,
8667  "Bad index in OT_API::GetBasketMemberMinimumTransferAmount.");
8668 
8669  return pItem->lMinimumTransferAmount;
8670  ;
8671  }
8672  else
8673  otErr << "OT_API::GetBasketMemberMinimumTransferAmount: Failed "
8674  "loading basket info from basket asset contract.\n";
8675 
8676  return 0;
8677 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::GetBasketMemberType ( const OTIdentifier BASKET_ASSET_TYPE_ID,
int32_t  nIndex,
OTIdentifier theOutputMemberType 
) const

Definition at line 8599 of file OpenTransactions.cpp.

8602 {
8603  // There is an OT_ASSERT_MSG in here for memory failure,
8604  // but it still might return nullptr if various verification fails.
8605  OTAssetContract* pContract =
8606  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8607  if (nullptr == pContract) return false;
8608  // No need to cleanup pContract.
8609  // Next load the Basket object out of that contract.
8610  Basket theBasket;
8611 
8612  // todo perhaps verify the basket here, even though I already verified the
8613  // asset contract itself...
8614  // Can't never be too sure.
8615  if (pContract->GetBasketInfo().GetLength() &&
8616  theBasket.LoadContractFromString(pContract->GetBasketInfo())) {
8617  if ((nIndex >= theBasket.Count()) || (nIndex < 0)) {
8618  otErr << "OT_API::GetBasketMemberType: Index out of bounds: "
8619  << nIndex << "\n";
8620  return false;
8621  }
8622 
8623  BasketItem* pItem = theBasket.At(nIndex);
8624  OT_ASSERT_MSG(nullptr != pItem,
8625  "Bad index in OT_API::GetBasketMemberType");
8626 
8627  theOutputMemberType = pItem->SUB_CONTRACT_ID;
8628 
8629  return true;
8630  }
8631  return false;
8632 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
int64_t opentxs::OT_API::GetBasketMinimumTransferAmount ( const OTIdentifier BASKET_ASSET_TYPE_ID) const

Definition at line 8684 of file OpenTransactions.cpp.

8686 {
8687  // There is an OT_ASSERT_MSG in here for memory failure,
8688  // but it still might return nullptr if various verification fails.
8689  OTAssetContract* pContract =
8690  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8691  if (nullptr == pContract) return 0;
8692  // No need to cleanup pContract.
8693  // Next load the Basket object out of that contract.
8694  Basket theBasket;
8695 
8696  // todo perhaps verify the basket here, even though I already verified the
8697  // asset contract itself...
8698  // Can't never be too sure.
8699  if (pContract->GetBasketInfo().GetLength() &&
8700  theBasket.LoadContractFromString(pContract->GetBasketInfo()))
8701  return theBasket.GetMinimumTransfer();
8702 
8703  return 0;
8704 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
int32_t opentxs::OT_API::getBoxReceipt ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID,
int32_t  nBoxType,
const int64_t &  lTransactionNum 
) const

Definition at line 13321 of file OpenTransactions.cpp.

13327 {
13328  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
13329  if (nullptr == pNym) return (-1);
13330  // By this point, pNym is a good pointer, and is on the wallet.
13331  // (No need to cleanup.)
13332  OTServerContract* pServer =
13333  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13334  if (nullptr == pServer) return (-1);
13335  // By this point, pServer is a good pointer. (No need to cleanup.)
13336  if (USER_ID != ACCOUNT_ID) // inbox/outbox (if it were nymbox, the USER_ID
13337  // and ACCOUNT_ID would match)
13338  {
13339  OTAccount* pAccount =
13340  GetOrLoadAccount(*pNym, ACCOUNT_ID, SERVER_ID, __FUNCTION__);
13341  if (nullptr == pAccount) return (-1);
13342  }
13343  // By this point, pAccount is a good pointer, and is on the wallet. (No need
13344  // to cleanup.)
13345  // Note: pAccount could be nullptr also, but this function doesn't actually
13346  // use
13347  // it anyway.
13348  // I just force it to load in order to keep things clean, since this is an
13349  // API call. (I'm
13350  // real strict on the API user, making him keep his nose clean.)
13351  OTMessage theMessage;
13352  int64_t lRequestNumber = 0;
13353 
13354  const OTString strServerID(SERVER_ID), strNymID(USER_ID),
13355  strAcctID(ACCOUNT_ID);
13356 
13357  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13358  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13359  theMessage.m_strRequestNum.Format(
13360  "%ld", lRequestNumber); // Always have to send this.
13361  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13362  // server request, I have to
13363  // increment it
13364 
13365  // (1) set up member variables
13366  theMessage.m_strCommand = "getBoxReceipt";
13367  theMessage.m_strNymID = strNymID;
13368  theMessage.m_strServerID = strServerID;
13369  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13370  // theMessage.m_strServerID is already
13371  // set. (It uses it.)
13372 
13373  theMessage.m_strAcctID = strAcctID;
13374  theMessage.m_lDepth = static_cast<int64_t>(nBoxType);
13375  theMessage.m_lTransactionNum = lTransactionNum;
13376 
13377  // (2) Sign the Message
13378  theMessage.SignContract(*pNym);
13379 
13380  // (3) Save the Message (with signatures and all, back to its internal
13381  // member m_strRawFile.)
13382  theMessage.SaveContract();
13383 
13384  // (Send it)
13385  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13386  m_pClient->ProcessMessageOut(theMessage);
13387 
13388  return m_pClient->CalcReturnVal(lRequestNumber);
13389 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTClient* opentxs::OT_API::GetClient ( ) const
inline

Definition at line 232 of file OpenTransactions.hpp.

233  {
234  return m_pClient;
235  }
int32_t opentxs::OT_API::getContract ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ASSET_ID 
) const

Definition at line 12956 of file OpenTransactions.cpp.

12959 {
12960  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12961  if (nullptr == pNym) return (-1);
12962  // By this point, pNym is a good pointer, and is on the wallet.
12963  // (No need to cleanup.)
12964  OTServerContract* pServer =
12965  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12966  if (nullptr == pServer) return (-1);
12967  // By this point, pServer is a good pointer. (No need to cleanup.)
12968  OTMessage theMessage;
12969  int64_t lRequestNumber = 0;
12970 
12971  OTString strServerID(SERVER_ID), strNymID(USER_ID),
12972  strAssetTypeID(ASSET_ID);
12973 
12974  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12975  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12976  theMessage.m_strRequestNum.Format(
12977  "%ld", lRequestNumber); // Always have to send this.
12978  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12979  // server request, I have to
12980  // increment it
12981 
12982  // (1) set up member variables
12983  theMessage.m_strCommand = "getContract";
12984  theMessage.m_strNymID = strNymID;
12985  theMessage.m_strServerID = strServerID;
12986  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12987  // theMessage.m_strServerID is already
12988  // set. (It uses it.)
12989 
12990  theMessage.m_strAssetID = strAssetTypeID;
12991 
12992  // (2) Sign the Message
12993  theMessage.SignContract(*pNym);
12994 
12995  // (3) Save the Message (with signatures and all, back to its internal
12996  // member m_strRawFile.)
12997  theMessage.SaveContract();
12998 
12999  // (Send it)
13000  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13001  m_pClient->ProcessMessageOut(theMessage);
13002 
13003  return m_pClient->CalcReturnVal(lRequestNumber);
13004 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::getInbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID 
) const

Definition at line 12554 of file OpenTransactions.cpp.

12557 {
12558  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12559  if (nullptr == pNym) return (-1);
12560  // By this point, pNym is a good pointer, and is on the wallet.
12561  // (No need to cleanup.)
12562  OTServerContract* pServer =
12563  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12564  if (nullptr == pServer) return (-1);
12565  // By this point, pServer is a good pointer. (No need to cleanup.)
12566  OTAccount* pAccount =
12567  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
12568  if (nullptr == pAccount) return (-1);
12569  // By this point, pAccount is a good pointer. (No need to cleanup.)
12570  OTMessage theMessage;
12571  int64_t lRequestNumber = 0;
12572 
12573  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCT_ID);
12574 
12575  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12576  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12577  theMessage.m_strRequestNum.Format(
12578  "%ld", lRequestNumber); // Always have to send this.
12579  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12580  // server request, I have to
12581  // increment it
12582 
12583  // (1) set up member variables
12584  theMessage.m_strCommand = "getInbox";
12585  theMessage.m_strNymID = strNymID;
12586  theMessage.m_strServerID = strServerID;
12587  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12588  // theMessage.m_strServerID is already
12589  // set. (It uses it.)
12590 
12591  theMessage.m_strAcctID = strAcctID;
12592 
12593  // (2) Sign the Message
12594  theMessage.SignContract(*pNym);
12595 
12596  // (3) Save the Message (with signatures and all, back to its internal
12597  // member m_strRawFile.)
12598  theMessage.SaveContract();
12599 
12600  // (Send it)
12601  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12602  m_pClient->ProcessMessageOut(theMessage);
12603 
12604  return m_pClient->CalcReturnVal(lRequestNumber);
12605 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::getMarketList ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

GET MARKET LIST

Connect to a specific server, as a specific Nym, and request the list of markets. (Flush the buffer before calling this. Then after you make this call, wait 50 ms and then pop the buffer and check the server reply for success. From there you can either read the reply data directly out of the reply message, or you can load it from storage (OT will probably auto-store the reply to storage, for your convenience.)

Definition at line 12072 of file OpenTransactions.cpp.

12074 {
12075  OTPseudonym* pNym = GetOrLoadPrivateNym(
12076  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
12077  if (nullptr == pNym) return (-1);
12078  // By this point, pNym is a good pointer, and is on the wallet.
12079  // (No need to cleanup.)
12080  OTServerContract* pServer =
12081  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12082  if (nullptr == pServer) return (-1);
12083  // By this point, pServer is a good pointer. (No need to cleanup.)
12084  OTMessage theMessage;
12085 
12086  OTString strServerID(SERVER_ID);
12087  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12088  int64_t lRequestNumber = 0;
12089  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12090  theMessage.m_strRequestNum.Format(
12091  "%ld", lRequestNumber); // Always have to send this.
12092  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12093  // server request, I have to
12094  // increment it
12095 
12096  OTString strNymID(USER_ID);
12097 
12098  // (1) Set up member variables
12099  theMessage.m_strCommand = "getMarketList";
12100  theMessage.m_strNymID = strNymID;
12101  theMessage.m_strServerID = strServerID;
12102  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12103  // theMessage.m_strServerID is already
12104  // set. (It uses it.)
12105 
12106  // (2) Sign the Message
12107  theMessage.SignContract(*pNym);
12108 
12109  // (3) Save the Message (with signatures and all, back to its internal
12110  // member m_strRawFile.)
12111  theMessage.SaveContract();
12112 
12113  // (Send it)
12114  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12115  m_pClient->ProcessMessageOut(theMessage);
12116 
12117  return m_pClient->CalcReturnVal(lRequestNumber);
12118 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::getMarketOffers ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier MARKET_ID,
const int64_t &  lDepth 
) const

GET ALL THE OFFERS ON A SPECIFIC MARKET

A specific Nym is requesting the Server to send a list of the offers on a specific Market ID– the bid/ask, and prices/amounts, basically–(up to lDepth or server Max)

Definition at line 12127 of file OpenTransactions.cpp.

12131 {
12132  OTPseudonym* pNym = GetOrLoadPrivateNym(
12133  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
12134  if (nullptr == pNym) return (-1);
12135  // By this point, pNym is a good pointer, and is on the wallet.
12136  // (No need to cleanup.)
12137  OTServerContract* pServer =
12138  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12139  if (nullptr == pServer) return (-1);
12140  // By this point, pServer is a good pointer. (No need to cleanup.)
12141  OTMessage theMessage;
12142 
12143  OTString strServerID(SERVER_ID), strMarketID(MARKET_ID);
12144 
12145  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12146  int64_t lRequestNumber = 0;
12147  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12148  theMessage.m_strRequestNum.Format(
12149  "%ld", lRequestNumber); // Always have to send this.
12150  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12151  // server request, I have to
12152  // increment it
12153 
12154  OTString strNymID(USER_ID);
12155  // (1) Set up member variables
12156  theMessage.m_strCommand = "getMarketOffers";
12157  theMessage.m_strNymID = strNymID;
12158  theMessage.m_strServerID = strServerID;
12159  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12160  // theMessage.m_strServerID is already
12161  // set. (It uses it.)
12162 
12163  theMessage.m_strNymID2 = strMarketID;
12164  theMessage.m_lDepth = lDepth;
12165 
12166  // (2) Sign the Message
12167  theMessage.SignContract(*pNym);
12168 
12169  // (3) Save the Message (with signatures and all, back to its internal
12170  // member m_strRawFile.)
12171  theMessage.SaveContract();
12172 
12173  // (Send it)
12174  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12175  m_pClient->ProcessMessageOut(theMessage);
12176 
12177  return m_pClient->CalcReturnVal(lRequestNumber);
12178 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::getMarketRecentTrades ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier MARKET_ID 
) const

GET RECENT TRADES FOR A SPECIFIC MARKET ID

Most likely, ticker data will be made available through a separate ZMQ instance, which will use the publisher/subscriber model to distribute ticker data. From there, those privileged subscribers can distribute it via RSS, store it for future analysis, display charts, etc.

(So this function is not here to usurp that purpose.)

Definition at line 12193 of file OpenTransactions.cpp.

12196 {
12197  OTPseudonym* pNym = GetOrLoadPrivateNym(
12198  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
12199  if (nullptr == pNym) return (-1);
12200  // By this point, pNym is a good pointer, and is on the wallet.
12201  // (No need to cleanup.)
12202  OTServerContract* pServer =
12203  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12204  if (nullptr == pServer) return (-1);
12205  // By this point, pServer is a good pointer. (No need to cleanup.)
12206  OTMessage theMessage;
12207 
12208  OTString strServerID(SERVER_ID), strMarketID(MARKET_ID);
12209  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12210  int64_t lRequestNumber = 0;
12211  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12212  theMessage.m_strRequestNum.Format(
12213  "%ld", lRequestNumber); // Always have to send this.
12214  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12215  // server request, I have to
12216  // increment it
12217 
12218  OTString strNymID(USER_ID);
12219  // (1) Set up member variables
12220  theMessage.m_strCommand = "getMarketRecentTrades";
12221  theMessage.m_strNymID = strNymID;
12222  theMessage.m_strServerID = strServerID;
12223  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12224  // theMessage.m_strServerID is already
12225  // set. (It uses it.)
12226 
12227  theMessage.m_strNymID2 = strMarketID;
12228 
12229  // (2) Sign the Message
12230  theMessage.SignContract(*pNym);
12231 
12232  // (3) Save the Message (with signatures and all, back to its internal
12233  // member m_strRawFile.)
12234  theMessage.SaveContract();
12235 
12236  // (Send it)
12237  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12238  m_pClient->ProcessMessageOut(theMessage);
12239 
12240  return m_pClient->CalcReturnVal(lRequestNumber);
12241 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::getMint ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ASSET_ID 
) const

Definition at line 13006 of file OpenTransactions.cpp.

13009 {
13010  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
13011  if (nullptr == pNym) return (-1);
13012  // By this point, pNym is a good pointer, and is on the wallet.
13013  // (No need to cleanup.)
13014  OTServerContract* pServer =
13015  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13016  if (nullptr == pServer) return (-1);
13017  // By this point, pServer is a good pointer. (No need to cleanup.)
13018  OTAssetContract* pAssetContract =
13019  GetAssetType(ASSET_ID, __FUNCTION__); // This ASSERTs and logs already.
13020  if (nullptr == pAssetContract) return (-1);
13021  // By this point, pAssetContract is a good pointer. (No need to cleanup.)
13022  OTMessage theMessage;
13023  int64_t lRequestNumber = 0;
13024 
13025  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13026  strAssetTypeID(ASSET_ID);
13027 
13028  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13029  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13030  theMessage.m_strRequestNum.Format(
13031  "%ld", lRequestNumber); // Always have to send this.
13032  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13033  // server request, I have to
13034  // increment it
13035 
13036  // (1) set up member variables
13037  theMessage.m_strCommand = "getMint";
13038  theMessage.m_strNymID = strNymID;
13039  theMessage.m_strServerID = strServerID;
13040  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13041  // theMessage.m_strServerID is already
13042  // set. (It uses it.)
13043 
13044  theMessage.m_strAssetID = strAssetTypeID;
13045 
13046  // (2) Sign the Message
13047  theMessage.SignContract(*pNym);
13048 
13049  // (3) Save the Message (with signatures and all, back to its internal
13050  // member m_strRawFile.)
13051  theMessage.SaveContract();
13052 
13053  // (Send it)
13054  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13055  m_pClient->ProcessMessageOut(theMessage);
13056 
13057  return m_pClient->CalcReturnVal(lRequestNumber);
13058 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool opentxs::OT_API::GetNym ( int32_t  iIndex,
OTIdentifier NYM_ID,
OTString NYM_NAME 
) const

Definition at line 1335 of file OpenTransactions.cpp.

1337 {
1338  OTWallet* pWallet =
1339  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1340  if (nullptr != pWallet) return pWallet->GetNym(iIndex, NYM_ID, NYM_NAME);
1341 
1342  return false;
1343 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTPseudonym * opentxs::OT_API::GetNym ( const OTIdentifier NYM_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1388 of file OpenTransactions.cpp.

1390 {
1391  if (NYM_ID.IsEmpty()) {
1392  otErr << __FUNCTION__ << ": NYM_ID is empty!";
1393  OT_FAIL;
1394  }
1395 
1396  OTWallet* pWallet = GetWallet(nullptr != szFunc ? szFunc : __FUNCTION__);
1397  if (nullptr != pWallet) {
1398  OTPseudonym* pNym = pWallet->GetNymByID(NYM_ID);
1399  if ((nullptr == pNym) &&
1400  (nullptr != szFunc)) // We only log if the caller asked us to.
1401  {
1402  const OTString strID(NYM_ID);
1403  otWarn << __FUNCTION__ << " " << szFunc
1404  << ": No Nym found in wallet with ID: " << strID << "\n";
1405  }
1406  return pNym;
1407  }
1408  return nullptr;
1409 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::getNym_MarketOffers ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

GET ALL THE ACTIVE (in Cron) MARKET OFFERS FOR A SPECIFIC NYM. (ON A SPECIFIC SERVER, OBVIOUSLY.) Remember to use Flush/Call/Wait/Pop to check the server reply for success or fail. Hmm for size reasons, this really will have to return a list of transaction #s, and then I request them one-by-one after that...

Definition at line 12251 of file OpenTransactions.cpp.

12253 {
12254  OTPseudonym* pNym = GetOrLoadPrivateNym(
12255  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
12256  if (nullptr == pNym) return (-1);
12257  // By this point, pNym is a good pointer, and is on the wallet.
12258  // (No need to cleanup.)
12259  OTServerContract* pServer =
12260  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12261  if (nullptr == pServer) return (-1);
12262  // By this point, pServer is a good pointer. (No need to cleanup.)
12263  OTMessage theMessage;
12264 
12265  OTString strServerID(SERVER_ID);
12266 
12267  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12268  int64_t lRequestNumber = 0;
12269  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12270  theMessage.m_strRequestNum.Format(
12271  "%ld", lRequestNumber); // Always have to send this.
12272  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12273  // server request, I have to
12274  // increment it
12275 
12276  OTString strNymID(USER_ID);
12277 
12278  // (1) Set up member variables
12279  theMessage.m_strCommand = "getNym_MarketOffers";
12280  theMessage.m_strNymID = strNymID;
12281  theMessage.m_strServerID = strServerID;
12282  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12283  // theMessage.m_strServerID is already
12284  // set. (It uses it.)
12285 
12286  // (2) Sign the Message
12287  theMessage.SignContract(*pNym);
12288 
12289  // (3) Save the Message (with signatures and all, back to its internal
12290  // member m_strRawFile.)
12291  theMessage.SaveContract();
12292 
12293  // (Send it)
12294  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12295  m_pClient->ProcessMessageOut(theMessage);
12296 
12297  return m_pClient->CalcReturnVal(lRequestNumber);
12298 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::getNymbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 12507 of file OpenTransactions.cpp.

12509 {
12510  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12511  if (nullptr == pNym) return (-1);
12512  // By this point, pNym is a good pointer, and is on the wallet.
12513  // (No need to cleanup.)
12514  OTServerContract* pServer =
12515  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12516  if (nullptr == pServer) return (-1);
12517  // By this point, pServer is a good pointer. (No need to cleanup.)
12518  OTMessage theMessage;
12519  int64_t lRequestNumber = 0;
12520 
12521  OTString strServerID(SERVER_ID), strNymID(USER_ID);
12522 
12523  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12524  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12525  theMessage.m_strRequestNum.Format(
12526  "%ld", lRequestNumber); // Always have to send this.
12527  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12528  // server request, I have to
12529  // increment it
12530 
12531  // (1) set up member variables
12532  theMessage.m_strCommand = "getNymbox";
12533  theMessage.m_strNymID = strNymID;
12534  theMessage.m_strServerID = strServerID;
12535  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12536  // theMessage.m_strServerID is already
12537  // set. (It uses it.)
12538 
12539  // (2) Sign the Message
12540  theMessage.SignContract(*pNym);
12541 
12542  // (3) Save the Message (with signatures and all, back to its internal
12543  // member m_strRawFile.)
12544  theMessage.SaveContract();
12545 
12546  // (Send it)
12547  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12548  m_pClient->ProcessMessageOut(theMessage);
12549 
12550  return m_pClient->CalcReturnVal(lRequestNumber);
12551 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTPseudonym * opentxs::OT_API::GetNymByIDPartialMatch ( const std::string  PARTIAL_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1468 of file OpenTransactions.cpp.

1470 {
1471  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
1472  OTWallet* pWallet = GetWallet(szFunc); // This logs and ASSERTs already.
1473  if (nullptr != pWallet) return pWallet->GetNymByIDPartialMatch(PARTIAL_ID);
1474 
1475  return nullptr;
1476 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::GetNymCount ( ) const

Definition at line 1299 of file OpenTransactions.cpp.

1300 {
1301  OTWallet* pWallet =
1302  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1303  if (nullptr != pWallet) return pWallet->GetNymCount();
1304 
1305  return 0;
1306 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTAccount * opentxs::OT_API::GetOrLoadAccount ( const OTPseudonym theNym,
const OTIdentifier ACCT_ID,
const OTIdentifier SERVER_ID,
const char *  szFuncName = nullptr 
) const

Tries to get the account from the wallet. Otherwise loads it from local storage.

Definition at line 4839 of file OpenTransactions.cpp.

4843 {
4844  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
4845  OTWallet* pWallet = GetWallet(szFunc); // This logs and ASSERTs already.
4846  if (nullptr == pWallet) return nullptr;
4847  // By this point, pWallet is a good pointer. (No need to cleanup.)
4848  return pWallet->GetOrLoadAccount(theNym, ACCT_ID, SERVER_ID,
4849  szFunc); // This logs plenty.
4850 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTAccount * opentxs::OT_API::GetOrLoadAccount ( const OTIdentifier NYM_ID,
const OTIdentifier ACCT_ID,
const OTIdentifier SERVER_ID,
const char *  szFuncName = nullptr 
) const

Tries to get the account from the wallet. Otherwise loads it from local storage.

Definition at line 4855 of file OpenTransactions.cpp.

4859 {
4860  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
4861  OTPseudonym* pNym = GetOrLoadPrivateNym(NYM_ID, false, szFunc);
4862  if (nullptr == pNym) return nullptr;
4863  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4864  // cleanup.)
4865  return GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID,
4866  szFunc); // This logs plenty.
4867 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTPseudonym * opentxs::OT_API::GetOrLoadNym ( const OTIdentifier NYM_ID,
bool  bChecking = false,
const char *  szFuncName = nullptr,
const OTPasswordData pPWData = nullptr 
) const

This function tries to load as public Nym first, then if it fails, it tries the private one next. (So as to avoid unnecessarily asking users for their passphrase.) Be sure to use GetOrLoadPublicNym() or GetOrLoadPrivateNym() if you want to force it one way or the other.

No need to cleanup the Nym returned here, since it's added to the wallet and the wallet takes ownership.

Definition at line 4814 of file OpenTransactions.cpp.

4817 {
4818  if (NYM_ID.IsEmpty()) {
4819  otErr << __FUNCTION__ << ": NYM_ID is empty!";
4820  OT_FAIL;
4821  }
4822 
4823  OTWallet* pWallet = GetWallet(szFuncName); // This logs and ASSERTs already.
4824  if (nullptr == pWallet) return nullptr;
4825  // By this point, pWallet is a good pointer. (No need to cleanup.)
4826  //
4827  // This already logs copiously, including szFuncName...
4828  //
4829 
4830  OTPasswordData thePWData(OT_PW_DISPLAY);
4831 
4832  return pWallet->GetOrLoadNym(NYM_ID, bChecking, szFuncName,
4833  nullptr == pPWData ? &thePWData : pPWData);
4834 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
OTPseudonym * opentxs::OT_API::GetOrLoadPrivateNym ( const OTIdentifier NYM_ID,
bool  bChecking = false,
const char *  szFuncName = nullptr,
const OTPasswordData pPWData = nullptr,
const OTPassword pImportPassword = nullptr 
) const

This function only tries to load as a private Nym. No need to cleanup, since it adds the Nym to the wallet.

It is smart enough to Get the Nym from the wallet, and if it sees that it's only a public nym (no private key) then it reloads it as a private nym at that time.

Definition at line 4784 of file OpenTransactions.cpp.

4787 {
4788  if (NYM_ID.IsEmpty()) {
4789  otErr << __FUNCTION__ << ": NYM_ID is empty!";
4790  OT_FAIL;
4791  }
4792 
4793  OTWallet* pWallet = GetWallet(szFuncName); // This logs and ASSERTs already.
4794  if (nullptr == pWallet) return nullptr;
4795  if (NYM_ID.IsEmpty()) return nullptr;
4796  // By this point, pWallet is a good pointer. (No need to cleanup.)
4797  //
4798  // This already logs copiously, including szFuncName...
4799  //
4800  OTPasswordData thePWData(OT_PW_DISPLAY);
4801  return pWallet->GetOrLoadPrivateNym(
4802  NYM_ID, bChecking, szFuncName,
4803  nullptr == pPWData ? &thePWData : pPWData, pImportPassword);
4804 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
OTPseudonym * opentxs::OT_API::GetOrLoadPublicNym ( const OTIdentifier NYM_ID,
const char *  szFuncName = nullptr 
) const

This function only tries to load as a public Nym. No need to cleanup, since it adds the Nym to the wallet.

Definition at line 4760 of file OpenTransactions.cpp.

4762 {
4763  if (NYM_ID.IsEmpty()) {
4764  otErr << __FUNCTION__ << ": NYM_ID is empty!";
4765  OT_FAIL;
4766  }
4767 
4768  OTWallet* pWallet = GetWallet(szFuncName); // This logs and ASSERTs already.
4769  if (nullptr == pWallet) return nullptr;
4770  // By this point, pWallet is a good pointer. (No need to cleanup.)
4771  //
4772  // This already logs copiously, including szFuncName...
4773  //
4774  return pWallet->GetOrLoadPublicNym(NYM_ID, szFuncName);
4775 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::getOutbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID 
) const

Definition at line 12608 of file OpenTransactions.cpp.

12611 {
12612  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12613  if (nullptr == pNym) return (-1);
12614  // By this point, pNym is a good pointer, and is on the wallet.
12615  // (No need to cleanup.)
12616  OTServerContract* pServer =
12617  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12618  if (nullptr == pServer) return (-1);
12619  // By this point, pServer is a good pointer. (No need to cleanup.)
12620  OTAccount* pAccount =
12621  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
12622  if (nullptr == pAccount) return (-1);
12623  // By this point, pAccount is a good pointer. (No need to cleanup.)
12624  OTMessage theMessage;
12625  int64_t lRequestNumber = 0;
12626 
12627  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCT_ID);
12628 
12629  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12630  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12631  theMessage.m_strRequestNum.Format(
12632  "%ld", lRequestNumber); // Always have to send this.
12633  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12634  // server request, I have to
12635  // increment it
12636 
12637  // (1) set up member variables
12638  theMessage.m_strCommand = "getOutbox";
12639  theMessage.m_strNymID = strNymID;
12640  theMessage.m_strServerID = strServerID;
12641  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12642  // theMessage.m_strServerID is already
12643  // set. (It uses it.)
12644 
12645  theMessage.m_strAcctID = strAcctID;
12646 
12647  // (2) Sign the Message
12648  theMessage.SignContract(*pNym);
12649 
12650  // (3) Save the Message (with signatures and all, back to its internal
12651  // member m_strRawFile.)
12652  theMessage.SaveContract();
12653 
12654  // (Send it)
12655  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12656  m_pClient->ProcessMessageOut(theMessage);
12657 
12658  return m_pClient->CalcReturnVal(lRequestNumber);
12659 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::getRequest ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 13502 of file OpenTransactions.cpp.

13504 {
13505  OTPseudonym* pNym = GetOrLoadPrivateNym(
13506  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13507  if (nullptr == pNym) return (-1);
13508  // By this point, pNym is a good pointer, and is on the wallet.
13509  // (No need to cleanup.)
13510  OTServerContract* pServer =
13511  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13512  if (nullptr == pServer) return (-1);
13513  // By this point, pServer is a good pointer. (No need to cleanup.)
13514  OTMessage theMessage;
13515 
13516  int32_t nReturnValue = m_pClient->ProcessUserCommand(
13517  OTClient::getRequest, theMessage, *pNym, *pServer,
13518  nullptr); // nullptr pAccount on this command.
13519  if (0 < nReturnValue) {
13520  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
13521  m_pTransportCallback);
13522  m_pClient->ProcessMessageOut(theMessage);
13523 
13524  return nReturnValue;
13525  }
13526  else
13527  otErr << "Error processing getRequest command in OT_API::getRequest\n";
13528 
13529  return (-1);
13530 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
OTMessage * opentxs::OT_API::GetSentMessage ( const int64_t &  lRequestNumber,
const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 8348 of file OpenTransactions.cpp.

8351 {
8352  OT_ASSERT_MSG((m_bInitialized && (m_pClient != nullptr)),
8353  "Not initialized; call OT_API::Init first.");
8354  OT_ASSERT_MSG(lRequestNumber > 0,
8355  "OT_API::GetSentMessage: lRequestNumber is less than 1.");
8356 
8357  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
8358 
8359  return m_pClient->GetMessageOutbuffer().GetSentMessage(
8360  lRequestNumber, strServerID, strNymID); // doesn't delete.
8361 }
EXPORT OTMessage * GetSentMessage(const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
OTMessageOutbuffer & GetMessageOutbuffer()
Definition: OTClient.hpp:363
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
bool opentxs::OT_API::GetServer ( int32_t  iIndex,
OTIdentifier THE_ID,
OTString THE_NAME 
) const

Definition at line 1345 of file OpenTransactions.cpp.

1347 {
1348  OTWallet* pWallet =
1349  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1350  if (nullptr != pWallet) return pWallet->GetServer(iIndex, THE_ID, THE_NAME);
1351 
1352  return false;
1353 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTServerContract * opentxs::OT_API::GetServer ( const OTIdentifier THE_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1411 of file OpenTransactions.cpp.

1413 {
1414  OTWallet* pWallet = GetWallet(nullptr != szFunc ? szFunc : __FUNCTION__);
1415  if (nullptr != pWallet) {
1416  OTServerContract* pContract = pWallet->GetServerContract(THE_ID);
1417  if ((nullptr == pContract) &&
1418  (nullptr != szFunc)) // We only log if the caller asked us to.
1419  {
1420  const OTString strID(THE_ID);
1421  otWarn << __FUNCTION__ << " " << szFunc
1422  << ": No server contract found "
1423  "in wallet with ID: " << strID << "\n";
1424  }
1425  return pContract;
1426  }
1427  return nullptr;
1428 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otWarn
OTServerContract * opentxs::OT_API::GetServerContractPartialMatch ( const std::string  PARTIAL_ID,
const char *  szFuncName = nullptr 
) const

Definition at line 1478 of file OpenTransactions.cpp.

1480 {
1481  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
1482  OTWallet* pWallet = GetWallet(szFunc); // This logs and ASSERTs already.
1483  if (nullptr != pWallet)
1484  return pWallet->GetServerContractPartialMatch(PARTIAL_ID);
1485 
1486  return nullptr;
1487 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::GetServerCount ( ) const

Definition at line 1308 of file OpenTransactions.cpp.

1309 {
1310  OTWallet* pWallet =
1311  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1312  if (nullptr != pWallet) return pWallet->GetServerCount();
1313 
1314  return 0;
1315 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
time64_t opentxs::OT_API::GetTime ( ) const

TIME (in seconds, as int64_t)

This will return the current time in seconds, as a int64_t int32_t.

Todo: consider making this available on the server side as well, so the smart contracts can see what time it is.

Definition at line 3211 of file OpenTransactions.cpp.

3212 {
3213  return OTTimeGetCurrentTime();
3214 }
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
int32_t opentxs::OT_API::getTransactionNumber ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 9343 of file OpenTransactions.cpp.

9345 {
9346  OTPseudonym* pNym = GetOrLoadPrivateNym(
9347  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
9348  if (nullptr == pNym) return (-1);
9349  // By this point, pNym is a good pointer, and is on the wallet. (No need to
9350  // cleanup.)
9351  OTServerContract* pServer =
9352  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
9353  if (nullptr == pServer) return (-1);
9354  // By this point, pServer is a good pointer. (No need to cleanup.)
9355 
9356  const int32_t nCount = pNym->GetTransactionNumCount(SERVER_ID);
9357  const int32_t nMaxCount = 50; // todo no hardcoding. (max transaction nums
9358  // allowed out at a single time.)
9359 
9360  if (nCount > nMaxCount) {
9361  otOut << "OT_API::getTransactionNumber: Failure: That Nym already has "
9362  "more than " << nMaxCount
9363  << " transaction numbers signed out. (Use those first.)\n";
9364  return 0; // Java code needs to know that no msg went out, BUT it's
9365  // because we already have TOO
9366  // MANY numbers (i.e. "a good reason.") This means "process your Nymbox
9367  // and grab your intermediary
9368  // files, and try again!" So, we return 0 to indicate this.
9369  //
9370  // return (-1);
9371  }
9372  OTMessage theMessage;
9373 
9374  int32_t nReturnValue = m_pClient->ProcessUserCommand(
9375  OTClient::getTransactionNum, theMessage, *pNym, *pServer,
9376  nullptr); // nullptr pAccount on this command.
9377  if (0 < nReturnValue) {
9378  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
9379  m_pTransportCallback);
9380  m_pClient->ProcessMessageOut(theMessage);
9381 
9382  return nReturnValue;
9383  }
9384  else
9385  otErr << "OT_API::getTransactionNumber: Error processing "
9386  "getTransactionNumber command. Return value: " << nReturnValue
9387  << "\n";
9388 
9389  return (-1);
9390 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
OTLOG_IMPORT OTLogStream otOut
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
TransportCallback * opentxs::OT_API::GetTransportCallback ( ) const

Definition at line 819 of file OpenTransactions.cpp.

820 {
821  if (nullptr != m_pTransportCallback) {
822  return m_pTransportCallback;
823  }
824  else {
825  OT_FAIL;
826  }
827 }
#define OT_FAIL
Definition: Assert.hpp:139
OTWallet * opentxs::OT_API::GetWallet ( const char *  szFuncName = nullptr) const

Definition at line 1377 of file OpenTransactions.cpp.

1378 {
1379  // Any function that calls GetWallet() thus asserts here.
1380  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
1381  const char* szFunc = (nullptr != szFuncName) ? szFuncName : __FUNCTION__;
1382  OTWallet* pWallet = m_pWallet; // This is where we "get" the wallet. :P
1383  if (nullptr == pWallet)
1384  otOut << szFunc << ": -- The Wallet is not loaded.\n";
1385  return pWallet;
1386 }
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
bool opentxs::OT_API::GetWalletFilename ( OTString strPath) const

Definition at line 786 of file OpenTransactions.cpp.

787 {
788  if (m_strWalletFilename.Exists()) {
789  strPath = m_strWalletFilename;
790  return true;
791  }
792  else {
793  strPath.Set("");
794  return false;
795  }
796 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
bool opentxs::OT_API::HarvestAllNumbers ( const OTIdentifier SERVER_ID,
const OTIdentifier NYM_ID,
const OTString THE_CRON_ITEM 
) const

Definition at line 4728 of file OpenTransactions.cpp.

4730 {
4731  OTPseudonym* pNym = GetOrLoadPrivateNym(
4732  NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4733  if (nullptr == pNym) return false;
4734  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4735  // cleanup.)
4736  std::unique_ptr<OTCronItem> pCronItem(
4737  OTCronItem::NewCronItem(THE_CRON_ITEM));
4738  if (nullptr == pCronItem) {
4739  otOut << __FUNCTION__
4740  << ": Error loading the cron item (a cron item is a "
4741  "smart contract, or some other recurring transaction such "
4742  "as a market offer, or a payment plan.) "
4743  "Contents:\n\n" << THE_CRON_ITEM << "\n\n";
4744  return false;
4745  }
4746  pCronItem->HarvestOpeningNumber(*pNym); // <==== the Nym is actually
4747  // harvesting the numbers from the
4748  // Cron Item, and not the other way
4749  // around.
4750  pCronItem->HarvestClosingNumbers(*pNym); // <==== the Nym is actually
4751  // harvesting the numbers from the
4752  // Cron Item, and not the other way
4753  // around.
4754  return true;
4755 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTCronItem * NewCronItem(const OTString &strCronItem)
Definition: OTCronItem.cpp:165
bool opentxs::OT_API::HarvestClosingNumbers ( const OTIdentifier SERVER_ID,
const OTIdentifier NYM_ID,
const OTString THE_CRON_ITEM 
) const

Definition at line 4683 of file OpenTransactions.cpp.

4686 {
4687  OTPseudonym* pNym = GetOrLoadPrivateNym(
4688  NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4689  if (nullptr == pNym) return false;
4690  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4691  // cleanup.)
4692  std::unique_ptr<OTCronItem> pCronItem(
4693  OTCronItem::NewCronItem(THE_CRON_ITEM));
4694  if (nullptr == pCronItem) {
4695  otOut << __FUNCTION__
4696  << ": Error loading the cron item (a cron item is a "
4697  "smart contract, or some other recurring transaction such "
4698  "as a market offer, or a payment plan.) Contents:\n\n"
4699  << THE_CRON_ITEM << "\n\n";
4700  return false;
4701  }
4702  pCronItem->HarvestClosingNumbers(*pNym); // <==== the Nym is actually
4703  // harvesting the numbers from the
4704  // Cron Item, and not the other way
4705  // around.
4706  return true;
4707 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTCronItem * NewCronItem(const OTString &strCronItem)
Definition: OTCronItem.cpp:165
bool opentxs::OT_API::HaveAlreadySeenReply ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const int64_t &  lRequestNumber 
) const

Definition at line 8520 of file OpenTransactions.cpp.

8523 {
8524  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
8525  if (nullptr == pNym) return false;
8526  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8527  // cleanup.)
8528 
8529  // "Client verifies it has already seen a server reply."
8530  // bool OTPseudonym:::VerifyAcknowledgedNum(const OTString & strServerID,
8531  // const int64_t & lRequestNum);
8532  //
8533  const OTString strServerID(SERVER_ID);
8534  return pNym->VerifyAcknowledgedNum(strServerID, lRequestNumber);
8535 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::InitOTApp ( )
static

Definition at line 556 of file OpenTransactions.cpp.

557 {
558  OT_ASSERT(!OT_API::bCleanupOTApp);
559 
560  if (!OT_API::bInitOTApp) {
561  if (!OTLog::Init("client")) {
562  assert(false);
563  }
564 
565  otOut << "\n\nWelcome to Open Transactions -- version "
566  << OTLog::Version() << "\n";
567 
568  otWarn << "(transport build: OTMessage -> OTEnvelope -> ZMQ )\n";
569 
570 // SIGNALS
571 //
572 #if defined(OT_SIGNAL_HANDLING)
573  //
574  OTLog::SetupSignalHandler(); // <===== SIGNALS
575  //
576 // This is optional! You can always remove it using the OT_NO_SIGNAL_HANDLING
577 // option, and plus, the internals only execute once anyway. (It keeps count.)
578 #endif
579  OTCrypto::It()->Init(); // (OpenSSL gets initialized here.)
580  // TODO in the case of Windows, figure err into this return val somehow.
581  // (Or log it or something.)
582  //
583 
584  OT_API::bInitOTApp = true;
585  return true;
586  }
587  else {
588  otErr << __FUNCTION__
589  << ": ERROR: This function can only be called once.\n";
590  return false;
591  }
592 }
static EXPORT OTCrypto * It()
Definition: OTCrypto.cpp:630
OTLOG_IMPORT OTLogStream otOut
static EXPORT bool Init(const OTString &strThreadContext="", const int32_t &nLogLevel=0)
Definition: OTLog.cpp:300
static EXPORT const char * Version()
Definition: OTLog.cpp:399
static EXPORT void SetupSignalHandler()
Definition: OTLog.cpp:1315
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otWarn
EXPORT void Init() const
Definition: OTCrypto.cpp:646
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::IsBasketCurrency ( const OTIdentifier BASKET_ASSET_TYPE_ID) const

Definition at line 8541 of file OpenTransactions.cpp.

8543 {
8544  // There is an OT_ASSERT_MSG in here for memory failure,
8545  // but it still might return nullptr if various verification fails.
8546  OTAssetContract* pContract =
8547  GetAssetType(BASKET_ASSET_TYPE_ID, __FUNCTION__);
8548  if (nullptr == pContract) return false;
8549  // No need to cleanup pContract.
8550  // Next load the Basket object out of that contract.
8551  Basket theBasket;
8552 
8553  // todo perhaps verify the basket here, even though I already verified the
8554  // asset contract itself...
8555  // Can't never be too sure...
8556  //
8557  if (pContract->GetBasketInfo().Exists() &&
8558  theBasket.LoadContractFromString(pContract->GetBasketInfo())) {
8559  if (theBasket.Count() > 0) return true;
8560  }
8561 
8562  return false;
8563 }
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT bool opentxs::OT_API::IsInitialized ( ) const
inline

Definition at line 219 of file OpenTransactions.hpp.

220  {
221  return m_bInitialized;
222  }
bool opentxs::OT_API::IsNym_RegisteredAtServer ( const OTIdentifier NYM_ID,
const OTIdentifier SERVER_ID 
) const

Definition at line 1619 of file OpenTransactions.cpp.

1621 {
1622  if (NYM_ID.IsEmpty()) {
1623  otErr << __FUNCTION__ << ": NYM_ID is empty!";
1624  OT_FAIL;
1625  }
1626  OTPseudonym* pNym =
1627  GetNym(NYM_ID, __FUNCTION__); // This logs and ASSERTs already.
1628  if (nullptr == pNym) return false;
1629  // Below this point, pNym is a good ptr, and will be cleaned up
1630  // automatically.
1631  const OTString strServerID(SERVER_ID);
1632  return pNym->IsRegisteredAtServer(strServerID);
1633 }
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
int32_t opentxs::OT_API::issueAssetType ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTString THE_CONTRACT 
) const

Definition at line 12839 of file OpenTransactions.cpp.

12842 {
12843  OTWallet* pWallet = GetWallet(__FUNCTION__);
12844  if (nullptr == pWallet) return (-1);
12845  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12846  if (nullptr == pNym) return (-1);
12847  // By this point, pNym is a good pointer, and is on the wallet.
12848  // (No need to cleanup.)
12849  OTServerContract* pServer =
12850  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12851  if (nullptr == pServer) return (-1);
12852  // By this point, pServer is a good pointer. (No need to cleanup.)
12853  // otErr << "OT_API::issueAssetType: About to trim this contract: **BEGIN:"
12854  // << THE_CONTRACT << "***END\n\n";
12855 
12856  std::string str_Trim(THE_CONTRACT.Get());
12857  std::string str_Trim2 = OTString::trim(str_Trim);
12858  OTString strTrimContract(str_Trim2.c_str());
12859  OTAssetContract theAssetContract;
12860 
12861  if (!theAssetContract.LoadContractFromString(strTrimContract)) {
12862  otOut << __FUNCTION__
12863  << ": Failed trying to load asset contract from string:\n\n"
12864  << strTrimContract << "\n\n";
12865  }
12866  else {
12867  OTIdentifier newID;
12868  theAssetContract.CalculateContractID(newID);
12869  theAssetContract.SetIdentifier(newID); // probably unnecessary
12870  OTMessage theMessage;
12871  int64_t lRequestNumber = 0;
12872 
12873  OTString strServerID(SERVER_ID), strNymID(USER_ID);
12874 
12875  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12876  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12877  theMessage.m_strRequestNum.Format(
12878  "%ld", lRequestNumber); // Always have to send this.
12879  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12880  // server request, I have
12881  // to increment it
12882 
12883  // (1) set up member variables
12884  theMessage.m_strCommand = "issueAssetType";
12885  theMessage.m_strNymID = strNymID;
12886  theMessage.m_strServerID = strServerID;
12887  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12888  // theMessage.m_strServerID is
12889  // already set. (It uses it.)
12890 
12891  newID.GetString(theMessage.m_strAssetID);
12892  OTString strAssetContract(theAssetContract);
12893  theMessage.m_ascPayload.SetString(strAssetContract);
12894 
12895  // (2) Sign the Message
12896  theMessage.SignContract(*pNym);
12897 
12898  // (3) Save the Message (with signatures and all, back to its internal
12899  // member m_strRawFile.)
12900  theMessage.SaveContract();
12901  // Save the contract to local storage and add to wallet.
12902  //
12903  OTString strFilename; // In this case the filename isn't actually used,
12904  // since SaveToContractFolder will
12905  // handle setting up the filename and overwrite it anyway. But I still
12906  // prefer to set it
12907  // up correctly, rather than pass a blank. I'm just funny like that.
12908  strFilename = theMessage.m_strAssetID.Get();
12909 
12910  OTString strFoldername(OTFolders::Contract().Get());
12911 
12912  OTAssetContract* pContract =
12913  new OTAssetContract(theMessage.m_strAssetID, strFoldername,
12914  strFilename, theMessage.m_strAssetID);
12915  OT_ASSERT(nullptr != pContract);
12916 
12917  // Check the server signature on the contract here. (Perhaps the message
12918  // is good enough?
12919  // After all, the message IS signed by the server and contains the
12920  // Account.
12921  // if (pContract->LoadContract() && pContract->VerifyContract())
12922  if (!pContract->LoadContractFromString(strTrimContract)) {
12923  otOut << __FUNCTION__
12924  << ": Failed(2) trying to load asset contract "
12925  "from string:\n\n" << strTrimContract << "\n\n";
12926  }
12927  else if (!pContract->VerifyContract()) {
12928  otOut << __FUNCTION__ << ": Failed verifying asset contract:\n\n"
12929  << strTrimContract << "\n\n";
12930  }
12931  else {
12932  // Next make sure the wallet has this contract on its list...
12933  pWallet->AddAssetContract(
12934  *pContract); // this saves both the contract and the wallet.
12935  pContract =
12936  nullptr; // Success. The wallet "owns" it now, no need to
12937  // clean it up.
12938  }
12939  // cleanup
12940  if (pContract) {
12941  delete pContract;
12942  pContract = nullptr;
12943  }
12944 
12945  // (Send it)
12946  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
12947  m_pTransportCallback);
12948  m_pClient->ProcessMessageOut(theMessage);
12949 
12950  return m_pClient->CalcReturnVal(lRequestNumber);
12951  }
12952 
12953  return -1;
12954 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
static EXPORT std::string & trim(std::string &str)
Definition: OTString.cpp:398
int32_t opentxs::OT_API::issueBasket ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTString BASKET_INFO 
) const

Definition at line 8768 of file OpenTransactions.cpp.

8771 {
8772  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
8773  if (nullptr == pNym) return (-1);
8774  // By this point, pNym is a good pointer, and is on the wallet. (No need to
8775  // cleanup.)
8776  OTServerContract* pServer = GetServer(SERVER_ID, __FUNCTION__);
8777  if (nullptr == pServer) return (-1);
8778  // AT SOME POINT, BASKET_INFO has been populated with the relevant data.
8779  // (see test client for example.)
8780  OTString strServerID(SERVER_ID), strNymID(USER_ID);
8781 
8782  OTMessage theMessage;
8783  int64_t lRequestNumber = 0;
8784 
8785  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
8786  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
8787  theMessage.m_strRequestNum.Format(
8788  "%ld", lRequestNumber); // Always have to send this.
8789  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
8790  // server request, I have to
8791  // increment it
8792 
8793  // (1) Set up member variables
8794  theMessage.m_strCommand = "issueBasket";
8795  theMessage.m_strNymID = strNymID;
8796  theMessage.m_strServerID = strServerID;
8797  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
8798  // theMessage.m_strServerID is already
8799  // set. (It uses it.)
8800 
8801  theMessage.m_ascPayload.SetString(BASKET_INFO);
8802 
8803  // (2) Sign the Message
8804  theMessage.SignContract(*pNym);
8805 
8806  // (3) Save the Message (with signatures and all, back to its internal
8807  // member m_strRawFile.)
8808  theMessage.SaveContract();
8809 
8810  // (Send it)
8811  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
8812  m_pClient->ProcessMessageOut(theMessage);
8813 
8814  return m_pClient->CalcReturnVal(lRequestNumber);
8815 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
int32_t opentxs::OT_API::issueMarketOffer ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ASSET_ACCT_ID,
const OTIdentifier CURRENCY_ACCT_ID,
const int64_t &  MARKET_SCALE,
const int64_t &  MINIMUM_INCREMENT,
const int64_t &  TOTAL_ASSETS_ON_OFFER,
const int64_t &  PRICE_LIMIT,
bool  bBuyingOrSelling,
time64_t  tLifespanInSeconds = OT_TIME_DAY_IN_SECONDS,
char  STOP_SIGN = 0,
int64_t  ACTIVATION_PRICE = 0 
) const

Definition at line 11723 of file OpenTransactions.cpp.

11739 {
11740  OTPseudonym* pNym = GetOrLoadPrivateNym(
11741  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
11742  if (nullptr == pNym) return (-1);
11743  // By this point, pNym is a good pointer, and is on the wallet. (No need to
11744  // cleanup.)
11745  OTServerContract* pServer =
11746  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
11747  if (nullptr == pServer) return (-1);
11748  // By this point, pServer is a good pointer. (No need to cleanup.)
11749  OTAccount* pAssetAccount =
11750  GetOrLoadAccount(*pNym, ASSET_ACCT_ID, SERVER_ID, __FUNCTION__);
11751  if (nullptr == pAssetAccount) return (-1);
11752  // By this point, pAssetAccount is a good pointer. (No need to cleanup.)
11753  OTAccount* pCurrencyAccount =
11754  GetOrLoadAccount(*pNym, CURRENCY_ACCT_ID, SERVER_ID, __FUNCTION__);
11755  if (nullptr == pCurrencyAccount) return (-1);
11756  // By this point, pCurrencyAccount is a good pointer. (No need to cleanup.)
11757  const OTIdentifier& ASSET_TYPE_ID = pAssetAccount->GetAssetTypeID();
11758  const OTIdentifier& CURRENCY_TYPE_ID = pCurrencyAccount->GetAssetTypeID();
11759  if (ASSET_TYPE_ID == CURRENCY_TYPE_ID) {
11760  otOut << __FUNCTION__
11761  << ": The asset account and currency account cannot "
11762  "have the same asset type ID. (You can't, for "
11763  "example, trade dollars against other dollars. Why "
11764  "bother trading them in the first place?)\n";
11765  return (-1);
11766  }
11767  OTMessage theMessage;
11768  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
11769  if (pNym->GetTransactionNumCount(strServerID) < 3) {
11770  otOut << __FUNCTION__
11771  << ": At least 3 Transaction Numbers are necessary to "
11772  "issue a market offer. "
11773  "Try requesting the server for more (you are low.)\n";
11774  return (-1);
11775  }
11776  int64_t lStoredTransactionNumber = 0, lAssetAcctClosingNo = 0,
11777  lCurrencyAcctClosingNo = 0;
11778  bool bGotTransNum = pNym->GetNextTransactionNum(
11779  *pNym, strServerID, lStoredTransactionNumber, false); // bSave=false
11780  bool bGotAssetClosingNum = pNym->GetNextTransactionNum(
11781  *pNym, strServerID, lAssetAcctClosingNo,
11782  false); // bSave=false -- (true by default, FYI.)
11783  bool bGotCurrencyClosingNum = pNym->GetNextTransactionNum(
11784  *pNym, strServerID, lCurrencyAcctClosingNo, true); // bSave=true
11785  if (!bGotTransNum || !bGotAssetClosingNum || !bGotCurrencyClosingNum) {
11786  otErr << __FUNCTION__
11787  << ": Supposedly there were 3 transaction numbers "
11788  "available, but the call(s)\n"
11789  "still failed. (Re-adding back to Nym, and failing out "
11790  "of this function.)\n";
11791  if (bGotTransNum)
11792  pNym->AddTransactionNum(*pNym, strServerID,
11793  lStoredTransactionNumber,
11794  false); // bSave=true
11795  if (bGotAssetClosingNum)
11796  pNym->AddTransactionNum(*pNym, strServerID, lAssetAcctClosingNo,
11797  false); // bSave=true
11798  if (bGotCurrencyClosingNum)
11799  pNym->AddTransactionNum(*pNym, strServerID, lCurrencyAcctClosingNo,
11800  false); // bSave=true
11801  if (bGotTransNum || bGotAssetClosingNum || bGotCurrencyClosingNum)
11802  pNym->SaveSignedNymfile(*pNym);
11803  }
11804  else {
11805  const time64_t VALID_FROM = GetTime(); // defaults to RIGHT NOW
11806  // aka OT_API_GetTime() if
11807  // set to 0 anyway.
11808  const time64_t VALID_TO = OTTimeAddTimeInterval(
11809  VALID_FROM, // defaults to 24 hours (a "Day Order") aka
11810  // OT_API_GetTime() + 86,400
11811  OTTimeGetSecondsFromTime(OT_TIME_ZERO == tLifespanInSeconds
11813  : tLifespanInSeconds));
11814  int64_t lTotalAssetsOnOffer = 1, lMinimumIncrement = 1,
11815  lPriceLimit = 0, // your price limit, per scale of assets.
11816  lMarketScale = 1, lActivationPrice = 0;
11817  if (TOTAL_ASSETS_ON_OFFER > 0)
11818  lTotalAssetsOnOffer =
11819  TOTAL_ASSETS_ON_OFFER; // otherwise, defaults to 1.
11820  if (MARKET_SCALE > 0)
11821  lMarketScale = MARKET_SCALE; // otherwise, defaults to 1.
11822  if (MINIMUM_INCREMENT > 0)
11823  lMinimumIncrement = MINIMUM_INCREMENT; // otherwise, defaults to 1.
11824  if (PRICE_LIMIT > 0)
11825  lPriceLimit = PRICE_LIMIT; // otherwise, defaults to 0. (0 Being a
11826  // market order.)
11827  char cStopSign = 0;
11828 
11829  if ((ACTIVATION_PRICE > 0) &&
11830  (('<' == STOP_SIGN) || ('>' == STOP_SIGN))) {
11831  cStopSign = STOP_SIGN;
11832  lActivationPrice = ACTIVATION_PRICE;
11833  }
11834  lMinimumIncrement *= lMarketScale; // minimum increment is PER SCALE.
11835  // lTotalAssetsOnOffer *= lMinimumIncrement; // This was a bug.
11836  // (Left as a warning.)
11837 
11838  OTString strOfferType("market order");
11839 
11840  if (lPriceLimit > 0) strOfferType = "limit order";
11841 
11842  if (0 != cStopSign) {
11843  if (lPriceLimit > 0)
11844  strOfferType.Format("stop limit order, at threshhold: %c%ld",
11845  cStopSign, lActivationPrice);
11846  else
11847  strOfferType.Format("stop order, at threshhold: %c%ld",
11848  cStopSign, lActivationPrice);
11849  }
11850 
11851  OTString strPrice("");
11852 
11853  if (lPriceLimit > 0) strPrice.Format("Price: %ld\n", lPriceLimit);
11854 
11855  otOut << "Placing market offer " << lStoredTransactionNumber
11856  << ", type: " << (bBuyingOrSelling ? "selling" : "buying") << ", "
11857  << strOfferType << "\n" << strPrice
11858  << "Assets for sale/purchase: " << lTotalAssetsOnOffer
11859  << "\n"
11860  "In minimum increments of: " << lMinimumIncrement
11861  << "\n"
11862  "At market of scale: " << lMarketScale
11863  << "\n"
11864  "Valid From: " << OTTimeGetSecondsFromTime(VALID_FROM)
11865  << " To: " << OTTimeGetSecondsFromTime(VALID_TO) << "\n";
11866 
11867  OTOffer theOffer(SERVER_ID, ASSET_TYPE_ID, CURRENCY_TYPE_ID,
11868  lMarketScale);
11869  OTTrade theTrade(SERVER_ID, ASSET_TYPE_ID, ASSET_ACCT_ID, USER_ID,
11870  CURRENCY_TYPE_ID, CURRENCY_ACCT_ID);
11871  // MAKE OFFER...
11872  //
11873  bool bCreateOffer = theOffer.MakeOffer(
11874  bBuyingOrSelling, // True == SELLING, False == BUYING
11875  lPriceLimit, // Per Minimum Increment...
11876  lTotalAssetsOnOffer, // Total assets available for sale or purchase.
11877  lMinimumIncrement, // The minimum increment that must be bought or
11878  // sold for each transaction
11879  lStoredTransactionNumber, // Transaction number matches on
11880  // transaction, item, offer, and trade.
11881  VALID_FROM, // defaults to RIGHT NOW aka OT_API_GetTime()
11882  VALID_TO); // defaults to 24 hours (a "Day Order") aka
11883  // OT_API_GetTime() + 86,400
11884  // ISSUE TRADE.
11885  bool bIssueTrade = false;
11886 
11887  if (bCreateOffer) {
11888  bCreateOffer = theOffer.SignContract(*pNym);
11889  if (bCreateOffer) {
11890  bCreateOffer = theOffer.SaveContract();
11891  if (bCreateOffer) {
11892  bIssueTrade = theTrade.IssueTrade(
11893  theOffer, cStopSign,
11894  lActivationPrice); // <==== ISSUE TRADE <=====
11895  // This is new: the closing transaction number is now used
11896  // for CLOSING recurring
11897  // cron items, like market offers and payment plans. It's
11898  // also useful for baskets.
11899  // Since this is a market offer, it needs a closing number
11900  // (for later cancellation
11901  // or expiration.)
11902  // lAssetAcctClosingNo=0, lCurrencyAcctClosingNo=0;
11903  //
11904  theTrade.AddClosingTransactionNo(lAssetAcctClosingNo);
11905  theTrade.AddClosingTransactionNo(lCurrencyAcctClosingNo);
11906 
11907  if (bIssueTrade) {
11908  bIssueTrade = theTrade.SignContract(*pNym);
11909  if (bIssueTrade) bIssueTrade = theTrade.SaveContract();
11910  } // if ( bIssueTrade )
11911  }
11912  }
11913  } // if ( bCreateOffer )
11914  if (bCreateOffer && bIssueTrade) {
11915  int64_t lRequestNumber = 0;
11916  OTString str_ASSET_ACCT_ID(ASSET_ACCT_ID);
11917 
11918  // Create a transaction
11919  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
11920  USER_ID, ASSET_ACCT_ID, SERVER_ID, OTTransaction::marketOffer,
11921  lStoredTransactionNumber);
11922 
11923  // set up the transaction item (each transaction may have multiple
11924  // items...)
11925  OTItem* pItem = OTItem::CreateItemFromTransaction(
11926  *pTransaction, OTItem::marketOffer,
11927  (OTIdentifier*)(&CURRENCY_ACCT_ID));
11928  // the "To" account (normally used for a TRANSFER transaction) is
11929  // used here
11930  // storing the Currency Acct ID. The Server will expect the Trade
11931  // object bundled
11932  // within this item to have an Asset Acct ID and "Currency" Acct ID
11933  // that match
11934  // those on this Item. Otherwise it will reject the offer.
11935  //
11936  OT_ASSERT_MSG(nullptr != pItem, "OT_API::issueMarketOffer: Error "
11937  "allocating memory in the OT API");
11938 
11939  OTString strTrade;
11940  theTrade.SaveContractRaw(strTrade);
11941 
11942  // Add the trade string as the attachment on the transaction item.
11943  pItem->SetAttachment(strTrade); // The trade is contained in the
11944  // attachment string. (The offer is
11945  // within the trade.)
11946 
11947  // sign the item
11948  pItem->SignContract(*pNym);
11949  pItem->SaveContract();
11950 
11951  // the Transaction "owns" the item now and will handle cleaning it
11952  // up.
11953  pTransaction->AddItem(*pItem); // the Transaction's destructor will
11954  // cleanup the item. It "owns" it
11955  // now.
11956  // TRANSACTION AGREEMENT
11957 
11958  // pBalanceItem is signed and saved within this call. No need to do
11959  // that again.
11960  OTItem* pStatementItem =
11961  pNym->GenerateTransactionStatement(*pTransaction);
11962 
11963  if (nullptr !=
11964  pStatementItem) // will never be nullptr. Will assert above
11965  // before it gets here.
11966  pTransaction->AddItem(
11967  *pStatementItem); // Better not be nullptr...
11968  // message will fail...
11969  // But better check
11970  // anyway.
11971  // sign the transaction
11972  pTransaction->SignContract(*pNym);
11973  pTransaction->SaveContract();
11974 
11975  // set up the ledger
11976  OTLedger theLedger(USER_ID, ASSET_ACCT_ID, SERVER_ID);
11977  theLedger.GenerateLedger(ASSET_ACCT_ID, SERVER_ID,
11978  OTLedger::message); // bGenerateLedger
11979  // defaults to false,
11980  // which is correct.
11981  theLedger.AddTransaction(*pTransaction); // now the ledger "owns"
11982  // and will handle cleaning
11983  // up the transaction.
11984 
11985  // sign the ledger
11986  theLedger.SignContract(*pNym);
11987  theLedger.SaveContract();
11988 
11989  // extract the ledger in ascii-armored form... encoding...
11990  OTString strLedger(theLedger);
11991  OTASCIIArmor ascLedger(strLedger);
11992 
11993  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
11994  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
11995  theMessage.m_strRequestNum.Format(
11996  "%ld", lRequestNumber); // Always have to send this.
11997  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it
11998  // for a server
11999  // request, I have to
12000  // increment it
12001 
12002  // (1) Set up member variables
12003  theMessage.m_strCommand = "notarizeTransactions";
12004  theMessage.m_strNymID = strNymID;
12005  theMessage.m_strServerID = strServerID;
12006  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12007  // theMessage.m_strServerID is
12008  // already set. (It uses it.)
12009 
12010  theMessage.m_strAcctID = str_ASSET_ACCT_ID;
12011  theMessage.m_ascPayload = ascLedger;
12012 
12013  OTIdentifier NYMBOX_HASH;
12014  const std::string str_server(strServerID.Get());
12015  const bool bNymboxHash =
12016  pNym->GetNymboxHash(str_server, NYMBOX_HASH);
12017  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12018 
12019  if (!bNymboxHash)
12020  otErr << __FUNCTION__ << ": Failed getting NymboxHash from Nym "
12021  "for server: " << str_server << "\n";
12022 
12023  // (2) Sign the Message
12024  theMessage.SignContract(*pNym);
12025 
12026  // (3) Save the Message (with signatures and all, back to its
12027  // internal member m_strRawFile.)
12028  theMessage.SaveContract();
12029 
12030  // (Send it)
12031  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
12032  m_pTransportCallback);
12033  m_pClient->ProcessMessageOut(theMessage);
12034 
12035  return m_pClient->CalcReturnVal(lRequestNumber);
12036 
12037  } // if (bCreateOffer && bIssueTrade)
12038  else {
12039  otOut << __FUNCTION__
12040  << ": Unable to create offer or issue trade. Sorry.\n";
12041 
12042  // IF FAILED, add the transaction number (and closing number)
12043  // BACK to the list of available numbers.
12044  //
12045  pNym->AddTransactionNum(*pNym, strServerID,
12046  lStoredTransactionNumber,
12047  false); // bSave defaults to true
12048  pNym->AddTransactionNum(*pNym, strServerID, lAssetAcctClosingNo,
12049  false);
12050  pNym->AddTransactionNum(
12051  *pNym, strServerID, lCurrencyAcctClosingNo,
12052  true); // bSave=true (No sense saving thrice in a row.)
12053  }
12054  } // got transaction number.
12055 
12056  return (-1);
12057 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT time64_t GetTime() const
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int64_t time64_t
Definition: Common.hpp:209
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
#define OT_TIME_DAY_IN_SECONDS
Definition: Common.hpp:176
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTAccount * opentxs::OT_API::LoadAssetAccount ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6359 of file OpenTransactions.cpp.

6362 {
6363  OTWallet* pWallet =
6364  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
6365  if (nullptr == pWallet) return nullptr;
6366  // By this point, pWallet is a good pointer. (No need to cleanup.)
6367  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6368  if (nullptr == pNym) return nullptr;
6369  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6370  // cleanup.)
6371  return pWallet->LoadAccount(*pNym, ACCOUNT_ID, SERVER_ID, __FUNCTION__);
6372 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
OTAssetContract * opentxs::OT_API::LoadAssetContract ( const OTIdentifier ASSET_ID) const

Definition at line 6316 of file OpenTransactions.cpp.

6317 {
6318  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
6319  OTString strAssetTypeID(ASSET_ID);
6320 
6321  OTString strFoldername = OTFolders::Contract().Get();
6322  OTString strFilename = strAssetTypeID.Get();
6323  if (!OTDB::Exists(strFoldername.Get(), strFilename.Get())) {
6324  otErr << "OT_API::LoadAssetContract: File does not exist: "
6325  << strFoldername.Get() << OTLog::PathSeparator() << strFilename
6326  << "\n";
6327  return nullptr;
6328  }
6329  OTAssetContract* pContract = new OTAssetContract(
6330  strAssetTypeID, strFoldername, strFilename, strAssetTypeID);
6331  OT_ASSERT_MSG(nullptr != pContract,
6332  "Error allocating memory for Asset "
6333  "Contract in OT_API::LoadAssetContract\n");
6334 
6335  if (pContract->LoadContract() && pContract->VerifyContract())
6336  return pContract;
6337  else
6338  otOut << "OT_API::LoadAssetContract: Unable to load or verify "
6339  "asset contract (Maybe it's just not there, and "
6340  "needs to be downloaded.) Asset ID: " << strAssetTypeID
6341  << "\n";
6342  delete pContract;
6343  pContract = nullptr;
6344 
6345  return nullptr;
6346 }
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OT_API::LoadConfigFile ( )

Definition at line 831 of file OpenTransactions.cpp.

832 {
833  // Setup Config File
834  OTString strConfigPath, strConfigFilename;
835 
837  return false;
838  }
839 
840  // Create Config Object (OTSettings)
841  OTString strConfigFilePath = "";
842  if (!OTDataFolder::GetConfigFilePath(strConfigFilePath)) {
843  OT_FAIL;
844  }
845  OTSettings* p_Config = nullptr;
846  p_Config = new OTSettings(strConfigFilePath);
847 
848  // First Load, Create new fresh config file if failed loading.
849  if (!p_Config->Load()) {
850  otOut << __FUNCTION__
851  << ": Note: Unable to Load Config. Creating a new file: "
852  << strConfigFilename << "\n";
853  if (!p_Config->Reset()) return false;
854  if (!p_Config->Save()) return false;
855  }
856 
857  if (!p_Config->Reset()) return false;
858 
859  // Second Load, Throw Assert if Failed loading.
860  if (!p_Config->Load()) {
861  otErr << __FUNCTION__
862  << ": Error: Unable to load config file: " << strConfigFilename
863  << " It should exist, as we just saved it!\n";
864  OT_FAIL;
865  }
866 
867  // LOG LEVEL
868  {
869  bool bIsNewKey;
870  int64_t lValue;
871  p_Config->CheckSet_long("logging", "log_level", 0, lValue, bIsNewKey);
872  OTLog::SetLogLevel(static_cast<int32_t>(lValue));
873  }
874 
875  // WALLET
876 
877  // WALLET FILENAME
878  //
879  // Clean and Set
880  {
881  bool bIsNewKey;
882  OTString strValue;
883  p_Config->CheckSet_str("wallet", "wallet_filename",
884  CLIENT_WALLET_FILENAME, strValue, bIsNewKey);
885  OT_API::SetWalletFilename(strValue);
886  otWarn << "Using Wallet: " << strValue << "\n";
887  }
888 
889  // LATENCY
890  {
891  const char* szComment =
892  ";; LATENCY:\n\n"
893  ";; For sending and receiving:\n"
894  ";; blocking=true (usually not recommended) means OT will hang on "
895  "the send/receive\n"
896  ";; call, and wait indefinitely until the send or receive has "
897  "actually occurred.\n"
898  ";; IF BLOCKING IS FALSE (normal, default):\n"
899  ";; - no_tries is the number of times OT will try to send or "
900  "receive a message.\n"
901  ";; - ms is the number of milliseconds it will wait between each "
902  "attempt.\n"
903  ";; UPDATE: send_ms and receive_ms now DOUBLE after each failed "
904  "attempt! (up to 3 tries)\n"
905  ";; Meaning that after 3 tries, it's already waited over 21 "
906  "seconds trying to get\n"
907  ";; the message. \n"
908  ";; send_delay_after happens after EVERY SINGLE server "
909  "request/reply, which can be\n"
910  ";; multiple times per use case. (They can add up quick...)\n";
911 
912  bool b_SectionExist;
913  p_Config->CheckSetSection("latency", szComment, b_SectionExist);
914  }
915 
916  {
917  if (nullptr == m_pSocket) {
918  OT_FAIL;
919  }
920 
921  const OTSocket::Defaults socketDefaults(
927 
928  m_pSocket->Init(socketDefaults, p_Config); // setup the socket.
929  }
930 
931  // SECURITY (beginnings of..)
932 
933  // Master Key Timeout
934  {
935  const char* szComment =
936  "; master_key_timeout is how int64_t the master key will be in "
937  "memory until a thread wipes it out.\n"
938  "; 0 : means you have to type your password EVERY time OT uses a "
939  "private key. (Even multiple times in a single function.)\n"
940  "; 300 : means you only have to type it once per 5 minutes.\n"
941  "; -1 : means you only type it once PER RUN (popular for "
942  "servers.)\n";
943 
944  bool bIsNewKey;
945  int64_t lValue;
946  p_Config->CheckSet_long("security", "master_key_timeout",
948  bIsNewKey, szComment);
949  OTCachedKey::It()->SetTimeoutSeconds(static_cast<int32_t>(lValue));
950  }
951 
952  // Use System Keyring
953  {
954  bool bValue, bIsNewKey;
955  p_Config->CheckSet_bool("security", "use_system_keyring",
956  CLIENT_USE_SYSTEM_KEYRING, bValue, bIsNewKey);
957  OTCachedKey::It()->UseSystemKeyring(bValue);
958  }
959 
960  // Use System Keyring
961  {
962  bool bValue, bIsNewKey;
963  p_Config->CheckSet_bool("security", "use_system_keyring",
964  CLIENT_USE_SYSTEM_KEYRING, bValue, bIsNewKey);
965  OTCachedKey::It()->UseSystemKeyring(bValue);
966 
967 #if defined(OT_KEYRING_FLATFILE)
968  // Is there a password folder? (There shouldn't be, but we allow it...)
969  //
970  if (bValue) {
971  bool bIsNewKey2;
972  OTString strValue;
973  p_Config->CheckSet_str("security", "password_folder",
974  CLIENT_PASSWORD_FOLDER, strValue,
975  bIsNewKey2);
976  if (strValue.Exists()) {
977  OTKeyring::FlatFile_SetPasswordFolder(strValue.Get());
978  otOut << " **DANGEROUS!** Using password folder: " << strValue
979  << "\n";
980  }
981  }
982 #endif
983  }
984 
985  // Done Loading... Lets save any changes...
986  if (!p_Config->Save()) {
987  otErr << __FUNCTION__ << ": Error! Unable to save updated Config!!!\n";
988  OT_FAIL;
989  }
990 
991  // Finsihed Saving... now lets cleanup!
992  if (!p_Config->Reset()) return false;
993 
994  if (nullptr != p_Config) delete p_Config;
995  p_Config = nullptr;
996 
997  return true;
998 }
#define CLIENT_MASTER_KEY_TIMEOUT_DEFAULT
static EXPORT bool GetConfigFilePath(OTString &strConfigFilePath)
#define CLIENT_DEFAULT_LATENCY_RECEIVE_MS
static EXPORT bool SetLogLevel(const int32_t &nLogLevel)
Definition: OTLog.cpp:443
OTLOG_IMPORT OTLogStream otOut
static EXPORT bool IsInitialized()
#define CLIENT_DEFAULT_LATENCY_DELAY_AFTER
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
#define CLIENT_DEFAULT_LATENCY_SEND_MS
EXPORT bool Init(const Defaults &defaults)
Definition: OTSocket.cpp:202
#define CLIENT_DEFAULT_IS_BLOCKING
#define CLIENT_WALLET_FILENAME
#define CLIENT_DEFAULT_LATENCY_RECEIVE_NO_TRIES
#define CLIENT_USE_SYSTEM_KEYRING
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
EXPORT bool SetWalletFilename(const OTString &strPath)
#define CLIENT_DEFAULT_LATENCY_SEND_NO_TRIES
#define CLIENT_PASSWORD_FOLDER
OTLedger * opentxs::OT_API::LoadExpiredBox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6700 of file OpenTransactions.cpp.

6702 {
6703  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6704  if (nullptr == pNym) return nullptr;
6705 
6706  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6707  // cleanup.)
6708  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
6710  OT_ASSERT_MSG(
6711  nullptr != pLedger,
6712  "OT_API::LoadExpiredBox: Error allocating memory in the OT API.");
6713  // Beyond this point, I know that pLedger will need to be deleted or
6714  // returned.
6715  const bool bLoaded = pLedger->LoadExpiredBox();
6716 
6717  bool bVerified = false;
6718 
6719  if (bLoaded) bVerified = pLedger->VerifyAccount(*pNym);
6720 
6721  if (bLoaded && bVerified)
6722  return pLedger;
6723  else {
6724  OTString strUserID(USER_ID);
6725  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6726  << "\n";
6727  delete pLedger;
6728  pLedger = nullptr;
6729  }
6730  return nullptr;
6731 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadExpiredBoxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6733 of file OpenTransactions.cpp.

6735 {
6736  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6737  if (nullptr == pNym) return nullptr;
6738  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6739  // cleanup.)
6740  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
6742  OT_ASSERT_MSG(nullptr != pLedger, "OT_API::LoadExpiredBoxNoVerify: Error "
6743  "allocating memory in the OT API.");
6744  // Beyond this point, I know that pLedger will need to be deleted or
6745  // returned.
6746  if (pLedger->LoadExpiredBox()) // The Verify would have gone here.
6747  return pLedger;
6748  else {
6749  OTString strUserID(USER_ID);
6750  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6751  << "\n";
6752  delete pLedger;
6753  pLedger = nullptr;
6754  }
6755  return nullptr;
6756 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadInbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6443 of file OpenTransactions.cpp.

6446 {
6447  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6448  if (nullptr == pNym) return nullptr;
6449  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6450  // cleanup.)
6451  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6452  OTLedger::inbox);
6453  OT_ASSERT_MSG(nullptr != pLedger,
6454  "OT_API::LoadInbox: Error allocating memory in the OT API.");
6455 
6456  // Beyond this point, I know that pLedger will need to be deleted or
6457  // returned.
6458  if (pLedger->LoadInbox() && pLedger->VerifyAccount(*pNym))
6459  return pLedger;
6460  else {
6461  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6462  otWarn << "OT_API::LoadInbox: Unable to load or verify inbox: "
6463  << strAcctID << "\n For user: " << strUserID << "\n";
6464  delete pLedger;
6465  pLedger = nullptr;
6466  }
6467  return nullptr;
6468 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadInboxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6481 of file OpenTransactions.cpp.

6484 {
6485  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6486  if (nullptr == pNym) return nullptr;
6487  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6488  // cleanup.)
6489  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6490  OTLedger::inbox);
6491  OT_ASSERT_MSG(
6492  nullptr != pLedger,
6493  "OT_API::LoadInboxNoVerify: Error allocating memory in the OT API.");
6494 
6495  // Beyond this point, I know that pLedger will need to be deleted or
6496  // returned.
6497  if (pLedger->LoadInbox()) // The Verify would go here.
6498  return pLedger;
6499  else {
6500  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6501  otWarn << "OT_API::LoadInboxNoVerify: Unable to load inbox: "
6502  << strAcctID << "\n For user: " << strUserID << "\n";
6503  delete pLedger;
6504  pLedger = nullptr;
6505  }
6506  return nullptr;
6507 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
Mint * opentxs::OT_API::LoadMint ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
) const

Definition at line 6245 of file OpenTransactions.cpp.

6247 {
6248  const OTString strServerID(SERVER_ID);
6249  const OTString strAssetTypeID(ASSET_ID);
6250  OTServerContract* pServerContract = GetServer(SERVER_ID, __FUNCTION__);
6251  if (nullptr == pServerContract) return nullptr;
6252  const OTPseudonym* pServerNym = pServerContract->GetContractPublicNym();
6253  if (nullptr == pServerNym) {
6254  otErr << __FUNCTION__
6255  << ": Failed trying to get contract public Nym for ServerID: "
6256  << strServerID << " \n";
6257  return nullptr;
6258  }
6259  Mint* pMint = Mint::MintFactory(strServerID, strAssetTypeID);
6260  OT_ASSERT_MSG(nullptr != pMint,
6261  "OT_API::LoadMint: Error allocating memory in the OT API");
6262  // responsible to delete or return pMint below this point.
6263  if (!pMint->LoadMint() || !pMint->VerifyMint(*pServerNym)) {
6264  otOut << __FUNCTION__
6265  << ": Unable to load or verify Mintfile : " << OTFolders::Mint()
6266  << OTLog::PathSeparator() << strServerID << OTLog::PathSeparator()
6267  << strAssetTypeID << "\n";
6268  delete pMint;
6269  pMint = nullptr;
6270  return nullptr;
6271  }
6272  return pMint;
6273 }
static EXPORT const OTString & Mint()
Definition: OTFolders.cpp:323
static EXPORT Mint * MintFactory()
Definition: Mint.cpp:154
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
OTLedger * opentxs::OT_API::LoadNymbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6378 of file OpenTransactions.cpp.

6380 {
6381  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6382  if (nullptr == pNym) return nullptr;
6383  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6384  // cleanup.)
6385  OTLedger* pLedger =
6386  OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID, OTLedger::nymbox);
6387  OT_ASSERT_MSG(nullptr != pLedger,
6388  "OT_API::LoadNymbox: Error allocating memory in the OT API.");
6389  // Beyond this point, I know that pLedger will need to be deleted or
6390  // returned.
6391  if (pLedger->LoadNymbox() && pLedger->VerifyAccount(*pNym))
6392  return pLedger;
6393  else {
6394  OTString strUserID(USER_ID);
6395  otOut << "OT_API::LoadNymbox: Unable to load or verify nymbox: "
6396  << strUserID << "\n";
6397  delete pLedger;
6398  pLedger = nullptr;
6399  }
6400  return nullptr;
6401 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLedger * opentxs::OT_API::LoadNymboxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6413 of file OpenTransactions.cpp.

6415 {
6416  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6417  if (nullptr == pNym) return nullptr;
6418  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6419  // cleanup.)
6420  OTLedger* pLedger =
6421  OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID, OTLedger::nymbox);
6422  OT_ASSERT_MSG(
6423  nullptr != pLedger,
6424  "OT_API::LoadNymboxNoVerify: Error allocating memory in the OT API.");
6425  // Beyond this point, I know that pLedger will need to be deleted or
6426  // returned.
6427  if (pLedger->LoadNymbox()) // The Verify would go here.
6428  return pLedger;
6429  else {
6430  OTString strUserID(USER_ID);
6431  otOut << "OT_API::LoadNymboxNoVerify: Unable to load nymbox: "
6432  << strUserID << "\n";
6433  delete pLedger;
6434  pLedger = nullptr;
6435  }
6436  return nullptr;
6437 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLedger * opentxs::OT_API::LoadOutbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6513 of file OpenTransactions.cpp.

6516 {
6517  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6518  if (nullptr == pNym) return nullptr;
6519  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6520  // cleanup.)
6521  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6523  OT_ASSERT_MSG(nullptr != pLedger,
6524  "OT_API::LoadOutbox: Error allocating memory in the OT API.");
6525 
6526  // Beyond this point, I know that pLedger is loaded and will need to be
6527  // deleted or returned.
6528 
6529  if (pLedger->LoadOutbox() && pLedger->VerifyAccount(*pNym))
6530  return pLedger;
6531  else {
6532  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6533 
6534  otWarn << "OT_API::LoadOutbox: Unable to load or verify "
6535  "outbox: " << strAcctID << "\n For user: " << strUserID
6536  << "\n";
6537 
6538  delete pLedger;
6539  pLedger = nullptr;
6540  }
6541  return nullptr;
6542 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadOutboxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6555 of file OpenTransactions.cpp.

6558 {
6559  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6560  if (nullptr == pNym) return nullptr;
6561  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6562  // cleanup.)
6563  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6565  OT_ASSERT_MSG(
6566  nullptr != pLedger,
6567  "OT_API::LoadOutboxNoVerify: Error allocating memory in the OT API.");
6568 
6569  // Beyond this point, I know that pLedger is loaded and will need to be
6570  // deleted or returned.
6571 
6572  if (pLedger->LoadOutbox()) // The Verify would go here.
6573  return pLedger;
6574  else {
6575  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6576  otWarn << "OT_API::LoadOutboxNoVerify: Unable to load outbox: "
6577  << strAcctID << "\n For user: " << strUserID << "\n";
6578 
6579  delete pLedger;
6580  pLedger = nullptr;
6581  }
6582  return nullptr;
6583 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadPaymentInbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6585 of file OpenTransactions.cpp.

6587 {
6588  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6589  if (nullptr == pNym) return nullptr;
6590  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6591  // cleanup.)
6592  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
6594  OT_ASSERT_MSG(
6595  nullptr != pLedger,
6596  "OT_API::LoadPaymentInbox: Error allocating memory in the OT API.");
6597  // Beyond this point, I know that pLedger will need to be deleted or
6598  // returned.
6599  if (pLedger->LoadPaymentInbox() && pLedger->VerifyAccount(*pNym))
6600  return pLedger;
6601  else {
6602  OTString strUserID(USER_ID), strAcctID(USER_ID);
6603  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6604  << " / " << strAcctID << "\n";
6605  delete pLedger;
6606  pLedger = nullptr;
6607  }
6608  return nullptr;
6609 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadPaymentInboxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 6611 of file OpenTransactions.cpp.

6613 {
6614  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6615  if (nullptr == pNym) return nullptr;
6616  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6617  // cleanup.)
6618  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
6620  OT_ASSERT_MSG(nullptr != pLedger, "OT_API::LoadPaymentInboxNoVerify: Error "
6621  "allocating memory in the OT API.");
6622  // Beyond this point, I know that pLedger will need to be deleted or
6623  // returned.
6624  if (pLedger->LoadPaymentInbox()) // The Verify would have gone here.
6625  return pLedger;
6626  else {
6627  OTString strUserID(USER_ID), strAcctID(USER_ID);
6628  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6629  << " / " << strAcctID << "\n";
6630  delete pLedger;
6631  pLedger = nullptr;
6632  }
6633  return nullptr;
6634 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTPseudonym * opentxs::OT_API::LoadPrivateNym ( const OTIdentifier NYM_ID,
bool  bChecking = false,
const char *  szFuncName = nullptr,
const OTPasswordData pPWData = nullptr,
const OTPassword pImportPassword = nullptr 
) const

CALLER is responsible to delete the Nym that's returned here! (Low level.)

Definition at line 4538 of file OpenTransactions.cpp.

4542 {
4543  if (NYM_ID.IsEmpty()) {
4544  otErr << __FUNCTION__ << ": NYM_ID is empty!";
4545  OT_FAIL;
4546  }
4547  // Grab the name, if there is one.
4548  // That way if we have to reload it, we'll be able to preserve the name.
4549  OTString strName;
4550  const OTString strNymID(NYM_ID);
4551  // If the Nym is already in the wallet, we grab the name from the wallet, so
4552  // we can
4553  // set the same name onto that Nym again when he's re-loaded.
4554  //
4555  OTPseudonym* pNym =
4556  GetNym(NYM_ID, szFuncName); // This already logs and ASSERTs
4557  strName = (nullptr != pNym) ? pNym->GetNymName().Get() : strNymID.Get();
4558  // now strName contains either "" or the Nym's name from wallet.
4559  OTPasswordData thePWData(OT_PW_DISPLAY);
4560  if (nullptr == pPWData) pPWData = &thePWData;
4561  return OTPseudonym::LoadPrivateNym(NYM_ID, bChecking, &strName, szFuncName,
4562  pPWData,
4563  pImportPassword); // CALLER must delete!
4564 }
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
static EXPORT OTPseudonym * LoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const OTString *pstrName=nullptr, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr)
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
OTPseudonym * opentxs::OT_API::LoadPublicNym ( const OTIdentifier NYM_ID,
const char *  szFuncName = nullptr 
) const

CALLER is responsible to delete this Nym! (Low level.)

Definition at line 4515 of file OpenTransactions.cpp.

4517 {
4518  if (NYM_ID.IsEmpty()) {
4519  otErr << __FUNCTION__ << ": NYM_ID is empty!";
4520  OT_FAIL;
4521  }
4522 
4523  // const char * szFunc = (nullptr != szFuncName) ? szFuncName :
4524  // __FUNCTION__;
4525  // Grab the name, if there is one.
4526  // That way if we have to reload it, we'll be able to preserve the name.
4527  OTString strName;
4528  const OTString strNymID(NYM_ID);
4529  OTPseudonym* pNym =
4530  GetNym(NYM_ID, szFuncName); // This already logs and ASSERTs
4531  strName = (nullptr != pNym) ? pNym->GetNymName().Get() : strNymID.Get();
4532  // now strName contains either "" or the Nym's name from wallet.
4533  return OTPseudonym::LoadPublicNym(NYM_ID, &strName, szFuncName);
4534 }
static EXPORT OTPseudonym * LoadPublicNym(const OTIdentifier &NYM_ID, const OTString *pstrName=nullptr, const char *szFuncName=nullptr)
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
Purse * opentxs::OT_API::LoadPurse ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID,
const OTIdentifier USER_ID,
const OTString pstrDisplay = nullptr 
) const

Definition at line 5258 of file OpenTransactions.cpp.

5262 {
5263  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5264  const OTString strReason((nullptr == pstrDisplay)
5265  ? "Loading purse from local storage."
5266  : pstrDisplay->Get());
5267  OTPasswordData thePWData(strReason);
5268  const OTString strServerID(SERVER_ID);
5269  const OTString strUserID(USER_ID);
5270  const OTString strAssetTypeID(ASSET_ID);
5271  OTPseudonym* pNym =
5272  GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__,
5273  &thePWData); // These copiously log, and ASSERT.
5274  if (nullptr == pNym) return nullptr;
5275  Purse* pPurse = new Purse(SERVER_ID, ASSET_ID, USER_ID);
5276  OT_ASSERT_MSG(nullptr != pPurse,
5277  "Error allocating memory in the OT API."); // responsible to
5278  // delete or return
5279  // pPurse below
5280  // this point.
5281 
5282  if (pPurse->LoadPurse(strServerID.Get(), strUserID.Get(),
5283  strAssetTypeID.Get())) {
5284  if (pPurse->VerifySignature(*pNym) &&
5285  (SERVER_ID == pPurse->GetServerID()) &&
5286  (ASSET_ID == pPurse->GetAssetID())) {
5287  return pPurse;
5288  }
5289  else
5290  otOut << __FUNCTION__ << ": Failed verifying purse.\n";
5291  }
5292  else
5293  otInfo << __FUNCTION__ << ": Failed loading purse.\n";
5294  delete pPurse;
5295  pPurse = nullptr;
5296 
5297  return nullptr;
5298 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otInfo
OTNym_or_SymmetricKey * opentxs::OT_API::LoadPurseAndOwnerForMerge ( const OTString strPurse,
Purse thePurse,
OTPassword thePassword,
bool  bCanBePublic = false,
const OTIdentifier pOWNER_ID = nullptr,
const OTString pstrDisplay = nullptr 
) const

Definition at line 5528 of file OpenTransactions.cpp.

5546 {
5547  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5548  OTPasswordData thePWData((nullptr == pstrDisplay) ? OT_PW_DISPLAY
5549  : pstrDisplay->Get());
5550  OTNym_or_SymmetricKey* pOwner = nullptr;
5551  if (strPurse.Exists() && thePurse.LoadContractFromString(strPurse)) {
5552  OTIdentifier idPurseNym;
5553 
5554  if (thePurse.IsNymIDIncluded() && !thePurse.GetNymID(idPurseNym))
5555  otErr << __FUNCTION__
5556  << ": Failed trying to get the NymID from the "
5557  "purse (though one WAS apparently present.)\n";
5558  // Purse is encrypted based on Nym.
5559  //
5560  // If the purse includes a NymID, then we'll use it. (If we can't use
5561  // that specific one, then we have failed.)
5562  else if (thePurse.IsNymIDIncluded() ||
5563  // Else if the purse does NOT include a NymID (but also is NOT
5564  // password protected, meaning a Nym still exists, but just
5565  // isn't named) then we'll use pOWNER_ID passed in. If that's
5566  // nullptr, or we fail to find the Nym with it, then we have
5567  // failed.
5568  (!thePurse.IsNymIDIncluded() &&
5569  !thePurse.IsPasswordProtected()) // && (nullptr != pOWNER_ID))
5570  // //
5571  // checked inside the block.
5572  ) {
5573  const OTIdentifier* pActualOwnerID =
5574  thePurse.IsNymIDIncluded() ? &idPurseNym : pOWNER_ID;
5575 
5576  if (nullptr == pActualOwnerID) {
5577  otErr << __FUNCTION__
5578  << ": Failed: The purse is encrypted to a "
5579  "specific Nym (not a passphrase) "
5580  "but that Nym is not specified in the purse, nor "
5581  "was it passed into this "
5582  "function. (Failure. Unable to access purse.)\n";
5583  return nullptr;
5584  }
5585  OTPseudonym* pOwnerNym =
5586  bCanBePublic
5587  ? GetOrLoadNym(*pActualOwnerID, false, __FUNCTION__,
5588  &thePWData)
5590  *pActualOwnerID, false, __FUNCTION__,
5591  &thePWData); // These copiously log, and ASSERT.
5592  if (nullptr == pOwnerNym) {
5593  const OTString strAttemptedID(*pActualOwnerID);
5594  otErr << __FUNCTION__
5595  << ": Failed: The purse is encrypted to a specific NymID "
5596  "(not a passphrase) which was either specified inside "
5597  "the purse, "
5598  "or wasn't specified so we guessed the user ID. "
5599  "Either way, we "
5600  "then failed loading that Nym: " << strAttemptedID
5601  << "\n"
5602  "(Failure. Unable to access purse.)\n";
5603  return nullptr;
5604  }
5605  // We found the Nym. If it was the Nym listed in the purse, then
5606  // it's almost certainly the right one.
5607  // Else if it was the Nym we guessed, it could be right and it could
5608  // be wrong. We won't find out in that
5609  // case, until we actually try to use it for decrypting tokens on
5610  // the purse (and then we'll fail at that
5611  // time, if it's the wrong Nym.)
5612  //
5613  pOwner = new OTNym_or_SymmetricKey(
5614  *pOwnerNym, pstrDisplay); // Can't put &strReason here. (It goes
5615  // out of scope.)
5616  OT_ASSERT(nullptr != pOwner);
5617  }
5618  // Else if purse IS password protected, then use its internal key.
5619  else if (thePurse.IsPasswordProtected()) // Purse is encrypted based on
5620  // its own built-in symmetric
5621  // key.
5622  {
5623  OTSymmetricKey* pSymmetricKey = thePurse.GetInternalKey();
5624  OT_ASSERT(nullptr != pSymmetricKey);
5625  const bool bGotPassphrase = thePurse.GetPassphrase(
5626  thePassword, thePWData.GetDisplayString());
5627 
5628  if (!bGotPassphrase)
5629  otOut << __FUNCTION__
5630  << ": Authentication failed, or otherwise failed "
5631  "retrieving secret from user.\n";
5632  // Below this point, we know thePassword is good, and we know
5633  // pSymmetricKey is good.
5634  // Therefore...
5635  //
5636  else {
5637  pOwner = new OTNym_or_SymmetricKey(*pSymmetricKey, thePassword,
5638  pstrDisplay); // Can't put
5639  // &strReason
5640  // here. (It goes
5641  // out of scope.)
5642  OT_ASSERT(nullptr != pOwner);
5643  }
5644  }
5645  else
5646  otErr << __FUNCTION__ << ": Failed: Somehow this purse is not "
5647  "password-protected, nor "
5648  "is it Nym-protected. (This error should "
5649  "never actually happen.)\n";
5650  // (By this point, pOwner is all set up and ready to go.)
5651  }
5652  else
5653  otOut << __FUNCTION__ << ": Failure loading purse from string:\n"
5654  << strPurse << "\n";
5655  return pOwner;
5656 }
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
OTNym_or_SymmetricKey * opentxs::OT_API::LoadPurseAndOwnerFromString ( const OTIdentifier theServerID,
const OTIdentifier theAssetTypeID,
const OTString strPurse,
Purse thePurse,
OTPassword thePassword,
bool  bForEncrypting = true,
const OTIdentifier pOWNER_ID = nullptr,
const OTString pstrDisplay1 = nullptr,
const OTString pstrDisplay2 = nullptr 
) const

Definition at line 5379 of file OpenTransactions.cpp.

5395 {
5396  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5397  const bool bDoesOwnerIDExist =
5398  (nullptr !=
5399  pOWNER_ID); // If not true, purse MUST be password-protected.
5400  OTPasswordData thePWData1(
5401  (nullptr == pstrDisplay1)
5402  ? "Enter the master passphrase for your wallet. "
5403  "(LoadPurseAndOwnerFromString)"
5404  : pstrDisplay1->Get()); // for purses already owned by the wallet
5405  OTPasswordData thePWData2(
5406  (nullptr == pstrDisplay2)
5407  ? "Enter the passphrase for this purse. "
5408  "(LoadPurseAndOwnerFromString)"
5409  : pstrDisplay2->Get()); // for password-protected purses.
5410  OTPseudonym* pOwnerNym =
5411  nullptr; // In the case where there is an owner, this will point to it.
5412  if (bDoesOwnerIDExist) {
5413  pOwnerNym =
5414  bForEncrypting
5415  ? GetOrLoadNym(*pOWNER_ID, false, __FUNCTION__, &thePWData1)
5417  *pOWNER_ID, false, __FUNCTION__,
5418  &thePWData1); // These copiously log, and ASSERT.
5419  if (nullptr == pOwnerNym) return nullptr;
5420  }
5421  // By this point, pOwnerNym may be a good pointer, and on the wallet. (No
5422  // need to cleanup.)
5423  // Or, it may also be nullptr, in the case that the purse is
5424  // password-protected.
5425  // bDoesOwnerIDExist is an easy way to tell, either way.
5426  OTNym_or_SymmetricKey* pOwner = nullptr;
5427  if (strPurse.Exists() && thePurse.LoadContractFromString(strPurse)) {
5428  const bool bNymIDIncludedInPurse = thePurse.IsNymIDIncluded();
5429  OTIdentifier idPurseNym;
5430 
5431  if (thePurse.GetServerID() != theServerID)
5432  otErr << __FUNCTION__ << ": Failed: ServerID doesn't match.\n";
5433  else if (thePurse.GetAssetID() != theAssetTypeID)
5434  otErr << __FUNCTION__ << ": Failed: AssetTypeID doesn't match.\n";
5435  else if (bNymIDIncludedInPurse && !thePurse.GetNymID(idPurseNym))
5436  otErr << __FUNCTION__
5437  << ": Failed trying to get the NymID from the "
5438  "purse (though one WAS apparently present.)\n";
5439  else if (bNymIDIncludedInPurse && !bDoesOwnerIDExist) {
5440  const OTString strPurseNymID(idPurseNym);
5441  otErr << __FUNCTION__
5442  << ": Error: The purse is owned by a NymID, but no "
5443  "NymID was passed into "
5444  "this function.\nNym who owns the purse: " << strPurseNymID
5445  << "\n\n";
5446  }
5447  else if (bNymIDIncludedInPurse &&
5448  !(pOwnerNym->GetConstID() == idPurseNym)) {
5449  const OTString strPurseNymID(idPurseNym),
5450  strNymActuallyPassed(pOwnerNym->GetConstID());
5451  otErr << __FUNCTION__
5452  << ": Error: the API call mentions Nym A, but the "
5453  "purse is actually owned by Nym B.\nNym A: "
5454  << strNymActuallyPassed << "\nNym B: " << strPurseNymID
5455  << "\n\n";
5456  }
5457  else if (!bDoesOwnerIDExist && !thePurse.IsPasswordProtected())
5458  otErr << __FUNCTION__
5459  << ": Failed: The USER_ID was nullptr, which is only allowed "
5460  "for a password-protected purse. (And this purse is NOT "
5461  "password-protected.) Please provide a USER_ID.\n";
5462  // By this point, we know the purse loaded up properly, and the server
5463  // and asset IDs match
5464  // what we expected. We also know that if the purse included a NymID, it
5465  // matches the USER_ID
5466  // that was passed in. We also know that if a User ID was NOT passed in,
5467  // that the purse WAS
5468  // definitely a password-protected purse.
5469  //
5470  else if (thePurse.IsPasswordProtected()) // Purse is encrypted based on
5471  // its own built-in symmetric
5472  // key.
5473  {
5474  OTSymmetricKey* pSymmetricKey = thePurse.GetInternalKey();
5475  OT_ASSERT(nullptr != pSymmetricKey);
5476  const bool bGotPassphrase = thePurse.GetPassphrase(
5477  thePassword, thePWData2.GetDisplayString());
5478 
5479  if (!bGotPassphrase)
5480  otOut << __FUNCTION__
5481  << ": Authentication failed, or otherwise failed "
5482  "retrieving secret from user.\n";
5483  // Below this point, we know thePassword is good, and we know
5484  // pSymmetricKey is good.
5485  // Therefore...
5486  //
5487  else {
5488  pOwner = new OTNym_or_SymmetricKey(*pSymmetricKey, thePassword,
5489  pstrDisplay2); // Can't put
5490  // &strReason
5491  // here. (It
5492  // goes out of
5493  // scope.)
5494  OT_ASSERT(nullptr != pOwner);
5495  }
5496  }
5497  else if (bDoesOwnerIDExist) // Purse is encrypted based on Nym.
5498  {
5499  pOwner = new OTNym_or_SymmetricKey(
5500  *pOwnerNym, pstrDisplay1); // Can't put &strReason here. (It
5501  // goes out of scope.)
5502  OT_ASSERT(nullptr != pOwner);
5503  }
5504  else
5505  otErr << __FUNCTION__
5506  << ": Failed: The purse is not password-protected, "
5507  "but rather, is locked by a Nym. "
5508  "However, no USER_ID was passed in! Please supply a "
5509  "USER_ID in order "
5510  "to open this purse.\n";
5511  // (By this point, pOwner is all set up and ready to go.)
5512  }
5513  else
5514  otOut << __FUNCTION__ << ": Failure loading purse from string:\n"
5515  << strPurse << "\n";
5516  return pOwner;
5517 }
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
OTLedger * opentxs::OT_API::LoadRecordBox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6638 of file OpenTransactions.cpp.

6641 {
6642  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6643  if (nullptr == pNym) return nullptr;
6644 
6645  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6646  // cleanup.)
6647  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6649  OT_ASSERT_MSG(
6650  nullptr != pLedger,
6651  "OT_API::LoadRecordBox: Error allocating memory in the OT API.");
6652  // Beyond this point, I know that pLedger will need to be deleted or
6653  // returned.
6654  const bool bLoaded = pLedger->LoadRecordBox();
6655 
6656  bool bVerified = false;
6657 
6658  if (bLoaded) bVerified = pLedger->VerifyAccount(*pNym);
6659 
6660  if (bLoaded && bVerified)
6661  return pLedger;
6662  else {
6663  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6664  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6665  << " / " << strAcctID << "\n";
6666  delete pLedger;
6667  pLedger = nullptr;
6668  }
6669  return nullptr;
6670 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTLedger * opentxs::OT_API::LoadRecordBoxNoVerify ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

Definition at line 6672 of file OpenTransactions.cpp.

6675 {
6676  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
6677  if (nullptr == pNym) return nullptr;
6678  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6679  // cleanup.)
6680  OTLedger* pLedger = OTLedger::GenerateLedger(USER_ID, ACCOUNT_ID, SERVER_ID,
6682  OT_ASSERT_MSG(nullptr != pLedger, "OT_API::LoadRecordBoxNoVerify: Error "
6683  "allocating memory in the OT API.");
6684  // Beyond this point, I know that pLedger will need to be deleted or
6685  // returned.
6686  if (pLedger->LoadRecordBox()) // The Verify would have gone here.
6687  return pLedger;
6688  else {
6689  OTString strUserID(USER_ID), strAcctID(ACCOUNT_ID);
6690  otWarn << __FUNCTION__ << ": Unable to load or verify: " << strUserID
6691  << " / " << strAcctID << "\n";
6692  delete pLedger;
6693  pLedger = nullptr;
6694  }
6695  return nullptr;
6696 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otWarn
OTServerContract * opentxs::OT_API::LoadServerContract ( const OTIdentifier SERVER_ID) const

Definition at line 6279 of file OpenTransactions.cpp.

6281 {
6282  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
6283  OTString strServerID(SERVER_ID);
6284 
6285  OTString strFoldername = OTFolders::Contract().Get();
6286  OTString strFilename = strServerID.Get();
6287  if (!OTDB::Exists(strFoldername.Get(), strFilename.Get())) {
6288  otErr << "OT_API::LoadServerContract: File does not exist: "
6289  << strFoldername.Get() << OTLog::PathSeparator() << strFilename
6290  << "\n";
6291  return nullptr;
6292  }
6293  OTServerContract* pContract = new OTServerContract(
6294  strServerID, strFoldername, strFilename, strServerID);
6295  OT_ASSERT_MSG(nullptr != pContract,
6296  "Error allocating memory for Server "
6297  "Contract in OT_API::LoadServerContract\n");
6298 
6299  if (pContract->LoadContract() && pContract->VerifyContract())
6300  return pContract;
6301  else
6302  otOut << "OT_API::LoadServerContract: Unable to load or "
6303  "verify server contract. (Maybe it's just not there, "
6304  "and needs to be downloaded.) Server ID: " << strServerID
6305  << "\n";
6306  delete pContract;
6307  pContract = nullptr;
6308 
6309  return nullptr;
6310 }
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
bool opentxs::OT_API::LoadWallet ( ) const

Definition at line 1090 of file OpenTransactions.cpp.

1091 {
1092  OT_ASSERT_MSG(m_bInitialized,
1093  "Not initialized; call OT_API::Init first.\n");
1094  OT_ASSERT_MSG(
1095  m_bDefaultStore,
1096  "Default Storage not Initialized; call OT_API::Init first.\n");
1097 
1098  OTString strWalletFilename;
1099  bool bGetWalletFilenameSuccess =
1100  OT_API::GetWalletFilename(strWalletFilename);
1101 
1102  OT_ASSERT_MSG(
1103  bGetWalletFilenameSuccess,
1104  "OT_API::GetWalletFilename failed, wallet filename isn't set!");
1105 
1106  // Atempt Load
1107  otInfo << "m_pWallet->LoadWallet() with: " << strWalletFilename << "\n";
1108  bool bSuccess = m_pWallet->LoadWallet(strWalletFilename.Get());
1109 
1110  if (bSuccess)
1111  otInfo << __FUNCTION__
1112  << ": Success invoking m_pWallet->LoadWallet() with filename: "
1113  << strWalletFilename << "\n";
1114  else
1115  otErr << __FUNCTION__
1116  << ": Failed invoking m_pWallet->LoadWallet() with filename: "
1117  << strWalletFilename << "\n";
1118  return bSuccess;
1119 }
EXPORT bool LoadWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1617
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otInfo
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetWalletFilename(OTString &strPath) const
bool opentxs::OT_API::Msg_HarvestTransactionNumbers ( const OTMessage theMsg,
const OTIdentifier USER_ID,
bool  bHarvestingForRetry,
bool  bReplyWasSuccess,
bool  bReplyWasFailure,
bool  bTransactionWasSuccess,
bool  bTransactionWasFailure 
) const

Definition at line 4628 of file OpenTransactions.cpp.

4635 {
4636  OTPseudonym* pNym = GetOrLoadPrivateNym(
4637  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4638  if (nullptr == pNym) return false;
4639  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4640  // cleanup.)
4641  return theMsg.HarvestTransactionNumbers(
4642  *pNym, bHarvestingForRetry, bReplyWasSuccess, bReplyWasFailure,
4643  bTransactionWasSuccess, bTransactionWasFailure);
4644 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int32_t opentxs::OT_API::notarizeDeposit ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const OTString THE_PURSE 
) const

Definition at line 9643 of file OpenTransactions.cpp.

9647 {
9648  OTString strPurseReason(
9649  "Depositing a cash purse. Enter passphrase for the purse.");
9650  OTPasswordData thePWDataWallet(
9651  "Depositing a cash purse. Enter master passphrase for wallet.");
9652  OTPseudonym* pNym = GetOrLoadPrivateNym(
9653  USER_ID, false, __FUNCTION__,
9654  &thePWDataWallet); // These copiously log, and ASSERT.
9655  if (nullptr == pNym) return (-1);
9656  // By this point, pNym is a good pointer, and is on the wallet. (No need to
9657  // cleanup.)
9658  OTServerContract* pServer =
9659  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
9660  if (nullptr == pServer) return (-1);
9661  // By this point, pServer is a good pointer. (No need to cleanup.)
9662  OTAccount* pAccount =
9663  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
9664  if (nullptr == pAccount) return (-1);
9665  // By this point, pAccount is a good pointer, and is on the wallet. (No need
9666  // to cleanup.)
9667  OTIdentifier CONTRACT_ID;
9668  OTString strContractID;
9669 
9670  CONTRACT_ID = pAccount->GetAssetTypeID();
9671  CONTRACT_ID.GetString(strContractID);
9672  OTMessage theMessage;
9673 
9674  OTString strServerID(SERVER_ID), strNymID(USER_ID), strFromAcct(ACCT_ID);
9675 
9676  const OTPseudonym* pServerNym = pServer->GetContractPublicNym();
9677  const OTIdentifier SERVER_USER_ID(*pServerNym);
9678  Purse thePurse(SERVER_ID, CONTRACT_ID, SERVER_USER_ID);
9679 
9680  int64_t lStoredTransactionNumber = 0;
9681  bool bGotTransNum = false;
9682  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
9683  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
9684 
9685  if (nullptr == pInbox) {
9686  otOut << __FUNCTION__ << ": Error: Failed loading inbox!\n";
9687  return (-1);
9688  }
9689  if (nullptr == pOutbox) {
9690  otOut << __FUNCTION__ << ": Error: Failed loading outbox!\n";
9691  return (-1);
9692  }
9693 
9694  bGotTransNum = pNym->GetNextTransactionNum(*pNym, strServerID,
9695  lStoredTransactionNumber);
9696  if (!bGotTransNum) {
9697  otOut << __FUNCTION__ << ": Next Transaction Number Available: Suggest "
9698  "requesting the server for a new one.\n";
9699  return (-1);
9700  }
9701 
9702  if (nullptr == pServerNym) OT_FAIL;
9703 
9704  bool bSuccess = false;
9705 
9706  // Create a transaction
9707  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
9708  USER_ID, ACCT_ID, SERVER_ID, OTTransaction::deposit,
9709  lStoredTransactionNumber);
9710  // set up the transaction item (each transaction may have multiple items...)
9711  OTItem* pItem =
9713 
9714  // What's going on here?
9715  // A purse can be encrypted by a private key (controlled by a Nym) or by a
9716  // symmetric
9717  // key (embedded inside the purse along with a corresponding master key.)
9718  // The below
9719  // function is what actually loads up pPurse from string (THE_PURSE) and
9720  // this call
9721  // also returns pOwner, which is a pointer to a special wrapper class (which
9722  // you must
9723  // delete, when you're done with it) which contains a pointer EITHER to the
9724  // owner Nym
9725  // for that purse, OR to the "owner" symmetric key for that purse.
9726  //
9727  // This way, any subsequent purse operations can use pOwner, regardless of
9728  // whether there
9729  // is actually a Nym inside, or a symmetric key. (None of the purse
9730  // operations will care,
9731  // since they can use pOwner either way.)
9732  //
9733  OTPassword thePassword;
9734  Purse theSourcePurse(thePurse);
9735 
9736  std::unique_ptr<OTNym_or_SymmetricKey> pPurseOwner(
9738  THE_PURSE, theSourcePurse, thePassword,
9739  false, // MUST be private, if a nym.
9740  &USER_ID, // This can be nullptr, *IF* purse is password-protected.
9741  // (It's just ignored in that case.) Otherwise if it's
9742  // Nym-protected, the purse will have a NymID on it
9743  // already, which is what LoadPurseAndOwnerForMerge will
9744  // try first. If not (it's optional), then USER_ID is the
9745  // ID it will try next, before failing altogether.
9746  &strPurseReason));
9747  if (nullptr != pPurseOwner) {
9748  OTNym_or_SymmetricKey theServerNymAsOwner(*pServerNym);
9749 
9750  while (!theSourcePurse.IsEmpty()) {
9751  Token* pToken = theSourcePurse.Pop(*pPurseOwner);
9752 
9753  if (nullptr != pToken) {
9754  // TODO need 2-recipient envelopes. My request to the server is
9755  // encrypted to the server's nym,
9756  // but it should be encrypted to my Nym also, so both have
9757  // access to decrypt it.
9758 
9759  // Now the token is ready, let's add it to a purse
9760  // By pushing theToken into thePurse with *pServerNym, I encrypt
9761  // it to pServerNym.
9762  // So now only the server Nym can decrypt that token and pop it
9763  // out of that purse.
9764  if (false ==
9765  pToken->ReassignOwnership(
9766  *pPurseOwner, // must be private, if a nym.
9767  theServerNymAsOwner)) // can be public, if a nym.
9768  {
9769  otErr << "OT_API::notarizeDeposit: Error re-assigning "
9770  "ownership of token (to server.)\n";
9771  delete pToken;
9772  pToken = nullptr;
9773  bSuccess = false;
9774  break;
9775  }
9776  else {
9777  otLog3 << "OT_API::notarizeDeposit: Success "
9778  "re-assigning ownership of token (to "
9779  "server.)\n";
9780 
9781  bSuccess = true;
9782 
9783  pToken->ReleaseSignatures();
9784  pToken->SignContract(*pNym);
9785  pToken->SaveContract();
9786 
9787  thePurse.Push(theServerNymAsOwner, *pToken);
9788 
9789  int64_t lTemp = pItem->GetAmount();
9790  pItem->SetAmount(lTemp += pToken->GetDenomination());
9791  }
9792  delete pToken;
9793  pToken = nullptr;
9794  }
9795  else {
9796  otErr << "Error loading token from purse.\n";
9797  break;
9798  }
9799  } // while
9800  }
9801  if (bSuccess) {
9802  int64_t lRequestNumber = 0;
9803  // Save the purse into a string...
9804  OTString strPurse;
9805  thePurse.SignContract(*pNym);
9806  thePurse.SaveContract();
9807  thePurse.SaveContractRaw(strPurse);
9808 
9809  // Add the purse string as the attachment on the transaction item.
9810  pItem->SetAttachment(
9811  strPurse); // The purse is contained in the reference string.
9812 
9813  // sign the item
9814  pItem->SignContract(*pNym);
9815  pItem->SaveContract();
9816 
9817  // the Transaction "owns" the item now and will handle cleaning it up.
9818  pTransaction->AddItem(*pItem); // the Transaction's destructor will
9819  // cleanup the item. It "owns" it now.
9820 
9821  // BALANCE AGREEMENT
9822  //
9823  // pBalanceItem is signed and saved within this call. No need to do that
9824  // again.
9825  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
9826  pItem->GetAmount(), *pTransaction, *pNym, *pAccount, *pOutbox);
9827 
9828  if (nullptr != pBalanceItem) // will never be nullptr. Will assert above
9829  // before it gets here.
9830  pTransaction->AddItem(*pBalanceItem); // Better not be nullptr...
9831  // message will fail... But
9832  // better check anyway.
9833 
9834  // sign the transaction
9835  pTransaction->SignContract(*pNym);
9836  pTransaction->SaveContract();
9837 
9838  // set up the ledger
9839  OTLedger theLedger(USER_ID, ACCT_ID, SERVER_ID);
9840  theLedger.GenerateLedger(ACCT_ID, SERVER_ID,
9841  OTLedger::message); // bGenerateLedger defaults
9842  // to false, which is
9843  // correct.
9844  theLedger.AddTransaction(*pTransaction); // now the ledger "owns" and
9845  // will handle cleaning up the
9846  // transaction.
9847 
9848  // sign the ledger
9849  theLedger.SignContract(*pNym);
9850  theLedger.SaveContract();
9851 
9852  // extract the ledger in ascii-armored form... encoding...
9853  OTString strLedger(theLedger);
9854  OTASCIIArmor ascLedger(strLedger);
9855 
9856  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
9857  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
9858  theMessage.m_strRequestNum.Format(
9859  "%ld", lRequestNumber); // Always have to send this.
9860  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
9861  // server request, I have
9862  // to increment it
9863 
9864  // (1) Set up member variables
9865  theMessage.m_strCommand = "notarizeTransactions";
9866  theMessage.m_strNymID = strNymID;
9867  theMessage.m_strServerID = strServerID;
9868  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
9869  // theMessage.m_strServerID is
9870  // already set. (It uses it.)
9871 
9872  theMessage.m_strAcctID = strFromAcct;
9873  theMessage.m_ascPayload = ascLedger;
9874 
9875  OTIdentifier NYMBOX_HASH;
9876  const std::string str_server(strServerID.Get());
9877  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
9878  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
9879 
9880  if (!bNymboxHash)
9881  otErr << "Failed getting NymboxHash from Nym for server: "
9882  << str_server << "\n";
9883 
9884  // (2) Sign the Message
9885  theMessage.SignContract(*pNym);
9886 
9887  // (3) Save the Message (with signatures and all, back to its internal
9888  // member m_strRawFile.)
9889  theMessage.SaveContract();
9890 
9891  // (Send it)
9892  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
9893  m_pTransportCallback);
9894  m_pClient->ProcessMessageOut(theMessage);
9895 
9896  return m_pClient->CalcReturnVal(lRequestNumber);
9897 
9898  } // bSuccess
9899  else {
9900  delete pItem;
9901  pItem = nullptr;
9902  delete pTransaction;
9903  pTransaction = nullptr;
9904 
9905  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
9906  pNym->AddTransactionNum(*pNym, strServerID, lStoredTransactionNumber,
9907  true); // bSave=true
9908  }
9909 
9910  return (-1);
9911 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerForMerge(const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bCanBePublic=false, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::notarizeTransfer ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_FROM,
const OTIdentifier ACCT_TO,
const int64_t &  AMOUNT,
const OTString NOTE 
) const

Definition at line 12302 of file OpenTransactions.cpp.

12308 {
12309  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12310  if (nullptr == pNym) return (-1);
12311  // By this point, pNym is a good pointer, and is on the wallet.
12312  // (No need to cleanup.)
12313  OTServerContract* pServer =
12314  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12315  if (nullptr == pServer) return (-1);
12316  // By this point, pServer is a good pointer. (No need to cleanup.)
12317  OTAccount* pAccount =
12318  GetOrLoadAccount(*pNym, ACCT_FROM, SERVER_ID, __FUNCTION__);
12319  if (nullptr == pAccount) return (-1);
12320  // By this point, pAccount is a good pointer. (No need to cleanup.)
12321  OTMessage theMessage;
12322 
12323  const int64_t lAmount = AMOUNT;
12324 
12325  OTString strServerID(SERVER_ID), strNymID(USER_ID), strFromAcct(ACCT_FROM),
12326  strToAcct(ACCT_TO);
12327 
12328  int64_t lStoredTransactionNumber = 0;
12329  bool bGotTransNum = pNym->GetNextTransactionNum(*pNym, strServerID,
12330  lStoredTransactionNumber);
12331 
12332  if (bGotTransNum) {
12333  // Create a transaction
12334  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
12335  USER_ID, ACCT_FROM, SERVER_ID, OTTransaction::transfer,
12336  lStoredTransactionNumber);
12337 
12338  // set up the transaction item (each transaction may have multiple
12339  // items...)
12340  OTItem* pItem = OTItem::CreateItemFromTransaction(
12341  *pTransaction, OTItem::transfer, &ACCT_TO);
12342  pItem->SetAmount(lAmount);
12343 
12344  // The user can include a note here for the recipient.
12345  if (NOTE.Exists() && NOTE.GetLength() > 2) {
12346  pItem->SetNote(NOTE);
12347  }
12348 
12349  // sign the item
12350  pItem->SignContract(*pNym);
12351  pItem->SaveContract();
12352 
12353  pTransaction->AddItem(*pItem); // the Transaction's destructor will
12354  // cleanup the item. It "owns" it now.
12355  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
12356  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
12357 
12358  if (nullptr == pInbox) {
12359  otOut << "OT_API::notarizeTransfer: Failed loading inbox for acct: "
12360  << strFromAcct << "\n";
12361  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
12362  // NUMBERS.
12363  pNym->AddTransactionNum(*pNym, strServerID,
12364  lStoredTransactionNumber,
12365  true); // bSave=true
12366  }
12367  else if (nullptr == pOutbox) {
12368  otOut << "OT_API::notarizeTransfer: Failed loading outbox "
12369  "for acct: " << strFromAcct << "\n";
12370  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
12371  // NUMBERS.
12372  pNym->AddTransactionNum(*pNym, strServerID,
12373  lStoredTransactionNumber,
12374  true); // bSave=true
12375  }
12376  else {
12377  int64_t lRequestNumber = 0;
12378  // Need to setup a dummy outbox transaction (to mimic the one that
12379  // will be on the server side when this pending transaction is
12380  // actually put into the real outbox.)
12381  // When the server adds its own, and then compares the two, they
12382  // should both show the same pending transaction, in order for this
12383  // balance agreement to be valid..
12384  // Otherwise the server would have to refuse it for being inaccurate
12385  // (server can't sign something inaccurate!) So I throw a dummy on
12386  // there before generating balance statement.
12387  //
12388  OTTransaction* pOutboxTransaction = OTTransaction::GenerateTransaction(
12389  *pOutbox, OTTransaction::pending,
12390  1 /*todo pick some number that everyone agrees doesn't matter, like 1. The referring-to is the important
12391  number in this case, and perhaps server should update this value too before signing and returning.*/); // todo use a constant instead of '1'
12392  OT_ASSERT(nullptr != pOutboxTransaction); // for now.
12393 
12394  OTString strItem(*pItem);
12395  pOutboxTransaction->SetReferenceString(
12396  strItem); // So the GenerateBalanceStatement function below can
12397  // get the other info off this item (like amount, etc)
12398  pOutboxTransaction->SetReferenceToNum(pItem->GetTransactionNum());
12399 
12400  // pOutboxTransaction->SignContract(*pNym); //
12401  // Unnecessary to sign/save, since this is just a dummy data for
12402  // verification purposes, and isn't being
12403  // pOutboxTransaction->SaveContract(); //
12404  // serialized anywhere. (I download the actual outbox from server,
12405  // and verify against last signed receipt.)
12406 
12407  pOutbox->AddTransaction(*pOutboxTransaction); // no need to cleanup
12408  // pOutboxTransaction
12409  // since pOutbox will
12410  // handle it now.
12411  // BALANCE AGREEMENT
12412 
12413  // pBalanceItem is signed and saved within this call. No need to do
12414  // that twice.
12415  //
12416  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
12417  lAmount * (-1), *pTransaction, *pNym, *pAccount, *pOutbox);
12418 
12419  if (nullptr !=
12420  pBalanceItem) // will never be nullptr. Will assert above
12421  // before it gets here.
12422  pTransaction->AddItem(
12423  *pBalanceItem); // Better not be nullptr...
12424  // message will fail...
12425  // But better check
12426  // anyway.
12427  // sign the transaction
12428  pTransaction->SignContract(*pNym);
12429  pTransaction->SaveContract();
12430 
12431  // set up the ledger
12432  OTLedger theLedger(USER_ID, ACCT_FROM, SERVER_ID);
12433  theLedger.GenerateLedger(ACCT_FROM, SERVER_ID,
12434  OTLedger::message); // bGenerateLedger
12435  // defaults to false,
12436  // which is correct.
12437  theLedger.AddTransaction(*pTransaction);
12438 
12439  // sign the ledger
12440  theLedger.SignContract(*pNym);
12441  theLedger.SaveContract();
12442 
12443  // extract the ledger in ascii-armored form
12444  OTString strLedger(theLedger);
12445  OTASCIIArmor ascLedger;
12446 
12447  // Encoding...
12448  ascLedger.SetString(strLedger);
12449  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12450  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12451  theMessage.m_strRequestNum.Format(
12452  "%ld", lRequestNumber); // Always have to send this.
12453  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it
12454  // for a server
12455  // request, I have to
12456  // increment it
12457 
12458  // (1) Set up member variables
12459  theMessage.m_strCommand = "notarizeTransactions";
12460  theMessage.m_strNymID = strNymID;
12461  theMessage.m_strServerID = strServerID;
12462  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12463  // theMessage.m_strServerID is
12464  // already set. (It uses it.)
12465 
12466  theMessage.m_strAcctID = strFromAcct;
12467  theMessage.m_ascPayload = ascLedger;
12468 
12469  OTIdentifier NYMBOX_HASH;
12470  const std::string str_server(strServerID.Get());
12471  const bool bNymboxHash =
12472  pNym->GetNymboxHash(str_server, NYMBOX_HASH);
12473  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12474 
12475  if (!bNymboxHash)
12476  otErr << "Failed getting NymboxHash from Nym for server: "
12477  << str_server << "\n";
12478 
12479  // (2) Sign the Message
12480  theMessage.SignContract(*pNym);
12481 
12482  // (3) Save the Message (with signatures and all, back to its
12483  // internal member m_strRawFile.)
12484  theMessage.SaveContract();
12485 
12486  // (Send it)
12487  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
12488  m_pTransportCallback);
12489  m_pClient->ProcessMessageOut(theMessage);
12490 
12491  return m_pClient->CalcReturnVal(lRequestNumber);
12492  }
12493  }
12494  else
12495  otOut << "No transaction numbers were available. Suggest "
12496  "requesting the server for one.\n";
12497 
12498  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
12499  // pNym->AddTransactionNum(*pNym, strServerID,
12500  // lStoredTransactionNumber, true); // bSave=true
12501  // Duh! No need to re-add a transaction num when the error is that there
12502  // weren't any transaction numbers...
12503 
12504  return -1;
12505 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::notarizeWithdrawal ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const int64_t &  AMOUNT 
) const

Definition at line 9392 of file OpenTransactions.cpp.

9396 {
9397  OTWallet* pWallet =
9398  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
9399  if (nullptr == pWallet) return (-1);
9400  OTPseudonym* pNym = GetOrLoadPrivateNym(
9401  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
9402  if (nullptr == pNym) return (-1);
9403  // By this point, pNym is a good pointer, and is on the wallet. (No need to
9404  // cleanup.)
9405  OTServerContract* pServer =
9406  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
9407  if (nullptr == pServer) return (-1);
9408  // By this point, pServer is a good pointer. (No need to cleanup.)
9409  OTAccount* pAccount =
9410  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
9411  if (nullptr == pAccount) return (-1);
9412  // By this point, pAccount is a good pointer, and is on the wallet. (No need
9413  // to cleanup.)
9414  OTIdentifier CONTRACT_ID;
9415  OTString strContractID, strServerID(SERVER_ID);
9416  CONTRACT_ID = pAccount->GetAssetTypeID();
9417  CONTRACT_ID.GetString(strContractID);
9418  if (!OTDB::Exists(OTFolders::Mint().Get(), strServerID.Get(),
9419  strContractID.Get())) {
9420  otErr << "OT_API::notarizeWithdrawal: File does not exist: "
9421  << OTFolders::Mint() << OTLog::PathSeparator() << strServerID
9422  << OTLog::PathSeparator() << strContractID << "\n";
9423  return -1;
9424  }
9425  std::unique_ptr<Mint> pMint(Mint::MintFactory(strServerID, strContractID));
9426  OT_ASSERT(nullptr != pMint);
9427  OTMessage theMessage;
9428 
9429  const int64_t lTotalAmount = AMOUNT;
9430  int64_t lAmount = lTotalAmount;
9431 
9432  OTString strNymID(USER_ID), strFromAcct(ACCT_ID);
9433 
9434  int64_t lStoredTransactionNumber = 0;
9435  bool bGotTransNum = false;
9436  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
9437  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
9438 
9439  if (nullptr == pInbox) {
9440  otOut << __FUNCTION__ << ": Error: Failed loading inbox!\n";
9441  return (-1);
9442  }
9443  if (nullptr == pOutbox) {
9444  otOut << __FUNCTION__ << ": Error: Failed loading outbox!\n";
9445  return (-1);
9446  }
9447 
9448  bGotTransNum = pNym->GetNextTransactionNum(*pNym, strServerID,
9449  lStoredTransactionNumber);
9450  if (!bGotTransNum) {
9451  otOut << __FUNCTION__ << ": Next Transaction Number Available: Suggest "
9452  "requesting the server for a new one.\n";
9453  return (-1);
9454  }
9455 
9456  // Create a transaction
9457  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
9458  USER_ID, ACCT_ID, SERVER_ID, OTTransaction::withdrawal,
9459  lStoredTransactionNumber);
9460 
9461  // set up the transaction item (each transaction may have multiple items...)
9462  OTItem* pItem =
9464  pItem->SetAmount(lTotalAmount);
9465 
9466  OTString strNote("Gimme cash!"); // TODO: Note is unnecessary for cash
9467  // withdrawal. Research uses / risks.
9468  pItem->SetNote(strNote);
9469  const OTPseudonym* pServerNym = pServer->GetContractPublicNym();
9470 
9471  const OTIdentifier SERVER_USER_ID(*pServerNym);
9472  if ((nullptr != pServerNym) && pMint->LoadMint() &&
9473  pMint->VerifyMint((OTPseudonym&)*pServerNym)) {
9474  int64_t lRequestNumber = 0;
9475  Purse* pPurse = new Purse(SERVER_ID, CONTRACT_ID, SERVER_USER_ID);
9476  Purse* pPurseMyCopy = new Purse(SERVER_ID, CONTRACT_ID, USER_ID);
9477 
9478  // Create all the necessary tokens for the withdrawal amount.
9479  // Push copies of each token into a purse to be sent to the server,
9480  // as well as a purse to be kept for unblinding when we receive the
9481  // server response. (Coin private unblinding keys are not sent to
9482  // the server, obviously.)
9483  int64_t lTokenAmount = 0;
9484  while ((lTokenAmount = pMint->GetLargestDenomination(lAmount)) > 0) {
9485  lAmount -= lTokenAmount;
9486 
9487  // Create the relevant token request with same server/asset ID as
9488  // the purse.
9489  // the purse does NOT own the token at this point. The token's
9490  // constructor
9491  // just uses it to copy some IDs, since they must match.
9492  //
9493  std::unique_ptr<Token> pToken(
9495  *pPurse, *pNym, *pMint, lTokenAmount));
9496  OT_ASSERT(nullptr != pToken);
9497 
9498  // Sign it and save it.
9499  pToken->SignContract(*pNym);
9500  pToken->SaveContract();
9501 
9502  // Now the proto-token is generated, let's add it to a purse
9503  // By pushing *pToken into pPurse with *pServerNym, I encrypt it to
9504  // pServerNym.
9505  // So now only the server Nym can decrypt that token and pop it out
9506  // of that purse.
9507  pPurse->Push(*pServerNym, *pToken);
9508 
9509  // I'm saving my own copy of all this, encrypted to my nym
9510  // instead of the server's, so I can get to my private coin data.
9511  // The server's copy of pToken is already Pushed, so I can re-use
9512  // the variable now for my own purse.
9513  pToken->ReleaseSignatures();
9514  pToken->SetSavePrivateKeys(); // This time it will save the private
9515  // keys when I sign it
9516  pToken->SignContract(*pNym);
9517  pToken->SaveContract();
9518 
9519  pPurseMyCopy->Push(*pNym, *pToken); // Now my copy of the purse has
9520  // a version of the token,
9521  }
9522  // Save the purse into a string...
9523  OTString strPurse;
9524  pPurse->SignContract(*pNym);
9525  pPurse->SaveContract();
9526  pPurse->SaveContractRaw(strPurse);
9527 
9528  // Add the purse string as the attachment on the transaction item.
9529  pItem->SetAttachment(
9530  strPurse); // The purse is contained in the reference string.
9531  pPurseMyCopy->SignContract(
9532  *pNym); // encrypted to me instead of the server, and including
9533  pPurseMyCopy->SaveContract(); // the private keys for unblinding the
9534  // server response.
9535  // This thing is neat and tidy. The wallet can just save it as an
9536  // ascii-armored string as a
9537  // purse field inside the wallet file. It doesn't do that for now
9538  // (TODO) but it easily could.
9539  // Add the purse to the wallet
9540  // (We will need it to look up the private coin info for unblinding the
9541  // token,
9542  // when the response comes from the server.)
9543  pWallet->AddPendingWithdrawal(*pPurseMyCopy);
9544 
9545  delete pPurse;
9546  pPurse = nullptr; // We're done with this one.
9547  pPurseMyCopy = nullptr; // The wallet owns my copy now and will handle
9548  // cleaning it up.
9549 
9550  // sign the item
9551  pItem->SignContract(*pNym);
9552  pItem->SaveContract();
9553 
9554  pTransaction->AddItem(*pItem); // the Transaction's destructor will
9555  // cleanup the item. It "owns" it now.
9556  // BALANCE AGREEMENT
9557 
9558  // pBalanceItem is signed and saved within this call. No need to do that
9559  // again.
9560  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
9561  lTotalAmount * (-1), *pTransaction, *pNym, *pAccount, *pOutbox);
9562 
9563  if (nullptr != pBalanceItem) // will never be nullptr. Will assert above
9564  // before it gets here.
9565  pTransaction->AddItem(*pBalanceItem); // Better not be nullptr...
9566  // message will fail... But
9567  // better check anyway.
9568 
9569  // sign the transaction
9570  pTransaction->SignContract(*pNym);
9571  pTransaction->SaveContract();
9572 
9573  // set up the ledger
9574  OTLedger theLedger(USER_ID, ACCT_ID, SERVER_ID);
9575  theLedger.GenerateLedger(ACCT_ID, SERVER_ID,
9576  OTLedger::message); // bGenerateLedger defaults
9577  // to false, which is
9578  // correct.
9579  theLedger.AddTransaction(*pTransaction);
9580 
9581  // sign the ledger
9582  theLedger.SignContract(*pNym);
9583  theLedger.SaveContract();
9584 
9585  // extract the ledger in ascii-armored form
9586  OTString strLedger(theLedger);
9587  OTASCIIArmor ascLedger; // I can't pass strLedger into this constructor
9588  // because I want to encode it
9589 
9590  // Encoding...
9591  ascLedger.SetString(strLedger);
9592  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
9593  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
9594  theMessage.m_strRequestNum.Format(
9595  "%ld", lRequestNumber); // Always have to send this.
9596  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
9597  // server request, I have
9598  // to increment it
9599 
9600  // (1) Set up member variables
9601  theMessage.m_strCommand = "notarizeTransactions";
9602  theMessage.m_strNymID = strNymID;
9603  theMessage.m_strServerID = strServerID;
9604  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
9605  // theMessage.m_strServerID is
9606  // already set. (It uses it.)
9607 
9608  theMessage.m_strAcctID = strFromAcct;
9609  theMessage.m_ascPayload = ascLedger;
9610 
9611  OTIdentifier NYMBOX_HASH;
9612  const std::string str_server(strServerID.Get());
9613  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
9614  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
9615 
9616  if (!bNymboxHash)
9617  otErr << "Failed getting NymboxHash from Nym for server: "
9618  << str_server << "\n";
9619 
9620  // (2) Sign the Message
9621  theMessage.SignContract(*pNym);
9622 
9623  // (3) Save the Message (with signatures and all, back to its internal
9624  // member m_strRawFile.)
9625  theMessage.SaveContract();
9626 
9627  // (Send it)
9628  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
9629  m_pTransportCallback);
9630  m_pClient->ProcessMessageOut(theMessage);
9631 
9632  return m_pClient->CalcReturnVal(lRequestNumber);
9633  }
9634  else {
9635  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
9636  pNym->AddTransactionNum(*pNym, strServerID, lStoredTransactionNumber,
9637  true); // bSave=true
9638  }
9639 
9640  return (-1);
9641 }
static EXPORT const OTString & Mint()
Definition: OTFolders.cpp:323
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
static EXPORT Mint * MintFactory()
Definition: Mint.cpp:154
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
static EXPORT Token * InstantiateAndGenerateTokenRequest(const Purse &thePurse, const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())
Definition: Token.cpp:1086
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
bool opentxs::OT_API::NumList_Add ( OTNumList theList,
const OTNumList theNewNumbers 
) const

Definition at line 3140 of file OpenTransactions.cpp.

3142 {
3143  OTNumList tempNewList(theList);
3144 
3145  const bool bSuccess = tempNewList.Add(theNewNumbers);
3146 
3147  if (bSuccess) {
3148  theList.Release();
3149  theList.Add(tempNewList);
3150  return true;
3151  }
3152  return false;
3153 }
int32_t opentxs::OT_API::NumList_Count ( const OTNumList theList) const

Definition at line 3199 of file OpenTransactions.cpp.

3200 {
3201  return theList.Count();
3202 }
bool opentxs::OT_API::NumList_Remove ( OTNumList theList,
const OTNumList theOldNumbers 
) const

Definition at line 3155 of file OpenTransactions.cpp.

3157 {
3158  OTNumList tempNewList(theList), tempOldList(theOldNumbers);
3159 
3160  while (tempOldList.Count() > 0) {
3161  int64_t lPeek = 0;
3162 
3163  if (!tempOldList.Peek(lPeek) || !tempOldList.Pop()) OT_FAIL;
3164 
3165  if (!tempNewList.Remove(lPeek)) return false;
3166  }
3167 
3168  theList.Release();
3169  theList.Add(tempNewList);
3170  return true;
3171 }
#define OT_FAIL
Definition: Assert.hpp:139
bool opentxs::OT_API::NumList_VerifyAll ( const OTNumList theList,
const OTNumList theQueryNumbers 
) const

Definition at line 3193 of file OpenTransactions.cpp.

3195 {
3196  return theList.Verify(theQueryNumbers);
3197 }
bool opentxs::OT_API::NumList_VerifyQuery ( const OTNumList theList,
const OTNumList theQueryNumbers 
) const

Definition at line 3175 of file OpenTransactions.cpp.

3177 {
3178  OTNumList theTempQuery(theQueryNumbers);
3179 
3180  while (theTempQuery.Count() > 0) {
3181  int64_t lPeek = 0;
3182 
3183  if (!theTempQuery.Peek(lPeek) || !theTempQuery.Pop()) OT_FAIL;
3184 
3185  if (!theList.Verify(lPeek)) return false;
3186  }
3187 
3188  return true;
3189 }
#define OT_FAIL
Definition: Assert.hpp:139
int32_t opentxs::OT_API::payDividend ( const OTIdentifier SERVER_ID,
const OTIdentifier ISSUER_USER_ID,
const OTIdentifier DIVIDEND_FROM_ACCT_ID,
const OTIdentifier SHARES_ASSET_TYPE_ID,
const OTString DIVIDEND_MEMO,
const int64_t &  AMOUNT_PER_SHARE 
) const

Definition at line 9917 of file OpenTransactions.cpp.

9934 {
9935  OTPseudonym* pNym =
9936  GetOrLoadPrivateNym(ISSUER_USER_ID, false,
9937  __FUNCTION__); // These copiously log, and ASSERT.
9938  if (nullptr == pNym) return (-1);
9939  // By this point, pNym is a good pointer, and is on the wallet. (No need to
9940  // cleanup.)
9941  OTServerContract* pServer =
9942  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
9943  if (nullptr == pServer) return (-1);
9944  // By this point, pServer is a good pointer. (No need to cleanup.)
9945  OTAccount* pDividendSourceAccount =
9946  GetOrLoadAccount(*pNym, DIVIDEND_FROM_ACCT_ID, SERVER_ID, __FUNCTION__);
9947  if (nullptr == pDividendSourceAccount) return (-1);
9948  // By this point, pDividendSourceAccount is a good pointer, and is on the
9949  // wallet. (No need to cleanup.)
9950  OTAssetContract* pSharesContract = GetAssetType(
9951  SHARES_ASSET_TYPE_ID, __FUNCTION__); // This ASSERTs and logs already.
9952  if (nullptr == pSharesContract) return (-1);
9953  // By this point, pSharesContract is a good pointer. (No need to cleanup.)
9954  OTWallet* pWallet =
9955  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
9956  if (nullptr == pWallet) return (-1);
9957  OTAccount* pSharesIssuerAcct =
9958  pWallet->GetIssuerAccount(SHARES_ASSET_TYPE_ID);
9959 
9960  if (nullptr == pSharesIssuerAcct) {
9961  otErr << __FUNCTION__
9962  << ": Failure: Unable to find issuer account for the "
9963  "shares asset type. Are you sure you're the issuer?\n";
9964  return (-1);
9965  }
9966  const OTIdentifier SHARES_ISSUER_ACCT_ID(*pSharesIssuerAcct);
9967  if (!pDividendSourceAccount->VerifyOwner(*pNym)) {
9968  otErr << __FUNCTION__
9969  << ": Failure: Nym doesn't verify as owner of the source "
9970  "account for the dividend payout.\n";
9971  return (-1);
9972  }
9973  if (!pSharesIssuerAcct->VerifyOwner(*pNym)) {
9974  otErr << __FUNCTION__
9975  << ": Failure: Nym doesn't verify as owner of issuer "
9976  "account for the shares (the shares we're paying the dividend "
9977  "on...)\n";
9978  return (-1);
9979  }
9980  OT_ASSERT_MSG(pSharesIssuerAcct->GetBalance() <= 0,
9981  "Assert (strange): issuer account should never have a "
9982  "higher-than-zero balance.\n");
9983 
9984  if (0 == pSharesIssuerAcct->GetBalance()) {
9985  otErr << __FUNCTION__
9986  << ": Failure: There are no shares issued for that asset type. "
9987  "(Therefore you cannot pay any dividend...)\n";
9988  return (-1);
9989  }
9990  const int64_t lAmountPerShare = AMOUNT_PER_SHARE;
9991 
9992  if (lAmountPerShare <= 0) {
9993  otErr << __FUNCTION__
9994  << ": Failure: The amount per share must be larger than zero.\n";
9995  return (-1);
9996  }
9997  // If there are 100,000 Pepsi shares, then the Pepsi issuer acct will have
9998  // -100,000 balance.
9999  // Therefore we multiply by -1, resulting in 100,000. Then we multiple that
10000  // by the amount to be
10001  // paid per share, let's say $5, resulting in a lTotalCostOfDividend of
10002  // $500,000 that must be
10003  // available in the dollar account (in order to successfully pay this
10004  // dividend.)
10005  //
10006  const int64_t lTotalCostOfDividend =
10007  ((-1) * pSharesIssuerAcct->GetBalance()) * lAmountPerShare;
10008  // Let's make sure we have enough money in the dividend source account, to
10009  // pay the total cost..
10010  //
10011  if (pDividendSourceAccount->GetBalance() < lTotalCostOfDividend) {
10012  otErr << __FUNCTION__ << ": Failure: There's not enough ("
10013  << pDividendSourceAccount->GetBalance()
10014  << ") in the source "
10015  "account, to cover the total cost of the dividend ("
10016  << lTotalCostOfDividend << ".)\n";
10017  return (-1);
10018  }
10019  OTMessage theMessage;
10020 
10021  OTString strServerID(SERVER_ID), strNymID(ISSUER_USER_ID),
10022  strFromAcct(DIVIDEND_FROM_ACCT_ID);
10023 
10024  int64_t lStoredTransactionNumber = 0;
10025  bool bGotTransNum = pNym->GetNextTransactionNum(*pNym, strServerID,
10026  lStoredTransactionNumber);
10027 
10028  if (bGotTransNum) {
10029  // Expiration (ignored by server -- it sets its own for its vouchers.)
10030  const time64_t VALID_FROM =
10031  OTTimeGetCurrentTime(); // This time is set to TODAY NOW
10032  const time64_t VALID_TO = OTTimeAddTimeInterval(
10033  VALID_FROM, OTTimeGetSecondsFromTime(
10034  OT_TIME_SIX_MONTHS_IN_SECONDS)); // 6 months.
10035  // The server only uses the amount and asset type from this cheque when
10036  // it
10037  // constructs the actual voucher (to the dividend payee.) And remember
10038  // there
10039  // might be a hundred shareholders, so the server would create a hundred
10040  // vouchers in that case.
10041  //
10042  OTCheque theRequestVoucher(
10043  SERVER_ID, SHARES_ASSET_TYPE_ID); // <====== Server needs this
10044  // (SHARES_ASSET_TYPE_ID)
10045 
10046  bool bIssueCheque = theRequestVoucher.IssueCheque(
10047  lAmountPerShare, // <====== Server needs this (lAmountPerShare.)
10048  lStoredTransactionNumber, // server actually ignores this and
10049  // supplies its own transaction number for
10050  // any vouchers.
10051  VALID_FROM, VALID_TO, SHARES_ISSUER_ACCT_ID, ISSUER_USER_ID,
10052  DIVIDEND_MEMO);
10053 
10054  /*
10055  NOTE: The above cheque isn't actually USED for anything, except as a
10056  vehicle to send additional
10057  data to the server. For example, the server will need to know the asset
10058  type ID for the shares.
10059  It gets that information from this voucher's asset type ID. It will
10060  also need to know the amount-
10061  per-share, which is also on this voucher, as its amount. The voucher
10062  code already does a similar
10063  thing, and this code already copied the voucher code since they were so
10064  similar, so we're just
10065  using the same mechanism here. It's consistent.
10066  On the server side, we'll also need to know the issuer account ID for
10067  the shares asset type, so
10068  we set that as the "from" account on the request voucher (again, just
10069  as a way of transmitting it.)
10070  */
10071  std::unique_ptr<OTLedger> pInbox(
10072  pDividendSourceAccount->LoadInbox(*pNym));
10073  std::unique_ptr<OTLedger> pOutbox(
10074  pDividendSourceAccount->LoadOutbox(*pNym));
10075 
10076  if (nullptr == pInbox) {
10077  otOut << __FUNCTION__ << ": Failed loading inbox for acct "
10078  << strFromAcct << "\n";
10079 
10080  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10081  // NUMBERS.
10082  pNym->AddTransactionNum(*pNym, strServerID,
10083  lStoredTransactionNumber,
10084  true); // bSave=true
10085  }
10086  else if (nullptr == pOutbox) {
10087  otOut << __FUNCTION__ << ": Failed loading outbox for acct "
10088  << strFromAcct << "\n";
10089 
10090  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10091  // NUMBERS.
10092  pNym->AddTransactionNum(*pNym, strServerID,
10093  lStoredTransactionNumber,
10094  true); // bSave=true
10095  }
10096  else if (!bIssueCheque) {
10097  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE
10098  // NUMBERS.
10099  pNym->AddTransactionNum(*pNym, strServerID,
10100  lStoredTransactionNumber,
10101  true); // bSave=true
10102  }
10103  else {
10104  // Create a transaction
10105  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
10106  ISSUER_USER_ID, DIVIDEND_FROM_ACCT_ID, SERVER_ID,
10107  OTTransaction::payDividend, lStoredTransactionNumber);
10108  // set up the transaction item (each transaction may have multiple
10109  // items...)
10110  OTItem* pItem = OTItem::CreateItemFromTransaction(
10111  *pTransaction, OTItem::payDividend);
10112  pItem->SetAmount(lTotalCostOfDividend); // <=== Notice, while the
10113  // CHEQUE is for
10114  // lAmountPerShare, the
10115  // item's AMOUNT is set to
10116  // lTotalCostOfDividend.
10117  OTString strNote("Pay Dividend: "); // The server just needs both of
10118  // those, so that's how we send
10119  // them (Similar to the voucher
10120  // code.)
10121  pItem->SetNote(strNote);
10122 
10123  // Add the voucher request string as the attachment on the
10124  // transaction item.
10125  theRequestVoucher.SignContract(*pNym);
10126  theRequestVoucher.SaveContract();
10127  OTString strVoucher(theRequestVoucher);
10128  pItem->SetAttachment(strVoucher); // The voucher request is
10129  // contained in the reference
10130  // string.
10131 
10132  // sign the item
10133  pItem->SignContract(*pNym);
10134  pItem->SaveContract();
10135 
10136  pTransaction->AddItem(*pItem); // the Transaction's destructor will
10137  // cleanup the item. It "owns" it
10138  // now.
10139  // BALANCE AGREEMENT
10140  //
10141  // The item is signed and saved within this call as well. No need to
10142  // do that again.
10143  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
10144  lTotalCostOfDividend * (-1), *pTransaction, *pNym,
10145  *pDividendSourceAccount, *pOutbox);
10146 
10147  // Notice the balance agreement is made for the "total cost of the
10148  // dividend", which we calculated as the issuer's
10149  // account balance, times -1, times the amount per share. So for
10150  // 100,000 shares of Pepsi, at a dividend payout of
10151  // $2 per share, then $200,000 must be removed from my dollar
10152  // account, in order to cover it. Therefore I sign a
10153  // balance agreement for $200,000. The server removes it all at
10154  // once, and then iterates through a loop, sending
10155  // vouchers to people. If any fail, or there is any left over, then
10156  // vouchers are sent back to pNym again, containing
10157  // the difference.
10158  // todo failsafe: We can't just loop, int64_t-term, and send a
10159  // voucher at the end. What if it crashes halfway through
10160  // the loop? It seems that the dividend payout still needs to be
10161  // "REGISTERED" somewhere until successfully completed.
10162  // (And therefore, that this concept must be repeated throughout OT
10163  // for other transactions, not just this example.)
10164  // This is already done with Cron, but just thinking about how to
10165  // best do it for "single action" transactions.
10166 
10167  if (nullptr != pBalanceItem)
10168  pTransaction->AddItem(
10169  *pBalanceItem); // Better not be nullptr...
10170  // message will fail...
10171  // But better check
10172  // anyway.
10173  // sign the transaction
10174  pTransaction->SignContract(*pNym);
10175  pTransaction->SaveContract();
10176 
10177  // set up the ledger
10178  OTLedger theLedger(ISSUER_USER_ID, DIVIDEND_FROM_ACCT_ID,
10179  SERVER_ID);
10180  theLedger.GenerateLedger(DIVIDEND_FROM_ACCT_ID, SERVER_ID,
10181  OTLedger::message); // bGenerateLedger
10182  // defaults to false,
10183  // which is correct.
10184  theLedger.AddTransaction(*pTransaction);
10185 
10186  // sign the ledger
10187  theLedger.SignContract(*pNym);
10188  theLedger.SaveContract();
10189 
10190  // extract the ledger in ascii-armored form
10191  OTString strLedger(theLedger);
10192  OTASCIIArmor ascLedger(strLedger);
10193 
10194  int64_t lRequestNumber = 0;
10195 
10196  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
10197  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
10198  theMessage.m_strRequestNum.Format(
10199  "%ld", lRequestNumber); // Always have to send this.
10200  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it
10201  // for a server
10202  // request, I have to
10203  // increment it
10204 
10205  // (1) Set up member variables
10206  theMessage.m_strCommand = "notarizeTransactions";
10207  theMessage.m_strNymID = strNymID;
10208  theMessage.m_strServerID = strServerID;
10209  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
10210  // theMessage.m_strServerID is
10211  // already set. (It uses it.)
10212 
10213  theMessage.m_strAcctID = strFromAcct;
10214  theMessage.m_ascPayload = ascLedger;
10215 
10216  OTIdentifier NYMBOX_HASH;
10217  const std::string str_server(strServerID.Get());
10218  const bool bNymboxHash =
10219  pNym->GetNymboxHash(str_server, NYMBOX_HASH);
10220  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10221 
10222  if (!bNymboxHash)
10223  otErr << __FUNCTION__
10224  << ": Failed getting NymboxHash from Nym for server: "
10225  << str_server << "\n";
10226 
10227  // (2) Sign the Message
10228  theMessage.SignContract(*pNym);
10229 
10230  // (3) Save the Message (with signatures and all, back to its
10231  // internal member m_strRawFile.)
10232  theMessage.SaveContract();
10233 
10234  // (Send it)
10235  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
10236  m_pTransportCallback);
10237  m_pClient->ProcessMessageOut(theMessage);
10238 
10239  return m_pClient->CalcReturnVal(lRequestNumber);
10240  }
10241  }
10242  else
10243  otOut << __FUNCTION__
10244  << ": No Transaction Numbers were available. "
10245  "Suggest requesting the server for a new one.\n";
10246 
10247  return (-1);
10248 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int64_t time64_t
Definition: Common.hpp:209
#define OT_TIME_SIX_MONTHS_IN_SECONDS
Definition: Common.hpp:170
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTMessage * opentxs::OT_API::PopMessageBuffer ( const int64_t &  lRequestNumber,
const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 8311 of file OpenTransactions.cpp.

8314 {
8315  OT_ASSERT_MSG((m_bInitialized && (m_pClient != nullptr)),
8316  "Not initialized; call OT_API::Init first.");
8317  OT_ASSERT_MSG(lRequestNumber > 0,
8318  "OT_API::PopMessageBuffer: lRequestNumber is less than 1.");
8319 
8320  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
8321 
8322  return m_pClient->GetMessageBuffer().Pop(lRequestNumber, strServerID,
8323  strNymID); // deletes
8324 }
EXPORT OTMessage * Pop(const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTMessageBuffer & GetMessageBuffer()
Definition: OTClient.hpp:359
int32_t opentxs::OT_API::processInbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const OTString ACCT_LEDGER 
) const

Definition at line 12771 of file OpenTransactions.cpp.

12775 {
12776  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12777  if (nullptr == pNym) return (-1);
12778  // By this point, pNym is a good pointer, and is on the wallet.
12779  // (No need to cleanup.)
12780  OTServerContract* pServer =
12781  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12782  if (nullptr == pServer) return (-1);
12783  // By this point, pServer is a good pointer. (No need to cleanup.)
12784  OTAccount* pAccount =
12785  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
12786  if (nullptr == pAccount) return (-1);
12787  // By this point, pAccount is a good pointer. (No need to cleanup.)
12788  OTMessage theMessage;
12789  int64_t lRequestNumber = 0;
12790 
12791  OTString strServerID(SERVER_ID), strNymID(USER_ID), strAcctID(ACCT_ID);
12792 
12793  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
12794  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
12795  theMessage.m_strRequestNum.Format(
12796  "%ld", lRequestNumber); // Always have to send this.
12797  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
12798  // server request, I have to
12799  // increment it
12800 
12801  // (1) set up member variables
12802  theMessage.m_strCommand = "processInbox";
12803  theMessage.m_strNymID = strNymID;
12804  theMessage.m_strServerID = strServerID;
12805  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
12806  // theMessage.m_strServerID is already
12807  // set. (It uses it.)
12808 
12809  theMessage.m_strAcctID = strAcctID;
12810 
12811  // Presumably ACCT_LEDGER was already set up before this function was
12812  // called...
12813  // See test client for example of it being done.
12814  theMessage.m_ascPayload.SetString(ACCT_LEDGER);
12815 
12816  OTIdentifier NYMBOX_HASH;
12817  const std::string str_server(strServerID.Get());
12818  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
12819  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12820 
12821  if (!bNymboxHash)
12822  otErr << "Failed getting NymboxHash from Nym for server: " << str_server
12823  << "\n";
12824 
12825  // (2) Sign the Message
12826  theMessage.SignContract(*pNym);
12827 
12828  // (3) Save the Message (with signatures and all, back to its internal
12829  // member m_strRawFile.)
12830  theMessage.SaveContract();
12831 
12832  // (Send it)
12833  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
12834  m_pClient->ProcessMessageOut(theMessage);
12835 
12836  return m_pClient->CalcReturnVal(lRequestNumber);
12837 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
int32_t opentxs::OT_API::processNymbox ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 12667 of file OpenTransactions.cpp.

12669 {
12670  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
12671  if (nullptr == pNym) return (-1);
12672  // By this point, pNym is a good pointer, and is on the wallet.
12673  // (No need to cleanup.)
12674  const OTString strNymID(USER_ID);
12675  OTServerContract* pServer =
12676  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
12677  if (nullptr == pServer) return (-1);
12678  // By this point, pServer is a good pointer. (No need to cleanup.)
12679  OTMessage theMessage;
12680  bool bSuccess = false;
12681  int32_t nReceiptCount = (-1);
12682  int32_t nRequestNum = (-1);
12683  bool bIsEmpty = true;
12684 
12685  {
12686  OTPseudonym& theNym = *pNym;
12687  OTServerContract& theServer = *pServer;
12688 
12689  // Load up the appropriate Nymbox...
12690  OTLedger theNymbox(USER_ID, USER_ID, SERVER_ID);
12691 
12692  bool bLoadedNymbox = theNymbox.LoadNymbox();
12693  bool bVerifiedNymbox =
12694  bLoadedNymbox ? theNymbox.VerifyAccount(theNym) : false;
12695 
12696  if (!bLoadedNymbox)
12697  otOut << "OT_API::processNymbox: Failed loading Nymbox: "
12698  << strNymID << " \n";
12699  else if (!bVerifiedNymbox)
12700  otOut << "OT_API::processNymbox: Failed verifying Nymbox: "
12701  << strNymID << " \n";
12702  else {
12703  nReceiptCount = theNymbox.GetTransactionCount();
12704  bIsEmpty = (nReceiptCount < 1);
12705 
12706  if (!bIsEmpty)
12707  bSuccess = m_pClient->AcceptEntireNymbox(
12708  theNymbox, SERVER_ID, theServer, theNym, theMessage);
12709 
12710  if (!bSuccess) {
12711  if (bIsEmpty) {
12712  otWarn << "OT_API::processNymbox: Nymbox (" << strNymID
12713  << ") is "
12714  "empty (so, skipping processNymbox.)\n";
12715  nRequestNum = 0;
12716  nReceiptCount = 0; // redundant.
12717  }
12718  else {
12719  otOut << "OT_API::processNymbox: Failed trying to "
12720  "accept the entire Nymbox. (And no, it's "
12721  "not empty.)\n";
12722  nReceiptCount = (-1);
12723  }
12724  }
12725  else // Success!
12726  {
12727  OTIdentifier NYMBOX_HASH;
12728  const OTString strServerID(SERVER_ID);
12729  const std::string str_server(strServerID.Get());
12730  const bool bNymboxHash =
12731  theNym.GetNymboxHash(str_server, NYMBOX_HASH);
12732  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12733 
12734  if (!bNymboxHash)
12735  otErr << "Failed getting NymboxHash from Nym for server: "
12736  << str_server << "\n";
12737 
12738  // (2) Sign the Message
12739  theMessage.SignContract(theNym);
12740 
12741  // (3) Save the Message (with signatures and all, back to its
12742  // internal member m_strRawFile.)
12743  theMessage.SaveContract();
12744  }
12745  }
12746  }
12747 
12748  if (bSuccess) {
12749  // Instead of the receipt count, in the case of success sending, we
12750  // return the
12751  // actual request number for the message that was sent.
12752  // (Otherwise 0 means Nymbox was empty, and -1 means there was an
12753  // error.)
12754  //
12755  nRequestNum = atoi(theMessage.m_strRequestNum.Get());
12756 
12757  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
12758  m_pTransportCallback);
12759  m_pClient->ProcessMessageOut(theMessage);
12760 
12761  return nRequestNum;
12762  }
12763  // if successful, ..., else if not successful--and wasn't empty--then error.
12764  else if (!bIsEmpty)
12765  otErr << "Error performing processNymbox command in "
12766  "OT_API::processNymbox\n";
12767 
12768  return nReceiptCount;
12769 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool AcceptEntireNymbox(OTLedger &theNymbox, const OTIdentifier &theServerID, const OTServerContract &theServerContract, OTPseudonym &theNym, OTMessage &theMessage)
Definition: OTClient.cpp:259
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
OTPaymentPlan * opentxs::OT_API::ProposePaymentPlan ( const OTIdentifier SERVER_ID,
const time64_t VALID_FROM,
const time64_t VALID_TO,
const OTIdentifier SENDER_ACCT_ID,
const OTIdentifier SENDER_USER_ID,
const OTString PLAN_CONSIDERATION,
const OTIdentifier RECIPIENT_ACCT_ID,
const OTIdentifier RECIPIENT_USER_ID,
const int64_t &  INITIAL_PAYMENT_AMOUNT,
const time64_t INITIAL_PAYMENT_DELAY,
const int64_t &  PAYMENT_PLAN_AMOUNT,
const time64_t PAYMENT_PLAN_DELAY,
const time64_t PAYMENT_PLAN_PERIOD,
time64_t  PAYMENT_PLAN_LENGTH = OT_TIME_ZERO,
int32_t  PAYMENT_PLAN_MAX_PAYMENTS = 0 
) const

Definition at line 4996 of file OpenTransactions.cpp.

5020 { // two arguments are optional.
5021  OTPseudonym* pNym = GetOrLoadPrivateNym(
5022  RECIPIENT_USER_ID, false, __FUNCTION__); // This logs, ASSERTs, etc.
5023  if (nullptr == pNym) return nullptr;
5024  // By this point, pNym is a good pointer, and is on the wallet. (No need to
5025  // cleanup.)
5026  OTAccount* pAccount =
5027  GetOrLoadAccount(*pNym, RECIPIENT_ACCT_ID, SERVER_ID, __FUNCTION__);
5028  if (nullptr == pAccount) return nullptr;
5029  // By this point, pAccount is a good pointer, and is on the wallet. (No need
5030  // to cleanup.)
5031  OTPaymentPlan* pPlan =
5032  new OTPaymentPlan(SERVER_ID, pAccount->GetAssetTypeID(), SENDER_ACCT_ID,
5033  SENDER_USER_ID, RECIPIENT_ACCT_ID, RECIPIENT_USER_ID);
5034  OT_ASSERT_MSG(nullptr != pPlan,
5035  "OT_API::ProposePaymentPlan: Error allocating "
5036  "memory in the OT API for new "
5037  "OTPaymentPlan.\n");
5038  // At this point, I know that pPlan is a good pointer that I either
5039  // have to delete, or return to the caller. CLEANUP WARNING!
5040  bool bSuccessSetProposal =
5041  pPlan->SetProposal(*pNym, PLAN_CONSIDERATION, VALID_FROM, VALID_TO);
5042  // WARNING!!!! SetProposal() burns TWO transaction numbers for RECIPIENT.
5043  // (*pNym)
5044  // BELOW THIS POINT, if you have an error, then you must retrieve those
5045  // numbers from
5046  // the plan, and set them BACK on pNym before you return!!!
5047  const OTString strServerID(SERVER_ID);
5048 
5049  if (!bSuccessSetProposal) {
5050  otOut << __FUNCTION__ << ": Failed trying to set the proposal.\n";
5051  pPlan->HarvestOpeningNumber(*pNym);
5052  pPlan->HarvestClosingNumbers(*pNym);
5053  delete pPlan;
5054  pPlan = nullptr;
5055  return nullptr;
5056  }
5057  bool bSuccessSetInitialPayment = true; // the default, in case user chooses
5058  // not to even have this payment.
5059  bool bSuccessSetPaymentPlan =
5060  true; // the default, in case user chooses not to have a payment plan
5061  if ((INITIAL_PAYMENT_AMOUNT > 0) &&
5062  (INITIAL_PAYMENT_DELAY >= OT_TIME_ZERO)) {
5063  // The Initial payment delay is measured in seconds, starting from the
5064  // "Creation Date".
5065  bSuccessSetInitialPayment = pPlan->SetInitialPayment(
5066  INITIAL_PAYMENT_AMOUNT, INITIAL_PAYMENT_DELAY);
5067  }
5068  if (!bSuccessSetInitialPayment) {
5069  otOut << __FUNCTION__
5070  << ": Failed trying to set the initial payment.\n";
5071  pPlan->HarvestOpeningNumber(*pNym);
5072  pPlan->HarvestClosingNumbers(*pNym);
5073  delete pPlan;
5074  pPlan = nullptr;
5075  return nullptr;
5076  }
5077  //
5078  // " 6 minutes == 360 Seconds\n"
5079  // "10 minutes == 600 Seconds\n"
5080  // "1 hour == 3600 Seconds\n"
5081  // "1 day == 86400 Seconds\n"
5082  // "30 days == 2592000 Seconds\n"
5083  // "3 months == 7776000 Seconds\n"
5084  // "6 months == 15552000 Seconds\n\n"
5085  //
5086  if (PAYMENT_PLAN_AMOUNT > 0) // If there are regular payments.
5087  {
5088  // The payment plan delay is measured in seconds, starting from the
5089  // "Creation Date".
5090  time64_t PAYMENT_DELAY =
5091  OT_TIME_MONTH_IN_SECONDS; // Defaults to 30 days, measured in
5092  // seconds (if you pass 0.)
5093 
5094  if (PAYMENT_PLAN_DELAY > OT_TIME_ZERO)
5095  PAYMENT_DELAY = PAYMENT_PLAN_DELAY;
5096  time64_t PAYMENT_PERIOD =
5097  OT_TIME_MONTH_IN_SECONDS; // Defaults to 30 days, measured in
5098  // seconds (if you pass 0.)
5099 
5100  if (PAYMENT_PLAN_PERIOD > OT_TIME_ZERO)
5101  PAYMENT_PERIOD = PAYMENT_PLAN_PERIOD;
5102  time64_t PLAN_LENGTH =
5103  OT_TIME_ZERO; // Defaults to 0 seconds (for no max length).
5104 
5105  if (PAYMENT_PLAN_LENGTH > OT_TIME_ZERO)
5106  PLAN_LENGTH = PAYMENT_PLAN_LENGTH;
5107  int32_t nMaxPayments =
5108  0; // Defaults to 0 maximum payments (for no maximum).
5109 
5110  if (PAYMENT_PLAN_MAX_PAYMENTS > 0)
5111  nMaxPayments = PAYMENT_PLAN_MAX_PAYMENTS;
5112  bSuccessSetPaymentPlan =
5113  pPlan->SetPaymentPlan(PAYMENT_PLAN_AMOUNT, PAYMENT_DELAY,
5114  PAYMENT_PERIOD, PLAN_LENGTH, nMaxPayments);
5115  }
5116  if (!bSuccessSetPaymentPlan) {
5117  otOut << __FUNCTION__ << ": Failed trying to set the payment plan.\n";
5118  pPlan->HarvestOpeningNumber(*pNym);
5119  pPlan->HarvestClosingNumbers(*pNym);
5120  delete pPlan;
5121  pPlan = nullptr;
5122  return nullptr;
5123  }
5124  pPlan->SignContract(*pNym); // Here we have saved the MERCHANT's VERSION.
5125  pPlan->SaveContract(); // A copy of this will be attached to the CUSTOMER's
5126  // version as well.
5127  //
5128  // DROP A COPY into the Outpayments box...
5129  //
5130  // (Since we used a transaction number to propose the plan, we
5131  // have to track it until it's deposited or until we cancel it.)
5132  //
5133  const OTString strInstrument(*pPlan);
5134  OTMessage* pMessage = new OTMessage;
5135  OT_ASSERT(nullptr != pMessage);
5136 
5137  const OTString strNymID(RECIPIENT_USER_ID), strNymID2(SENDER_USER_ID);
5138 
5139  pMessage->m_strCommand = "outpaymentsMessage";
5140  pMessage->m_strNymID = strNymID;
5141  pMessage->m_strNymID2 = strNymID2;
5142  pMessage->m_strServerID = strServerID;
5143  pMessage->m_ascPayload.SetString(strInstrument);
5144 
5145  pMessage->SignContract(*pNym);
5146  pMessage->SaveContract();
5147 
5148  pNym->AddOutpayments(*pMessage); // Now the Nym is responsible to delete it.
5149  // It's in his "outpayments".
5150  OTPseudonym* pSignerNym = pNym;
5151  pNym->SaveSignedNymfile(*pSignerNym);
5152  return pPlan;
5153 }
OTLOG_IMPORT OTLogStream otOut
#define OT_TIME_MONTH_IN_SECONDS
Definition: Common.hpp:174
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int64_t time64_t
Definition: Common.hpp:209
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
#define OT_TIME_ZERO
Definition: Common.hpp:180
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
Purse * opentxs::OT_API::Purse_Empty ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTString THE_PURSE,
const OTString pstrDisplay = nullptr 
) const

Definition at line 5825 of file OpenTransactions.cpp.

5829 {
5830  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5831  const OTString strReason((nullptr == pstrDisplay)
5832  ? "Making an empty copy of a cash purse."
5833  : pstrDisplay->Get());
5834  // OTPasswordData thePWData(strReason);
5835  Purse* pPurse = Purse::PurseFactory(THE_PURSE, SERVER_ID, ASSET_TYPE_ID);
5836 
5837  if (nullptr == pPurse) {
5838  otOut << __FUNCTION__
5839  << ": Error: THE_PURSE is an empty string. Please pass a "
5840  "real purse when calling this function.\n";
5841  return nullptr;
5842  }
5843  pPurse->ReleaseTokens();
5844  // NOTE: Caller must release/sign/save pReturnPurse, once this returns, in
5845  // order to effect the change.
5846  return pPurse;
5847 }
OTLOG_IMPORT OTLogStream otOut
static EXPORT Purse * PurseFactory(OTString strInput)
Definition: Purse.cpp:671
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
Token * opentxs::OT_API::Purse_Peek ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTString THE_PURSE,
const OTIdentifier pOWNER_ID = nullptr,
const OTString pstrDisplay = nullptr 
) const

Returns the TOKEN on top of the stock (LEAVING it on top of the stack, but giving you a decrypted copy of it.)

USER_ID can be nullptr, if the purse is password-protected. (It's just ignored in that case.) Otherwise MUST contain the NymID for the Purse owner (necessary to decrypt the token.)

CALLER must delete!!

returns nullptr if failure.

Definition at line 5669 of file OpenTransactions.cpp.

5681 {
5682  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5683  const OTString strReason1(
5684  (nullptr == pstrDisplay)
5685  ? "Enter your master passphrase for your wallet. (Purse_Peek)"
5686  : pstrDisplay->Get());
5687  const OTString strReason2(
5688  (nullptr == pstrDisplay)
5689  ? "Enter the passphrase for this purse. (Purse_Peek)"
5690  : pstrDisplay->Get());
5691  // OTPasswordData thePWData(strReason);
5692  Purse thePurse(SERVER_ID, ASSET_TYPE_ID);
5693  OTPassword thePassword; // Only used in the case of password-protected
5694  // purses.
5695  // What's going on here?
5696  // A purse can be encrypted by a private key (controlled by a Nym) or by a
5697  // symmetric
5698  // key (embedded inside the purse along with a corresponding master key.)
5699  // The below
5700  // function is what actually loads up thePurse from string (THE_PURSE) and
5701  // this call
5702  // also returns pOwner, which is a pointer to a special wrapper class (which
5703  // you must
5704  // delete, when you're done with it) which contains a pointer EITHER to the
5705  // owner Nym
5706  // for that purse, OR to the "owner" symmetric key for that purse.
5707  //
5708  // This way, any subsequent purse operations can use pOwner, regardless of
5709  // whether there
5710  // is actually a Nym inside, or a symmetric key. (None of the purse
5711  // operations will care,
5712  // since they can use pOwner either way.)
5713  //
5714  std::unique_ptr<OTNym_or_SymmetricKey> pOwner(LoadPurseAndOwnerFromString(
5715  SERVER_ID, ASSET_TYPE_ID, THE_PURSE, thePurse, thePassword,
5716  false, // bForEncrypting=true by default. (Peek needs to decrypt.)
5717  pOWNER_ID, &strReason1, &strReason2));
5718  if (nullptr == pOwner)
5719  return nullptr; // This already logs, no need for more logs.
5720  Token* pToken = nullptr;
5721 
5722  if (thePurse.IsEmpty())
5723  otOut << __FUNCTION__ << ": Failed attempt to peek; purse is empty.\n";
5724  else {
5725  pToken = thePurse.Peek(*pOwner);
5726 
5727  if (nullptr == pToken)
5728  otOut << __FUNCTION__
5729  << ": Failed peeking a token from a "
5730  "purse that supposedly had tokens on it...\n";
5731  }
5732  return pToken;
5733 }
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerFromString(const OTIdentifier &theServerID, const OTIdentifier &theAssetTypeID, const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bForEncrypting=true, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay1=nullptr, const OTString *pstrDisplay2=nullptr) const
Purse * opentxs::OT_API::Purse_Pop ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTString THE_PURSE,
const OTIdentifier pOWNER_ID = nullptr,
const OTString pstrDisplay = nullptr 
) const

Returns the PURSE after popping a single token off of it.

NOTE: Caller must delete! NOTE: Caller must sign/save in order to effect the change.

OWNER_ID can be nullptr, if the purse is password-protected. (It's just ignored in that case.) Otherwise MUST contain the NymID for the Purse owner (necessary to decrypt the token.)

The reason you don't see a signer being passed here (to save the purse again, after popping) is because OTAPI.cpp Purse_Pop does the saving. (That's the function that calls this one.) So IT has a signer ID passed in, in addition to the owner ID–but we don't need that here.)

returns nullptr if failure.

Definition at line 5751 of file OpenTransactions.cpp.

5763 {
5764  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5765  const OTString strReason1(
5766  (nullptr == pstrDisplay)
5767  ? "Enter your master passphrase for your wallet. (Purse_Pop)"
5768  : pstrDisplay->Get());
5769  const OTString strReason2(
5770  (nullptr == pstrDisplay)
5771  ? "Enter the passphrase for this purse. (Purse_Pop)"
5772  : pstrDisplay->Get());
5773  // OTPasswordData thePWData(strReason);
5774  std::unique_ptr<Purse> pPurse(new Purse(SERVER_ID, ASSET_TYPE_ID));
5775 
5776  OTPassword thePassword; // Only used in the case of password-protected
5777  // purses.
5778  // What's going on here?
5779  // A purse can be encrypted by a private key (controlled by a Nym) or by a
5780  // symmetric
5781  // key (embedded inside the purse along with a corresponding master key.)
5782  // The below
5783  // function is what actually loads up pPurse from string (THE_PURSE) and
5784  // this call
5785  // also returns pOwner, which is a pointer to a special wrapper class (which
5786  // you must
5787  // delete, when you're done with it) which contains a pointer EITHER to the
5788  // owner Nym
5789  // for that purse, OR to the "owner" symmetric key for that purse.
5790  //
5791  // This way, any subsequent purse operations can use pOwner, regardless of
5792  // whether there
5793  // is actually a Nym inside, or a symmetric key. (None of the purse
5794  // operations will care,
5795  // since they can use pOwner either way.)
5796  //
5797  std::unique_ptr<OTNym_or_SymmetricKey> pOwner(LoadPurseAndOwnerFromString(
5798  SERVER_ID, ASSET_TYPE_ID, THE_PURSE, *pPurse, thePassword,
5799  false, // bForEncrypting=true by default, but Pop needs to decrypt.
5800  pOWNER_ID, &strReason1, &strReason2));
5801  if (nullptr == pOwner)
5802  return nullptr; // This already logs, no need for more logs.
5803  Purse* pReturnPurse = nullptr;
5804 
5805  if (pPurse->IsEmpty())
5806  otOut << __FUNCTION__ << ": Failed attempt to pop; purse is empty.\n";
5807  else {
5808  std::unique_ptr<Token> pToken(pPurse->Pop(*pOwner));
5809 
5810  if (nullptr == pToken)
5811  otOut << __FUNCTION__
5812  << ": Failed popping a token from a "
5813  "purse that supposedly had tokens on it...\n";
5814  else {
5815  pReturnPurse = pPurse.release();
5816  }
5817  }
5818  return pReturnPurse;
5819 
5820  // NOTE: Caller must release/sign/save pReturnPurse, once this returns, in
5821  // order to effect the change.
5822 }
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerFromString(const OTIdentifier &theServerID, const OTIdentifier &theAssetTypeID, const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bForEncrypting=true, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay1=nullptr, const OTString *pstrDisplay2=nullptr) const
Purse * opentxs::OT_API::Purse_Push ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTString THE_PURSE,
const OTString THE_TOKEN,
const OTIdentifier pOWNER_ID = nullptr,
const OTString pstrDisplay = nullptr 
) const

Returns the PURSE after pushing a single token onto it.

NOTE: Caller must delete! NOTE: Caller must sign/save in order to effect the change.

USER_ID can be nullptr, if the purse is password-protected. (It's just ignored in that case.) Otherwise MUST contain the NymID for the Purse owner (necessary to encrypt the token.)

returns nullptr if failure.

Definition at line 5860 of file OpenTransactions.cpp.

5871 {
5872  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5873  const OTString strReason1(
5874  (nullptr == pstrDisplay)
5875  ? "Enter your master passphrase for your wallet. (Purse_Push)"
5876  : pstrDisplay->Get());
5877  const OTString strReason2(
5878  (nullptr == pstrDisplay)
5879  ? "Enter the passphrase for this purse. (Purse_Push)"
5880  : pstrDisplay->Get());
5881  // OTPasswordData thePWData(strReason);
5882  if (!THE_PURSE.Exists()) {
5883  otOut << __FUNCTION__ << ": Purse does not exist.\n";
5884  return nullptr;
5885  }
5886  else if (!THE_TOKEN.Exists()) {
5887  otOut << __FUNCTION__ << ": Token does not exist.\n";
5888  return nullptr;
5889  }
5890  OTString strToken(THE_TOKEN);
5891  std::unique_ptr<Token> pToken(
5892  Token::TokenFactory(strToken, SERVER_ID, ASSET_TYPE_ID));
5893 
5894  if (nullptr == pToken) // TokenFactory instantiates AND loads from string.
5895  {
5896  otOut << __FUNCTION__
5897  << ": Unable to instantiate or load token from string:\n\n"
5898  << THE_TOKEN << "\n\n";
5899  return nullptr;
5900  }
5901  std::unique_ptr<Purse> pPurse(new Purse(SERVER_ID, ASSET_TYPE_ID));
5902  OTPassword thePassword; // Only used in the case of password-protected
5903  // purses.
5904  // What's going on here?
5905  // A purse can be encrypted by a private key (controlled by a Nym) or by a
5906  // symmetric
5907  // key (embedded inside the purse along with a corresponding master key.)
5908  // The below
5909  // function is what actually loads up pPurse from string (THE_PURSE) and
5910  // this call
5911  // also returns pOwner, which is a pointer to a special wrapper class (which
5912  // you must
5913  // delete, when you're done with it) which contains a pointer EITHER to the
5914  // owner Nym
5915  // for that purse, OR to the "owner" symmetric key for that purse.
5916  //
5917  // This way, any subsequent purse operations can use pOwner, regardless of
5918  // whether there
5919  // is actually a Nym inside, or a symmetric key. (None of the purse
5920  // operations will care,
5921  // since they can use pOwner either way.)
5922  //
5923  std::unique_ptr<OTNym_or_SymmetricKey> pOwner(LoadPurseAndOwnerFromString(
5924  SERVER_ID, ASSET_TYPE_ID, THE_PURSE, *pPurse, thePassword,
5925  true, // bForEncrypting=true by default.
5926  pOWNER_ID, &strReason1, &strReason2));
5927  if (nullptr == pOwner)
5928  return nullptr; // This already logs, no need for more logs.
5929  Purse* pReturnPurse = nullptr;
5930 
5931  const bool bPushed = pPurse->Push(*pOwner, *pToken);
5932 
5933  if (!bPushed)
5934  otOut << __FUNCTION__ << ": Failed pushing a token onto a purse.\n";
5935  else {
5936  pReturnPurse = pPurse.release();
5937  }
5938  return pReturnPurse;
5939 
5940  // NOTE: Caller must release/sign/save pReturnPurse, once this returns, in
5941  // order to effect the change.
5942 }
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerFromString(const OTIdentifier &theServerID, const OTIdentifier &theAssetTypeID, const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bForEncrypting=true, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay1=nullptr, const OTString *pstrDisplay2=nullptr) const
static EXPORT Token * TokenFactory(OTString strInput)
Definition: Token.cpp:518
int32_t opentxs::OT_API::queryAssetTypes ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTASCIIArmor ENCODED_MAP 
) const

Definition at line 13071 of file OpenTransactions.cpp.

13074 {
13075  /*
13076  // Java code will create a StringMap object:
13077 
13078  String strEncodedObj(""); // output will go here.
13079  StringMap stringMap = null; // we are about to create this object
13080 
13081  Storable storable =
13082  otapi.CreateObject(StoredObjectType.STORED_OBJ_STRING_MAP);
13083 
13084  if (storable != null)
13085  {
13086  stringMap = StringMap.ot_dynamic_cast(storable);
13087  if (stringMap != null)
13088  {
13089  // ADD ALL THE ASSET IDs HERE (To the string map, so you
13090  // can ask the server about them...)
13091  //
13092  for_each(the asset IDs you want to query the server about)
13093  {
13094  stringMap.SetValue(ASSET_TYPE_ID, "exists");
13095  }
13096 
13097  strEncodedObj = otapi.EncodeObject(stringMap);
13098  }
13099  }
13100 
13101  if (null == strEncodedObj)
13102  Error;
13103  ----------------------------------------------------------------------
13104 
13105  Then send the server message:
13106 
13107  var theRequest := OTAPI_Func(ot_Msg.QUERY_ASSET_TYPES, SERVER_ID, NYM_ID,
13108  strEncodedObj);
13109  var strResponse = theRequest.SendRequest(theRequest,
13110  "QUERY_ASSET_TYPES");
13111 
13112  String strReplyMap = null;
13113 
13114  // When the server reply comes back, get the payload from it:
13115  //
13116  if (strResponse != null)
13117  strReplyMap = OT_API_Message_GetPayload(strReply);
13118  ----------------------------------------------------------------------
13119 
13120  // Pass the payload (the StringMap from the server's reply) to
13121  otapi.DecodeObject:
13122  //
13123  if (strReplyMap != null)
13124  {
13125  StringMap stringMap = null;
13126  Storable storable =
13127  otapi.DecodeObject(StoredObjectType.STORED_OBJ_STRING_MAP, strReplyMap);
13128  if (storable != null)
13129  {
13130  stringMap = StringMap.ot_dynamic_cast(storable);
13131  if (stringMap != null)
13132  {
13133  // Loop through string map. For each asset ID key, the value
13134  will
13135  // say either "true" or "false".
13136  //
13137  for_each(stringMap)
13138  {
13139  strValue = stringMap.GetValue(ASSET_TYPE_ID);
13140 
13141  if (strValue.compare("true") == 0)
13142  {
13143  // ... do something here ...
13144  }
13145  }
13146  }
13147  }
13148  }
13149 
13150  */
13151  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
13152  if (nullptr == pNym) return (-1);
13153  // By this point, pNym is a good pointer, and is on the wallet.
13154  // (No need to cleanup.)
13155  OTServerContract* pServer =
13156  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13157  if (nullptr == pServer) return (-1);
13158  // By this point, pServer is a good pointer. (No need to cleanup.)
13159  OTMessage theMessage;
13160  int64_t lRequestNumber = 0;
13161 
13162  OTString strServerID(SERVER_ID), strNymID(USER_ID);
13163 
13164  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13165  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13166  theMessage.m_strRequestNum.Format(
13167  "%ld", lRequestNumber); // Always have to send this.
13168  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13169  // server request, I have to
13170  // increment it
13171 
13172  // (1) set up member variables
13173  theMessage.m_strCommand = "queryAssetTypes";
13174  theMessage.m_strNymID = strNymID;
13175  theMessage.m_strServerID = strServerID;
13176  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13177  // theMessage.m_strServerID is already
13178  // set. (It uses it.)
13179 
13180  theMessage.m_ascPayload = ENCODED_MAP;
13181 
13182  // (2) Sign the Message
13183  theMessage.SignContract(*pNym);
13184 
13185  // (3) Save the Message (with signatures and all, back to its internal
13186  // member m_strRawFile.)
13187  theMessage.SaveContract();
13188 
13189  // (Send it)
13190  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13191  m_pClient->ProcessMessageOut(theMessage);
13192 
13193  return m_pClient->CalcReturnVal(lRequestNumber);
13194 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool opentxs::OT_API::RecordPayment ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
bool  bIsInbox,
int32_t  nIndex,
bool  bSaveCopy 
) const

Definition at line 7029 of file OpenTransactions.cpp.

7035 {
7036  OTPseudonym* pNym = GetOrLoadPrivateNym(USER_ID, false, __FUNCTION__);
7037  if (nullptr == pNym) return false;
7038  // By this point, pNym is a good pointer, and is on the wallet. (No need to
7039  // cleanup.)
7040  OTLedger* pRecordBox = nullptr;
7041  OTLedger* pExpiredBox = nullptr;
7042  OTLedger* pActualBox =
7043  nullptr; // This points to either pRecordBox or pExpiredBox.
7044  std::unique_ptr<OTLedger> theRecordBoxAngel;
7045  std::unique_ptr<OTLedger> theExpiredBoxAngel;
7046  if (bSaveCopy) {
7047  pRecordBox = LoadRecordBox(SERVER_ID, USER_ID, USER_ID);
7048  pExpiredBox = LoadExpiredBox(SERVER_ID, USER_ID);
7049  theRecordBoxAngel.reset(pRecordBox);
7050  theExpiredBoxAngel.reset(pExpiredBox);
7051  if (nullptr == pRecordBox) {
7052  pRecordBox = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
7053  OTLedger::recordBox, true);
7054  if (nullptr == pRecordBox) {
7055  otErr << __FUNCTION__
7056  << ": Unable to load or create record box "
7057  "(and thus unable to do anything with it.)\n";
7058  return false;
7059  }
7060  theRecordBoxAngel.reset(pRecordBox);
7061  }
7062  if (nullptr == pExpiredBox) {
7063  pExpiredBox = OTLedger::GenerateLedger(USER_ID, USER_ID, SERVER_ID,
7064  OTLedger::expiredBox, true);
7065  if (nullptr == pExpiredBox) {
7066  otErr << __FUNCTION__
7067  << ": Unable to load or create expired box"
7068  "(and thus unable to do anything with it.)\n";
7069  return false;
7070  }
7071  theExpiredBoxAngel.reset(pExpiredBox);
7072  }
7073  }
7074  pActualBox = pRecordBox;
7075  OTLedger* pPaymentInbox = nullptr;
7076  std::unique_ptr<OTLedger> thePaymentBoxAngel;
7077 
7078  bool bIsExpired = false;
7079 
7080  // first block:
7081  OTTransaction* pTransaction = nullptr;
7082  std::unique_ptr<OTTransaction> theTransactionAngel;
7083 
7084  // second block:
7085  std::unique_ptr<OTMessage> theMessageAngel;
7086 
7087  bool bRemoved = false, bNeedToSaveTheNym = false;
7088 
7089  if (bIsInbox) {
7090  pPaymentInbox = LoadPaymentInbox(SERVER_ID, USER_ID);
7091  thePaymentBoxAngel.reset(pPaymentInbox);
7092  if (nullptr == pPaymentInbox) {
7093  otErr << __FUNCTION__
7094  << ": Unable to load payment inbox "
7095  "(and thus unable to do anything with it.)\n";
7096  return false;
7097  }
7098  if ((nIndex < 0) || (nIndex >= pPaymentInbox->GetTransactionCount())) {
7099  otErr << __FUNCTION__
7100  << ": Unable to find transaction in payment inbox "
7101  "based on index " << nIndex << ". (Out of bounds.)\n";
7102  return false;
7103  }
7104  pTransaction = pPaymentInbox->GetTransactionByIndex(nIndex);
7105 
7106  if (nullptr == pTransaction) {
7107  otErr << __FUNCTION__
7108  << ": Unable to find transaction in payment inbox "
7109  "based on index " << nIndex << ".\n";
7110  return false;
7111  }
7112  std::unique_ptr<OTPayment> pPayment(
7113  GetInstrument(*pNym, nIndex, *pPaymentInbox));
7114 
7115  pPayment->IsExpired(bIsExpired);
7116 
7117  if (bIsExpired) pActualBox = pExpiredBox;
7118  // Remove it from the payments inbox...
7119  //
7120  const int64_t lTransactionNum = pTransaction->GetTransactionNum();
7121 
7122  if (!pPaymentInbox->DeleteBoxReceipt(lTransactionNum)) {
7123  otErr << __FUNCTION__
7124  << ": Failed trying to delete the box receipt for a "
7125  "transaction being removed from the payment inbox: "
7126  << lTransactionNum << "\n";
7127  }
7128  bRemoved = pPaymentInbox->RemoveTransaction(
7129  lTransactionNum, false); // bDeleteIt=true by default. We pass false
7130  // since we are moving it to another box.
7131  // Note that we still need to save
7132  // pPaymentInbox somewhere below, assuming
7133  // it's all successful.
7134  theTransactionAngel.reset(
7135  pTransaction); // If below we put pTransaction onto the Record Box,
7136  // then we have to set this to nullptr.
7137 
7138  // NOTE: pTransaction is still good, below this point, and will be
7139  // cleaned up automatically
7140  // whenever we exit this function.
7141 
7142  // Anything else?
7143  // Note: no need to harvest transaction number for incoming payments.
7144  // But for outgoing (see below) then harvesting becomes an issue.
7145 
7146  }
7147  else // Outpayments box (which is not stored in an OTLedger like payments
7148  // inbox, but rather, is stored similarly to outmail.)
7149  {
7150  //
7151  if ((nIndex < 0) || (nIndex >= pNym->GetOutpaymentsCount())) {
7152  otErr << __FUNCTION__
7153  << ": Unable to find payment in outpayment box based "
7154  "on index " << nIndex << ". (Out of bounds.)\n";
7155  return false;
7156  }
7157  OTMessage* pMessage = pNym->GetOutpaymentsByIndex(nIndex);
7158 
7159  if (nullptr == pMessage) {
7160  otErr << __FUNCTION__
7161  << ": Unable to find payment message in outpayment "
7162  "box based on index " << nIndex << ".\n";
7163  return false;
7164  }
7165  OTString strInstrument;
7166  if (!pMessage->m_ascPayload.GetString(strInstrument)) {
7167  otErr << __FUNCTION__
7168  << ": Unable to find payment instrument in outpayment "
7169  "message at index " << nIndex << ".\n";
7170  return false;
7171  }
7172  OTPayment thePayment(strInstrument);
7173 
7174  if (thePayment.IsValid() && thePayment.SetTempValues()) {
7175  // EXPIRED?
7176  //
7177  thePayment.IsExpired(bIsExpired);
7178 
7179  if (bIsExpired) pActualBox = pExpiredBox;
7180  // Anything but a purse?
7181  //
7182  int64_t lPaymentOpeningNum = 0;
7183  int64_t lPaymentTransNum = 0;
7184  if (thePayment.GetOpeningNum(lPaymentOpeningNum,
7185  USER_ID)) // cheques, invoices,
7186  // vouchers, smart contracts,
7187  // payment plans.
7188  {
7189  // We we-grab the transaction number at this time. That way if
7190  // it's a transaction num that
7191  // belongs to some other Nym (and is different than our own
7192  // opening number) then we will
7193  // get the different number here.
7194  //
7195  if (!thePayment.GetTransactionNum(lPaymentTransNum)) {
7196  otErr << __FUNCTION__
7197  << ": Should never happen! "
7198  "Failed to get transaction num from payment "
7199  "RIGHT AFTER succeeded getting opening "
7200  "num.\n";
7201  }
7202  // However, if it IS a different number, in the case of smart
7203  // contracts and payment plans,
7204  // we then change it BACK to the opening number again. Read the
7205  // next comment for details why.
7206  //
7207  bool bIsRecurring = false;
7208 
7209  if ((OTPayment::PAYMENT_PLAN == thePayment.GetType()) ||
7210  (OTPayment::SMART_CONTRACT == thePayment.GetType())) {
7211  bIsRecurring = true;
7212  lPaymentTransNum = lPaymentOpeningNum;
7213  // We do this because the ACTUAL transaction number on a
7214  // smart contract or payment plan
7215  // might be different that THIS Nym's opening number (it
7216  // might be some other Nym's opening
7217  // number.) But even if that's the case, we still want to
7218  // harvest THIS Nym's opening number,
7219  // not the other Nym's opening number. So for these
7220  // instruments, we set the "transaction number"
7221  // to be THIS Nym's opening number. (Versus just saying, "Oh
7222  // the trans number is for some other
7223  // Nym, so just ignore this" which would cause us to not
7224  // harvest the numbers for THIS Nym that
7225  // we probably SHOULD be harvesting.
7226  }
7227 
7228  // See what account the payment instrument is drawn from.
7229  // Is it mine?
7230  // If so, load up the inbox and see if there are any related
7231  // receipts inside.
7232  // If so, do NOT harvest the transaction numbers from the
7233  // instrument.
7234  // Otherwise, harvest them. (The instrument hasn't been redeemed
7235  // yet.)
7236  // Also, use the transaction number on the instrument to see if
7237  // it's signed out to me.
7238  //
7239  // Hmm: If the instrument is definitely expired, and there's
7240  // definitely nothing in the asset
7241  // accountinbox, then I can DEFINITELY harvest it back.
7242  //
7243  // But if the instrument is definitely NOT expired, and the
7244  // transaction # IS signed out to ME,
7245  // then I can't just harvest the numbers, since the original
7246  // recipient could still come through
7247  // and deposit that cheque. So in this case, I would HAVE to
7248  // cancel the transaction, and then
7249  // such cancellation would automatically harvest while
7250  // processing the successful server reply.
7251  //
7252  // Therefore make sure not to move the instrument here, unless
7253  // it's definitely expired.
7254  // Whereas if it's not expired, then the API must cancel it with
7255  // the server, and can't simply
7256  // come in here and move/harvest it. So this function can only
7257  // be for expired transactions or
7258  // those where the transaction number is no longer issued. (And
7259  // in cases where it's expired but
7260  // STILL issued, then it definitely DOES need to harvest.)
7261  //
7262 
7263  bool bShouldHarvestPayment = false;
7264  bool bNeedToLoadAssetAcctInbox = false;
7265  OTIdentifier theSenderUserID, theSenderAcctID;
7266 
7267  bool bPaymentSenderIsNym = false;
7268  bool bFromAcctIsAvailable = false;
7269  if (thePayment.IsVoucher()) {
7270  bPaymentSenderIsNym =
7271  (thePayment.GetRemitterUserID(theSenderUserID) &&
7272  pNym->CompareID(theSenderUserID));
7273  bFromAcctIsAvailable =
7274  thePayment.GetRemitterAcctID(theSenderAcctID);
7275  }
7276  else {
7277  bPaymentSenderIsNym =
7278  (thePayment.GetSenderUserID(theSenderUserID) &&
7279  pNym->CompareID(theSenderUserID));
7280  bFromAcctIsAvailable =
7281  thePayment.GetSenderAcctID(theSenderAcctID);
7282  }
7283  if (bPaymentSenderIsNym || // true for cheques as well as
7284  // vouchers. (We grab the remitter
7285  // above, for vouchers.)
7286  bIsRecurring) // false for cheques/vouchers; true for
7287  // payment plans and smart contracts.
7288  {
7289  // NOTE: With bPaymentSenderIsNym, we know pNym owns the
7290  // transaction number on the cheque.
7291  // NOTE: with bIsRecurring, we know pNym is one of the
7292  // parties of the smart contract.
7293  // (Since we found an opening number for pNym on it.)
7294 
7295  const OTString strServerID(SERVER_ID);
7296 
7297  // If the transaction # isn't signed out to me, then there's
7298  // no need to check the inbox
7299  // for any receipts, since those would have to have been
7300  // already closed out, in order for
7301  // the number not to be signed out to me anymore.
7302  //
7303  // Therefore let's check that first, before bothering to
7304  // load the inbox.
7305  //
7306  if (pNym->VerifyTentativeNum(
7307  strServerID, lPaymentTransNum)) // If I'm in the
7308  // middle of trying
7309  // to sign it out...
7310  {
7311  otErr << __FUNCTION__
7312  << ": Error: Why on earth is this "
7313  "transaction number (" << lPaymentTransNum
7314  << ") on an outgoing "
7315  "payment instrument, if it's still on my "
7316  "'Tentative' list? If I haven't even "
7317  "signed out that number, how did I send "
7318  "an instrument to someone else with that "
7319  "number on it?\n";
7320  return false;
7321  }
7322  bool bIsIssued =
7323  pNym->VerifyIssuedNum(strServerID, lPaymentTransNum);
7324 
7325  // If pNym is the sender AND the payment instrument IS
7326  // expired.
7327  //
7328  if (bIsExpired) {
7329  if (bIsIssued) // ...and if this number is still signed
7330  // out to pNym...
7331  {
7332  // If the instrument is definitely expired, and its
7333  // number is still issued to pNym, and
7334  // there's definitely no related chequeReceipts in
7335  // the asset acocunt inbox, then I
7336  // can DEFINITELY harvest it back. After all, it
7337  // hasn't been used, and since it's
7338  // expired, now it CAN'T be used. So might as well
7339  // harvest the number back, since we've
7340  // established that it's still signed out.
7341  //
7342  // You might ask, but what if there IS a
7343  // chequeReceipt in the asset account inbox? How
7344  // does that change things? The answer is, because
7345  // the transaction # might still be signed
7346  // out to me, even in a case where the payment
7347  // instrument is expired, but a chequeReceipt
7348  // still IS present! How so? Simple: I sent him the
7349  // cheque, he cashed it. It's in my outpayments
7350  // still, because his chequeReceipt is in my inbox
7351  // still, and hasn't been processed out.
7352  // Meanwhile I wait a few weeks, and then the
7353  // instrument, meanwhile, expires. It's already
7354  // been processed, so it doesn't matter that it's
7355  // expired. But nonetheless, according to the
7356  // dates affixed to it, it IS expired, and the
7357  // receipt IS present. So this is clearly a
7358  // realistic and legitimate case for our logic to
7359  // take into account. When this happens, we
7360  // should NOT harvest the transaction # back when
7361  // recording the payment, because that number
7362  // has been used already!
7363  //
7364  // That, in a nutshell, is why we have to load the
7365  // inbox and see if that receipt's there,
7366  // to MAKE SURE whether the instrument was
7367  // negotiated already, before it expired, even
7368  // though
7369  // I haven't accepted the receipt and closed out the
7370  // transaction # yet, because it impacts
7371  // our decision of whether or not to harvest back
7372  // the number.
7373  //
7374  // The below two statements are interpreted based on
7375  // this logic (see comment for each.)
7376  //
7377  bShouldHarvestPayment = true; // If NO
7378  // chequeReceipt/paymentReceipt/finalReceipt
7379  // in inbox, definitely SHOULD harvest
7380  // back the trans # (since the cheque's
7381  // expired and could never otherwise be
7382  // closed out)...
7383  bNeedToLoadAssetAcctInbox = true; // ...But if
7384  // chequeReceipt/paymentReceipt/finalReceipt
7385  // IS in inbox, definitely should NOT
7386  // harvest back the # (since it's already
7387  // been used.)
7388  //
7389  // =====> Therefore bNeedToLoadAssetAcctInbox is a
7390  // caveat, which OVERRIDES bShouldHarvestPayment.
7391  // <=====
7392  }
7393  else // pNym is sender, payment instrument IS expired,
7394  // and most importantly: the transaction # is no
7395  // longer signed out
7396  { // to pNym. Normally the closing of the # (by
7397  // accepting whatever its related receipt was)
7398  // should
7399  // have already
7400  // removed the outpayment, so we are cleared here to
7401  // go ahead and remove it.
7402  //
7403  bShouldHarvestPayment =
7404  false; // The # isn't signed out anymore, so we
7405  // don't want to harvest it (which would
7406  // cause the wallet to try and use it
7407  // again -- but we don't want that, since
7408  // we can't be using numnbers that aren't
7409  // even signed out to us!)
7410  bNeedToLoadAssetAcctInbox =
7411  false; // No need to check the inbox since the #
7412  // isn't even signed out anymore. Even if
7413  // some related receipt was in the inbox
7414  // (for some non-cheque instrument, say)
7415  // we'd still never need to harvest it
7416  // back for re-use, since it's not even
7417  // signed out to us anymore, and we can
7418  // only use numbers that are signed out
7419  // to us.
7420  }
7421  } // if bIsExpired.
7422  else // Not expired. pNym is the sender but the payment
7423  // instrument is NOT expired.
7424  {
7425  // Remember that the transaction number is still signed
7426  // out to me until I accept that
7427  // chequeReceipt. So whether the receipt is there or
7428  // not, the # will still be signed
7429  // out to me. But if there's no receipt yet in my inbox,
7430  // that means the cheque hasn't
7431  // been cashed yet. And THAT means I still have time to
7432  // cancel it. I can't just discard
7433  // the payment instrument, since its trans# would still
7434  // need to be harvested if it's not
7435  // being cancelled (so as to get it closed out on some
7436  // other instrument, presumably), but
7437  // I can't just harvest a number when there's some
7438  // instrument still floating around out
7439  // there, with that same number already on it! I HAVE to
7440  // cancel it.
7441  //
7442  // If I discard it without harvesting, and if the
7443  // recipient never cashes it, then that
7444  // transaction # will end up signed out to me FOREVER
7445  // (bad thing.) So I would have to
7446  // cancel it first, in order to discard it. The server's
7447  // success reply to my cancel
7448  // would be the proper time to discard the old
7449  // outpayment. Until I see that, how do I know
7450  // if I won't need it in the future, for harvesting
7451  // back?
7452  //
7453  if (bIsIssued) // If this number is still signed out to
7454  // pNym...
7455  {
7456  // If the instrument is definitely NOT expired, and
7457  // the transaction # definitely IS issued to ME,
7458  // then I can't just harvest the numbers, since the
7459  // original recipient could still come through
7460  // and deposit that cheque. So in this case, I
7461  // would HAVE to cancel the transaction first, and
7462  // then
7463  // such cancellation could sign a new transaction
7464  // statement with that # removed from my list of
7465  // "signed out" numbers. Only then am I safe from
7466  // the cheque being cashed by the recipient,
7467  // and only then could I even think about harvesting
7468  // the number back--that itself being unnecessary,
7469  // since the transaction # would then be
7470  // cancelled/closed and thus would eliminate any
7471  // need of
7472  // harvesting it (since now I will never use it.)
7473  //
7474  // Also, if I DON'T cancel it, then I don't want to
7475  // remove it from the outpayments box, because
7476  // it will be removed automatically whenever the
7477  // cheque is eventually cashed, and until/unless
7478  // that
7479  // happens, I need to keep it around for potential
7480  // harvesting or cancellation. Therefore I can't
7481  // discard the instrument either--I need to keep it
7482  // in the outpayments box for now, in case it's
7483  // needed later.
7484  //
7485  otOut << __FUNCTION__
7486  << ": This outpayment isn't expired "
7487  "yet, and the transaction number "
7488  "(" << lPaymentTransNum
7489  << ") is still signed out. "
7490  "(Skipping moving it to record box "
7491  "-- it will be moved automatically "
7492  "once you cancel the transaction "
7493  "or the recipient deposits it.)\n";
7494  return false;
7495  }
7496  else // The payment is NOT expired yet, but most
7497  // importantly, its transaction # is NOT signed
7498  // out to pNym anymore.
7499  { // Normally the closing of the # (by accepting
7500  // whatever its related receipt was) should have
7501  // already
7502  // removed the outpayment by now, so we are cleared
7503  // here to go ahead and remove it.
7504  //
7505  bShouldHarvestPayment =
7506  false; // The # isn't signed out anymore, so we
7507  // don't want to harvest it (which would
7508  // cause the wallet to try and use it
7509  // again.)
7510  bNeedToLoadAssetAcctInbox =
7511  false; // No need to check the inbox since the #
7512  // isn't even signed out anymore and
7513  // we're certainly not interested in
7514  // harvesting it if it's not even signed
7515  // out to us.
7516  }
7517  } // !bIsExpired
7518  } // sender is pNym
7519 
7520  // TODO: Add OPTIONAL field to Purse: "Remitter".
7521  // This way the sender has the OPTION to attach his ID "for the
7522  // record" even though
7523  // a cash transaction HAS NO "SENDER."
7524  //
7525  // This would make it convenient for a purse to, for example,
7526  // create a second copy
7527  // of the cash, encrypted to the remitter's public key. This is
7528  // important, since the
7529  // if the remitter has the cash in his outpayment's box, he will
7530  // want a way to recover
7531  // it if his friend returns and says, "I lost that USB key! Do
7532  // you still have that cash?!?"
7533  //
7534  // In fact we may want to use the field for that purpose,
7535  // WHETHER OR NOT the final sent
7536  // instrument actually includes the remitter's ID.
7537 
7538  // If the SenderUserID on this instrument isn't Nym's ID (as in
7539  // the case of vouchers),
7540  // or isn't even there (as in the case of cash) then why is it
7541  // in Nym's payment outbox?
7542  // Well, maybe the recipient of your voucher, lost it. You still
7543  // need to be able to
7544  // get another copy for him, or get it refunded (if you are
7545  // listed as the remitter...)
7546  // Therefore you keep it in your outpayments box "just in case."
7547  // In the case of cash,
7548  // the same could be true.
7549  //
7550  // In a way it doesn't matter, since eventually those
7551  // instruments will expire and then
7552  // they will be swept into the record box with everything else
7553  // (probably by this function.)
7554  //
7555  // But what if the instruments never expire? Say a voucher with
7556  // a very very int64_t expiration
7557  // date? It's still going to sit there, stuck in your
7558  // outpayments box, even though the
7559  // recipient have have cashed it int64_t, int64_t ago! The only
7560  // way to get rid of it is to have
7561  // the server send you a notice when it's cashed, which is only
7562  // possible if your ID is
7563  // listed as the remitter. (Otherwise the server wouldn't know
7564  // who to send the notice to.)
7565  //
7566  // Further, there's no PROVING whether the server sent you
7567  // notice for anything -- whether
7568  // you are listed as the remitter or not, the server could
7569  // choose to LIE and just NOT TELL
7570  // YOU that the voucher was cashed. How would you know the
7571  // difference? Thus "Notice" is
7572  // an important problem, peripheral to OT. Balances are safe
7573  // from any change without a
7574  // proper signed and authorized receipt--that is a powerful
7575  // strength of OT--but notice
7576  // cannot be proven.
7577  //
7578  // If the remitter has no way to prove that the recipient
7579  // actually deposited the cheque,
7580  // (even though most servers will of course provide this, they
7581  // cannot PROVE that they
7582  // provided it) then what good is the instrument to the
7583  // remitter? What good is such a
7584  // cashier's cheque? Well, the voucher is still in my
7585  // outpayments, so I can see the transaction
7586  // number on it, and then I should be able to query the server
7587  // and see which transaction
7588  // numbers are signed out to it. In which case a simple server
7589  // message (available to all
7590  // users) will return the numbers signed out to the server and
7591  // thus I can see whether or
7592  // not the number on the voucher is still valid. If it's not,
7593  // the server reply to that
7594  // message would be the appropriate place to move the outpayment
7595  // to the record box.
7596  //
7597  // What if we don't want to have these transaction numbers
7598  // signed out to the server at all?
7599  // Maybe we use numbers signed out to the users instead. Then
7600  // when the voucher is cashed,
7601  // instead of checking the server's list of issued transaction
7602  // numbers to see if the voucher
7603  // is valid, we would be checking the remitter's list instead.
7604  // And thus whenever the voucher
7605  // is cashed, we would have to drop a voucherReceipt in the
7606  // REMITTER's inbox (and nymbox)
7607  // so he would know to discard the transaction number.
7608  //
7609  // This would require adding the voucherReceipt, and would
7610  // restrict the use of vouchers to
7611  // those people who have an asset account (though that's
7612  // currently the only people who can
7613  // use them now anyway, since vouchers are withdrawn from
7614  // accounts) but it would eliminate
7615  // the need for the server nym to store all the transaction
7616  // numbers for all the open vouchers,
7617  // and it would also eliminate the problem of "no notice" for
7618  // the remitters of vouchers.
7619  // They'd be guaranteed, in fact, to get notice, since the
7620  // voucherReceipt is what removes
7621  // the transaction number from the user's list of signed-out
7622  // transaction numbers (and thus
7623  // prevents anyone from spending the voucher twice, which the
7624  // server wants to avoid at all
7625  // costs.) Thus if the server wants to avoid having a voucher
7626  // spent twice, then it needs to
7627  // get that transaction number off of my list of numbers, and it
7628  // can't do that without putting
7629  // a receipt in my inbox to justify the removal of the number.
7630  // Otherwise my receipt verifications
7631  // will start failing and I'll be unable to do any new
7632  // transactions, and then the server will
7633  // have to explain why it removed a transaction number from my
7634  // list, even though it still was
7635  // on my list during the last transaction statement, and even
7636  // though there's no new receipt in
7637  // my inbox to justify removing it.
7638  //
7639  // Conclusion, DONE: vouchers WITH a remitter acct, should store
7640  // the remitter's user AND acct IDs,
7641  // and should use a transaction # that's signed out to the
7642  // remitter (instead of the server) and
7643  // should drop a voucherReceipt in the remitter's asset account
7644  // inbox when they are cashed.
7645  // These vouchers are guaranteed to provide notice to the
7646  // remitter.
7647  //
7648  // Whereas vouchers WITHOUT a remitter acct should store the
7649  // remitter's user ID (or not), but should
7650  // NOT store the remitter's acct ID, and should use a
7651  // transaction # that's signed out to the server,
7652  // and should drop a notice in the Nymbox of the remitter IF his
7653  // user ID is available, but it should
7654  // be understood that such notice is a favor the server is
7655  // doing, and not something that's PROVABLE
7656  // as in the case of the vouchers in the above paragraph.
7657  //
7658  // This is similar to smart contracts, which can only be
7659  // activated by a party who has an
7660  // asset account, so he has somewhere to receive the
7661  // finalReceipt for that contract. (And thus
7662  // close out the transcation number he used to open it...)
7663  //
7664  // Perhaps we'll just offer both types of vouchers, and just let
7665  // users choose which they are willing
7666  // to pay for, and which trade-off is most palatable to them
7667  // (having to have an asset account to
7668  // get notice, or instead verifying the voucher's spent status
7669  // based on some publicly-available
7670  // listing of the transaction #'s currently signed out to the
7671  // server.)
7672  //
7673  // In the case of having transaction #'s signed out to the
7674  // server, perhaps the server's internal storage
7675  // of these should be paired each with the NymID of the owner
7676  // nym for that number, just so no one
7677  // would ever have any incentive to try and use one of those
7678  // numbers on some instrument somehow, and
7679  // also so that the server wouldn't necessarily have to post the
7680  // entire list of numbers, but just
7681  // rather give you the ones that are relevant to you (although
7682  // the entire list may have to be posted
7683  // in some public way in any case, for notice reasons.)
7684  //
7685  // By this point, you may be wondering, but what does all this
7686  // have to do with the function
7687  // we're in now? Well... in the below block, with a voucher,
7688  // pNym would NOT be the sender.
7689  // The voucher would still be drawn off a server account. But
7690  // nevertheless, pNym might still be
7691  // the owner of the transaction # for that voucher (assuming I
7692  // change OT around to use the above
7693  // system, which I will have to do if I want provable notice for
7694  // vouchers.) And if pNym is the
7695  // owner of that number, then he will want the option later of
7696  // refunding it or re-issuing it,
7697  // and he will have to possibly load up his inbox to make sure
7698  // there's no voucherReceipt in it,
7699  // etc. So for now, the vouchers will be handled by the below
7700  // code, but in the future, they might
7701  // be moved to the above code.
7702  //
7703  //
7704  else // pNym is not the sender.
7705  {
7706  // pNym isn't even the "sender" (although he is) but since
7707  // it's cash or voucher,
7708  // he's not waiting on any transaction number to close out
7709  // or be harvested.
7710  // (In the case of cash, in fact, we might as well just put
7711  // it straight in the records
7712  // and bypass the outpayments box entirely.) But this
7713  // function can sweep it into there
7714  // all in due time anyway, once it expires, so it seems
7715  // harmless to leave it there before
7716  // then. Plus, that way we always know which tokens are
7717  // still potentially exchangeable,
7718  // for cases where the recipient never cashed them.
7719  //
7720  if (bIsExpired) {
7721  // pNym is NOT the sender AND the payment instrument IS
7722  // expired.
7723  // Therefore, say in the case of sent vouchers and sent
7724  // cash, there
7725  // may have been some legitimate reason for keeping them
7726  // in outpayments
7727  // up until this point, but now that the instrument is
7728  // expired, might as
7729  // well get it out of the outpayments box and move it to
7730  // the record box.
7731  // Let the client software do its own historical
7732  // archiving.
7733  //
7734  bShouldHarvestPayment =
7735  false; // The # isn't signed out to pNym, so we
7736  // don't want to harvest it (which would
7737  // cause the wallet to try and use it even
7738  // though it's signed out to someone else --
7739  // bad.)
7740  bNeedToLoadAssetAcctInbox =
7741  false; // No need to check the inbox since the #
7742  // isn't even signed out to pNym and we're
7743  // certainly not interested in harvesting it
7744  // if it's not even signed out to us. (Thus
7745  // no reason to check the inbox.)
7746  }
7747  else // pNym is NOT the sender and the payment instrument
7748  // is NOT expired.
7749  {
7750  // For example, for a sent voucher that has not expired
7751  // yet.
7752  // Those we'll keep here for now, until some server
7753  // notice is
7754  // received, or the instrument expires. What if we need
7755  // to re-issue
7756  // the cheque to the recipient who lost it? Or what if
7757  // we want to
7758  // cancel it before he tries to cash it? Since it's not
7759  // expired yet,
7760  // it's wise to keep a copy in the outpayments box for
7761  // now.
7762  //
7763  otOut << __FUNCTION__
7764  << ": This outpayment isn't expired yet.\n";
7765  return false;
7766  }
7767  }
7768  //
7769  bool bFoundReceiptInInbox = false;
7770  OTSmartContract* pSmartContract = nullptr;
7771  OTPaymentPlan* pPlan = nullptr;
7772  //
7773  // In certain cases (logic above) it is determined that we have
7774  // to load the
7775  // asset account inbox and make sure there aren't any
7776  // chequeReceipts there,
7777  // before we go ahead and harvest any transaction numbers.
7778  //
7779  if (bNeedToLoadAssetAcctInbox &&
7780  (bFromAcctIsAvailable || bIsRecurring)) {
7781  bool bIsSmartContract = false;
7782  if (bIsRecurring) {
7783  std::unique_ptr<OTTrackable> pTrackable(
7784  thePayment.Instantiate());
7785  if (nullptr == pTrackable) {
7786  OTString strPaymentContents;
7787  thePayment.GetPaymentContents(strPaymentContents);
7788  otErr << __FUNCTION__
7789  << ": Failed instantiating OTPayment "
7790  "containing:\n" << strPaymentContents
7791  << "\n";
7792  return false;
7793  }
7794  pSmartContract =
7795  dynamic_cast<OTSmartContract*>(pTrackable.get());
7796  pPlan = dynamic_cast<OTPaymentPlan*>(pTrackable.get());
7797  if (nullptr != pSmartContract) {
7798  bIsSmartContract = true; // In this case we have to
7799  // loop through all the
7800  // accounts on the smart
7801  // contract...
7802  }
7803  else if (nullptr != pPlan) {
7804  // Payment plan is a funny case.
7805  // The merchant (RECIPIENT aka payee) creates the
7806  // payment plan, and then he SENDS
7807  // it to the customer (SENDER aka payer). From
7808  // there, the customer ACTIVATES it on
7809  // the server. BOTH could potentially have it in
7810  // their outpayments box. In one case.
7811  // the Nym is the "sender" and in another case, he's
7812  // the "recipient."
7813  // (So we need to figure out which, and set the
7814  // account accordingly.)
7815  //
7816  if (USER_ID == pPlan->GetRecipientUserID())
7817  theSenderAcctID = pPlan->GetRecipientAcctID();
7818  else if (USER_ID == pPlan->GetSenderUserID())
7819  theSenderAcctID = pPlan->GetSenderAcctID();
7820  else
7821  otErr << __FUNCTION__
7822  << ": ERROR: Should never happen: "
7823  "USER_ID didn't match this "
7824  "payment plan for sender OR "
7825  "recipient. "
7826  "(Expected one or the other.)\n";
7827  }
7828  }
7829  if (bIsSmartContract) // In this case we have to loop
7830  // through all the accounts on the
7831  // smart contract... We have to
7832  { // check the inbox on each, to make sure there aren't any
7833  // related paymentReceipts or final receipts.
7834  const int32_t nPartyCount =
7835  pSmartContract->GetPartyCount();
7836 
7837  for (int32_t nCurrentParty = 0;
7838  nCurrentParty < nPartyCount; ++nCurrentParty) {
7839  OTParty* pParty =
7840  pSmartContract->GetPartyByIndex(nCurrentParty);
7841  OT_ASSERT(nullptr != pParty);
7842  if (nullptr != pParty) {
7843  const int32_t nAcctCount =
7844  pParty->GetAccountCount();
7845 
7846  for (int32_t nCurrentAcct = 0;
7847  nCurrentAcct < nAcctCount;
7848  ++nCurrentAcct) {
7849  OTPartyAccount* pPartyAcct =
7850  pParty->GetAccountByIndex(nCurrentAcct);
7851  OT_ASSERT(nullptr != pPartyAcct);
7852  if (nullptr != pPartyAcct) {
7853  OTAgent* pAgent =
7854  pPartyAcct->GetAuthorizedAgent();
7855 
7856  // If pNym is a signer for pPartyAcct,
7857  // then we need to check pPartyAcct's
7858  // inbox
7859  // to make sure there aren't any
7860  // paymentReceipts or finalReceipts
7861  // lingering in there...
7862  //
7863  if (pAgent->IsValidSigner(*pNym)) {
7864  const OTString& strAcctID =
7865  pPartyAcct->GetAcctID();
7866  const OTIdentifier theAcctID(
7867  strAcctID);
7868 
7869  OTLedger theSenderInbox(
7870  USER_ID, theAcctID, SERVER_ID);
7871 
7872  const bool
7873  bSuccessLoadingSenderInbox =
7874  (theSenderInbox
7875  .LoadInbox() &&
7876  theSenderInbox
7877  .VerifyAccount(*pNym));
7878  if (bSuccessLoadingSenderInbox) {
7879  // Loop through the inbox and
7880  // see if there are any receipts
7881  // for lPaymentTransNum inside.
7882  //
7883  if (GetPaymentReceipt(
7884  theSenderInbox
7885  .GetTransactionMap(),
7886  lPaymentTransNum,
7887  nullptr) ||
7888  theSenderInbox
7889  .GetFinalReceipt(
7890  lPaymentTransNum)) {
7891  bFoundReceiptInInbox = true;
7892  break;
7893  }
7894  // else we didn't find a receipt
7895  // in the asset account inbox,
7896  // which means we are safe to
7897  // harvest.
7898  }
7899  // else unable to load inbox. Maybe
7900  // it's empty, never been used
7901  // before. i.e. it doesn't even
7902  // exist.
7903  } // pNym is valid signer for agent
7904  } // nullptr != pPartyAccount
7905  } // loop party accounts.
7906 
7907  if (bFoundReceiptInInbox) break;
7908  }
7909  } // loop parties
7910  } // smart contract
7911  else // not a smart contract. (It's a payment plan or a
7912  // cheque, most likely.)
7913  {
7914  OTLedger theSenderInbox(USER_ID, theSenderAcctID,
7915  SERVER_ID);
7916 
7917  const bool bSuccessLoadingSenderInbox =
7918  (theSenderInbox.LoadInbox() &&
7919  theSenderInbox.VerifyAccount(*pNym));
7920  if (bSuccessLoadingSenderInbox) {
7921  // Loop through the inbox and see if there are any
7922  // receipts for lPaymentTransNum inside.
7923  // Technically this would have to be a
7924  // chequeReceipt, or possibly a voucherReceipt if I
7925  // add
7926  // that (see giant comment above.)
7927  //
7928  // There are other instrument types but only a
7929  // cheque, at this point, would be in my outpayments
7930  // box AND could have a receipt in my asset account
7931  // inbox. So let's see if there's a chequeReceipt
7932  // in there that corresponds to lPaymentTransNum...
7933  //
7934  OTTransaction* pChequeReceipt =
7935  theSenderInbox.GetChequeReceipt(
7936  lPaymentTransNum); // cheque
7937 
7938  if (nullptr != pChequeReceipt) {
7939  bFoundReceiptInInbox = true;
7940  }
7941  // No cheque receipt? Ok let's see if there's a
7942  // paymentReceipt or finalReceipt (for a payment
7943  // plan...)
7944  else if (GetPaymentReceipt(
7945  theSenderInbox.GetTransactionMap(),
7946  lPaymentTransNum, nullptr) ||
7947  theSenderInbox.GetFinalReceipt(
7948  lPaymentTransNum)) // payment plan.
7949  {
7950  bFoundReceiptInInbox = true;
7951  }
7952  // else we didn't find a receipt in the asset
7953  // account inbox, which means we are safe to
7954  // harvest.
7955  }
7956  // else unable to load inbox. Maybe it's empty, never
7957  // been used before. i.e. it doesn't even exist.
7958  } // not a smart contract
7959  } // if (bNeedToLoadAssetAcctInbox && (bFromAcctIsAvailable ||
7960  // bIsRecurring))
7961  // If we should harvest the transaction numbers,
7962  // AND if we don't need to double-check that against the asset
7963  // inbox to make sure the receipt's not there,
7964  // (or if we do, that it was a successful double-check and the
7965  // receipt indeed is not there.)
7966  //
7967  if (bShouldHarvestPayment &&
7968  ((!bNeedToLoadAssetAcctInbox) ||
7969  (bNeedToLoadAssetAcctInbox && !bFoundReceiptInInbox))) {
7970  // Harvest the transaction number(s).
7971  //
7972  if (nullptr != pSmartContract) {
7973  pSmartContract->HarvestOpeningNumber(*pNym);
7974  pSmartContract->HarvestClosingNumbers(*pNym);
7975  }
7976  else if (nullptr != pPlan) {
7977  pPlan->HarvestOpeningNumber(*pNym);
7978  pPlan->HarvestClosingNumbers(*pNym);
7979  }
7980  else {
7981  pNym->ClawbackTransactionNumber(
7982  SERVER_ID, lPaymentTransNum, false); // bSave=false
7983  }
7984 
7985  bNeedToSaveTheNym = true;
7986 
7987  // Note, food for thought: IF the receipt had popped into
7988  // your asset inbox on the server
7989  // side, since the last time you downloaded your inbox, then
7990  // you could be making the wrong
7991  // decision here, and harvesting a number that's already
7992  // spent. (You just didn't know it yet.)
7993  //
7994  // What happens in that case, when I download the inbox
7995  // again? A new receipt is there, and a
7996  // transaction # is used, which I thought was still
7997  // available for use? (Since I harvested it?)
7998  // The appearance of the receipt in the inbox, as long as
7999  // properly formed and signed by me,
8000  // should be enough information for the client side to
8001  // adjust its records, because if it
8002  // doesn't anticipate this possibility, then it will be
8003  // forced to resync entirely, which I want
8004  // to avoid in all cases period.
8005  //
8006  // In this block, we clawed back the number because if
8007  // there's no chequeReceipt in the inbox,
8008  // then that means the cheque has never been used, since if
8009  // I had closed the chequeReceipt out
8010  // already, then the transaction number on that cheque would
8011  // already have been closed out at
8012  // that time.
8013  // We only clawback for expired instruments, where the
8014  // transaction # is still outstanding
8015  // and where no receipt is present in the asset acct inbox.
8016  // If the instrument is not expired,
8017  // then you must cancel it properly. And if the cheque
8018  // receipt is in the inbox, then you must
8019  // close it properly.
8020  }
8021  } // if (thePayment.GetTransactionNum(lPaymentTransNum))
8022  else if (bSaveCopy && (nullptr != pActualBox) &&
8023  thePayment.IsPurse()) {
8024  OT_ASSERT(nullptr != pActualBox);
8025 
8026  // A purse has no transaction number on itself, and if it's in
8027  // the outpayment box,
8028  // it has no transaction number from its ledger, either! It's
8029  // numberless. So what
8030  // we do for now is, we use the expiration timestamp for the
8031  // purse to create its
8032  // "transaction number" (we also add a billion to it, and then
8033  // increment it until
8034  // we are sure it's unused in the box already) for the new
8035  // receipt we're inserting
8036  // for this purse into the record box. (Otherwise we'd have to
8037  // skip this part and
8038  // we wouldn't save a record of the purse at all.)
8039  //
8040  // ALSO NOTE that people shouldn't really be discarding the
8041  // purse anyway from the outpayment
8042  // box, since it will ALREADY disappear once it expires.
8043  // (Presumably you'd want the option to
8044  // recover it, at any time prior to that point...) But we still
8045  // must consider that people sent
8046  // cash and they just want it erased, so...
8047  //
8048  time64_t tValidTo = OT_TIME_ZERO;
8049 
8050  if (thePayment.GetValidTo(tValidTo)) {
8051  lPaymentTransNum = OTTimeGetSecondsFromTime(tValidTo) +
8052  1000000000; // todo hardcoded. (But
8053  // should be harmless since
8054  // this is record box.)
8055 
8056  // Since we're using a made-up transaction number here,
8057  // let's
8058  // make sure it's not already being used. If it is, we'll
8059  // increment it until nothing is found.
8060  //
8061  while (nullptr !=
8062  pActualBox->GetTransaction(lPaymentTransNum))
8063  ++lPaymentTransNum;
8064  }
8065  else
8066  otErr << __FUNCTION__
8067  << ": Failed trying to get 'valid to' from purse.\n";
8068  }
8069  // Create the notice to put in the Record Box.
8070  //
8071  if (bSaveCopy && (nullptr != pActualBox) &&
8072  (lPaymentTransNum > 0)) {
8073  OT_ASSERT(nullptr != pActualBox);
8074 
8075  OTTransaction* pNewTransaction =
8077  *pActualBox, OTTransaction::notice, lPaymentTransNum);
8078 
8079  if (nullptr != pNewTransaction) // The above has an OT_ASSERT
8080  // within, but I just like to check
8081  // my pointers.
8082  {
8083  pNewTransaction->SetReferenceToNum(
8084  lPaymentTransNum); // referencing myself here. We'll see
8085  // how it works out.
8086  pNewTransaction->SetReferenceString(
8087  strInstrument); // the cheque, invoice, etc that used to
8088  // be in the outpayments box.
8089 
8090  pNewTransaction->SignContract(*pNym);
8091  pNewTransaction->SaveContract();
8092  pTransaction = pNewTransaction;
8093 
8094  theTransactionAngel.reset(pTransaction);
8095  }
8096  else // should never happen
8097  {
8098  const OTString strUserID(USER_ID);
8099  otErr << __FUNCTION__
8100  << ": Failed while trying to generate "
8101  "transaction in order to "
8102  "add a new transaction (for a payment "
8103  "instrument from the outpayments box) "
8104  "to Record Box: " << strUserID << "\n";
8105  }
8106  }
8107  } // if (thePayment.IsValid() && thePayment.SetTempValues())
8108  //
8109  // Now we actually remove the message from the outpayments...
8110  //
8111  bRemoved = pNym->RemoveOutpaymentsByIndex(
8112  nIndex, false); // bDeleteIt=true by default
8113  theMessageAngel.reset(
8114  pMessage); // Since we chose to keep pMessage alive after removing
8115  // it from the outpayments, we set the angel here to make
8116  // sure it gets cleaned up later whenever we return out
8117  // of this godforsaken function.
8118 
8119  // Anything else?
8120  } // outpayments box.
8121  //
8122  // Okay by this point, whether the payment was in the payments inbox, or
8123  // whether it was in the outpayments box, either way, it has now been
8124  // removed
8125  // from that box. (Otherwise we would have returned already by this point.)
8126  //
8127  // It's still safer to explicitly check bRemoved, just in case.
8128  //
8129  if (bRemoved) {
8130  if (bSaveCopy && (nullptr != pActualBox) && (nullptr != pTransaction)) {
8131  OT_ASSERT(nullptr != pActualBox);
8132 
8133  const bool bAdded = pActualBox->AddTransaction(*pTransaction);
8134 
8135  if (!bAdded) {
8136  otErr << __FUNCTION__ << ": Unable to add transaction "
8137  << pTransaction->GetTransactionNum()
8138  << " to record box (after "
8139  "tentatively removing from payment "
8140  << (bIsInbox ? "inbox" : "outbox")
8141  << ", an action that is now canceled.)\n";
8142  return false;
8143  }
8144  else {
8145  // If successfully added to the record box, then no need
8146  // anymore to clean it up ourselves.
8147  theTransactionAngel.release();
8148  }
8149 
8150  pActualBox->ReleaseSignatures();
8151  pActualBox->SignContract(*pNym);
8152  pActualBox->SaveContract();
8153  if (bIsExpired)
8154  pActualBox->SaveExpiredBox(); // todo log failure.
8155  else
8156  pActualBox->SaveRecordBox(); // todo log failure.
8157 
8158  // Any inbox/nymbox/outbox ledger will only itself contain
8159  // abbreviated versions of the receipts, including their hashes.
8160  //
8161  // The rest is stored separately, in the box receipt, which is
8162  // created
8163  // whenever a receipt is added to a box, and deleted after a receipt
8164  // is removed from a box.
8165  //
8166  pTransaction->SaveBoxReceipt(*pActualBox); // todo: log failure
8167  }
8168  if (bIsInbox) {
8169  pPaymentInbox->ReleaseSignatures();
8170  pPaymentInbox->SignContract(*pNym);
8171  pPaymentInbox->SaveContract();
8172  const bool bSavedInbox =
8173  pPaymentInbox->SavePaymentInbox(); // todo: log failure
8174  if (!bSavedInbox)
8175  otOut << "/n" << __FUNCTION__
8176  << ": Unable to Save PaymentInbox./n";
8177  }
8178  else // outbox
8179  {
8180  // Outpayments are currently stored in the Nymfile.
8181  //
8182  bNeedToSaveTheNym = true;
8183  }
8184  if (bNeedToSaveTheNym) {
8185  pNym->SaveSignedNymfile(*pNym);
8186  }
8187  }
8188  else {
8189  otErr << __FUNCTION__ << ": Unable to remove from payment "
8190  << (bIsInbox ? "inbox" : "outbox") << " based on index " << nIndex
8191  << ".\n";
8192  return false;
8193  }
8194  //
8195  return true;
8196 }
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
EXPORT OTLedger * LoadRecordBox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTLedger * LoadPaymentInbox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int64_t time64_t
Definition: Common.hpp:209
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTPayment * GetInstrument(const OTPseudonym &theNym, const int32_t &nIndex, OTLedger &ledger)
Definition: Helpers.cpp:149
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
Definition: OTLedger.cpp:946
OTLOG_IMPORT OTLogStream otErr
EXPORT OTLedger * LoadExpiredBox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID) const
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
bool opentxs::OT_API::RemoveSentMessage ( const int64_t &  lRequestNumber,
const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID 
) const

Definition at line 8363 of file OpenTransactions.cpp.

8366 {
8367  OT_ASSERT_MSG(m_bInitialized && (m_pClient != nullptr),
8368  "Not initialized; call OT_API::Init first.");
8369  OT_ASSERT_MSG(lRequestNumber > 0,
8370  "OT_API::RemoveSentMessage: lRequestNumber is less than 1.");
8371 
8372  const OTString strServerID(SERVER_ID), strNymID(USER_ID);
8373 
8374  return m_pClient->GetMessageOutbuffer().RemoveSentMessage(
8375  lRequestNumber, strServerID, strNymID); // deletes.
8376 }
EXPORT bool RemoveSentMessage(const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
OTMessageOutbuffer & GetMessageOutbuffer()
Definition: OTClient.hpp:363
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
bool opentxs::OT_API::ResyncNymWithServer ( OTPseudonym theNym,
const OTLedger theNymbox,
const OTPseudonym theMessageNym 
) const

Definition at line 8274 of file OpenTransactions.cpp.

8276 {
8277  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
8278  if (OTLedger::nymbox != theNymbox.GetType()) {
8279  otErr << "OT_API::ResyncNymWithServer: Error: Expected a Nymbox, "
8280  "but you passed in a " << theNymbox.GetTypeString() << ".\n";
8281  return false;
8282  }
8283  if (!theNym.CompareID(theNymbox.GetUserID())) {
8284  const OTString id1(theNym.GetConstID()), id2(theNymbox.GetUserID());
8285  otErr << "OT_API::ResyncNymWithServer: Error: NymID of Nym (" << id1
8286  << ") "
8287  "doesn't match NymID on (supposedly) his own Nymbox "
8288  "(" << id2 << ").\n";
8289  return false;
8290  }
8291  // if (!theNym.CompareID(theMessageNym))
8292  // {
8293  // const OTString id1(theNym.GetConstID()),
8294  // id2(theMessageNym.GetConstID());
8295  // otErr << "OT_API::ResyncNymWithServer: Error: NymID of Nym
8296  // (" << id1 << ") doesn't match NymID on (supposedly) his server-side
8297  // doppelganger
8298  // (" << id2 << ").\n";
8299  // return false;
8300  // }
8301 
8302  return theNym.ResyncWithServer(theNymbox, theMessageNym);
8303 }
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::SavePurse ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID,
const OTIdentifier USER_ID,
Purse THE_PURSE 
) const

Definition at line 5300 of file OpenTransactions.cpp.

5303 {
5304  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5305  if (THE_PURSE.IsPasswordProtected()) {
5306  otOut << __FUNCTION__
5307  << ": Failure: This purse is password-protected (exported) "
5308  "and cannot be saved inside the wallet without first "
5309  "re-importing it.\n";
5310  }
5311  else if ((THE_PURSE.GetServerID() != SERVER_ID) ||
5312  (THE_PURSE.GetAssetID() != ASSET_ID)) {
5313  otOut << __FUNCTION__ << ": Error: Wrong server or asset ID passed in, "
5314  "considering the purse that was passed.\n";
5315  }
5316  else {
5317  const OTString strServerID(SERVER_ID);
5318  const OTString strAssetTypeID(ASSET_ID);
5319  const OTString strUserID(USER_ID);
5320  if (THE_PURSE.SavePurse(strServerID.Get(), strUserID.Get(),
5321  strAssetTypeID.Get()))
5322  return true;
5323  }
5324  const OTString strPurse(THE_PURSE);
5325  otOut << __FUNCTION__ << ": Failed saving purse:\n\n" << strPurse << "\n\n";
5326  return false;
5327 }
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
int32_t opentxs::OT_API::sendUserInstrument ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier USER_ID_RECIPIENT,
const OTString RECIPIENT_PUBKEY,
const OTPayment THE_INSTRUMENT,
const OTPayment pINSTRUMENT_FOR_SENDER = nullptr 
) const

Definition at line 13743 of file OpenTransactions.cpp.

13759 {
13760  OTPseudonym* pNym = GetOrLoadPrivateNym(
13761  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13762  if (nullptr == pNym) return (-1);
13763  // By this point, pNym is a good pointer, and is on the wallet.
13764  // (No need to cleanup.)
13765  OTServerContract* pServer =
13766  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13767  if (nullptr == pServer) return (-1);
13768  // By this point, pServer is a good pointer. (No need to cleanup.)
13769  OTMessage theMessage;
13770  int32_t nReturnValue = -1;
13771  int64_t lRequestNumber = 0;
13772 
13773  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13774  strNymID2(USER_ID_RECIPIENT);
13775  OTString strInstrument, strInstrumentForSender;
13776  const bool bGotPaymentContents =
13777  THE_INSTRUMENT.GetPaymentContents(strInstrument);
13778  const bool bGotSenderPmntCnts =
13779  (nullptr == pINSTRUMENT_FOR_SENDER)
13780  ? false
13781  : pINSTRUMENT_FOR_SENDER->GetPaymentContents(
13782  strInstrumentForSender);
13783  // PREPARE TO SAVE A COPY IN THE OUTPAYMENT BOX
13784  //
13785  if (!THE_INSTRUMENT.IsPurse()) {
13786  // store a copy in the outpayments.
13787  // (not encrypted, since the Nymfile will be encrypted anyway.)
13788  //
13789  // UPDATE: We are now storing a copy in outpayments when the
13790  // cheque is WRITTEN. But for other instruments (like cash, or
13791  // vouchers) we cannot store them in outpayments until they are
13792  // SENT. ...Meaning we must record at this point regardless.
13793  // Should we have an exception here for cheques?
13794  //
13795  // Solution: Let's just make sure there's not already one there...
13796  //
13797  int64_t lTempTransNum = 0;
13798  bool bGotTransNum =
13799  THE_INSTRUMENT.GetOpeningNum(lTempTransNum, USER_ID);
13800  int32_t lOutpaymentsIndex =
13801  bGotTransNum ? GetOutpaymentsIndexByTransNum(*pNym, lTempTransNum)
13802  : (-1);
13803 
13804  if (lOutpaymentsIndex > (-1)) // found something that matches...
13805  {
13806  // Remove it from Outpayments box. We're adding an updated version
13807  // of this same instrument here anyway. We can erase the old one.
13808  //
13809  if (!pNym->RemoveOutpaymentsByIndex(
13810  lOutpaymentsIndex)) // <==== REMOVED! (So the one added
13811  // below isn't a duplicate.)
13812  {
13813  otErr << __FUNCTION__
13814  << ": Error calling RemoveOutpaymentsByIndex for Nym: "
13815  << strNymID << "\n";
13816  }
13817  // Save Nym to local storage, since an outpayment was erased.
13818  // Note: we're saving below anyway. Might as well not save twice.
13819  //
13820  // else if (!pNym->SaveSignedNymfile(*pNym))
13821  // otErr << __FUNCTION__ << ": Error saving Nym: "
13822  // << strNymID << "\n";
13823  }
13824  else
13825  otOut << __FUNCTION__
13826  << ": FYI, didn't remove an older copy of the "
13827  "instrument from the payments outbox, "
13828  "since I couldn't find it in there.\n";
13829  }
13830  // OUTPAYMENT COPY:
13831  std::unique_ptr<OTMessage> pMessage(new OTMessage);
13832 
13833  pMessage->m_strCommand = "outpaymentsMessage";
13834  pMessage->m_strNymID = strNymID;
13835  pMessage->m_strNymID2 = strNymID2;
13836  pMessage->m_strServerID = strServerID;
13837  pMessage->m_ascPayload.SetString(bGotSenderPmntCnts ? strInstrumentForSender
13838  : strInstrument);
13839  // If they're the same, we only save a copy in the outbox.
13840  // (We only SEND if they are different.)
13841  //
13842  if (USER_ID != USER_ID_RECIPIENT) {
13843  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13844  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13845  theMessage.m_strRequestNum.Format(
13846  "%ld", lRequestNumber); // Always have to send this.
13847  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13848  // server request, I have
13849  // to increment it
13850 
13851  // (1) set up member variables
13852  theMessage.m_strCommand = "sendUserInstrument";
13853  theMessage.m_strNymID = strNymID;
13854  theMessage.m_strNymID2 = strNymID2;
13855  theMessage.m_strServerID = strServerID;
13856  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13857  // theMessage.m_strServerID is
13858  // already set. (It uses it.)
13859 
13860  OTEnvelope theEnvelope;
13861  std::unique_ptr<OTAsymmetricKey> pPubkey(OTAsymmetricKey::KeyFactory());
13862  if (!pPubkey->SetPublicKey(RECIPIENT_PUBKEY)) {
13863  otOut << __FUNCTION__
13864  << ": Failed setting public key from string ===>"
13865  << RECIPIENT_PUBKEY << "<===\n";
13866  }
13867  else if (bGotPaymentContents &&
13868  theEnvelope.Seal(*pPubkey, strInstrument) &&
13869  theEnvelope.GetAsciiArmoredData(theMessage.m_ascPayload)) {
13870  // (2) Sign the Message
13871  theMessage.SignContract(*pNym);
13872 
13873  // (3) Save the Message (with signatures and all, back to its
13874  // internal member m_strRawFile.)
13875  theMessage.SaveContract();
13876  // Back to the outpayments message...
13877  // (We may want it saved in the outpayment box, before the reply
13878  // from the
13879  // above message comes in. Actually that might be wrong, since we
13880  // care more
13881  // about the receipt from the recipient depositing the instrument,
13882  // then we do
13883  // about the reply for the sendInstrument itself. Anyway, better
13884  // safe than sorry...)
13885  //
13886  pMessage->m_strRequestNum.Format("%ld", lRequestNumber);
13887 
13888  pMessage->SignContract(*pNym);
13889  pMessage->SaveContract();
13890 
13891  pNym->AddOutpayments(*(pMessage.release()));
13892  OTPseudonym* pSignerNym = pNym;
13893  pNym->SaveSignedNymfile(*pSignerNym); // <==== SAVED.
13894  // (Send it)
13895  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
13896  m_pTransportCallback);
13897  m_pClient->ProcessMessageOut(theMessage);
13898  nReturnValue = m_pClient->CalcReturnVal(lRequestNumber);
13899  }
13900  else
13901  otOut << __FUNCTION__ << ": Failed sealing envelope.\n";
13902  }
13903  else // (USER_ID == USER_ID_RECIPIENT)
13904  {
13905  // You may be wondering why this code seems to repeat?
13906  // The answer is because above, it needs to happen BEFORE
13907  // the message is sent, since the processing of the server
13908  // reply may expect the outpayments copy to already exist.
13909  //
13910  // (NOTE: That may actually not be true. That is more true for
13911  // when the receipt comes in, from the recipient depositing
13912  // the cheque, versus the server reply to the sendInstrument
13913  // itself. Anyway...)
13914  //
13915  // Whereas here, it needs to happen in the case where the
13916  // message is NOT sent. (USER as RECIPIENT means "just put
13917  // a copy in my outpayments box.")
13918  //
13919  // But if it DOES happen BEFORE, then we want to properly
13920  // add the request number to it, even though we apparently
13921  // don't use the request number on outpayments messages.
13922  // Whereas here, we don't have a request number, so it just
13923  // gets set to 0.
13924  //
13925  pMessage->m_strRequestNum.Format(
13926  "%ld", lRequestNumber); // Will be 0 in this case.
13927 
13928  pMessage->SignContract(*pNym);
13929  pMessage->SaveContract();
13930 
13931  pNym->AddOutpayments(*(pMessage.release()));
13932  OTPseudonym* pSignerNym = pNym;
13933  pNym->SaveSignedNymfile(*pSignerNym); // <==== SAVED.
13934  nReturnValue = 0; // 0 means, nothing was sent, but no error occurred.
13935  }
13936  return nReturnValue;
13937 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTAsymmetricKey * KeyFactory()
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
int32_t GetOutpaymentsIndexByTransNum(const OTPseudonym &nym, int64_t lTransNum)
Definition: Helpers.cpp:323
int32_t opentxs::OT_API::sendUserMessage ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier USER_ID_RECIPIENT,
const OTString RECIPIENT_PUBKEY,
const OTString THE_MESSAGE 
) const

Definition at line 13637 of file OpenTransactions.cpp.

13644 {
13645  OTPseudonym* pNym = GetOrLoadPrivateNym(
13646  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13647  if (nullptr == pNym) return (-1);
13648  // By this point, pNym is a good pointer, and is on the wallet.
13649  // (No need to cleanup.)
13650  OTServerContract* pServer =
13651  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13652  if (nullptr == pServer) return (-1);
13653  // By this point, pServer is a good pointer. (No need to cleanup.)
13654  OTMessage theMessage;
13655  int64_t lRequestNumber = 0;
13656 
13657  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13658  strNymID2(USER_ID_RECIPIENT);
13659 
13660  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13661  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13662  theMessage.m_strRequestNum.Format(
13663  "%ld", lRequestNumber); // Always have to send this.
13664  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13665  // server request, I have to
13666  // increment it
13667 
13668  // (1) set up member variables
13669  theMessage.m_strCommand = "sendUserMessage";
13670  theMessage.m_strNymID = strNymID;
13671  theMessage.m_strNymID2 = strNymID2;
13672  theMessage.m_strServerID = strServerID;
13673  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13674  // theMessage.m_strServerID is already
13675  // set. (It uses it.)
13676 
13677  OTEnvelope theEnvelope;
13678  std::unique_ptr<OTAsymmetricKey> pPubkey(OTAsymmetricKey::KeyFactory());
13679  OT_ASSERT(nullptr != pPubkey);
13680 
13681  int32_t nReturnValue = -1;
13682 
13683  if (!pPubkey->SetPublicKey(RECIPIENT_PUBKEY)) {
13684  otOut << "OT_API::sendUserMessage: Failed setting public key.\n";
13685  }
13686  else if (THE_MESSAGE.Exists() &&
13687  theEnvelope.Seal(*pPubkey, THE_MESSAGE) &&
13688  theEnvelope.GetAsciiArmoredData(theMessage.m_ascPayload)) {
13689  // (2) Sign the Message
13690  theMessage.SignContract(*pNym);
13691 
13692  // (3) Save the Message (with signatures and all, back to its internal
13693  // member m_strRawFile.)
13694  theMessage.SaveContract();
13695 
13696  // (Send it)
13697  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
13698  m_pTransportCallback);
13699  m_pClient->ProcessMessageOut(theMessage);
13700 
13701  // store a copy in the outmail.
13702  // (not encrypted, since the Nymfile will be encrypted anyway.
13703  //
13704  OTMessage* pMessage = new OTMessage;
13705 
13706  OT_ASSERT(nullptr != pMessage);
13707 
13708  pMessage->m_strCommand = "outmailMessage";
13709  pMessage->m_strNymID = strNymID;
13710  pMessage->m_strNymID2 = strNymID2;
13711  pMessage->m_strServerID = strServerID;
13712  pMessage->m_strRequestNum.Format("%ld", lRequestNumber);
13713 
13714  pMessage->m_ascPayload.SetString(THE_MESSAGE);
13715 
13716  pMessage->SignContract(*pNym);
13717  pMessage->SaveContract();
13718 
13719  pNym->AddOutmail(*pMessage); // Now the Nym is responsible to delete it.
13720  // It's in his "outmail".
13721  OTPseudonym* pSignerNym = pNym;
13722  pNym->SaveSignedNymfile(*pSignerNym); // commented out temp for testing.
13723 
13724  nReturnValue = m_pClient->CalcReturnVal(lRequestNumber);
13725  }
13726  else
13727  otOut << "OT_API::sendUserMessage: Failed sealing envelope.\n";
13728 
13729  return nReturnValue;
13730 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTAsymmetricKey * KeyFactory()
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OT_API::SetAccount_Name ( const OTIdentifier ACCT_ID,
const OTIdentifier SIGNER_NYM_ID,
const OTString ACCT_NEW_NAME 
) const

Definition at line 4478 of file OpenTransactions.cpp.

4481 {
4482  OTWallet* pWallet =
4483  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
4484  if (nullptr == pWallet) return false;
4485  // By this point, pWallet is a good pointer. (No need to cleanup.)
4486  OTPseudonym* pSignerNym = GetOrLoadPrivateNym(
4487  SIGNER_NYM_ID, false, __FUNCTION__); // This logs and ASSERTs already.
4488  if (nullptr == pSignerNym) return false;
4489  OTAccount* pAccount =
4490  GetAccount(ACCT_ID, __FUNCTION__); // This logs and ASSERTs already.
4491  if (nullptr == pAccount) return false;
4492  if (!ACCT_NEW_NAME.Exists()) // Any other validation to do on the name?
4493  {
4494  otOut << "OT_API::SetAccount_Name: New name is empty (bad).\n";
4495  }
4496  else {
4497  otInfo << "Saving updated account file to disk...\n";
4498  pAccount->SetName(ACCT_NEW_NAME);
4499  pAccount->ReleaseSignatures();
4500  if (pAccount->SignContract(*pSignerNym) && pAccount->SaveContract() &&
4501  pAccount->SaveAccount())
4502  return pWallet->SaveWallet(); // Only cause the account's name is
4503  // stored here, too.
4504  else
4505  otErr
4506  << "OT_API::SetAccount_Name: Failed doing this: if "
4507  "(pAccount->SignContract(*pSignerNym) "
4508  "&& pAccount->SaveContract() && pAccount->SaveAccount())\n";
4509  }
4510  return false;
4511 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
OTLOG_IMPORT OTLogStream otInfo
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::SetAssetType_Name ( const OTIdentifier ASSET_ID,
const OTString STR_NEW_NAME 
) const

Definition at line 1570 of file OpenTransactions.cpp.

1572 {
1573  OTWallet* pWallet =
1574  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1575  if (nullptr == pWallet) return false;
1576  // By this point, pWallet is a good pointer. (No need to cleanup.)
1577  OTAssetContract* pContract =
1578  GetAssetType(ASSET_ID, __FUNCTION__); // This ASSERTs and logs already.
1579  if (nullptr == pContract) return false;
1580  // By this point, pContract is a good pointer. (No need to cleanup.)
1581  // Might want to put some more data validation on the name?
1582  if (!STR_NEW_NAME.Exists())
1583  otOut << "OT_API::SetAssetType_Name: Bad: name is empty.\n";
1584  else {
1585  pContract->SetName(STR_NEW_NAME);
1586  return pWallet->SaveWallet(); // Only 'cause the name is actually stored
1587  // here.
1588  }
1589  return false;
1590 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetAssetType(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
bool opentxs::OT_API::SetNym_Name ( const OTIdentifier NYM_ID,
const OTIdentifier SIGNER_NYM_ID,
const OTString NYM_NEW_NAME 
) const

Definition at line 4435 of file OpenTransactions.cpp.

4438 {
4439  OTWallet* pWallet =
4440  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
4441  if (nullptr == pWallet) return false;
4442  // By this point, pWallet is a good pointer. (No need to cleanup.)
4443  // -----------------------------------------------------}
4444  OTPseudonym* pNym = GetNym(NYM_ID, __FUNCTION__);
4445  OTPseudonym* pSignerNym =
4446  GetOrLoadPrivateNym(SIGNER_NYM_ID, false, __FUNCTION__);
4447  if ((nullptr == pNym) || (nullptr == pSignerNym)) return false;
4448  // By this point, pNym and pSignerNym are good pointers. (No need to
4449  // cleanup.)
4450  // -----------------------------------------------------}
4451  // Might want to put some more data validation on the name?
4452  if (!NYM_NEW_NAME.Exists())
4453  otOut << "OT_API::SetNym_Name: Empty name (bad).\n";
4454  else {
4455  OTString strOldName(pNym->GetNymName()); // just in case.
4456  pNym->SetNymName(NYM_NEW_NAME);
4457  if (pNym->SaveSignedNymfile(*pSignerNym)) {
4458  bool bSaveWallet = pWallet->SaveWallet(); // Only cause the nym's
4459  // name is stored here,
4460  // too.
4461  if (!bSaveWallet)
4462  otErr << __FUNCTION__
4463  << ": Failed while trying to save wallet.\n";
4464  return bSaveWallet;
4465  }
4466  else
4467  pNym->SetNymName(
4468  strOldName); // Set it back to the old name if failure.
4469  }
4470  return false;
4471 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
OTLOG_IMPORT OTLogStream otErr
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
bool opentxs::OT_API::SetServer_Name ( const OTIdentifier SERVER_ID,
const OTString STR_NEW_NAME 
) const

Definition at line 1597 of file OpenTransactions.cpp.

1599 {
1600  OTWallet* pWallet =
1601  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
1602  if (nullptr == pWallet) return false;
1603  // By this point, pWallet is a good pointer. (No need to cleanup.)
1604  OTServerContract* pContract =
1605  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
1606  if (nullptr == pContract) return false;
1607  // By this point, pContract is a good pointer. (No need to cleanup.)
1608  // Might want to put some more data validation on the name?
1609  if (!STR_NEW_NAME.Exists())
1610  otOut << __FUNCTION__ << ": Bad: name is empty.\n";
1611  else {
1612  pContract->SetName(STR_NEW_NAME);
1613  return pWallet->SaveWallet(); // Only 'cause the name is actually stored
1614  // here.
1615  }
1616  return false;
1617 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
bool opentxs::OT_API::SetTransportCallback ( TransportCallback pTransportCallback)

Definition at line 809 of file OpenTransactions.cpp.

810 {
811  if (nullptr != pTransportCallback) {
812  m_pTransportCallback = pTransportCallback;
813  return true;
814  }
815  else
816  return false;
817 }
bool opentxs::OT_API::SetWallet ( const OTString strFilename)

Definition at line 1000 of file OpenTransactions.cpp.

1001 {
1002 
1003  if (!m_bInitialized) {
1004  otErr << __FUNCTION__
1005  << ": Not initialized; call OT_API::Init first.\n";
1006  OT_FAIL;
1007  }
1008 
1009  {
1010  bool bExists = strFilename.Exists();
1011  if (bExists) {
1012  otErr << __FUNCTION__ << ": strFilename dose not exist!\n";
1013  OT_FAIL;
1014  }
1015  }
1016 
1017  OT_ASSERT_MSG(strFilename.Exists(),
1018  "OT_API::SetWalletFilename: strFilename does not exist.\n");
1019  OT_ASSERT_MSG((3 < strFilename.GetLength()),
1020  "OT_API::SetWalletFilename: strFilename is too short.\n");
1021 
1022  // Set New Wallet Filename
1023  otOut << __FUNCTION__ << ": Setting Wallet Filename... \n";
1024  OTString strWalletFilename;
1025  OT_API::GetWalletFilename(strWalletFilename);
1026 
1027  if (strFilename.Compare(strWalletFilename)) {
1028  otWarn << __FUNCTION__ << ": Wallet Filename: " << strFilename
1029  << " is same as in configuration. (skipping)\n";
1030  return true;
1031  }
1032  else
1033  strWalletFilename.Set(strWalletFilename);
1034 
1035  // Will save updated config filename.
1036 
1037  // Create Config Object (OTSettings)
1038  OTString strConfigFilePath;
1039  OTDataFolder::GetConfigFilePath(strConfigFilePath);
1040  OTSettings* p_Config(new OTSettings(strConfigFilePath));
1041 
1042  // First Load, Create new fresh config file if failed loading.
1043  if (!p_Config->Load()) {
1044  otOut << __FUNCTION__
1045  << ": Note: Unable to Load Config. Creating a new file: "
1046  << strConfigFilePath << "\n";
1047  if (!p_Config->Reset()) return false;
1048  if (!p_Config->Save()) return false;
1049  }
1050 
1051  if (!p_Config->Reset()) return false;
1052 
1053  // Second Load, Throw Assert if Failed loading.
1054  if (!p_Config->Load()) {
1055  otErr << __FUNCTION__
1056  << ": Error: Unable to load config file: " << strConfigFilePath
1057  << " It should exist, as we just saved it!\n";
1058  OT_FAIL;
1059  }
1060 
1061  // Set New Wallet Filename
1062  {
1063  bool bNewOrUpdated;
1064  p_Config->Set_str("wallet", "wallet_filename", strWalletFilename,
1065  bNewOrUpdated, "; Wallet updated\n");
1066 
1067  OT_API::SetWalletFilename(strWalletFilename);
1068  }
1069 
1070  // Done Loading... Lets save any changes...
1071  if (!p_Config->Save()) {
1072  otErr << __FUNCTION__ << ": Error! Unable to save updated Config!!!\n";
1073  OT_FAIL;
1074  }
1075 
1076  // Finsihed Saving... now lets cleanup!
1077  if (!p_Config->Reset()) return false;
1078 
1079  otOut << __FUNCTION__ << ": Updated Wallet filename: " << strWalletFilename
1080  << " \n";
1081 
1082  return true;
1083 }
static EXPORT bool GetConfigFilePath(OTString &strConfigFilePath)
OTLOG_IMPORT OTLogStream otOut
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otWarn
OTLOG_IMPORT OTLogStream otErr
EXPORT bool SetWalletFilename(const OTString &strPath)
EXPORT bool GetWalletFilename(OTString &strPath) const
bool opentxs::OT_API::SetWalletFilename ( const OTString strPath)

Definition at line 799 of file OpenTransactions.cpp.

800 {
801  if (strPath.Exists()) {
802  m_strWalletFilename = strPath;
803  return true;
804  }
805  else
806  return false;
807 }
bool opentxs::OT_API::SignContract ( const OTIdentifier theSignerNymID,
const OTString strContract,
OTString strOutput 
) const
OT-Sign a CONTRACT.  (First signature)

Tries to instantiate the contract object, based on the string passed in. Then it releases ALL signatures, and then signs the contract. Returns the signed contract, or nullptr if failure.

OT-Sign a CONTRACT. (First signature)

const char * OT_API_SignContract(const char * SIGNER_NYM_ID, const char * THE_CONTRACT);

Tries to instantiate the contract object, based on the string passed in. Releases all signatures, and then signs the contract. Returns the signed contract, or nullptr if failure.

NOTE: The actual OT functionality (Use Cases) NEVER requires you to sign via this function. Why not? because, anytime a signature is needed on something, the relevant OT API call will require you to pass in the Nym, and the API already signs internally wherever it deems appropriate. Thus, this function is only for advanced uses, for OT-Scripts, server operators, etc.

Definition at line 3407 of file OpenTransactions.cpp.

3410 {
3411  OTPseudonym* pNym = GetOrLoadPrivateNym(
3412  theSignerNymID, false, __FUNCTION__); // This logs and ASSERTs already.
3413  if (nullptr == pNym) return false;
3414  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3415  // cleanup.)
3416  if (!strContract.Exists()) {
3417  otOut << __FUNCTION__
3418  << ": Empty contract passed in. (Returning false.)\n";
3419  return false;
3420  }
3421  //
3422  std::unique_ptr<OTContract> pContract(
3424 
3425  if (nullptr == pContract)
3426  pContract.reset(OTScriptable::InstantiateScriptable(strContract));
3427 
3428  if (nullptr == pContract)
3429  pContract.reset(::InstantiateContract(strContract));
3430 
3431  if (nullptr == pContract) {
3432  otOut << __FUNCTION__ << ": I tried my best. "
3433  "Unable to instantiate contract passed in:\n\n"
3434  << strContract << "\n\n";
3435  return false;
3436  }
3437 
3438  pContract->ReleaseSignatures();
3439  pContract->SignContract(*pNym);
3440  pContract->SaveContract();
3441  strOutput.Release();
3442  pContract->SaveContractRaw(strOutput);
3443  return true;
3444 }
static EXPORT OTTransactionType * TransactionFactory(OTString strInput)
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::SmartContract_AddAccount ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString PARTY_NAME,
const OTString ACCT_NAME,
const OTString ASSET_TYPE_ID,
OTString strOutput 
) const

Definition at line 3741 of file OpenTransactions.cpp.

3753 {
3754  OTPseudonym* pNym = GetOrLoadPrivateNym(
3755  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
3756  if (nullptr == pNym) return false;
3757  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3758  // cleanup.)
3759  std::unique_ptr<OTScriptable> pContract(
3760  OTScriptable::InstantiateScriptable(THE_CONTRACT));
3761  if (nullptr == pContract) {
3762  otOut << "OT_API::SmartContract_AddAccount: Error loading "
3763  "smart contract:\n\n" << THE_CONTRACT << "\n\n";
3764  return false;
3765  }
3766  const std::string str_party_name(PARTY_NAME.Get());
3767 
3768  OTParty* pParty = pContract->GetParty(str_party_name);
3769 
3770  if (nullptr == pParty) {
3771  otOut << "OT_API::SmartContract_AddAccount: Failure: Party "
3772  "doesn't exist. \n";
3773  return false;
3774  }
3775  const std::string str_name(ACCT_NAME.Get()),
3776  str_asset_id(ASSET_TYPE_ID.Get());
3777 
3778  if (nullptr != pParty->GetAccount(str_name)) {
3779  otOut << "OT_API::SmartContract_AddAccount: Failed adding: "
3780  "account is already there with that name (" << str_name
3781  << ") on "
3782  "party: " << str_party_name << " \n";
3783  return false;
3784  }
3785  const OTString strAgentName, strAcctName(str_name.c_str()), strAcctID,
3786  strAssetTypeID(str_asset_id.c_str());
3787 
3788  if (false ==
3789  pParty->AddAccount(strAgentName, strAcctName, strAcctID, strAssetTypeID,
3790  0)) {
3791  otOut << "OT_API::SmartContract_AddAccount: Failed trying to "
3792  "add account (" << str_name << ") to party: " << str_party_name
3793  << " \n";
3794  return false;
3795  }
3796  // Success!
3797  //
3798  pContract->ReleaseSignatures();
3799  pContract->SignContract(*pNym);
3800  pContract->SaveContract();
3801  strOutput.Release();
3802  pContract->SaveContractRaw(strOutput);
3803  return true;
3804 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::SmartContract_AddBylaw ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString BYLAW_NAME,
OTString strOutput 
) const

Definition at line 4093 of file OpenTransactions.cpp.

4102 {
4103  const char* BYLAW_LANGUAGE = "chai"; // todo hardcoding.
4104  OTPseudonym* pNym = GetOrLoadPrivateNym(
4105  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4106  if (nullptr == pNym) return false;
4107  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4108  // cleanup.)
4109  std::unique_ptr<OTScriptable> pContract(
4110  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4111  if (nullptr == pContract) {
4112  otOut << "OT_API::SmartContract_AddBylaw: Error loading smart "
4113  "contract:\n\n" << THE_CONTRACT << "\n\n";
4114  return false;
4115  }
4116  const std::string str_bylaw_name(BYLAW_NAME.Get()),
4117  str_language(BYLAW_LANGUAGE);
4118 
4119  OTBylaw* pBylaw = pContract->GetBylaw(str_bylaw_name);
4120 
4121  if (nullptr != pBylaw) {
4122  otOut << "OT_API::SmartContract_AddBylaw: Failure: Bylaw "
4123  "already exists: " << BYLAW_NAME << " \n";
4124  return false;
4125  }
4126  pBylaw = new OTBylaw(str_bylaw_name.c_str(), str_language.c_str());
4127  OT_ASSERT(nullptr != pBylaw);
4128 
4129  if (!pContract->AddBylaw(*pBylaw)) // takes ownership.
4130  {
4131  otOut << "OT_API::SmartContract_AddBylaw: Failed while trying "
4132  "to add bylaw: " << BYLAW_NAME << " \n";
4133  delete pBylaw;
4134  pBylaw = nullptr;
4135  return false;
4136  }
4137  // Success!
4138  //
4139  pContract->ReleaseSignatures();
4140  pContract->SignContract(*pNym);
4141  pContract->SaveContract();
4142  strOutput.Release();
4143  pContract->SaveContractRaw(strOutput);
4144  return true;
4145 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OT_API::SmartContract_AddCallback ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString BYLAW_NAME,
const OTString CALLBACK_NAME,
const OTString CLAUSE_NAME,
OTString strOutput 
) const

Definition at line 4202 of file OpenTransactions.cpp.

4215 {
4216  OTPseudonym* pNym = GetOrLoadPrivateNym(
4217  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4218  if (nullptr == pNym) return false;
4219  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4220  // cleanup.)
4221  std::unique_ptr<OTScriptable> pContract(
4222  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4223  if (nullptr == pContract) {
4224  otOut << "OT_API::SmartContract_AddCallback: Error loading "
4225  "smart contract:\n\n" << THE_CONTRACT << "\n\n";
4226  return false;
4227  }
4228  const std::string str_bylaw_name(BYLAW_NAME.Get());
4229 
4230  OTBylaw* pBylaw = pContract->GetBylaw(str_bylaw_name);
4231 
4232  if (nullptr == pBylaw) {
4233  otOut << "OT_API::SmartContract_AddCallback: Failure: Bylaw "
4234  "doesn't exist: " << str_bylaw_name << " \n";
4235  return false;
4236  }
4237  const std::string str_name(CALLBACK_NAME.Get()),
4238  str_clause(CLAUSE_NAME.Get());
4239 
4240  if (nullptr != pBylaw->GetCallback(str_name)) {
4241  otOut << "OT_API::SmartContract_AddCallback: Failure: "
4242  "Callback (" << str_name
4243  << ") already exists on bylaw: " << str_bylaw_name << " \n";
4244  return false;
4245  }
4246  if (!pBylaw->AddCallback(str_name.c_str(), str_clause.c_str())) {
4247  otOut << "OT_API::SmartContract_AddCallback: Failed trying to "
4248  "add callback (" << str_name << ", clause " << str_clause
4249  << ") to bylaw: " << str_bylaw_name << " \n";
4250  return false;
4251  }
4252  // Success!
4253  //
4254  pContract->ReleaseSignatures();
4255  pContract->SignContract(*pNym);
4256  pContract->SaveContract();
4257  strOutput.Release();
4258  pContract->SaveContractRaw(strOutput);
4259  return true;
4260 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::SmartContract_AddClause ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString BYLAW_NAME,
const OTString CLAUSE_NAME,
const OTString SOURCE_CODE,
OTString strOutput 
) const

Definition at line 4262 of file OpenTransactions.cpp.

4274 {
4275  OTPseudonym* pNym = GetOrLoadPrivateNym(
4276  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4277  if (nullptr == pNym) return false;
4278  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4279  // cleanup.)
4280  std::unique_ptr<OTScriptable> pContract(
4281  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4282  if (nullptr == pContract) {
4283  otOut << "OT_API::SmartContract_AddClause: Error loading "
4284  "smart contract:\n\n" << THE_CONTRACT << "\n\n";
4285  return false;
4286  }
4287  const std::string str_bylaw_name(BYLAW_NAME.Get());
4288 
4289  OTBylaw* pBylaw = pContract->GetBylaw(str_bylaw_name);
4290 
4291  if (nullptr == pBylaw) {
4292  otOut << "OT_API::SmartContract_AddClause: Failure: Bylaw "
4293  "doesn't exist: " << str_bylaw_name
4294  << " \n Input contract: \n\n" << THE_CONTRACT << "\n\n";
4295  return false;
4296  }
4297  const std::string str_name(CLAUSE_NAME.Get()), str_code(SOURCE_CODE.Get());
4298 
4299  if (nullptr != pBylaw->GetClause(str_name)) {
4300  otOut << "OT_API::SmartContract_AddClause: Failed adding: "
4301  "clause is already there with that name (" << str_name
4302  << ") on "
4303  "bylaw: " << str_bylaw_name << " \n";
4304  return false;
4305  }
4306  if (!pBylaw->AddClause(str_name.c_str(), str_code.c_str())) {
4307  otOut << "OT_API::SmartContract_AddClause: Failed trying to "
4308  "add clause (" << str_name << ") to bylaw: " << str_bylaw_name
4309  << " \n";
4310  return false;
4311  }
4312  // Success!
4313  //
4314  pContract->ReleaseSignatures();
4315  pContract->SignContract(*pNym);
4316  pContract->SaveContract();
4317  strOutput.Release();
4318  pContract->SaveContractRaw(strOutput);
4319  return true;
4320 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::SmartContract_AddHook ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString BYLAW_NAME,
const OTString HOOK_NAME,
const OTString CLAUSE_NAME,
OTString strOutput 
) const

Definition at line 4147 of file OpenTransactions.cpp.

4162 {
4163  OTPseudonym* pNym = GetOrLoadPrivateNym(
4164  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4165  if (nullptr == pNym) return false;
4166  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4167  // cleanup.)
4168  std::unique_ptr<OTScriptable> pContract(
4169  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4170  if (nullptr == pContract) {
4171  otOut << "OT_API::SmartContract_AddHook: Error loading smart "
4172  "contract:\n\n" << THE_CONTRACT << "\n\n";
4173  return false;
4174  }
4175  const std::string str_bylaw_name(BYLAW_NAME.Get());
4176 
4177  OTBylaw* pBylaw = pContract->GetBylaw(str_bylaw_name);
4178 
4179  if (nullptr == pBylaw) {
4180  otOut << "OT_API::SmartContract_AddHook: Failure: Bylaw "
4181  "doesn't exist: " << str_bylaw_name << " \n";
4182  return false;
4183  }
4184  const std::string str_name(HOOK_NAME.Get()), str_clause(CLAUSE_NAME.Get());
4185 
4186  if (!pBylaw->AddHook(str_name, str_clause)) {
4187  otOut << "OT_API::SmartContract_AddHook: Failed trying to add "
4188  "hook (" << str_name << ", clause " << str_clause
4189  << ") to bylaw: " << str_bylaw_name << " \n";
4190  return false;
4191  }
4192  // Success!
4193  //
4194  pContract->ReleaseSignatures();
4195  pContract->SignContract(*pNym);
4196  pContract->SaveContract();
4197  strOutput.Release();
4198  pContract->SaveContractRaw(strOutput);
4199  return true;
4200 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
bool opentxs::OT_API::SmartContract_AddParty ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString PARTY_NAME,
const OTString AGENT_NAME,
OTString strOutput 
) const

Definition at line 3683 of file OpenTransactions.cpp.

3694 {
3695  OTPseudonym* pNym = GetOrLoadPrivateNym(
3696  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
3697  if (nullptr == pNym) return false;
3698  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3699  // cleanup.)
3700  std::unique_ptr<OTScriptable> pContract(
3701  OTScriptable::InstantiateScriptable(THE_CONTRACT));
3702  if (nullptr == pContract) {
3703  otOut << __FUNCTION__ << ": Error loading smart contract:\n\n"
3704  << THE_CONTRACT << "\n\n";
3705  return false;
3706  }
3707  const std::string str_party_name(PARTY_NAME.Get()),
3708  str_agent_name(AGENT_NAME.Get());
3709 
3710  OTParty* pParty = pContract->GetParty(str_party_name);
3711 
3712  if (nullptr != pParty) {
3713  otOut << __FUNCTION__ << ": Failure: Party already exists. \n";
3714  return false;
3715  }
3716 
3717  pParty = new OTParty(str_party_name.c_str(), true /*bIsOwnerNym*/,
3718  nullptr /*OwnerID not set until confirm*/,
3719  str_agent_name.c_str(),
3720  true); // bCreateAgent=false by default.
3721  OT_ASSERT(nullptr != pParty);
3722 
3723  if (!pContract->AddParty(*pParty)) // takes ownership.
3724  {
3725  otOut << __FUNCTION__
3726  << ": Failed while trying to add party: " << PARTY_NAME << " \n";
3727  delete pParty;
3728  pParty = nullptr;
3729  return false;
3730  }
3731  // Success!
3732  //
3733  pContract->ReleaseSignatures();
3734  pContract->SignContract(*pNym);
3735  pContract->SaveContract();
3736  strOutput.Release();
3737  pContract->SaveContractRaw(strOutput);
3738  return true;
3739 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OT_API::SmartContract_AddVariable ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString BYLAW_NAME,
const OTString VAR_NAME,
const OTString VAR_ACCESS,
const OTString VAR_TYPE,
const OTString VAR_VALUE,
OTString strOutput 
) const

Definition at line 4322 of file OpenTransactions.cpp.

4340 {
4341  OTPseudonym* pNym = GetOrLoadPrivateNym(
4342  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4343  if (nullptr == pNym) return false;
4344  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4345  // cleanup.)
4346  std::unique_ptr<OTScriptable> pContract(
4347  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4348  if (nullptr == pContract) {
4349  otOut << "OT_API::SmartContract_AddVariable: Error loading "
4350  "smart contract:\n\n" << THE_CONTRACT << "\n\n";
4351  return false;
4352  }
4353  const std::string str_bylaw_name(BYLAW_NAME.Get());
4354 
4355  OTBylaw* pBylaw = pContract->GetBylaw(str_bylaw_name);
4356 
4357  if (nullptr == pBylaw) {
4358  otOut << "OT_API::SmartContract_AddVariable: Failure: Bylaw "
4359  "doesn't exist: " << str_bylaw_name << " \n";
4360  return false;
4361  }
4362  const std::string str_name(VAR_NAME.Get()), str_access(VAR_ACCESS.Get()),
4363  str_type(VAR_TYPE.Get()), str_value(VAR_VALUE.Get());
4364 
4365  if (nullptr != pBylaw->GetVariable(str_name)) {
4366  otOut << "OT_API::SmartContract_AddVariable: Failure: "
4367  "Variable (" << str_name
4368  << ") already exists on bylaw: " << str_bylaw_name << " \n";
4369  return false;
4370  }
4372 
4373  if (str_access.compare("constant") == 0)
4374  theAccess = OTVariable::Var_Constant;
4375  else if (str_access.compare("persistent") == 0)
4376  theAccess = OTVariable::Var_Persistent;
4377  else if (str_access.compare("important") == 0)
4378  theAccess = OTVariable::Var_Important;
4380 
4381  if (str_type.compare("bool") == 0)
4382  theType = OTVariable::Var_Bool;
4383  else if (str_type.compare("integer") == 0)
4384  theType = OTVariable::Var_Integer;
4385  else if (str_type.compare("string") == 0)
4386  theType = OTVariable::Var_String;
4387  if ((OTVariable::Var_Error_Type == theType) ||
4388  (OTVariable::Var_Error_Access == theAccess)) {
4389  otOut << "OT_API::SmartContract_AddVariable: Failed due to bad "
4390  "variable type or bad access type. \n";
4391  return false;
4392  }
4393  bool bAdded = false;
4394 
4395  switch (theType) {
4396  case OTVariable::Var_Bool: {
4397  const bool bValue = (str_value.compare("true") == 0);
4398  bAdded = pBylaw->AddVariable(str_name, bValue, theAccess);
4399  } break;
4400  case OTVariable::Var_Integer: {
4401  const int32_t nValue = atoi(str_value.c_str());
4402  bAdded = pBylaw->AddVariable(str_name, nValue, theAccess);
4403  } break;
4405  bAdded = pBylaw->AddVariable(str_name, str_value, theAccess);
4406  break;
4407  default:
4408  // SHOULD NEVER HAPPEN (We already return above, if the variable type
4409  // isn't correct.)
4410  OT_FAIL_MSG("Should never happen. You aren't seeing this.");
4411  break;
4412  }
4413 
4414  if (!bAdded) {
4415  otOut << "OT_API::SmartContract_AddVariable: Failed trying to "
4416  "add variable (" << str_name
4417  << ") to bylaw: " << str_bylaw_name << " \n";
4418  return false;
4419  }
4420  // Success!
4421  //
4422  pContract->ReleaseSignatures();
4423  pContract->SignContract(*pNym);
4424  pContract->SaveContract();
4425  strOutput.Release();
4426  pContract->SaveContractRaw(strOutput);
4427  return true;
4428 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_FAIL_MSG(s)
Definition: Assert.hpp:144
bool opentxs::OT_API::SmartContract_ConfirmAccount ( const OTString THE_CONTRACT,
const OTIdentifier SIGNER_NYM_ID,
const OTString PARTY_NAME,
const OTString ACCT_NAME,
const OTString AGENT_NAME,
const OTString ACCT_ID,
OTString strOutput 
) const

Definition at line 3835 of file OpenTransactions.cpp.

3842 {
3843  OTPseudonym* pNym = GetOrLoadPrivateNym(
3844  SIGNER_NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
3845  if (nullptr == pNym) return false;
3846  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3847  // cleanup.)
3848  const OTIdentifier theAcctID(ACCT_ID);
3849  OTAccount* pAccount = GetAccount(theAcctID, __FUNCTION__);
3850  if (nullptr == pAccount) return false;
3851  // By this point, pAccount is a good pointer, and is on the wallet. (No need
3852  // to cleanup.)
3853  std::unique_ptr<OTScriptable> pScriptable(
3854  OTScriptable::InstantiateScriptable(THE_CONTRACT));
3855  if (nullptr == pScriptable) {
3856  otOut << __FUNCTION__ << ": Error loading smart contract:\n\n"
3857  << THE_CONTRACT << "\n\n";
3858  return false;
3859  }
3860  OTSmartContract* pContract =
3861  dynamic_cast<OTSmartContract*>(pScriptable.get());
3862  if (nullptr == pContract) {
3863  otOut << __FUNCTION__
3864  << ": Failure casting to Smart Contract. "
3865  "Are you SURE it's a smart contract? Contents:\n"
3866  << THE_CONTRACT << "\n";
3867  return false;
3868  }
3869  const std::string str_party_name(PARTY_NAME.Get());
3870  OTParty* pParty = pContract->GetParty(str_party_name);
3871  if (nullptr == pParty) {
3872  otOut << __FUNCTION__
3873  << ": Failure: Party doesn't exist: " << PARTY_NAME << " \n";
3874  return false;
3875  }
3876  // Make sure there's not already an account here with the same ID (Server
3877  // disallows.)
3878  //
3879  OTPartyAccount* pDupeAcct = pParty->GetAccountByID(theAcctID);
3880  if (nullptr != pDupeAcct) // It's already there.
3881  {
3882  otOut << __FUNCTION__ << ": Failed, since a duplicate account ID ("
3883  << ACCT_ID << ") was already found on this contract. (Server "
3884  "disallows, sorry.)\n";
3885  return false;
3886  }
3887  // Find the account template based on its name, to affix the acct ID to.
3888  //
3889  const std::string str_name(ACCT_NAME.Get());
3890 
3891  OTPartyAccount* pPartyAcct = pParty->GetAccount(str_name);
3892  if (nullptr ==
3893  pPartyAcct) // It's not already there. (Though it should be...)
3894  {
3895  otOut << __FUNCTION__
3896  << ": Failed: No account found on contract with name: "
3897  << str_name << " \n";
3898  return false;
3899  }
3900  // the actual asset type ID
3901 
3902  const OTIdentifier theExpectedAssetTypeID(
3903  pPartyAcct->GetAssetTypeID()); // The expected asset type ID, converting
3904  // from a string.
3905  const OTIdentifier& theActualAssetTypeID =
3906  pAccount->GetAssetTypeID(); // the actual asset type ID, already an
3907  // identifier, from the actual account.
3908 
3909  if (theExpectedAssetTypeID != theActualAssetTypeID) {
3910  const OTString strAssetTypeID(theActualAssetTypeID);
3911  otOut << __FUNCTION__
3912  << ": Failed, since the asset type ID of the account ("
3913  << strAssetTypeID << ") does not match what was expected ("
3914  << pPartyAcct->GetAssetTypeID()
3915  << ") according to this contract.\n";
3916  return false;
3917  }
3918  // I'm leaving this here for now, since a party can only be a Nym for now
3919  // anyway (until I code entities.)
3920  // Therefore this account COULD ONLY be owned by that Nym anyway, and thus
3921  // will pass this test.
3922  // All the above functions aren't that stringent because they are about
3923  // designing the smart contract, not
3924  // executing it. But in THIS case, we are actually confirming the thing, and
3925  // adding our actual account #s
3926  // to it, signing it, etc, so I might as well save the person the hassle of
3927  // being rejected later because
3928  // he accidentally set it up with the wrong Nym.
3929  //
3930  if (!pAccount->VerifyOwner(*pNym)) {
3931  const OTString strNymID(SIGNER_NYM_ID);
3932  otOut << __FUNCTION__ << ": Failed, since this nym (" << strNymID
3933  << ") isn't the owner of this account (" << str_name << ").\n";
3934  return false;
3935  }
3936  // When the first ACCOUNT is confirmed, then at that moment, we know which
3937  // server
3938  // this smart contract is intended to execute on.
3939  //
3940  // If this is the first account being confirmed, then we will set the server
3941  // ID
3942  // for the smart contract based on the server ID of this account. Otherwise
3943  // if this
3944  // is not the first account being confirmed, then we will compare the server
3945  // ID
3946  // that's already on the smart contract, to the server ID for this account,
3947  // and make
3948  // sure they match. (Otherwise we will reject the confirmation.)
3949  //
3950  // Once the contract is activated, the server will verify all the parties
3951  // and accounts
3952  // anyway. So might as well save ourselves the hassle, if this doesn't match
3953  // up now.
3954  //
3955  if (pContract->SetServerIDIfEmpty(pAccount->GetPurportedServerID())) {
3956  // todo security: possibly want to verify here that this really is the
3957  // FIRST
3958  // account being confirmed in this smart contract, or at least the first
3959  // party.
3960  // Right now we're just using the server ID being empty as an easy way
3961  // to find
3962  // out, but technically a party could slip in a "signed version" without
3963  // setting
3964  // the server ID, and it might slip by here (though it would eventually
3965  // fail some
3966  // verification.) In the int64_t term we'll do a more thorough check
3967  // here, though.
3968  }
3969  else if (pContract->GetServerID() != pAccount->GetPurportedServerID()) {
3970  const OTString strServer1(pContract->GetServerID()),
3971  strServer2(pAccount->GetPurportedServerID());
3972  otOut << __FUNCTION__
3973  << ": Failure: The smart contract has a different "
3974  "server ID on it already (" << strServer1
3975  << ") than the one "
3976  "that goes with this account (server " << strServer2
3977  << ", for account " << ACCT_ID << ")\n";
3978  return false;
3979  }
3980  // BY THIS POINT, we know that the account is actually owned by the Nym,
3981  // and we know that it's got the proper asset type ID that was expected
3982  // according to the smart contract. We also know that the smart contract
3983  // has the same server ID as the account being confirmed.
3984  //
3985  pPartyAcct->SetAcctID(ACCT_ID.Get());
3986  pPartyAcct->SetAgentName(AGENT_NAME.Get());
3987  pContract->ReleaseSignatures();
3988  pContract->SignContract(*pNym);
3989  pContract->SaveContract();
3990  strOutput.Release();
3991  pContract->SaveContractRaw(strOutput);
3992  return true;
3993 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
bool opentxs::OT_API::SmartContract_ConfirmParty ( const OTString THE_CONTRACT,
const OTString PARTY_NAME,
const OTIdentifier NYM_ID,
OTString strOutput 
) const

Definition at line 3995 of file OpenTransactions.cpp.

4004 {
4005  OTPseudonym* pNym = GetOrLoadPrivateNym(
4006  NYM_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
4007  if (nullptr == pNym) return false;
4008  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4009  // cleanup.)
4010  std::unique_ptr<OTScriptable> pContract(
4011  OTScriptable::InstantiateScriptable(THE_CONTRACT));
4012 
4013  if (nullptr == pContract) {
4014  otOut << __FUNCTION__ << ": Error loading smart contract:\n\n"
4015  << THE_CONTRACT << "\n\n";
4016  return false;
4017  }
4018  const std::string str_party_name(PARTY_NAME.Get());
4019 
4020  OTParty* pParty = pContract->GetParty(str_party_name);
4021 
4022  if (nullptr == pParty) {
4023  otOut << __FUNCTION__ << ": Failure: Party (" << str_party_name
4024  << ") doesn't exist, so how can you confirm it?\n";
4025  return false;
4026  }
4027  OTParty* pNewParty = new OTParty(
4028  pParty->GetPartyName(),
4029  *pNym, // party keeps an internal pointer to pNym from here on.
4030  pParty->GetAuthorizingAgentName()); // Party name and agent name must
4031  // match, in order to replace /
4032  // activate this party.
4033  OT_ASSERT(nullptr != pNewParty);
4034  if (!pParty->CopyAcctsToConfirmingParty(*pNewParty)) {
4035  otOut << __FUNCTION__
4036  << ": Failed while trying to copy accounts, while "
4037  "confirming party: " << PARTY_NAME << " \n";
4038  delete pNewParty;
4039  pNewParty = nullptr;
4040  return false;
4041  }
4042  if (!pContract->ConfirmParty(*pNewParty)) // takes ownership.
4043  // (Deletes the
4044  // theoretical version of
4045  // the party, replaced by
4046  // our actual version
4047  // pNewParty.)
4048  {
4049  otOut << __FUNCTION__
4050  << ": Failed while trying to confirm party: " << PARTY_NAME
4051  << " \n";
4052  delete pNewParty;
4053  pNewParty = nullptr;
4054  return false;
4055  }
4056  // ConfirmParty(), unlike most others, actually signs and saves the contract
4057  // already.
4058  // Therefore, all that's needed here is to grab it in string form...
4059  // (No need to sign again, it's just a waste of resource..)
4060  // pContract->ReleaseSignatures();
4061  // pContract->SignContract(*pNym);
4062  // pContract->SaveContract();
4063 
4064  strOutput.Release();
4065  pContract->SaveContractRaw(strOutput);
4066  //
4067  // DROP A COPY into the Outpayments box...
4068  //
4069  // (Since we used a transaction number to confirm the party, we
4070  // have to track it until it's activated or until we cancel it.)
4071  //
4072  const OTString strInstrument(*pContract);
4073  OTMessage* pMessage = new OTMessage;
4074  OT_ASSERT(nullptr != pMessage);
4075 
4076  const OTString strNymID(NYM_ID);
4077 
4078  pMessage->m_strCommand = "outpaymentsMessage";
4079  pMessage->m_strNymID = strNymID;
4080  // pMessage->m_strServerID = strServerID;
4081  pMessage->m_ascPayload.SetString(strInstrument);
4082 
4083  pMessage->SignContract(*pNym);
4084  pMessage->SaveContract();
4085 
4086  pNym->AddOutpayments(*pMessage); // Now the Nym is responsible to delete it.
4087  // It's in his "outpayments".
4088  OTPseudonym* pSignerNym = pNym;
4089  pNym->SaveSignedNymfile(*pSignerNym);
4090  return true;
4091 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t opentxs::OT_API::SmartContract_CountNumsNeeded ( const OTString THE_CONTRACT,
const OTString AGENT_NAME 
) const

Definition at line 3806 of file OpenTransactions.cpp.

3812 {
3813  int32_t nReturnValue = 0;
3814  const std::string str_agent_name(AGENT_NAME.Get());
3815  std::unique_ptr<OTScriptable> pContract(
3816  OTScriptable::InstantiateScriptable(THE_CONTRACT));
3817 
3818  if (nullptr == pContract) {
3819  otOut << "OT_API::SmartContract_CountNumsNeeded: Error loading "
3820  "smart contract. \n";
3821  return nReturnValue;
3822  }
3823  // -- nReturnValue starts as 0.
3824  // -- If agent is authorizing agent for a party, nReturnValue++. (Opening
3825  // number.)
3826  // -- If agent is authorized agent for any of party's accts, nReturnValue++
3827  // for each. (Closing numbers.)
3828  //
3829  // (Then return the count.)
3830 
3831  nReturnValue = pContract->GetCountTransNumsNeededForAgent(str_agent_name);
3832  return nReturnValue;
3833 }
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
Token * opentxs::OT_API::Token_ChangeOwner ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTString THE_TOKEN,
const OTIdentifier SIGNER_NYM_ID,
const OTString OLD_OWNER,
const OTString NEW_OWNER,
const OTString pstrDisplay = nullptr 
) const

Definition at line 6086 of file OpenTransactions.cpp.

6092 {
6093  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
6094  OTString strWalletReason(
6095  (nullptr == pstrDisplay)
6096  ? "Enter your wallet's master passphrase. (Token_ChangeOwner.)"
6097  : pstrDisplay->Get());
6098  OTString strPurseReason(
6099  (nullptr == pstrDisplay)
6100  ? "Enter the passphrase for this purse. (Token_ChangeOwner.)"
6101  : pstrDisplay->Get());
6102  OTPasswordData thePWDataWallet(strWalletReason);
6103  OTPseudonym* pSignerNym = GetOrLoadPrivateNym(
6104  SIGNER_NYM_ID, false, __FUNCTION__,
6105  &thePWDataWallet); // These copiously log, and ASSERT.
6106  if (nullptr == pSignerNym) return nullptr;
6107  // By this point, pNym is a good pointer, and is on the wallet. (No need to
6108  // cleanup.)
6109  // ALL THE COMPLEXITY YOU SEE BELOW is mainly just about handling OLD_OWNER
6110  // and NEW_OWNER each as either a NymID or as a Purse (containing a
6111  // symmetric key and
6112  // a corresponding master key.)
6113  OTIdentifier oldOwnerNymID,
6114  newOwnerNymID; // if either owner is a Nym, the ID goes here.
6115  std::unique_ptr<Purse> theOldPurseAngel;
6116  OTPassword theOldPassword; // Only used in the case of password-protected
6117  // purses.
6118  OTNym_or_SymmetricKey* pOldOwner = nullptr;
6119  std::unique_ptr<OTNym_or_SymmetricKey> theOldOwnerAngel;
6120  std::unique_ptr<Purse> theNewPurseAngel;
6121  OTPassword theNewPassword; // Only used in the case of password-protected
6122  // purses.
6123  OTNym_or_SymmetricKey* pNewOwner = nullptr;
6124  std::unique_ptr<OTNym_or_SymmetricKey> theNewOwnerAngel;
6125  const bool bOldOwnerIsPurse = OLD_OWNER.Contains("PURSE");
6126  const bool bNewOwnerIsPurse = NEW_OWNER.Contains("PURSE");
6127  if (!bOldOwnerIsPurse) // The old owner is a NYM (public/private keys.)
6128  {
6129  oldOwnerNymID.SetString(OLD_OWNER);
6130  OTPseudonym* pOldNym = GetOrLoadPrivateNym(
6131  oldOwnerNymID, false, __FUNCTION__,
6132  &thePWDataWallet); // These copiously log, and ASSERT.
6133  // if (nullptr == pOldNym) pOldNym =
6134  // GetOrLoadPublicNym(oldOwnerNymID, __FUNCTION__); // must be private,
6135  // in order to decrypt the old token.
6136  if (nullptr == pOldNym) return nullptr;
6137  pOldOwner = new OTNym_or_SymmetricKey(*pOldNym, &strWalletReason);
6138  OT_ASSERT(nullptr != pOldOwner);
6139  theOldOwnerAngel.reset(pOldOwner);
6140  }
6141  else // The old owner is a PURSE (Symmetric/master keys, internal to that
6142  // purse.)
6143  {
6144  // if the old owner is a Purse (symmetric+master key), the entire
6145  // purse is loaded.
6146  Purse* pOldPurse = new Purse(SERVER_ID, ASSET_TYPE_ID);
6147  OT_ASSERT(nullptr != pOldPurse);
6148  theOldPurseAngel.reset(pOldPurse);
6149  pOldOwner = LoadPurseAndOwnerForMerge(
6150  OLD_OWNER, *pOldPurse, theOldPassword,
6151  false, // bCanBePublic=false by default. In this case, it definitely
6152  // must be private.
6153  &SIGNER_NYM_ID, // This can be nullptr, **IF** purse is
6154  // password-protected. (It's just ignored in that
6155  // case.) Otherwise if it's Nym-protected, the purse
6156  // will have a NymID on it already, which is what
6157  // LoadPurseAndOwnerForMerge will try first. If not
6158  // (it's optional), then SIGNER_NYM_ID is the ID it
6159  // will try next, before failing altogether.
6160  // ADDITIONAL NOTE: We don't expect the purse to
6161  // ever be Nym-based since in this function, we pass
6162  // a purse in order to pass the symmetric and master
6163  // keys. Otherwise if this token's owner was already
6164  // a Nym, then we would have passed a NymID in here,
6165  // instead of a purse, in the first place.
6166  &strPurseReason);
6167  theOldOwnerAngel.reset(pOldOwner);
6168  if (nullptr == pOldOwner)
6169  return nullptr; // This already logs, no need for more logs.
6170  }
6171  if (!bNewOwnerIsPurse) // The new owner is a NYM
6172  {
6173  newOwnerNymID.SetString(NEW_OWNER);
6174  OTPseudonym* pNewNym =
6175  GetOrLoadNym(newOwnerNymID, false, __FUNCTION__,
6176  &thePWDataWallet); // These copiously log, and ASSERT.
6177  if (nullptr == pNewNym) return nullptr;
6178  pNewOwner = new OTNym_or_SymmetricKey(*pNewNym, &strWalletReason);
6179  OT_ASSERT(nullptr != pNewOwner);
6180  theNewOwnerAngel.reset(pNewOwner);
6181  }
6182  else // The new owner is a PURSE
6183  {
6184  // if the new owner is a Purse (symmetric+master key), the entire purse
6185  // is loaded.
6186  Purse* pNewPurse = new Purse(SERVER_ID, ASSET_TYPE_ID);
6187  OT_ASSERT(nullptr != pNewPurse);
6188  theNewPurseAngel.reset(pNewPurse);
6189  pNewOwner = LoadPurseAndOwnerForMerge(
6190  NEW_OWNER, *pNewPurse, theNewPassword,
6191  true, // bCanBePublic=false by default, but set TRUE here, since you
6192  // SHOULD be able to re-assign ownership of a token to someone
6193  // else, without having to load their PRIVATE key (which you
6194  // don't have.) Sort of irrelevant here actually, since this
6195  // block is for purses only...
6196  &SIGNER_NYM_ID, // This can be nullptr, **IF** purse is
6197  // password-protected. (It's just ignored in that
6198  // case.) Otherwise if it's Nym-protected, the purse
6199  // will have a NymID on it already, which is what
6200  // LoadPurseAndOwnerForMerge will try first. If not
6201  // (it's optional), then SIGNER_NYM_ID is the ID it
6202  // will try next, before failing altogether.
6203  // ADDITIONAL NOTE: We don't expect the purse to
6204  // ever be Nym-based since in this function, we pass
6205  // a purse in order to pass the symmetric and master
6206  // keys. Otherwise if this token's owner was already
6207  // a Nym, then we would have passed a NymID in here,
6208  // instead of a purse, in the first place.
6209  &strPurseReason);
6210  theNewOwnerAngel.reset(pNewOwner);
6211  if (nullptr == pNewOwner)
6212  return nullptr; // This already logs, no need for more logs.
6213  }
6214  //
6215  // (By this point, pOldOwner and pNewOwner should both be good to go.)
6216  //
6217  std::unique_ptr<Token> pToken(
6218  Token::TokenFactory(THE_TOKEN, SERVER_ID, ASSET_TYPE_ID));
6219  OT_ASSERT(nullptr != pToken);
6220  if (false ==
6221  pToken->ReassignOwnership(*pOldOwner, // must be private, if a Nym.
6222  *pNewOwner)) // can be public, if a Nym.
6223  {
6224  otErr << __FUNCTION__ << ": Error re-assigning ownership of token.\n";
6225  }
6226  else {
6227  otLog3 << __FUNCTION__
6228  << ": Success re-assigning ownership of token.\n";
6229 
6230  pToken->ReleaseSignatures();
6231  pToken->SignContract(*pSignerNym);
6232  pToken->SaveContract();
6233 
6234  return pToken.release();
6235  }
6236 
6237  return nullptr;
6238 }
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
OTLOG_IMPORT OTLogStream otLog3
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
static EXPORT Token * TokenFactory(OTString strInput)
Definition: Token.cpp:518
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerForMerge(const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bCanBePublic=false, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
bool opentxs::OT_API::TransportFunction ( const OTServerContract theServerContract,
const OTEnvelope theEnvelope 
) const

Definition at line 1140 of file OpenTransactions.cpp.

1142 {
1143  if (!IsInitialized()) {
1144  otErr << __FUNCTION__ << ": Error: OT_API is not Initialized!\n";
1145  OT_FAIL;
1146  }
1147  if (nullptr == m_pClient) {
1148  otErr << __FUNCTION__ << ": Error: m_pClient is a nullptr!\n";
1149  OT_FAIL;
1150  }
1151  if (nullptr == m_pClient->m_pConnection) {
1152  otErr << __FUNCTION__ << ": Error: m_pConnection is a nullptr!\n";
1153  OT_FAIL;
1154  }
1155  OTPseudonym* pNym(m_pClient->m_pConnection->GetNym());
1156  if (nullptr == pNym) {
1157  otErr << __FUNCTION__ << ": Error: pNym is a nullptr!\n";
1158  OT_FAIL;
1159  }
1160  if (nullptr == m_pSocket) {
1161  otErr << __FUNCTION__ << ": Error: m_Socket is a nullptr!\n";
1162  OT_FAIL;
1163  }
1164  if (nullptr == m_pSocket->GetMutex()) {
1165  otErr << __FUNCTION__ << ": Error: m_Socket is a nullptr!\n";
1166  OT_FAIL;
1167  }
1168  if (!m_pSocket->IsInitialized()) {
1169  otErr << __FUNCTION__ << ": Error: m_Socket is not Initialized!\n";
1170  OT_FAIL;
1171  }
1172  std::lock_guard<std::mutex> lock(*m_pSocket->GetMutex());
1173  int32_t nServerPort = 0;
1174  OTString strServerHostname;
1175 
1176  if (false ==
1177  theServerContract.GetConnectInfo(strServerHostname, nServerPort)) {
1178  otErr << __FUNCTION__
1179  << ": Failed retrieving connection info from server contract.\n";
1180  return false;
1181  }
1182  OTString strConnectPath;
1183  strConnectPath.Format("tcp://%s:%d", strServerHostname.Get(), nServerPort);
1184 
1185  OTASCIIArmor ascEnvelope(theEnvelope);
1186 
1187  if (ascEnvelope.Exists()) {
1188  if (!m_pSocket->HasContext())
1189  if (!m_pSocket->NewContext())
1190  return false; // unable to make context. btw. should have been
1191  // already made.
1192 
1193  bool bSuccessSending =
1194  m_pSocket->Send(ascEnvelope, strConnectPath); // <========
1195 
1196  if (!bSuccessSending) {
1197  otErr << __FUNCTION__
1198  << ": Failed, even with error correction and retries, "
1199  "while trying to send message to server.";
1200  }
1201  else {
1202  OTString strRawServerReply;
1203  bool bSuccessReceiving =
1204  m_pSocket->Receive(strRawServerReply); // <========
1205 
1206  if (!bSuccessReceiving || !strRawServerReply.Exists()) {
1207  otErr << __FUNCTION__
1208  << ": Failed trying to receive expected reply "
1209  "from server.\n";
1210  }
1211  else {
1212  OTASCIIArmor ascServerReply;
1213  const bool bLoaded =
1214  strRawServerReply.Exists() &&
1215  ascServerReply.LoadFromString(strRawServerReply);
1216  OTString strServerReply;
1217  bool bRetrievedReply = false;
1218  if (!bLoaded)
1219  otErr << __FUNCTION__
1220  << ": Failed trying to load OTASCIIArmor "
1221  "object from string:\n\n" << strRawServerReply
1222  << "\n\n";
1223 
1224  else if (strRawServerReply.Contains(
1225  "ENVELOPE")) // Server sent this encrypted to my
1226  // public key, in an armored envelope.
1227  {
1228  OTEnvelope theServerEnvelope;
1229  if (theServerEnvelope.SetAsciiArmoredData(ascServerReply)) {
1230 
1231  bRetrievedReply =
1232  theServerEnvelope.Open(*pNym, strServerReply);
1233  }
1234  else {
1235  otErr << __FUNCTION__
1236  << ": Failed: while setting "
1237  "OTASCIIArmor'd string into an "
1238  "OTEnvelope.\n";
1239  }
1240  }
1241  // NOW ABLE TO HANDLE MESSAGES HERE IN ADDITION TO ENVELOPES!!!!
1242  // (Sometimes the server HAS to reply with an unencrypted reply,
1243  // and this is what makes it possible for the client to RECEIVE
1244  // that reply.)
1245  //
1246  // The Server doesn't have to accept both types, but the client
1247  // does,
1248  // since technically all clients cannot talk to it without
1249  // knowing its key first.
1250  //
1251  // ===> A CLIENT could POTENTIALLY have sent a message to server
1252  // when unregistered,
1253  // leaving server NO WAY to reply! Therefore server HAS to have
1254  // the OPTION to send
1255  // an unencrypted message, in that case, and the client HAS to
1256  // be able to receive it
1257  // properly!!
1258  //
1259  else if (strRawServerReply.Contains("MESSAGE")) // Server sent
1260  // this NOT
1261  // encrypted, in
1262  // an armored
1263  // message.
1264  {
1265  bRetrievedReply = ascServerReply.GetString(strServerReply);
1266  }
1267  else {
1268  otErr << __FUNCTION__
1269  << ": Error: Unknown reply type received from "
1270  "server. (Expected envelope or message.)\n"
1271  "\n\n PERHAPS YOU ARE RUNNING AN OLD VERSION "
1272  "OF THE SERVER ????? \n\n";
1273  }
1274  OTMessage* pServerReply(new OTMessage());
1275  OT_ASSERT(nullptr != pServerReply);
1276 
1277  if (bRetrievedReply && strServerReply.Exists() &&
1278  pServerReply->LoadContractFromString(strServerReply)) {
1279  // Now the fully-loaded message object (from the server,
1280  // this time) can be processed by the OT library...
1281  m_pClient->ProcessServerReply(
1282  *pServerReply); // Client takes ownership and will
1283  // handle cleanup.
1284  }
1285  else {
1286  if (nullptr != pServerReply) delete pServerReply;
1287  pServerReply = nullptr; // cleanup
1288 
1289  otErr << __FUNCTION__
1290  << ": Error loading server reply from string:\n\n"
1291  << strRawServerReply << "\n\n";
1292  }
1293  } // !success receiving.
1294  } // else (bSuccessSending)
1295  } // if envelope exists.
1296  return true;
1297 }
EXPORT bool HasContext() const
Definition: OTSocket.cpp:289
bool ProcessServerReply(OTMessage &theReply, OTLedger *pNymbox=nullptr)
Definition: OTClient.cpp:3764
EXPORT bool IsInitialized() const
EXPORT std::mutex * GetMutex()
Definition: OTSocket.cpp:197
OTServerConnection * m_pConnection
Definition: OTClient.hpp:357
virtual EXPORT bool Send(const OTASCIIArmor &ascEnvelope)=0
#define OT_ASSERT(x)
Definition: Assert.hpp:150
virtual EXPORT bool NewContext()=0
#define OT_FAIL
Definition: Assert.hpp:139
virtual EXPORT bool Receive(OTString &strServerReply)=0
OTLOG_IMPORT OTLogStream otErr
OTPseudonym * GetNym() const
EXPORT bool IsInitialized() const
Definition: OTSocket.cpp:284
int32_t opentxs::OT_API::triggerClause ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const int64_t &  lTransactionNum,
const OTString strClauseName,
const OTString pStrParam = nullptr 
) const

Definition at line 11074 of file OpenTransactions.cpp.

11079 {
11080  OTPseudonym* pNym = GetOrLoadPrivateNym(
11081  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
11082  if (nullptr == pNym) return (-1);
11083  // By this point, pNym is a good pointer, and is on the wallet.
11084  // (No need to cleanup.)
11085  OTServerContract* pServer =
11086  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
11087  if (nullptr == pServer) return (-1);
11088  // By this point, pServer is a good pointer. (No need to cleanup.)
11089  OTMessage theMessage;
11090  int64_t lRequestNumber = 0;
11091 
11092  OTString strServerID(SERVER_ID), strNymID(USER_ID);
11093 
11094  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
11095  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
11096  theMessage.m_strRequestNum.Format(
11097  "%ld", lRequestNumber); // Always have to send this.
11098  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
11099  // server request, I have to
11100  // increment it
11101 
11102  // (1) set up member variables
11103  theMessage.m_strCommand = "triggerClause";
11104  theMessage.m_strNymID = strNymID;
11105  theMessage.m_strServerID = strServerID;
11106  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
11107  // theMessage.m_strServerID is already
11108  // set. (It uses it.)
11109 
11110  theMessage.m_lTransactionNum = lTransactionNum;
11111  theMessage.m_strNymID2 = strClauseName;
11112 
11113  // Optional string parameter. Available as "param_string"
11114  // inside the script.
11115  //
11116  if ((nullptr != pStrParam) && (pStrParam->Exists()))
11117  theMessage.m_ascPayload.SetString(*pStrParam); // <===
11118 
11119  OTIdentifier NYMBOX_HASH;
11120  const std::string str_server(strServerID.Get());
11121  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
11122  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11123 
11124  if (!bNymboxHash)
11125  otErr << "Failed getting NymboxHash from Nym for server: " << str_server
11126  << "\n";
11127 
11128  // (2) Sign the Message
11129  theMessage.SignContract(*pNym);
11130 
11131  // (3) Save the Message (with signatures and all, back to its internal
11132  // member m_strRawFile.)
11133  theMessage.SaveContract();
11134 
11135  // (Send it)
11136  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
11137  m_pClient->ProcessMessageOut(theMessage);
11138 
11139  return m_pClient->CalcReturnVal(lRequestNumber);
11140 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
OTLOG_IMPORT OTLogStream otErr
int32_t opentxs::OT_API::usageCredits ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier USER_ID_CHECK,
int64_t  lAdjustment = 0 
) const

Definition at line 13532 of file OpenTransactions.cpp.

13536 {
13537  OTPseudonym* pNym = GetOrLoadPrivateNym(
13538  USER_ID, false, __FUNCTION__); // This ASSERTs and logs already.
13539  if (nullptr == pNym) return (-1);
13540  // By this point, pNym is a good pointer, and is on the wallet.
13541  // (No need to cleanup.)
13542  OTServerContract* pServer =
13543  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
13544  if (nullptr == pServer) return (-1);
13545  // By this point, pServer is a good pointer. (No need to cleanup.)
13546  OTMessage theMessage;
13547  int64_t lRequestNumber = 0;
13548 
13549  OTString strServerID(SERVER_ID), strNymID(USER_ID),
13550  strNymID2(USER_ID_CHECK);
13551 
13552  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
13553  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
13554  theMessage.m_strRequestNum.Format(
13555  "%ld", lRequestNumber); // Always have to send this.
13556  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
13557  // server request, I have to
13558  // increment it
13559 
13560  // (1) set up member variables
13561  theMessage.m_strCommand = "usageCredits";
13562  theMessage.m_strNymID = strNymID;
13563  theMessage.m_strNymID2 = strNymID2;
13564  theMessage.m_strServerID = strServerID;
13565  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
13566  // theMessage.m_strServerID is already
13567  // set. (It uses it.)
13568 
13569  theMessage.m_lDepth = lAdjustment; // Default is "no adjustment"
13570  // (@usageCredits returns current balance
13571  // regardless.)
13572 
13573  // (2) Sign the Message
13574  theMessage.SignContract(*pNym);
13575 
13576  // (3) Save the Message (with signatures and all, back to its internal
13577  // member m_strRawFile.)
13578  theMessage.SaveContract();
13579 
13580  // (Send it)
13581  m_pClient->SetFocusToServerAndNym(*pServer, *pNym, m_pTransportCallback);
13582  m_pClient->ProcessMessageOut(theMessage);
13583 
13584  return m_pClient->CalcReturnVal(lRequestNumber);
13585 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool opentxs::OT_API::VerifyAccountReceipt ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCOUNT_ID 
) const

=== Verify Account Receipt === Returns bool. Verifies any asset account (intermediary files) against its own last signed receipt. Obviously this will fail for any new account that hasn't done any transactions yet, and thus has no receipts.

=== Verify Account Receipt === Returns bool. Verifies any asset account (intermediary files) against its own last signed receipt. Obviously this will fail for any new account that hasn't done any transactions yet (and thus has no receipts.)

Definition at line 3630 of file OpenTransactions.cpp.

3633 {
3634  OTPseudonym* pNym = GetOrLoadPrivateNym(
3635  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
3636  if (nullptr == pNym) return false;
3637  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3638  // cleanup.)
3639  OTServerContract* pServer =
3640  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
3641  if (nullptr == pServer) return false;
3642  // By this point, pServer is a good pointer. (No need to cleanup.)
3643  OTPseudonym* pServerNym =
3644  const_cast<OTPseudonym*>(pServer->GetContractPublicNym());
3645  if (nullptr == pServerNym) {
3646  otErr << "OT_API::VerifyAccountReceipt: should never happen. "
3647  "pServerNym is nullptr.\n";
3648  return false;
3649  }
3650  return VerifyBalanceReceipt(*pServerNym, *pNym, SERVER_ID, ACCOUNT_ID);
3651 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::VerifyAndRetrieveXMLContents ( const OTString strContract,
const OTIdentifier theSignerNymID,
OTString strOutput 
)

Verify and Retrieve XML Contents.

Definition at line 3600 of file OpenTransactions.cpp.

3603 {
3604  OTContract* pContract = nullptr;
3605  const bool bSuccess =
3606  VerifySignature(strContract, theSignerNymID, &pContract);
3607  //
3608  // If pContract is not nullptr after the above call, then this Cleanup
3609  // object
3610  // will clean it up after we leave the scope of this block.
3611  //
3612  std::unique_ptr<OTContract> theAngel(pContract);
3613  strOutput.Release();
3614 
3615  if (nullptr !=
3616  pContract) // pContract will always exist, if we were successful.
3617  return (bSuccess && pContract->SaveContractRaw(strOutput));
3618 
3619  return bSuccess; // In practice this will only happen on failure. (Could
3620  // have put "return false".)
3621 }
EXPORT bool VerifySignature(const OTString &strContract, const OTIdentifier &theSignerNymID, OTContract **ppContract=nullptr) const
bool opentxs::OT_API::VerifySignature ( const OTString strContract,
const OTIdentifier theSignerNymID,
OTContract **  ppContract = nullptr 
) const

OT-Verify the signature on a CONTRACT. Returns true/false (success/fail)

OT-Verify the signature on a CONTRACT. Returns true/false (success/fail)

NOTICE that ppContract can be set, EVEN WHEN THIS RETURNS FALSE! Therefore, if you are low-level enough to actually be passing ppContract in here, then you had better check it, after the call, whether it returns success or fail! Either way, that pointer could be set, in which case YOU are responsible to clean it up! Check that pointer for nullptr!

if (!pContract->VerifyContract())    // This calls

VerifyContractID(), then GetContractPublicNym(), then VerifySignature() (with that Nym)

Definition at line 3513 of file OpenTransactions.cpp.

3522 {
3523  OTPasswordData thePWData(OT_PW_DISPLAY);
3524  OTPseudonym* pNym =
3525  GetOrLoadNym(theSignerNymID, false, __FUNCTION__,
3526  &thePWData); // This logs and ASSERTs already.
3527  if (nullptr == pNym) return false;
3528  // By this point, pNym is a good pointer, and is on the wallet. (No need to
3529  // cleanup.)
3530  if (!strContract.Exists()) {
3531  otOut << "OT_API::VerifySignature: Empty contract passed in. "
3532  "(Returning false.)\n";
3533  return false;
3534  }
3535  //
3536  OTContract* pContract = nullptr;
3537  std::unique_ptr<OTContract> theAngel;
3538 
3539  if (nullptr == pContract)
3540  pContract = OTTransactionType::TransactionFactory(strContract);
3541 
3542  if (nullptr == pContract)
3543  pContract = OTScriptable::InstantiateScriptable(strContract);
3544 
3545  if (nullptr == pContract) pContract = ::InstantiateContract(strContract);
3546 
3547  if (nullptr == pContract) {
3548  otOut << "OT_API::VerifySignature: I tried my best. Unable to "
3549  "instantiate contract passed in:\n\n" << strContract << "\n\n";
3550  return false;
3551  }
3552  // Since we created it ourselves using a factory, we can do this:
3553 
3554  // The caller wants to take the contract for himself, without us cleaning
3555  // it up in here.
3556  //
3557  if (nullptr != ppContract) *ppContract = pContract;
3558  // Else, we will clean it up ourselves...
3559  else
3560  theAngel.reset(pContract);
3561  // if (!pContract->VerifyContractID())
3565  // { // Therefore it's only
3566  // useful for server contracts and asset contracts. Here we can VerifyID and
3567  // Signature,
3568  // // and that's good enough
3569  // for here and most other places, generically speaking.
3570  // otOut << "OT_API::VerifySignature: Unable to verify
3571  // contract ID for contract passed in. NOTE: If you are experiencing "
3572  // "a problem here, CONTACT FELLOW TRAVELER and let
3573  // him know WHAT KIND OF CONTRACT, and what symptoms you are seeing, "
3574  // "versus what you were expecting to see. Contract
3575  // contents:\n\n" << strContract << "\n\n";
3576  // return false;
3577  // }
3578 
3579  if (!pContract->VerifySignature(*pNym)) {
3580  OTString strSignerNymID(theSignerNymID);
3581  otOut << "OT_API::VerifySignature: For Nym (" << strSignerNymID
3582  << "), unable to "
3583  "verify signature on contract passed in:\n\n" << strContract
3584  << "\n\n";
3585  return false;
3586  }
3587 
3588  return true;
3589 }
EXPORT OTPseudonym * GetOrLoadNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr) const
static EXPORT OTTransactionType * TransactionFactory(OTString strInput)
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
OTLOG_IMPORT OTLogStream otOut
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
bool opentxs::OT_API::Wallet_CanRemoveAccount ( const OTIdentifier ACCOUNT_ID) const

Definition at line 2332 of file OpenTransactions.cpp.

2333 {
2334  bool bInitialized = OTAPI_Wrap::OTAPI()->IsInitialized();
2335  if (!bInitialized) {
2336  otErr << __FUNCTION__
2337  << ": Not initialized; call OT_API::Init first.\n";
2338  OT_FAIL;
2339  }
2340 
2341  if (ACCOUNT_ID.IsEmpty()) {
2342  otErr << __FUNCTION__ << ": Null: ACCOUNT_ID passed in!\n";
2343  OT_FAIL;
2344  }
2345 
2346  const OTString strAccountID(ACCOUNT_ID);
2347 
2348  OTAccount* pAccount =
2349  OTAPI_Wrap::OTAPI()->GetAccount(ACCOUNT_ID, __FUNCTION__);
2350  if (nullptr == pAccount) return false;
2351  // Balance must be zero in order to close an account!
2352  else if (pAccount->GetBalance() != 0) {
2353  otOut << __FUNCTION__
2354  << ": Account balance MUST be zero in order to close "
2355  "an asset account: " << strAccountID << ".\n";
2356  return false;
2357  }
2358  bool BOOL_RETURN_VALUE = false;
2359 
2360  const OTIdentifier& theServerID = pAccount->GetPurportedServerID();
2361  const OTIdentifier& theUserID = pAccount->GetUserID();
2362 
2363  // There is an OT_ASSERT in here for memory failure,
2364  // but it still might return nullptr if various verification fails.
2365  std::unique_ptr<OTLedger> pInbox(
2366  OTAPI_Wrap::OTAPI()->LoadInbox(theServerID, theUserID, ACCOUNT_ID));
2367  std::unique_ptr<OTLedger> pOutbox(
2368  OTAPI_Wrap::OTAPI()->LoadOutbox(theServerID, theUserID, ACCOUNT_ID));
2369 
2370  if (nullptr == pInbox) {
2371  otOut << __FUNCTION__
2372  << ": Failure calling OT_API::LoadInbox.\n Account ID: "
2373  << strAccountID << "\n";
2374  }
2375  else if (nullptr == pOutbox) {
2376  otOut << __FUNCTION__
2377  << ": Failure calling OT_API::LoadOutbox.\n Account ID: "
2378  << strAccountID << "\n";
2379  }
2380  else if ((pInbox->GetTransactionCount() > 0) ||
2381  (pOutbox->GetTransactionCount() > 0)) {
2382  otOut << __FUNCTION__
2383  << ": Failure: You cannot remove an asset account if "
2384  "there are inbox/outbox items still waiting to be "
2385  "processed.\n";
2386  }
2387  else
2388  BOOL_RETURN_VALUE = true; // SUCCESS!
2389 
2390  return BOOL_RETURN_VALUE;
2391 }
EXPORT OTLedger * LoadInbox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTLedger * LoadOutbox(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID) const
EXPORT bool IsInitialized() const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_API * OTAPI()
Definition: OTAPI.cpp:244
bool opentxs::OT_API::Wallet_CanRemoveAssetType ( const OTIdentifier ASSET_ID) const

Definition at line 2200 of file OpenTransactions.cpp.

2201 {
2202  bool bInitialized = OTAPI_Wrap::OTAPI()->IsInitialized();
2203  if (!bInitialized) {
2204  otErr << __FUNCTION__
2205  << ": Not initialized; call OT_API::Init first.\n";
2206  OT_FAIL;
2207  }
2208 
2209  if (ASSET_ID.IsEmpty()) {
2210  otErr << __FUNCTION__ << ": Null: ASSET_ID passed in!\n";
2211  OT_FAIL;
2212  }
2213  OTString strName;
2214  const int32_t nCount = OTAPI_Wrap::OTAPI()->GetAccountCount();
2215 
2216  // Loop through all the accounts.
2217  for (int32_t i = 0; i < nCount; i++) {
2218  OTIdentifier accountID;
2219 
2220  OTAPI_Wrap::OTAPI()->GetAccount(i, accountID, strName);
2221  OTAccount* pAccount =
2222  OTAPI_Wrap::OTAPI()->GetAccount(accountID, __FUNCTION__);
2223  OTIdentifier theTYPE_ID(pAccount->GetAssetTypeID());
2224 
2225  if (ASSET_ID == theTYPE_ID) {
2226  OTString strASSET_ID(ASSET_ID), strTYPE_ID(theTYPE_ID);
2227 
2228  otOut << __FUNCTION__ << ": Unable to remove asset contract "
2229  << strASSET_ID << " from wallet: Account " << strTYPE_ID
2230  << " uses it.\n";
2231  return false;
2232  }
2233  }
2234  return true;
2235 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT int32_t GetAccountCount() const
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_API * OTAPI()
Definition: OTAPI.cpp:244
bool opentxs::OT_API::Wallet_CanRemoveNym ( const OTIdentifier NYM_ID) const

Definition at line 2247 of file OpenTransactions.cpp.

2248 {
2249  bool bInitialized = OTAPI_Wrap::OTAPI()->IsInitialized();
2250  if (!bInitialized) {
2251  otErr << __FUNCTION__
2252  << ": Not initialized; call OT_API::Init first.\n";
2253  OT_FAIL;
2254  }
2255 
2256  if (NYM_ID.IsEmpty()) {
2257  otErr << __FUNCTION__ << ": Null: NYM_ID passed in!\n";
2258  OT_FAIL;
2259  }
2260 
2261  OTPseudonym* pNym = OTAPI_Wrap::OTAPI()->GetNym(NYM_ID, __FUNCTION__);
2262  if (nullptr == pNym) return false;
2263  // Make sure the Nym doesn't have any accounts in the wallet.
2264  // (Client must close those before calling this.)
2265  //
2266  const int32_t nCount = OTAPI_Wrap::OTAPI()->GetAccountCount();
2267 
2268  // Loop through all the accounts.
2269  for (int32_t i = 0; i < nCount; i++) {
2270  OTIdentifier accountID;
2271  OTString strName;
2272 
2273  OTAPI_Wrap::OTAPI()->GetAccount(i, accountID, strName);
2274  OTAccount* pAccount =
2275  OTAPI_Wrap::OTAPI()->GetAccount(accountID, __FUNCTION__);
2276  OTIdentifier theNYM_ID(pAccount->GetUserID());
2277 
2278  if (theNYM_ID.IsEmpty()) {
2279  otErr << __FUNCTION__ << ": Bug in OT_API_Wallet_CanRemoveNym / "
2280  "OT_API_GetAccountWallet_NymID\n";
2281  return false;
2282  }
2283 
2284  // Looks like the Nym still has some accounts in this wallet.
2285  if (NYM_ID == theNYM_ID) {
2286  otOut << __FUNCTION__
2287  << ": Nym cannot be removed because there are "
2288  "still accounts in the wallet for that Nym.\n";
2289  return false;
2290  }
2291  }
2292 
2293  // Make sure the Nym isn't registered at any servers...
2294  // (Client must unregister at those servers before calling this function..)
2295  //
2296  const int32_t nServerCount = OTAPI_Wrap::OTAPI()->GetServerCount();
2297 
2298  for (int32_t i = 0; i < nServerCount; i++) {
2299  OTIdentifier theID;
2300  OTString strName;
2301  bool bGetServer = OTAPI_Wrap::OTAPI()->GetServer(i, theID, strName);
2302 
2303  if (bGetServer)
2304  if (!theID.IsEmpty()) {
2305  const OTString strServerID(theID);
2306 
2307  if (pNym->IsRegisteredAtServer(strServerID)) {
2308  otOut << __FUNCTION__
2309  << ": Nym cannot be removed because there "
2310  "are still servers in the wallet that "
2311  "the Nym is registered at.\n";
2312  return false;
2313  }
2314  }
2315  }
2316 
2317  // TODO: Make sure Nym doesn't have any cash in any purses...
2318 
2319  return true;
2320 }
EXPORT int32_t GetServerCount() const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT int32_t GetAccountCount() const
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_API * OTAPI()
Definition: OTAPI.cpp:244
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
bool opentxs::OT_API::Wallet_CanRemoveServer ( const OTIdentifier SERVER_ID) const

Definition at line 2135 of file OpenTransactions.cpp.

2136 {
2137  bool bInitialized = OTAPI_Wrap::OTAPI()->IsInitialized();
2138  if (!bInitialized) {
2139  otErr << __FUNCTION__
2140  << ": Not initialized; call OT_API::Init first.\n";
2141  OT_FAIL;
2142  }
2143  if (SERVER_ID.IsEmpty()) {
2144  otErr << __FUNCTION__ << ": Null: SERVER_ID passed in!\n";
2145  OT_FAIL;
2146  }
2147  OTString strName;
2148  const int32_t nCount = OTAPI_Wrap::OTAPI()->GetAccountCount();
2149 
2150  // Loop through all the accounts.
2151  for (int32_t i = 0; i < nCount; i++) {
2152  OTIdentifier accountID;
2153 
2154  OTAPI_Wrap::OTAPI()->GetAccount(i, accountID, strName);
2155  OTAccount* pAccount =
2156  OTAPI_Wrap::OTAPI()->GetAccount(accountID, __FUNCTION__);
2157 
2158  OTIdentifier purportedServerID(pAccount->GetPurportedServerID());
2159 
2160  if (SERVER_ID == purportedServerID) {
2161  OTString strPurportedServerID(purportedServerID),
2162  strSERVER_ID(SERVER_ID);
2163  otOut << __FUNCTION__ << ": Unable to remove server contract "
2164  << strSERVER_ID << " from wallet, because Account "
2165  << strPurportedServerID << " uses it.\n";
2166  return false;
2167  }
2168  }
2169 
2170  const int32_t nNymCount = OTAPI_Wrap::OTAPI()->GetNymCount();
2171 
2172  // Loop through all the Nyms. (One might be registered on that server.)
2173  //
2174  for (int32_t i = 0; i < nNymCount; i++) {
2175  OTIdentifier nymID;
2176  bool bGetNym = OTAPI_Wrap::OTAPI()->GetNym(i, nymID, strName);
2177 
2178  if (bGetNym)
2180  SERVER_ID)) {
2181  OTString strNymID(nymID), strSERVER_ID(SERVER_ID);
2182  otOut << __FUNCTION__ << ": Unable to remove server contract "
2183  << strSERVER_ID << " "
2184  "from wallet, because Nym " << strNymID
2185  << " is registered "
2186  "there. (Delete that first...)\n";
2187  return false;
2188  }
2189  }
2190  return true;
2191 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
EXPORT int32_t GetAccountCount() const
#define OT_FAIL
Definition: Assert.hpp:139
EXPORT bool IsNym_RegisteredAtServer(const OTIdentifier &NYM_ID, const OTIdentifier &SERVER_ID) const
OTLOG_IMPORT OTLogStream otErr
static EXPORT OT_API * OTAPI()
Definition: OTAPI.cpp:244
EXPORT bool GetNym(int32_t iIndex, OTIdentifier &NYM_ID, OTString &NYM_NAME) const
EXPORT int32_t GetNymCount() const
bool opentxs::OT_API::Wallet_ChangePassphrase ( ) const

Definition at line 1696 of file OpenTransactions.cpp.

1697 {
1698  bool bInitialized = OTAPI_Wrap::OTAPI()->IsInitialized();
1699  if (!bInitialized) {
1700  otErr << __FUNCTION__
1701  << ": Not initialized; call OT_API::Init first.\n";
1702  OT_FAIL;
1703  }
1704  OTWallet* pWallet = OTAPI_Wrap::OTAPI()->GetWallet(
1705  __FUNCTION__); // This logs and ASSERTs already.
1706  if (nullptr == pWallet) return false;
1707  // By this point, pWallet is a good pointer. (No need to cleanup.)
1708  OTString strReason("Enter existing wallet master passphrase");
1709 
1710  OTPassword old_passphrase;
1711  std::shared_ptr<OTCachedKey> ptrMasterKey(OTCachedKey::It());
1712  const bool bGotOldPassphrase =
1713  (ptrMasterKey && ptrMasterKey->IsGenerated() &&
1714  ptrMasterKey->GetMasterPassword(ptrMasterKey, old_passphrase,
1715  strReason.Get()));
1716  class ot_change_pw
1717  {
1718  std::list<OTPseudonym*>* m_plist_nyms; // We'll be responsible in this
1719  // class for cleaning these up.
1720 
1721  public:
1722  ot_change_pw(std::list<OTPseudonym*>& list_nyms)
1723  : m_plist_nyms(&list_nyms)
1724  {
1725  }
1726  ~ot_change_pw()
1727  {
1728  if (nullptr != m_plist_nyms) {
1729  while (!m_plist_nyms->empty()) // Here's the cleanup.
1730  {
1731  auto it = m_plist_nyms->begin();
1732  OTPseudonym* pNym = *it;
1733  OT_ASSERT(nullptr != pNym);
1734 
1735  delete pNym;
1736  pNym = nullptr;
1737  m_plist_nyms->erase(it);
1738  }
1739  }
1740  }
1741  };
1742  std::list<OTPseudonym*> list_nyms; // Any Nyms on this list will be cleaned
1743  // up automatically in the ot_change_pw
1744  // destructor. Thus
1745  ot_change_pw the_cleanup(list_nyms); // we cannot add Nyms here that are
1746  // also on the Wallet. We load our own
1747  // copies just for this list.
1748  bool bAtLeastOneNymHasCredentials = false;
1749  bool bSuccessLoading =
1750  true; // defaults to true in case there aren't any Nyms.
1751 
1752  // Loop through all the private Nyms and get them all loaded up into a list.
1753  //
1754  const int32_t nNymCount = pWallet->GetNymCount();
1755  for (int32_t iii = 0; iii < nNymCount; ++iii) {
1756  OTIdentifier NYM_ID;
1757  OTString NYM_NAME;
1758 
1759  const bool bGotNym = pWallet->GetNym(iii, NYM_ID, NYM_NAME);
1760  OT_ASSERT(bGotNym);
1761  const OTString strNymID(NYM_ID);
1762 
1763  // otherwise it's a public Nym, so we just skip it.
1764  if (OTPseudonym::DoesCertfileExist(strNymID)) // is there a private key
1765  // or credential available
1766  // for this Nym?
1767  { // In here, we know there's a private key...
1768 
1769  // CALLER responsible to delete!
1770  OTPseudonym* pNym = LoadPrivateNym(
1771  NYM_ID, false /*bChecking*/,
1772  __FUNCTION__); // This also loads credentials, if there are any.
1773 
1774  // We use LoadPrivateNym here instead. (meaning: need to clean them
1775  // up.)
1776  // Therefore use a nested class here to handle the cleanup.
1777  // This way we aren't changing the actual Nyms in the wallet until
1778  // it's re-loaded.
1779  // Any failure between now and then, and it's not re-loaded, and
1780  // none of the Nyms
1781  // were ever changed!
1782 
1783  if (nullptr == pNym) // Since we KNOW there's a private key, yet it
1784  // failed, therefore the user must have entered
1785  // the wrong password...
1786  {
1787  bSuccessLoading = false;
1788  break;
1789  }
1790  // else... (add to list for cleanup, on exit from this function.)
1791  list_nyms.push_back(pNym); // ONLY private Nyms, and they ALL must
1792  // successfully load and verify.
1793 
1794  if (pNym->GetMasterCredentialCount() > 0)
1795  bAtLeastOneNymHasCredentials = true;
1796  }
1797  }
1798  if (!bSuccessLoading) {
1799  otErr << __FUNCTION__
1800  << ": Error: Failed to load all the private Nyms. Wrong "
1801  "passphrase? (Aborting operation.)\n";
1802  return false;
1803  }
1804  // By this point we KNOW we have successfully loaded up ALL the private Nyms
1805  // for this wallet, and that list_nyms contains a pointer to each one...
1806  // ENCRYPT ALL CREDENTIALS FROM MASTER KEY INTO A TEMP KEY
1807  //
1808  OTPassword theTempPassword; // Used to store a temp password only. Only for
1809  // credentialed nyms.
1810  OTPasswordData thePWData("Enter existing wallet master passphrase");
1811 
1812  // At this point, for Nyms with credentials, we need to ReEncrypt the Nym's
1813  // credentials,
1814  // similar to importing or exporting the Nym from the wallet. Except this
1815  // time, we have
1816  // to ReEncrypt FROM a wallet-based Nym to a temporary passphrase, then
1817  // destroy and re-
1818  // create the wallet's cached master key, then ReEncrypt AGAIN from the
1819  // temporary passphrase
1820  // and back to the new master passphrase that was just generated.
1821  // Makes sense? It's the easiest way to do it based on the existing code we
1822  // have.
1823  //
1824  if (bAtLeastOneNymHasCredentials) // All the Nyms on our list are private,
1825  // by this point. And within this block,
1826  // they have credentials, too.
1827  {
1828  theTempPassword.randomizePassword(12); // the new random PW will be 12
1829  // bytes int64_t. (We discard it
1830  // after this function is done.)
1831  bool bSuccessReEncrypting = true;
1832  for (auto& it : list_nyms) {
1833  OTPseudonym* pNym = it;
1834  OT_ASSERT(nullptr != pNym);
1835  // We know at least one Nym has credentials. Does this one?
1836  //
1837  if (pNym->GetMasterCredentialCount() >
1838  0) // If this specific Nym has credentials...
1839  {
1840  // It won't ask for a passphrase when using the temp password,
1841  // since it already
1842  // has the password. So it will only ask for a passphrase when
1843  // it is NOT using
1844  // the temp password, e.g. when using the wallet's cached master
1845  // key. ABOVE (here)
1846  // that will be the OLD master key, and BELOW (after the master
1847  // key is re-created)
1848  // that will be the NEW master key.
1849  // That's why here, it says: "Enter your EXISTING wallet master
1850  // passphrase."
1851  //
1852  const bool bExported = pNym->ReEncryptPrivateCredentials(
1853  false /* (EXPORTING) bImporting=FALSE */, &thePWData,
1854  &theTempPassword);
1855  if (!bExported) {
1856  bSuccessReEncrypting = false; // At least this way if
1857  // there's a failure, it's
1858  // equally to all the Nyms,
1859  // and not halfway through.
1860  }
1861  }
1862  }
1863  if (!bSuccessReEncrypting) // FAILURE
1864  {
1865  otErr
1866  << __FUNCTION__
1867  << ": Failed trying to re-encrypt Nym's private credentials.\n";
1868  return false; // Nyms are cleaned up automatically when we return.
1869  }
1870  }
1871  // By this point, if there were credentials on any of the Nyms, they are all
1872  // now converted
1873  // (in RAM, not in local storage) to the temp password, and OUT of the
1874  // wallet's master key
1875  // (which we're about to destroy and re-create.)
1876  // Destroy the wallet's cached master key (in Ram, not on disk--yet.)
1877  //
1878  OTASCIIArmor ascBackup;
1879  OTCachedKey::It()->SerializeTo(ascBackup); // Just in case!
1880  OTCachedKey::It()->ResetMasterPassword(); // Which will force it to be
1881  // re-created next time someone
1882  // tries to use it...
1883 
1884  // NOTE: Below this point we cannot return without setting the master
1885  // passphrase BACK.
1886  // GENERATE the wallet's NEW MASTER KEY.
1887  //
1888  strReason.Set("Choose a new passphrase: ");
1889 
1890  // This step would be unnecessary if we knew for a fact that at least
1891  // one Nym exists. But in the off-chance that there ARE NO NYMS in the
1892  // wallet, we need to have this here, in order to MAKE SURE that the new
1893  // master key is generated. Otherwise it would never end up actually having
1894  // to generate the thing. (Since, if there are no Nyms to re-save, it would
1895  // never need to actually retrieve the master key, which is what triggers it
1896  // to generate if it's not already there.) So we just force that step here,
1897  // to make sure it happens, even if there are no Nyms to save below this
1898  // point.
1899  //
1900  OTPassword new_passphrase;
1901  std::shared_ptr<OTCachedKey> sharedPtr(OTCachedKey::It());
1902  const bool bRegenerate =
1903  sharedPtr->GetMasterPassword(sharedPtr, new_passphrase, strReason.Get(),
1904  true); // bVerifyTwice=false by default.
1905  if (!bRegenerate) // Failure generating new master key.
1906  {
1907  otErr << __FUNCTION__ << ": Error: Failed while trying to regenerate "
1908  "master key, in call: "
1909  "OTCachedKey::It()->GetMasterPassword. "
1910  "(Setting it back to the old "
1911  "one.)\n";
1912  if (!OTCachedKey::It()->SerializeFrom(ascBackup))
1913  otErr << __FUNCTION__
1914  << ": Error: Failed while trying to restore master "
1915  "key, in call: "
1916  "OTCachedKey::It()->GetMasterPassword. (While "
1917  "setting it back to the old one.)\n"
1918  "Original value: \n" << ascBackup << "\n";
1919  // todo security: is
1920  // it risky to have
1921  // the key displayed
1922  // in this log?
1923  return false;
1924  //
1925  // NOTE: Since we loaded our own copies of the Nyms, we haven't changed
1926  // the copies in the wallet,
1927  // nor the wallet itself. So we can just return, since our copies of the
1928  // Nyms will already be cleaned
1929  // up automatically.
1930  }
1931  else // SUCCESS creating new master key, so let's CONVERT AND RE-SAVE ALL
1932  { // THE NYMS, so they'll be using it from now on...
1933 
1934  // (Master key would normally be generated here, if we hadn't already
1935  // forced it above,
1936  // but we did that to make sure it got re-created in the event there are
1937  // zero nyms.)
1938 
1939  // Todo: save them to temp files and only copy over if everything
1940  // else is successful. Same with wallet. Also make backups.
1941  //
1942  bool bSuccessResaving =
1943  true; // in case the list is empty, we assume success here.
1944 
1945  // Let's save all these Nyms under the new master key.
1946  for (auto& it : list_nyms) {
1947  OTPseudonym* pNym = it;
1948  OT_ASSERT(nullptr != pNym);
1949  bool bSaved = false;
1950 
1951  // CREDENTIALS - Nym has credentials
1952  if (pNym->GetMasterCredentialCount() > 0) {
1953  // We had converted the Nyms to a temp key above, so now we need
1954  // to convert
1955  // from the temp key to the new wallet key. Then we can save
1956  // them and re-load
1957  // the wallet.
1958  //
1959  // We're supplying the temp password (from above), and importing
1960  // the Nyms back
1961  // from that, back into to the wallet's new master key. So it
1962  // will only ask
1963  // for a passphrase for the wallet, since the other passphrase
1964  // is already provided.
1965  // Therefore thePWData is relevant to the wallet only.
1966  //
1967  bool bSavedCredentials = false;
1968  const bool bImported = pNym->ReEncryptPrivateCredentials(
1969  true /*bImporting*/, // <==== CONVERT FROM TEMP PW TO NEW
1970  // MASTER KEY.
1971  &thePWData, &theTempPassword);
1972  if (bImported) // Success? Okay, let's Save those credentials we
1973  // just imported, to local storage.
1974  {
1975  bSavedCredentials = true;
1976  OTString strNymID, strCredList, strOutput;
1977  OTString::Map mapCredFiles;
1978 
1979  pNym->GetIdentifier(strNymID);
1980  pNym->GetPrivateCredentials(strCredList, &mapCredFiles);
1981  OTString strFilename;
1982  strFilename.Format("%s.cred", strNymID.Get());
1983  OTASCIIArmor ascArmor(strCredList);
1984  if (ascArmor.Exists() &&
1985  ascArmor.WriteArmoredString(
1986  strOutput,
1987  "CREDENTIAL LIST") && // bEscaped=false by default.
1988  strOutput.Exists()) {
1990  strOutput.Get(), OTFolders::Credential().Get(),
1991  strFilename.Get())) {
1992  otErr << __FUNCTION__
1993  << ": After converting credentials to "
1994  "new master key, failure trying to "
1995  "store private "
1996  "credential list for Nym: " << strNymID
1997  << "\n";
1998  bSavedCredentials = false;
1999  }
2000  }
2001  // Here we do the actual credentials.
2002  for (auto& it : mapCredFiles) {
2003  std::string str_cred_id = it.first;
2004  OTString strCredential(it.second);
2005  strOutput.Release();
2006  OTASCIIArmor ascLoopArmor(strCredential);
2007  if (ascLoopArmor.Exists() &&
2008  ascLoopArmor.WriteArmoredString(
2009  strOutput,
2010  "CREDENTIAL") && // bEscaped=false by default.
2011  strOutput.Exists()) {
2013  strOutput.Get(),
2015  strNymID.Get(), str_cred_id)) {
2016  otErr << __FUNCTION__
2017  << ": After converting "
2018  "credentials to new master key, "
2019  "failure trying to store private "
2020  "credential for Nym: " << strNymID
2021  << "\n";
2022  bSavedCredentials = false;
2023  }
2024  }
2025  }
2026  }
2027  bSaved = bImported && bSavedCredentials;
2028  } // If Nym has credentials. (Convert and save them, in the above
2029  // block.)
2030  else // Old-school: the old nyms (from before credentials code)
2031  // merely need to have their cert saved (here), which process
2032  // will automatically use the current (new) master key to
2033  // encrypt the private portion of that cert when saving. So it
2034  // gets converted and saved all in this one call. For new-style
2035  // Nyms (with credentials) see the above block instead.
2036  //
2037  bSaved = pNym->Savex509CertAndPrivateKey(true, &strReason);
2038  if (!bSaved) bSuccessResaving = false;
2039  }
2040  if (!bSuccessResaving) // Failed saving all the Nyms after switching
2041  // their credentials over.
2042  {
2043  OTASCIIArmor ascBackup2;
2044  OTCachedKey::It()->SerializeTo(ascBackup2); // Just in case!
2045  otErr << __FUNCTION__
2046  << ": ERROR: Failed re-saving Nym (into new Master "
2047  "Key.) It's possible "
2048  "some Nyms are already saved on the new key, while "
2049  "others are still stuck "
2050  "on the old key!! Therefore, asserting now. OLD KEY "
2051  "was:\n" << ascBackup << "\n\n NEW KEY is: " << ascBackup2
2052  << "\n";
2053  // Todo: security: keys are exposed
2054  // here. Is this log safe?
2055  OT_FAIL_MSG("ASSERT while trying to change wallet's master key and "
2056  "passphrase.\n");
2057  }
2058  else // SAVE THE WALLET.
2059  {
2060  // We've converted all the Nyms, so let's go ahead and convert the
2061  // extra
2062  // symmetric keys inside the wallet. (These are what a client app
2063  // might
2064  // use to encrypt its local database.)
2065  //
2066  if (bGotOldPassphrase) {
2067  if (!pWallet->ChangePassphrasesOnExtraKeys(old_passphrase,
2068  new_passphrase))
2069  otErr << __FUNCTION__
2070  << ": ERROR: "
2071  "pWallet->ChangePassphrasesOnExtraKeys "
2072  "failed. "
2073  "(Continuing, but your extra symmetric keys "
2074  "in the wallet "
2075  "may be messed up!)\n";
2076  }
2077  // By this point, we have successfully converted all the Nyms (our
2078  // local copies of the wallet's private nyms)
2079  // to the new master key, AND we have successfully saved those Nyms
2080  // to local storage. Now, if we just save and
2081  // re-load the wallet itself, it should load up using the new master
2082  // key, and it should load up its own copies
2083  // of those same Nyms again, using that new master key to decrypt
2084  // them. (Those new copies of those Nyms being
2085  // the ones that we saved to local storage just above, using our
2086  // local copies.)
2087  //
2088  // With the wallet updated thus, we can simply discard the local
2089  // copies, which will have outlived their usefulness.
2090  // They will already be destroyed on exit, automatically.
2091  //
2092  bool bLoaded = false;
2093  const bool bSaved = pWallet->SaveWallet();
2094  if (bSaved) // Next, re-load it so the Nyms we've changed will be
2095  // loaded up in their new forms. (The nyms local to this
2096  // function will be destroyed on exit, but they are
2097  // separate from the nyms in the wallet, which will
2098  // appear in their new forms upon loading, presuming the
2099  // Nyms were successfully saved above.)
2100  //
2101  bLoaded = pWallet->LoadWallet();
2102  else
2103  otErr << __FUNCTION__ << ": Failed saving wallet \n";
2104  if (!bLoaded) {
2105  OTASCIIArmor ascBackup2;
2106  OTCachedKey::It()->SerializeTo(ascBackup2); // Just in case!
2107  // Note: if we even got this far, that means we already saved
2108  // the Nyms under the new master Key,
2109  // to local storage. Therefore we NEED that new key, if it
2110  // wasn't properly saved in the wallet file
2111  // just now! (And we need to have made a real backup of the
2112  // wallet before attempting this...todo.)
2113  // In the meantime, the best thing we can do is just LOG that
2114  // key here, and hope the server operator
2115  // still has the log! Log both keys (new and old.)
2116  otErr
2117  << __FUNCTION__
2118  << ": ERROR: Failed saving or re-loading Wallet (with new "
2119  "Master Key.) "
2120  "Asserting now. OLD KEY was:\n" << ascBackup
2121  << "\n\n NEW KEY is: " << ascBackup2 << "\n";
2122  // Todo: security: keys are exposed here.
2123  // Is this log safe?
2124  OT_FAIL_MSG("ASSERT while trying to save and re-load wallet "
2125  "with new master key and passphrase.\n");
2126  }
2127  else
2128  otOut << "\nSuccess changing master passphrase for wallet!\n";
2129  return bLoaded;
2130  }
2131  }
2132  return false;
2133 }
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:698
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
static EXPORT bool DoesCertfileExist(const OTString &strNymID)
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
static EXPORT const OTString & Credential()
Definition: OTFolders.cpp:307
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_FAIL
Definition: Assert.hpp:139
#define OT_FAIL_MSG(s)
Definition: Assert.hpp:144
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT OTPseudonym * LoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT OT_API * OTAPI()
Definition: OTAPI.cpp:244
bool opentxs::OT_API::Wallet_ExportCert ( const OTIdentifier NYM_ID,
OTString strOutput 
) const

Definition at line 3092 of file OpenTransactions.cpp.

3094 {
3095  if (NYM_ID.IsEmpty()) {
3096  otErr << __FUNCTION__ << ": NYM_ID is empty!";
3097  OT_FAIL;
3098  }
3099  OTPasswordData thePWDataLoad(
3100  "Need Wallet Master passphrase to export any Cert.");
3101  OTPasswordData thePWDataSave("Create new passphrase for exported Cert.");
3102  OTString strReasonToSave(thePWDataSave.GetDisplayString());
3103  OTPseudonym* pNym =
3104  GetOrLoadPrivateNym(NYM_ID, false, __FUNCTION__,
3105  &thePWDataLoad); // This logs and ASSERTs already.
3106  if (nullptr == pNym) return false;
3107  // Pause the master key before exporting, since we want to save this Nym
3108  // WITHOUT the master key, which it will no longer have, outside of this
3109  // wallet.
3110  //
3111  if (!(OTCachedKey::It()->isPaused())) {
3112  OTCachedKey::It()->Pause();
3113  }
3114  OTString strCertfile;
3115  const bool bSavedCert =
3116  pNym->Savex509CertAndPrivateKeyToString(strCertfile, &strReasonToSave);
3117  // Unpause the master key.
3118  //
3119  if (OTCachedKey::It()->isPaused()) {
3120  OTCachedKey::It()->Unpause();
3121  }
3122  if (!bSavedCert) {
3123  otErr << __FUNCTION__
3124  << ": Failed while calling "
3125  "pNym->Savex509CertAndPrivateKeyToString(strCertfile, "
3126  "\"" << thePWDataSave.GetDisplayString() << "\")\n";
3127  return false;
3128  }
3129  if (strCertfile.Exists()) {
3130  strOutput.Concatenate("%s", strCertfile.Get());
3131  return true;
3132  }
3133 
3134  return false;
3135 }
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Wallet_ExportNym ( const OTIdentifier NYM_ID,
OTString strOutput 
) const

Definition at line 2543 of file OpenTransactions.cpp.

2545 {
2546  if (NYM_ID.IsEmpty()) {
2547  otErr << __FUNCTION__ << ": NYM_ID is empty!";
2548  OT_FAIL;
2549  }
2550  OTPasswordData thePWDataLoad("Enter wallet master passphrase.");
2551  OTPasswordData thePWDataSave("Create new passphrase for exported Nym.");
2552  OTString strReasonToSave(thePWDataSave.GetDisplayString());
2553  OTPseudonym* pNym =
2554  GetOrLoadPrivateNym(NYM_ID, false, __FUNCTION__,
2555  &thePWDataLoad); // This logs and ASSERTs already.
2556  if (nullptr == pNym) return false;
2557  std::string str_nym_name(pNym->GetNymName().Get());
2558  OTString strID;
2559  pNym->GetIdentifier(strID);
2560  std::string str_nym_id(strID.Get());
2561  // Below this point I can use:
2562  //
2563  // pNym, str_nym_name, and str_nym_id.
2564  //
2565  // I still need the certfile and the nymfile (both in string form.)
2566  //
2567  const bool bHasCredentials = (pNym->GetMasterCredentialCount() > 0);
2568 
2569  OTASCIIArmor ascCredentials, ascCredList;
2570  OTString strCertfile;
2571  bool bSavedCert = false;
2572  if (!bHasCredentials) {
2573  if (!OTCachedKey::It()->isPaused()) {
2574  OTCachedKey::It()->Pause();
2575  }
2576  bSavedCert = pNym->Savex509CertAndPrivateKeyToString(strCertfile,
2577  &strReasonToSave);
2578  if (OTCachedKey::It()->isPaused()) {
2579  OTCachedKey::It()->Unpause();
2580  }
2581  }
2582  else {
2583  // We don't have to pause OTCachedKey here like we did above, because
2584  // this already has built-in mechanisms to go around OTCachedKey.
2585  //
2586  const bool bReEncrypted = pNym->ReEncryptPrivateCredentials(
2587  false /*bImporting*/,
2588  &thePWDataSave); // Handles OTCachedKey already.
2589  if (bReEncrypted) {
2590  // Create a new OTDB::StringMap object.
2591 
2592  // this asserts already, on failure.
2593  std::unique_ptr<OTDB::Storable> pStorable(
2595  OTDB::StringMap* pMap =
2596  dynamic_cast<OTDB::StringMap*>(pStorable.get());
2597  if (nullptr == pMap)
2598  otErr << __FUNCTION__
2599  << ": Error: failed trying to load or create a "
2600  "STORED_OBJ_STRING_MAP.\n";
2601  else // It instantiated.
2602  {
2603  OTString strCredList;
2604  OTString::Map& theMap = pMap->the_map;
2605 
2606  pNym->GetPrivateCredentials(strCredList, &theMap);
2607  // Serialize the StringMap to a string...
2608 
2609  // Won't bother if there are zero credentials somehow.
2610  if (strCredList.Exists() && (!theMap.empty())) {
2611  std::string str_Encoded = OTDB::EncodeObject(*pMap);
2612  const bool bSuccessEncoding = (str_Encoded.size() > 0);
2613  if (bSuccessEncoding) {
2614  ascCredList.SetString(
2615  strCredList); // <========== Success
2616  ascCredentials.Set(
2617  str_Encoded.c_str()); // Payload contains
2618  // credentials list, payload2
2619  // contains actual
2620  // credentials.
2621  bSavedCert = true;
2622  }
2623  }
2624  }
2625  } // bReEncrypted.
2626  } // bHasCredentials==true
2627  if (!bSavedCert) {
2628  otErr << __FUNCTION__
2629  << ": Failed while saving Nym's private cert, or private "
2630  "credentials, to string.\n"
2631  "Reason I was doing this: \""
2632  << thePWDataSave.GetDisplayString() << "\"\n";
2633  return false;
2634  }
2635  OTString strNymfile;
2636  const bool bSavedNym = pNym->SavePseudonym(strNymfile);
2637 
2638  if (!bSavedNym) {
2639  otErr << __FUNCTION__
2640  << ": Failed while calling "
2641  "pNym->SavePseudonym(strNymfile) (to string)\n";
2642  return false;
2643  }
2644  // Create an OTDB::StringMap object.
2645  //
2646  // Set the name, id, [certfile|credlist credentials], and nymfile onto it.
2647  // (Our exported
2648  // Nym appears as an ASCII-armored text to the naked eye, but when loaded up
2649  // in code it
2650  // appears as a map of strings: name, id, [certfile|credlist credentials],
2651  // and nymfile.)
2652 
2653  // this asserts already, on failure.
2654  std::unique_ptr<OTDB::Storable> pStorable(
2656  OTDB::StringMap* pMap = dynamic_cast<OTDB::StringMap*>(pStorable.get());
2657  // It exists.
2658  //
2659  if (nullptr == pMap) {
2660  otErr << __FUNCTION__ << ": Error: failed trying to load or create a "
2661  "STORED_OBJ_STRING_MAP.\n";
2662  return false;
2663  }
2664  OTString::Map& theMap = pMap->the_map;
2665  theMap["id"] = str_nym_id;
2666  theMap["name"] = str_nym_name;
2667  theMap["nymfile"] = strNymfile.Get();
2668 
2669  if (strCertfile.Exists()) theMap["certfile"] = strCertfile.Get();
2670 
2671  if (ascCredList.Exists()) theMap["credlist"] = ascCredList.Get();
2672 
2673  if (ascCredentials.Exists()) theMap["credentials"] = ascCredentials.Get();
2674  // Serialize the StringMap to a string...
2675  //
2676  std::string str_Encoded = OTDB::EncodeObject(*pMap);
2677  bool bReturnVal = (str_Encoded.size() > 0);
2678 
2679  if (bReturnVal) {
2680  OTASCIIArmor ascTemp;
2681  ascTemp.Set(str_Encoded.c_str());
2682  strOutput.Release();
2683  bReturnVal = ascTemp.WriteArmoredString(
2684  strOutput, "EXPORTED NYM" // -----BEGIN OT EXPORTED NYM-----
2685  ); // (bool bEscaped=false by default.)
2686  }
2687 
2688  return bReturnVal;
2689 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
EXPORT Storable * CreateObject(StoredObjectType eType)
Definition: OTStorage.cpp:530
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
EXPORT std::string EncodeObject(Storable &theContents)
Definition: OTStorage.cpp:818
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Wallet_ImportCert ( const OTString DISPLAY_NAME,
const OTString FILE_CONTENTS,
OTIdentifier pNymID = nullptr 
) const

Definition at line 3018 of file OpenTransactions.cpp.

3021 {
3022  OTWallet* pWallet =
3023  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
3024  if (nullptr == pWallet) return false;
3025  // By this point, pWallet is a good pointer. (No need to cleanup.)
3026 
3027  // Do various verifications on the values to make sure there's no funny
3028  // business.
3029  //
3030  // If Nym with this ID is ALREADY in the wallet, set pNymID and return
3031  // false.
3032  // Create a new Nym object.
3033  //
3034  std::unique_ptr<OTPseudonym> pNym(new OTPseudonym);
3035 
3036  if (DISPLAY_NAME.Exists()) pNym->SetNymName(DISPLAY_NAME);
3037  // Pause the master key, since this Nym is coming from outside
3038  // the wallet.
3039  //
3040  if (!(OTCachedKey::It()->isPaused())) {
3041  OTCachedKey::It()->Pause();
3042  }
3043  // Set the public and private keys on the new Nym object based on the
3044  // certfile from the StringMap.
3045  //
3046  OTPasswordData thePWData("To import this Cert, what is its passphrase? ");
3047  const bool bIfNymLoadKeys =
3048  pNym->Loadx509CertAndPrivateKeyFromString(FILE_CONTENTS, &thePWData);
3049  // Unpause the master key. (This may go above the add to wallet, or it may
3050  // stay here, with the "convert to master key" below.)
3051  //
3052  if (OTCachedKey::It()->isPaused()) {
3053  OTCachedKey::It()->Unpause();
3054  }
3055  if (bIfNymLoadKeys && pNym->SetIdentifierByPubkey()) {
3056  if (nullptr != pNymID) *pNymID = pNym->GetConstID();
3057  OTPseudonym* pTempNym =
3058  GetOrLoadPrivateNym(pNym->GetConstID(), false,
3059  __FUNCTION__); // This logs and ASSERTs already.
3060 
3061  if (nullptr != pTempNym) // already there.
3062  {
3063  const OTString strNymID(pNym->GetConstID());
3064  otOut << __FUNCTION__
3065  << ": Tried to import the Cert for a Nym that's "
3066  "already in wallet: " << strNymID << "\n";
3067  return false;
3068  }
3069  // If success: Add to Wallet including name.
3070  //
3071  pWallet->AddNym(*(pNym.release())); // Insert to wallet's list of Nyms.
3072 
3073  const bool bConverted = pWallet->ConvertNymToCachedKey(*pNym);
3074 
3075  if (!bConverted) {
3076  otErr << __FUNCTION__ << ": Failed while calling "
3077  "pWallet->ConvertNymToCachedKey(*pNym)\n";
3078  }
3079  else {
3080  pNym->SaveSignedNymfile(*pNym);
3081  pWallet->SaveWallet(); // the conversion process adds values to the
3082  // wallet, so we must save it after.
3083  return true;
3084  }
3085  }
3086  else
3087  otErr << __FUNCTION__
3088  << ": Failed loading or verifying key from cert string.\n";
3089  return false;
3090 }
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Wallet_ImportNym ( const OTString FILE_CONTENTS,
OTIdentifier pNymID = nullptr 
) const

Definition at line 2701 of file OpenTransactions.cpp.

2703 {
2704  OTWallet* pWallet =
2705  GetWallet(__FUNCTION__); // This logs and ASSERTs already.
2706  if (nullptr == pWallet) return false;
2707  // By this point, pWallet is a good pointer. (No need to cleanup.)
2708  OTASCIIArmor ascArmor;
2709  const bool bLoadedArmor = OTASCIIArmor::LoadFromString(
2710  ascArmor, FILE_CONTENTS); // str_bookend="-----BEGIN" by default
2711  if (!bLoadedArmor || !ascArmor.Exists()) {
2712  otErr << __FUNCTION__
2713  << ": Failure loading string into OTASCIIArmor object:\n\n"
2714  << FILE_CONTENTS << "\n\n";
2715  return false;
2716  }
2717  std::unique_ptr<OTDB::Storable> pStorable(
2719  OTDB::StringMap* pMap = dynamic_cast<OTDB::StringMap*>(pStorable.get());
2720 
2721  if (nullptr == pMap) {
2722  otOut << __FUNCTION__
2723  << ": Failed decoding StringMap object while trying "
2724  "to import Nym:\n" << FILE_CONTENTS << "\n";
2725  return false;
2726  }
2727  std::map<std::string, std::string>& theMap = pMap->the_map;
2728  // By this point, there was definitely a StringMap encoded in the
2729  // FILE_CONTENTS...
2730  //
2731  // Decode the FILE_CONTENTS into a StringMap object,
2732  // and if success, make sure it contains these values:
2733  //
2734  // id: The NymID.
2735  // name: The display name from the wallet.
2736  // certfile: The public / private certfile in openssl format.
2737  // nymfile: The contents of the nymfile.
2738  //
2739  if (theMap.end() == theMap.find("id")) // todo hardcoding
2740  {
2741  // not found.
2742  otOut << __FUNCTION__
2743  << ": Unable to find 'id' field while trying to import Nym:\n"
2744  << FILE_CONTENTS << "\n";
2745  return false;
2746  }
2747  if (theMap.end() == theMap.find("name")) // todo hardcoding
2748  {
2749  // not found.
2750  otOut << __FUNCTION__
2751  << ": Unable to find 'name' field while trying to import Nym:\n"
2752  << FILE_CONTENTS << "\n";
2753  return false;
2754  }
2755  if (theMap.end() == theMap.find("nymfile")) // todo hardcoding
2756  {
2757  // not found.
2758  otOut << __FUNCTION__
2759  << ": Unable to find 'nymfile' field while trying to "
2760  "import Nym:\n" << FILE_CONTENTS << "\n";
2761  return false;
2762  }
2763  if ((theMap.end() == theMap.find("certfile")) && // todo hardcoding
2764  (theMap.end() == theMap.find("credlist"))) // Logic: No certfile AND no
2765  // credlist? Gotta have one
2766  // or the other.
2767  {
2768  // not found.
2769  otOut << __FUNCTION__
2770  << ": Unable to find a 'certfile' nor a 'credlist' "
2771  "field while trying to import Nym:\n" << FILE_CONTENTS << "\n";
2772  return false;
2773  }
2774  // Do various verifications on the values to make sure there's no funny
2775  // business.
2776  //
2777  // If Nym with this ID is ALREADY in the wallet, set pNymID and return
2778  // false.
2779  const OTIdentifier theNymID(theMap["id"].c_str());
2780  const OTString strNymName(theMap["name"].c_str());
2781 
2782  if (nullptr != pNymID) pNymID->SetString(theMap["id"].c_str());
2783  if (theNymID.IsEmpty()) {
2784  otErr << __FUNCTION__
2785  << ": Error: NYM_ID passed in is empty; returning false";
2786  return false;
2787  }
2788  // MAKE SURE IT'S NOT ALREADY IN THE WALLET.
2789  //
2790  std::unique_ptr<OTPseudonym> pNym(GetOrLoadPrivateNym(
2791  theNymID, true, __FUNCTION__)); // This logs and ASSERTs already.
2792 
2793  if (nullptr != pNym) // already there.
2794  {
2795  otOut << __FUNCTION__
2796  << ": Tried to import a Nym that's already in wallet: "
2797  << theMap["id"] << "\n";
2798  pNym.release();
2799  return false;
2800  }
2801  // Create a new Nym object.
2802  //
2803  const OTString strNymID(theNymID);
2804  pNym.reset(new OTPseudonym(theNymID));
2805 
2806  pNym->SetNymName(strNymName);
2807 
2808  // The Nym being imported has its own password. We ask for that here,
2809  // so we can preserve it in an OTPassword object and pass it around to
2810  // everyone who needs it.
2811  //
2812  // This way OT doesn't automatically ask for it a billion times as it
2813  // goes through the process of loading and copying these various keys
2814  // (None of which utilize the wallet's built-in cached master key, since
2815  // this Nym is being imported and thus is external to the wallet until
2816  // that process is complete.)
2817  //
2818  OTString strDisplay("Enter passphrase for the Nym being imported.");
2819 
2820  // Circumvents the cached key.
2821 
2822  // bAskTwice is true when exporting (since the export passphrase is being
2823  // created at that time.) But here during importing, we just ask once,
2824  // since the passphrase is being used, not created.
2825  std::unique_ptr<OTPassword> pExportPassphrase(
2826  OTSymmetricKey::GetPassphraseFromUser(&strDisplay, false));
2827 
2828  if (nullptr == pExportPassphrase) {
2829  otErr << __FUNCTION__ << ": Failed in GetPassphraseFromUser.\n";
2830  return false;
2831  }
2832 
2833  // Pause the master key, since this Nym is coming from outside
2834  // the wallet. We'll let it load with its own key. (No point using
2835  // the internal wallet master key here, since the Nym is coming from
2836  // outside, and doesn't use it anyway.)
2837  // This is true regardless of whether we load via the old system or
2838  // the new credentials system.
2839  //
2840  if (!(OTCachedKey::It()->isPaused())) {
2841  OTCachedKey::It()->Pause(); // BELOW THIS POINT, CACHED MASTER KEY IS
2842  // DISABLED.
2843  }
2844  // Set the credentials or keys on the new Nym object based on the
2845  // certfile from the StringMap.
2846  //
2847  bool bIfNymLoadKeys = false;
2848  OTString strReasonToLoad(
2849  "(ImportNym) To import this Nym, what is its passphrase? ");
2850  OTString strReasonToSave(
2851  "(ImportNym) What is your wallet's master passphrase? ");
2852 
2853  OTPasswordData thePWDataLoad(strReasonToLoad.Get());
2854  OTPasswordData thePWDataSave(strReasonToSave.Get());
2855  auto it_credlist = theMap.find("credlist");
2856  auto it_credentials = theMap.find("credentials");
2857  bool bHasCredentials = false;
2858  // found "credlist"
2859  //
2860  if (theMap.end() != it_credlist) {
2861  OTASCIIArmor ascCredList;
2862  OTString strCredList;
2863  if (it_credlist->second.size() > 0) {
2864  ascCredList.Set(it_credlist->second.c_str());
2865  ascCredList.GetString(strCredList);
2866  }
2867  // cred list exists, and found "credentials"...
2868  //
2869  if (strCredList.Exists() &&
2870  (theMap.end() != it_credentials)) // and found "credentials"
2871  {
2872  OTASCIIArmor ascCredentials;
2873  if (it_credentials->second.size() > 0) {
2874  ascCredentials.Set(it_credentials->second.c_str());
2875  std::unique_ptr<OTDB::Storable> pPrivateStorable(
2877  ascCredentials.Get()));
2878  OTDB::StringMap* pPrivateMap =
2879  dynamic_cast<OTDB::StringMap*>(pPrivateStorable.get());
2880  if (nullptr == pPrivateMap) {
2881  otOut << __FUNCTION__
2882  << ": Failed decoding StringMap object.\n";
2883  return false;
2884  }
2885  else // IF the list saved, then we save the credentials
2886  // themselves...
2887  {
2888  OTString::Map& thePrivateMap = pPrivateMap->the_map;
2889  if (false ==
2890  pNym->LoadFromString(strCredList, &thePrivateMap,
2891  &strReasonToLoad,
2892  pExportPassphrase.get())) {
2893  otErr << __FUNCTION__ << ": Failure loading nym "
2894  << strNymID << " from credential string.\n";
2895  return false;
2896  }
2897  else // Success
2898  {
2899  bIfNymLoadKeys = true; // <============
2900  bHasCredentials = true;
2901  }
2902  } // success decoding StringMap
2903  } // it_credentials.second().size() > 0
2904  } // strCredList.Exists() and it_credentials found.
2905  } // found "credlist"
2906  // found "certfile"
2907  else if (theMap.end() != theMap.find("certfile")) {
2908  const OTString strCert(theMap["certfile"]);
2909  bIfNymLoadKeys = pNym->Loadx509CertAndPrivateKeyFromString(
2910  strCert, &thePWDataLoad, pExportPassphrase.get());
2911  }
2912  // Unpause the OTCachedKey (wallet master key.)
2913  // Now that we've loaded up the "outsider" using its own key,
2914  // we now resume normal wallet master key operations so that when
2915  // we save the Nym, it will be saved using the wallet master key.
2916  // (Henceforth, it has been "imported.")
2917  //
2918  if (OTCachedKey::It()->isPaused()) {
2919  OTCachedKey::It()->Unpause(); // BELOW THIS POINT, CACHED MASTER KEY IS
2920  // BACK IN EFFECT. (Disabled above.)
2921  }
2922  //
2923  if (bIfNymLoadKeys && pNym->VerifyPseudonym()) {
2924  // Before we go on switching the credentials around, let's make sure
2925  // this Nym we're
2926  // importing isn't already in the wallet.
2927 
2928  if (bHasCredentials &&
2929  !pNym->ReEncryptPrivateCredentials(true, &thePWDataLoad,
2930  pExportPassphrase.get()))
2931  // Handles OTCachedKey internally, no need for pausing for this call
2932  {
2933  otErr
2934  << __FUNCTION__
2935  << ": Failed trying to re-encrypt Nym's private credentials.\n";
2936  return false;
2937  }
2938  // load Nymfile from string
2939  //
2940  const OTString strNymfile(theMap["nymfile"]);
2941 
2942  bool bConverted = false;
2943  const bool bLoaded =
2944  (strNymfile.Exists() && pNym->LoadFromString(strNymfile));
2945  // const bool bLoaded = (strNymfile.Exists() &&
2946  // pNym->LoadFromString(strNymfile, &thePrivateMap)); // Unnecessary,
2947  // since pNym has already loaded with this private info, and it will
2948  // stay loaded even through loading up the nymfile portion, which does
2949  // not overwrite it. Furthermore, we have since transformed that data,
2950  // re-encrypting it to a new key, and that's the important change that
2951  // we're trying to save here! Therefore I don't want to re-introduce
2952  // this (now old) version of the private info, therefore this is
2953  // commented out.
2954  // If success: Add to Wallet including name.
2955  //
2956  if (bLoaded) {
2957  // Insert to wallet's list of Nyms.
2958  pWallet->AddNym(*(pNym.release()));
2959  if (!pWallet->ConvertNymToCachedKey(
2960  *pNym)) // This also calls SaveX509CertAndPrivateKey, FYI.
2961  // (Or saves credentials, too, whichever is
2962  // applicable.)
2963  {
2964  otErr << __FUNCTION__
2965  << ": Failed while calling "
2966  "pWallet->ConvertNymToCachedKey(*pNym)\n";
2967  return false;
2968  }
2969  else
2970  bConverted = true;
2971  }
2972  else {
2973  otErr << __FUNCTION__ << ": Failed loading nymfile from string.\n";
2974  return false;
2975  }
2976  //
2977  if (bLoaded && bConverted) // bLoaded is probably superfluous here.
2978  {
2979  // save the nymfile.
2980  //
2981  if (!pNym->SaveSignedNymfile(*pNym)) {
2982  otErr << __FUNCTION__
2983  << ": Error: Failed calling SaveSignedNymfile.\n";
2984  return false;
2985  }
2986  // the conversion process adds values to the wallet, so we must save
2987  // it after.
2988  if (!pWallet->SaveWallet()) {
2989  otErr << __FUNCTION__
2990  << ": Error: Failed to save (updated) wallet.\n";
2991  return false;
2992  }
2993 
2994  return true; // <========= Success!
2995  }
2996  }
2997  else
2998  otErr << __FUNCTION__
2999  << ": Failed loading or verifying keys|credentials|pseudonym.\n";
3000  return false;
3001 }
std::map< std::string, std::string > Map
Definition: OTString.hpp:162
EXPORT OTWallet * GetWallet(const char *szFuncName=nullptr) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
static EXPORT OTPassword * GetPassphraseFromUser(const OTString *pstrDisplay=nullptr, bool bAskTwice=false)
OTLOG_IMPORT OTLogStream otErr
EXPORT Storable * DecodeObject(StoredObjectType theObjectType, std::string strInput)
Definition: OTStorage.cpp:830
bool opentxs::OT_API::Wallet_ImportPurse ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_TYPE_ID,
const OTIdentifier SIGNER_ID,
const OTString THE_PURSE,
const OTString pstrDisplay = nullptr 
)

Definition at line 5944 of file OpenTransactions.cpp.

5958 {
5959  OT_ASSERT_MSG(m_bInitialized, "Not initialized; call OT_API::Init first.");
5960  OTString strPurseReason((nullptr == pstrDisplay)
5961  ? "Enter passphrase for purse being imported."
5962  : pstrDisplay->Get());
5963  OTPasswordData thePWDataWallet(
5964  (nullptr == pstrDisplay) ? OT_PW_DISPLAY : pstrDisplay->Get());
5965  OTPassword thePassword; // Only used in the case of password-protected
5966  // purses.
5967  OTPseudonym* pNym = GetOrLoadPrivateNym(
5968  SIGNER_ID, false, __FUNCTION__,
5969  &thePWDataWallet); // These copiously log, and ASSERT.
5970  if (nullptr == pNym) return false;
5971  // By this point, pNym is a good pointer, and is on the wallet. (No need to
5972  // cleanup.)
5973  std::unique_ptr<Purse> pNewPurse(new Purse(SERVER_ID, ASSET_TYPE_ID));
5974  // What's going on here?
5975  // A purse can be encrypted by a private key (controlled by a Nym) or by a
5976  // symmetric
5977  // key (embedded inside the purse along with a corresponding master key.)
5978  // The below
5979  // function is what actually loads up pPurse from string (THE_PURSE) and
5980  // this call
5981  // also returns pOwner, which is a pointer to a special wrapper class (which
5982  // you must
5983  // delete, when you're done with it) which contains a pointer EITHER to the
5984  // owner Nym
5985  // for that purse, OR to the "owner" symmetric key for that purse.
5986  //
5987  // This way, any subsequent purse operations can use pOwner, regardless of
5988  // whether there
5989  // is actually a Nym inside, or a symmetric key. (None of the purse
5990  // operations will care,
5991  // since they can use pOwner either way.)
5992  //
5993  std::unique_ptr<OTNym_or_SymmetricKey> pNewOwner(LoadPurseAndOwnerForMerge(
5994  THE_PURSE, *pNewPurse, thePassword,
5995  false, // bCanBePublic=false by default. (Private Nym must be loaded, if
5996  // a nym is the owner.)
5997  &SIGNER_ID, // This can be nullptr, **IF** purse is password-protected.
5998  // (It's just ignored in that case.) Otherwise if it's
5999  // Nym-protected, the purse will have a NymID on it already,
6000  // which is what LoadPurseAndOwnerForMerge will try first.
6001  // If not (it's optional), then SIGNER_ID is the ID it will
6002  // try next, before failing altogether.
6003  &strPurseReason));
6004  if (nullptr == pNewOwner)
6005  return false; // This already logs, no need for more logs.
6006  std::unique_ptr<Purse> pOldPurse(
6007  LoadPurse(SERVER_ID, ASSET_TYPE_ID, SIGNER_ID));
6008 
6009  if (nullptr == pOldPurse) // apparently there's not already a purse of this
6010  // type, let's create it.
6011  {
6012  pOldPurse.reset(new Purse(SERVER_ID, ASSET_TYPE_ID, SIGNER_ID));
6013  }
6014  else if (!pOldPurse->VerifySignature(*pNym)) {
6015  otErr
6016  << __FUNCTION__
6017  << ": Failed to verify signature on old purse. (Very strange...)\n";
6018  return false;
6019  }
6020  // By this point, the old purse has either been loaded, or created.
6021  // Let's make sure the server and asset ID match between the purses,
6022  // since they are now actually loaded up.
6023  //
6024  if (pOldPurse->GetServerID() != pNewPurse->GetServerID()) {
6025  otOut << __FUNCTION__
6026  << ": Failure: ServerIDs don't match between these two purses.\n";
6027  return false;
6028  }
6029  else if (pOldPurse->GetAssetID() != pNewPurse->GetAssetID()) {
6030  otOut << __FUNCTION__
6031  << ": Failure: AssetIDs don't match between these two purses.\n";
6032  return false;
6033  }
6034  //
6035  // By this point, I have two owners, and two purses.
6036  //
6037  // NOTE: if I want to pass in a custom display string here, pNym could be
6038  // replaced with
6039  // pOldOwner (an OTNym_or_SymmetricKey instance) which can contain that
6040  // string.
6041  // (I'm referring to the string that contains the "reason" why the
6042  // passphrase needs to
6043  // be entered, so it can be shown to the user on the passphrase dialog.)
6044  //
6045  if (pOldPurse->Merge(*pNym, // signer
6046  *pNym, // old owner (must be private, if a nym.)
6047  *pNewOwner, // new owner (must be private, if a nym.)
6048  *pNewPurse)) // new purse (being merged into old.)
6049  {
6050  pOldPurse->ReleaseSignatures();
6051  pOldPurse->SignContract(*pNym);
6052  pOldPurse->SaveContract();
6053  return SavePurse(SERVER_ID, ASSET_TYPE_ID, SIGNER_ID, *pOldPurse);
6054  }
6055  else // Failed merge.
6056  {
6057  OTString strNymID1, strNymID2;
6058  pNym->GetIdentifier(strNymID1);
6059  pNewOwner->GetIdentifier(strNymID2);
6060  otOut << __FUNCTION__ << ": (OldNymID: " << strNymID1
6061  << ".) (New Owner ID: " << strNymID2 << ".) Failure merging new "
6062  "purse:\n\n" << THE_PURSE
6063  << "\n\n";
6064  }
6065  return false;
6066 }
EXPORT bool SavePurse(const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &USER_ID, Purse &THE_PURSE) const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
EXPORT Purse * LoadPurse(const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &USER_ID, const OTString *pstrDisplay=nullptr) const
#define OT_PW_DISPLAY
Definition: OTCallback.hpp:164
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
EXPORT OTNym_or_SymmetricKey * LoadPurseAndOwnerForMerge(const OTString &strPurse, Purse &thePurse, OTPassword &thePassword, bool bCanBePublic=false, const OTIdentifier *pOWNER_ID=nullptr, const OTString *pstrDisplay=nullptr) const
bool opentxs::OT_API::Wallet_RemoveAssetType ( const OTIdentifier ASSET_ID) const

Definition at line 2450 of file OpenTransactions.cpp.

2451 {
2452  bool bInitialized = IsInitialized();
2453  if (!bInitialized) {
2454  otErr << __FUNCTION__
2455  << ": Not initialized; call OT_API::Init first.\n";
2456  OT_FAIL;
2457  }
2458 
2459  if (ASSET_ID.IsEmpty()) {
2460  otErr << __FUNCTION__ << ": Null: ASSET_ID passed in!\n";
2461  OT_FAIL;
2462  }
2463 
2464  // Make sure there aren't any dependent accounts..
2465  if (!Wallet_CanRemoveAssetType(ASSET_ID)) return false;
2466 
2467  if (nullptr == m_pWallet) {
2468  otErr << __FUNCTION__ << ": No wallet found...!\n";
2469  OT_FAIL;
2470  }
2471 
2472  if (m_pWallet->RemoveAssetContract(ASSET_ID)) {
2473  m_pWallet->SaveWallet();
2474  otOut << __FUNCTION__ << ": Removed asset contract from the wallet: "
2475  << OTString(ASSET_ID) << "\n";
2476  return true;
2477  }
2478  return false;
2479 }
EXPORT bool Wallet_CanRemoveAssetType(const OTIdentifier &ASSET_ID) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool RemoveAssetContract(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1131
EXPORT bool SaveWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1566
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Wallet_RemoveNym ( const OTIdentifier NYM_ID) const

Definition at line 2487 of file OpenTransactions.cpp.

2488 {
2489  bool bInitialized = IsInitialized();
2490  if (!bInitialized) {
2491  otErr << __FUNCTION__
2492  << ": Not initialized; call OT_API::Init first.\n";
2493  OT_FAIL;
2494  }
2495 
2496  if (NYM_ID.IsEmpty()) {
2497  otErr << __FUNCTION__ << ": Null: ACCOUNT_ID passed in!\n";
2498  OT_FAIL;
2499  }
2500 
2501  // DONE: The below call proves already that there are no accounts laying
2502  // around
2503  // for this Nym. (No need to worry about "orphaned accounts.")
2504  //
2505  // DONE (finally):
2506  // However, the Nym might still be registered at various servers, even
2507  // without asset accounts.
2508  // Therefore, we need to iterate through the server contracts, and if the
2509  // Nym is registered at
2510  // any of the servers, then "deregister" (before deleting the Nym entirely.)
2511  // This is much
2512  // cleaner for the server side, who otherwise has to expired unused nyms
2513  // based on some rule
2514  // presumably to be found in the server contract.
2515  if (!Wallet_CanRemoveNym(NYM_ID)) return false;
2516 
2517  if (nullptr == m_pWallet) {
2518  otErr << __FUNCTION__ << ": No wallet found...!\n";
2519  OT_FAIL;
2520  }
2521 
2522  if (m_pWallet->RemoveNym(NYM_ID)) {
2523  otOut << __FUNCTION__
2524  << ": Success erasing Nym from wallet: " << OTString(NYM_ID)
2525  << "\n";
2526  m_pWallet->SaveWallet();
2527  return true;
2528  }
2529  else
2530  otOut << __FUNCTION__
2531  << ": Failure erasing Nym from wallet: " << OTString(NYM_ID)
2532  << "\n";
2533 
2534  return false;
2535 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool RemoveNym(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1101
EXPORT bool Wallet_CanRemoveNym(const OTIdentifier &NYM_ID) const
EXPORT bool SaveWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1566
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OT_API::Wallet_RemoveServer ( const OTIdentifier SERVER_ID) const

Definition at line 2399 of file OpenTransactions.cpp.

2400 {
2401  bool bInitialized = IsInitialized();
2402  if (!bInitialized) {
2403  otErr << __FUNCTION__
2404  << ": Not initialized; call OT_API::Init first.\n";
2405  OT_FAIL;
2406  }
2407 
2408  if (SERVER_ID.IsEmpty()) {
2409  otErr << __FUNCTION__ << ": Null: ASSET_ID passed in!\n";
2410  OT_FAIL;
2411  }
2412 
2413  // Make sure there aren't any dependent accounts..
2414  if (!Wallet_CanRemoveServer(SERVER_ID)) return false;
2415 
2416  // TODO: the above call proves that there are no accounts laying around
2417  // for this server ID. (No need to worry about "orphaned accounts.")
2418  //
2419  // However, there may still be Nyms registered at the server! Therefore,
2420  // we need to loop through the Nyms, and make sure none of them has been
2421  // registered at this server ID. If it has, then we need to message the
2422  // server
2423  // to "deregister" the Nym, which is much cleaner. Otherwise server's only
2424  // other alternative is to expire Nyms that have gone unused for some
2425  // specific
2426  // period of time, presumably those terms are described in the server
2427  // contract.
2428  //
2429 
2430  if (nullptr == m_pWallet) {
2431  otErr << __FUNCTION__ << ": No wallet found...\n";
2432  OT_FAIL;
2433  }
2434 
2435  if (m_pWallet->RemoveServerContract(SERVER_ID)) {
2436  m_pWallet->SaveWallet();
2437  otOut << __FUNCTION__ << ": Removed server contract from the wallet: "
2438  << OTString(SERVER_ID) << "\n";
2439  return true;
2440  }
2441  return false;
2442 }
EXPORT bool Wallet_CanRemoveServer(const OTIdentifier &SERVER_ID) const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool IsInitialized() const
EXPORT bool SaveWallet(const char *szFilename=nullptr)
Definition: OTWallet.cpp:1566
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT bool RemoveServerContract(const OTIdentifier &theTargetID)
Definition: OTWallet.cpp:1155
bool opentxs::OT_API::WalletExists ( ) const

Definition at line 1085 of file OpenTransactions.cpp.

1086 {
1087  return (nullptr != m_pWallet) ? true : false;
1088 }
int32_t opentxs::OT_API::withdrawVoucher ( const OTIdentifier SERVER_ID,
const OTIdentifier USER_ID,
const OTIdentifier ACCT_ID,
const OTIdentifier RECIPIENT_USER_ID,
const OTString CHEQUE_MEMO,
const int64_t &  AMOUNT 
) const

Definition at line 10250 of file OpenTransactions.cpp.

10256 {
10257  OTPseudonym* pNym = GetOrLoadPrivateNym(
10258  USER_ID, false, __FUNCTION__); // These copiously log, and ASSERT.
10259  if (nullptr == pNym) return (-1);
10260  // By this point, pNym is a good pointer, and is on the wallet. (No need to
10261  // cleanup.)
10262  OTServerContract* pServer =
10263  GetServer(SERVER_ID, __FUNCTION__); // This ASSERTs and logs already.
10264  if (nullptr == pServer) return (-1);
10265  // By this point, pServer is a good pointer. (No need to cleanup.)
10266  OTAccount* pAccount =
10267  GetOrLoadAccount(*pNym, ACCT_ID, SERVER_ID, __FUNCTION__);
10268  if (nullptr == pAccount) return (-1);
10269  // By this point, pAccount is a good pointer, and is on the wallet. (No need
10270  // to cleanup.)
10271  OTIdentifier CONTRACT_ID;
10272  OTString strContractID;
10273 
10274  CONTRACT_ID = pAccount->GetAssetTypeID();
10275  CONTRACT_ID.GetString(strContractID);
10276  OTMessage theMessage;
10277 
10278  const int64_t lAmount = AMOUNT;
10279 
10280  OTString strServerID(SERVER_ID), strNymID(USER_ID), strFromAcct(ACCT_ID);
10281 
10282  int64_t lWithdrawTransNum = 0, lVoucherTransNum = 0;
10283 
10284  bool bGotTransNum1 =
10285  pNym->GetNextTransactionNum(*pNym, strServerID, lWithdrawTransNum);
10286  bool bGotTransNum2 =
10287  pNym->GetNextTransactionNum(*pNym, strServerID, lVoucherTransNum);
10288 
10289  if (!bGotTransNum1 || !bGotTransNum2) {
10290  otOut << __FUNCTION__
10291  << ": Not enough Transaction Numbers were available. "
10292  "(Suggest requesting the server for more.)\n";
10293 
10294  if (bGotTransNum1)
10295  pNym->AddTransactionNum(*pNym, strServerID, lWithdrawTransNum,
10296  true); // bSave=true
10297  if (bGotTransNum2)
10298  pNym->AddTransactionNum(*pNym, strServerID, lVoucherTransNum,
10299  true); // bSave=true
10300 
10301  return (-1);
10302  }
10303  const OTString strChequeMemo(CHEQUE_MEMO);
10304  const OTString strRecipientUserID(RECIPIENT_USER_ID);
10305  // Expiration (ignored by server -- it sets its own for its vouchers.)
10306  const time64_t VALID_FROM =
10307  OTTimeGetCurrentTime(); // This time is set to TODAY NOW
10308  const time64_t VALID_TO = OTTimeAddTimeInterval(
10309  VALID_FROM,
10311  // The server only uses the memo, amount, and recipient from this cheque
10312  // when it
10313  // constructs the actual voucher.
10314  OTCheque theRequestVoucher(SERVER_ID, CONTRACT_ID);
10315  bool bIssueCheque = theRequestVoucher.IssueCheque(
10316  lAmount, lVoucherTransNum, VALID_FROM, VALID_TO, ACCT_ID, USER_ID,
10317  strChequeMemo,
10318  (strRecipientUserID.GetLength() > 2) ? &(RECIPIENT_USER_ID) : nullptr);
10319  std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(*pNym));
10320  std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(*pNym));
10321 
10322  if (nullptr == pInbox) {
10323  otOut << "OT_API::" << __FUNCTION__
10324  << ": Failed loading inbox for acct " << strFromAcct << "\n";
10325 
10326  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
10327  pNym->AddTransactionNum(*pNym, strServerID, lWithdrawTransNum,
10328  true); // bSave=true
10329  pNym->AddTransactionNum(*pNym, strServerID, lVoucherTransNum,
10330  true); // bSave=true
10331  }
10332  else if (nullptr == pOutbox) {
10333  otOut << "OT_API::" << __FUNCTION__
10334  << ": Failed loading outbox for acct " << strFromAcct << "\n";
10335 
10336  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
10337  pNym->AddTransactionNum(*pNym, strServerID, lWithdrawTransNum,
10338  true); // bSave=true
10339  pNym->AddTransactionNum(*pNym, strServerID, lVoucherTransNum,
10340  true); // bSave=true
10341  }
10342  else if (!bIssueCheque) {
10343  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
10344  pNym->AddTransactionNum(*pNym, strServerID, lWithdrawTransNum,
10345  true); // bSave=true
10346  pNym->AddTransactionNum(*pNym, strServerID, lVoucherTransNum,
10347  true); // bSave=true
10348  }
10349  else {
10350  // Create a transaction
10351  OTTransaction* pTransaction = OTTransaction::GenerateTransaction(
10352  USER_ID, ACCT_ID, SERVER_ID, OTTransaction::withdrawal,
10353  lWithdrawTransNum);
10354  // set up the transaction item (each transaction may have multiple
10355  // items...)
10356  OTItem* pItem = OTItem::CreateItemFromTransaction(
10357  *pTransaction, OTItem::withdrawVoucher);
10358  pItem->SetAmount(lAmount);
10359  OTString strNote(" ");
10360  pItem->SetNote(strNote);
10361 
10362  // Add the voucher request string as the attachment on the transaction
10363  // item.
10364  theRequestVoucher.SignContract(*pNym);
10365  theRequestVoucher.SaveContract();
10366  OTString strVoucher(theRequestVoucher);
10367  pItem->SetAttachment(strVoucher); // The voucher request is contained in
10368  // the reference string.
10369 
10370  // sign the item
10371  pItem->SignContract(*pNym);
10372  pItem->SaveContract();
10373 
10374  pTransaction->AddItem(*pItem); // the Transaction's destructor will
10375  // cleanup the item. It "owns" it now.
10376  // BALANCE AGREEMENT
10377  //
10378  // The item is signed and saved within this call as well. No need to do
10379  // that again.
10380  OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
10381  lAmount * (-1), *pTransaction, *pNym, *pAccount, *pOutbox);
10382 
10383  if (nullptr != pBalanceItem)
10384  pTransaction->AddItem(*pBalanceItem); // Better not be nullptr...
10385  // message will fail... But
10386  // better check anyway.
10387  // sign the transaction
10388  pTransaction->SignContract(*pNym);
10389  pTransaction->SaveContract();
10390 
10391  // set up the ledger
10392  OTLedger theLedger(USER_ID, ACCT_ID, SERVER_ID);
10393  theLedger.GenerateLedger(ACCT_ID, SERVER_ID,
10394  OTLedger::message); // bGenerateLedger defaults
10395  // to false, which is
10396  // correct.
10397  theLedger.AddTransaction(*pTransaction);
10398 
10399  // sign the ledger
10400  theLedger.SignContract(*pNym);
10401  theLedger.SaveContract();
10402 
10403  // extract the ledger in ascii-armored form
10404  OTString strLedger(theLedger);
10405  OTASCIIArmor ascLedger(strLedger);
10406 
10407  int64_t lRequestNumber = 0;
10408 
10409  // (0) Set up the REQUEST NUMBER and then INCREMENT IT
10410  pNym->GetCurrentRequestNum(strServerID, lRequestNumber);
10411  theMessage.m_strRequestNum.Format(
10412  "%ld", lRequestNumber); // Always have to send this.
10413  pNym->IncrementRequestNum(*pNym, strServerID); // since I used it for a
10414  // server request, I have
10415  // to increment it
10416 
10417  // (1) Set up member variables
10418  theMessage.m_strCommand = "notarizeTransactions";
10419  theMessage.m_strNymID = strNymID;
10420  theMessage.m_strServerID = strServerID;
10421  theMessage.SetAcknowledgments(*pNym); // Must be called AFTER
10422  // theMessage.m_strServerID is
10423  // already set. (It uses it.)
10424 
10425  theMessage.m_strAcctID = strFromAcct;
10426  theMessage.m_ascPayload = ascLedger;
10427 
10428  OTIdentifier NYMBOX_HASH;
10429  const std::string str_server(strServerID.Get());
10430  const bool bNymboxHash = pNym->GetNymboxHash(str_server, NYMBOX_HASH);
10431  NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10432 
10433  if (!bNymboxHash)
10434  otErr << __FUNCTION__
10435  << ": Failed getting NymboxHash from Nym for server: "
10436  << str_server << "\n";
10437 
10438  // (2) Sign the Message
10439  theMessage.SignContract(*pNym);
10440 
10441  // (3) Save the Message (with signatures and all, back to its internal
10442  // member m_strRawFile.)
10443  theMessage.SaveContract();
10444 
10445  // (Send it)
10446  m_pClient->SetFocusToServerAndNym(*pServer, *pNym,
10447  m_pTransportCallback);
10448  m_pClient->ProcessMessageOut(theMessage);
10449 
10450  return m_pClient->CalcReturnVal(lRequestNumber);
10451  }
10452 
10453  return (-1);
10454 }
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
int64_t time64_t
Definition: Common.hpp:209
#define OT_TIME_SIX_MONTHS_IN_SECONDS
Definition: Common.hpp:170
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT bool GetServer(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME) const
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
OTLOG_IMPORT OTLogStream otErr
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const
OTCheque * opentxs::OT_API::WriteCheque ( const OTIdentifier SERVER_ID,
const int64_t &  CHEQUE_AMOUNT,
const time64_t VALID_FROM,
const time64_t VALID_TO,
const OTIdentifier SENDER_ACCT_ID,
const OTIdentifier SENDER_USER_ID,
const OTString CHEQUE_MEMO,
const OTIdentifier pRECIPIENT_USER_ID = nullptr 
) const

Definition at line 4874 of file OpenTransactions.cpp.

4879 {
4880  OTPseudonym* pNym =
4881  GetOrLoadPrivateNym(SENDER_USER_ID, false, __FUNCTION__);
4882  if (nullptr == pNym) return nullptr;
4883  // By this point, pNym is a good pointer, and is on the wallet. (No need to
4884  // cleanup.)
4885  OTAccount* pAccount =
4886  GetOrLoadAccount(*pNym, SENDER_ACCT_ID, SERVER_ID, __FUNCTION__);
4887  if (nullptr == pAccount) return nullptr;
4888  // By this point, pAccount is a good pointer, and is on the wallet. (No need
4889  // to cleanup.)
4890  // To write a cheque, we need to burn one of our transaction numbers.
4891  // (Presumably the wallet
4892  // is also storing a couple of these, since they are needed to perform any
4893  // transaction.)
4894  //
4895  // I don't have to contact the server to write a cheque -- as long as I
4896  // already have a transaction
4897  // number I can use to write it with. (Otherwise I'd have to ask the server
4898  // to send me one first.)
4899  //
4900  OTString strServerID(SERVER_ID);
4901  int64_t lTransactionNumber =
4902  0; // Notice I use the server ID on the ACCOUNT.
4903 
4904  if (false ==
4905  pNym->GetNextTransactionNum(*pNym, strServerID, lTransactionNumber)) {
4906  otOut << __FUNCTION__
4907  << ": User attempted to write a cheque, but had no "
4908  "transaction numbers.\n";
4909  return nullptr;
4910  }
4911  // At this point, I know that lTransactionNumber contains one I can use.
4912  OTCheque* pCheque =
4913  new OTCheque(pAccount->GetRealServerID(), pAccount->GetAssetTypeID());
4914  OT_ASSERT_MSG(
4915  nullptr != pCheque,
4916  "OT_API::WriteCheque: Error allocating memory in the OT API.");
4917  // At this point, I know that pCheque is a good pointer that I either
4918  // have to delete, or return to the caller.
4919  bool bIssueCheque = pCheque->IssueCheque(
4920  CHEQUE_AMOUNT, lTransactionNumber, VALID_FROM, VALID_TO, SENDER_ACCT_ID,
4921  SENDER_USER_ID, CHEQUE_MEMO, pRECIPIENT_USER_ID);
4922  if (!bIssueCheque) {
4923  otErr << __FUNCTION__ << ": Failure calling OTCheque::IssueCheque().\n";
4924  delete pCheque;
4925  pCheque = nullptr;
4926  // IF FAILED, ADD TRANSACTION NUMBER BACK TO LIST OF AVAILABLE NUMBERS.
4927  pNym->AddTransactionNum(*pNym, strServerID, lTransactionNumber,
4928  true); // bSave=true
4929  return nullptr;
4930  }
4931  pCheque->SignContract(*pNym);
4932  pCheque->SaveContract();
4933  //
4934  // DROP A COPY into the Outpayments box...
4935  //
4936  // (Since we used a transaction number to write the cheque,
4937  // we have to track it until it's deposited or until we cancel
4938  // it.)
4939  //
4940  const OTString strInstrument(*pCheque);
4941  OTMessage* pMessage = new OTMessage;
4942  OT_ASSERT(nullptr != pMessage);
4943 
4944  const OTString strNymID(SENDER_USER_ID);
4945 
4946  pMessage->m_strCommand = "outpaymentsMessage";
4947  pMessage->m_strNymID = strNymID;
4948 
4949  if (nullptr != pRECIPIENT_USER_ID) {
4950  const OTString strNymID2(*pRECIPIENT_USER_ID);
4951  pMessage->m_strNymID2 = strNymID2;
4952  }
4953  pMessage->m_strServerID = strServerID;
4954  pMessage->m_ascPayload.SetString(strInstrument);
4955 
4956  pMessage->SignContract(*pNym);
4957  pMessage->SaveContract();
4958 
4959  pNym->AddOutpayments(*pMessage); // Now the Nym is responsible to delete it.
4960  // It's in his "outpayments".
4961  OTPseudonym* pSignerNym = pNym;
4962  pNym->SaveSignedNymfile(*pSignerNym);
4963  return pCheque;
4964 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTPseudonym * GetOrLoadPrivateNym(const OTIdentifier &NYM_ID, bool bChecking=false, const char *szFuncName=nullptr, const OTPasswordData *pPWData=nullptr, const OTPassword *pImportPassword=nullptr) const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otErr
EXPORT OTAccount * GetOrLoadAccount(const OTPseudonym &theNym, const OTIdentifier &ACCT_ID, const OTIdentifier &SERVER_ID, const char *szFuncName=nullptr) const

The documentation for this class was generated from the following files: