143 #include <irrxml/irrXML.hpp>
152 const OTIdentifier& theServerID,
const int64_t& lNewTransactionNumber,
166 pRecipient = &theServerNym;
169 else if ((
nullptr != pActualNym) &&
171 pRecipient = pActualNym;
174 if (
nullptr == pRecipient) {
180 otErr << __FUNCTION__
181 <<
": Failure loading Recipient's public key: " << strNymID
190 pRecipient = &theRecipientNym;
194 otErr << __FUNCTION__
195 <<
": Failure verifying Recipient's public key or loading "
196 "signed nymfile: " << strNymID <<
"\n";
207 pSender = &theServerNym;
210 else if ((
nullptr != pActualNym) &&
212 pSender = pActualNym;
215 if (
nullptr == pSender) {
221 otErr << __FUNCTION__
222 <<
": Failure loading Sender's public key: " << strNymID
233 pSender = &theSenderNym;
237 otErr << __FUNCTION__ <<
": Failure verifying Sender's public key "
238 "or loading signed nymfile: " << strNymID
253 strReference, pstrNote, pstrAttachment, pSender))
262 lNewTransactionNumber,
264 strReference, pstrNote, pstrAttachment, pRecipient))
275 const OTIdentifier& USER_ID,
const int64_t& lNewTransactionNumber,
276 const int64_t& lInReferenceTo,
const OTString& strReference,
279 OTLedger theLedger(USER_ID, USER_ID, SERVER_ID);
283 bool bSuccessLoading = theLedger.
LoadNymbox();
285 if (
true == bSuccessLoading)
291 if (!bSuccessLoading) {
292 otErr << __FUNCTION__ <<
": Failed loading or generating a nymbox. "
293 "(FAILED WRITING RECEIPT!!) \n";
342 if (
nullptr != pstrNote) {
349 if (
nullptr != pstrAttachment) {
359 pTransaction->
AddItem(*pItem1);
397 if (
nullptr == pActualNym) {
398 if (theServerNym.
CompareID(ACTUAL_NYM_ID))
399 pActualNym = &theServerNym;
412 otErr << __FUNCTION__
413 <<
": Failure loading public key for Nym: "
415 "(To update his NymboxHash.) \n";
424 otLog3 << __FUNCTION__ <<
": Loading actual Nym, since he "
425 "wasn't already loaded. (To "
426 "update his NymboxHash.)\n";
427 pActualNym = &theActualNym;
431 otErr << __FUNCTION__
432 <<
": Failure loading or verifying Actual Nym public "
435 "(To update his NymboxHash.)\n";
444 if (
nullptr != pActualNym) {
457 otErr << __FUNCTION__ <<
": Failed trying to create Nymbox.\n";
469 for (
size_t nIndex = 0; nIndex < nSizeClosing; ++nIndex) {
475 for (
size_t nIndex = 0; nIndex < nSizeRecipient; ++nIndex) {
489 for (
size_t nIndex = 0; nIndex < nSizeClosing; ++nIndex) {
491 if (lTemp > 0) numlistOutput.Add(lTemp);
496 for (
size_t nIndex = 0; nIndex < nSizeRecipient; ++nIndex) {
498 if (lTemp > 0) numlistOutput.Add(lTemp);
529 const int64_t& lNewTransactionNumber,
540 const char* szFunc =
"OTAgreement::onFinalReceipt";
546 OTString* pstrAttachment = &strUpdatedCronItem;
548 const OTString strOrigCronItem(theOrigCronItem);
564 pRecipient = pServerNym;
571 else if ((
nullptr != pRemover) &&
573 pRecipient = pRemover;
577 if (
nullptr == pRecipient) {
589 otErr << szFunc <<
": Failure loading Recipient's public key:\n"
599 pRecipient = &theRecipientNym;
603 otErr << szFunc <<
": Failure verifying Recipient's public key or "
604 "loading signed nymfile: " << strNymID <<
"\n";
622 const int64_t lSenderClosingNumber =
634 if ((lSenderOpeningNumber > 0) &&
645 theIDSet.erase(lSenderOpeningNumber);
657 lSenderOpeningNumber,
663 if ((
nullptr != pServerNym) && pServerNym->
CompareID(ACTUAL_NYM_ID))
664 pActualNym = pServerNym;
665 else if (theOriginator.
CompareID(ACTUAL_NYM_ID))
666 pActualNym = &theOriginator;
667 else if ((
nullptr != pRemover) && pRemover->
CompareID(ACTUAL_NYM_ID))
668 pActualNym = pRemover;
682 <<
": Failure loading public key for Nym : " << strNymID
684 "(To update his NymboxHash.) \n";
695 <<
": Loading actual Nym, since he wasn't already loaded. "
696 "(To update his NymboxHash.)\n";
697 pActualNym = &theActualNym;
703 <<
": Failure loading or verifying Actual Nym public key: "
705 "(To update his NymboxHash.)\n";
710 strOrigCronItem,
nullptr, pstrAttachment,
713 <<
": Failure dropping sender final receipt into nymbox.\n";
717 otErr << szFunc <<
": Failure verifying sender's opening number.\n";
720 if ((lSenderClosingNumber > 0) &&
729 lSenderClosingNumber,
731 strOrigCronItem,
nullptr,
736 <<
": Failure dropping receipt into sender's inbox.\n";
746 <<
": Failed verifying "
747 "lSenderClosingNumber=theOrigCronItem."
748 "GetClosingTransactionNoAt(0)>0 && "
749 "theOriginator.VerifyTransactionNum(lSenderClosingNumber)\n";
753 if ((
nullptr != pRecipient) && (lRecipientOpeningNumber > 0) &&
761 theIDSet.erase(lRecipientOpeningNumber);
773 lRecipientOpeningNumber,
780 nullptr, pstrAttachment,
785 <<
": Failure dropping recipient final receipt into nymbox.\n";
801 <<
": Failed verifying "
802 "lRecipientClosingNumber="
803 "GetRecipientClosingTransactionNoAt(1)>0 && "
804 "pRecipient->VerifyTransactionNum(lRecipientClosingNumber) && "
805 "VerifyIssuedNum(lRecipientOpeningNumber)\n";
809 if ((
nullptr != pRecipient) && (lRecipientClosingNumber > 0) &&
813 lNewTransactionNumber,
814 lRecipientClosingNumber,
817 strOrigCronItem,
nullptr, pstrAttachment))
819 <<
": Failure dropping receipt into recipient's inbox.\n";
829 <<
": Failed verifying "
830 "lRecipientClosingNumber="
831 "GetRecipientClosingTransactionNoAt(1)>0 && "
832 "pRecipient->VerifyTransactionNum(lRecipientClosingNumber) && "
833 "VerifyIssuedNum(lRecipientOpeningNumber)\n";
1002 "OTAgreement::GetClosingTransactionNoAt: index out of bounds.");
1013 const int64_t& lClosingTransactionNo)
1069 otOut <<
"OTAgreement::" << __FUNCTION__
1070 <<
" Weird: Nym tried to remove agreement (payment plan), even "
1071 "though he apparently wasn't the sender OR recipient.\n";
1075 otOut <<
"OTAgreement::" << __FUNCTION__
1076 <<
": Weird: Recipient tried to remove agreement "
1077 "(or payment plan); expected 2 closing numbers to be "
1078 "available--that weren't."
1085 otOut <<
"OTAgreement::" << __FUNCTION__ <<
": Recipient Closing "
1086 "number didn't verify (for "
1087 "removal from cron).\n";
1169 otOut << __FUNCTION__ <<
": Merchant has wrong NymID (should be same "
1170 "as RecipientUserID.)\n";
1174 otOut << __FUNCTION__ <<
": Error: Sender and recipient have the same "
1175 "Nym ID (not allowed.)\n";
1181 otOut << __FUNCTION__ <<
": Failure. You need at least 2 transaction "
1182 "numbers available to do this.\n";
1222 otErr << __FUNCTION__ <<
": Negative value for valid_to: " << lValidTo
1233 int64_t lTransactionNumber = 0, lClosingTransactionNo = 0;
1238 otOut << __FUNCTION__ <<
": Failure. You need at least 2 transaction "
1239 "numbers available to do this.\n";
1244 lTransactionNumber)) {
1245 otErr << __FUNCTION__
1246 <<
": Error: Strangely unable to get a transaction number.\n";
1251 lClosingTransactionNo)) {
1252 otErr << __FUNCTION__ <<
": Error: Strangely unable to get a closing "
1253 "transaction number.\n";
1255 lTransactionNumber,
true);
1275 otLog4 <<
"Successfully performed SetProposal.\n";
1290 otOut << __FUNCTION__ <<
": Error: Sender and recipient have the same "
1291 "Nym ID (not allowed.)\n";
1294 else if ((
nullptr != p_id_MERCHANT_NYM) &&
1296 otOut << __FUNCTION__ <<
": Merchant has wrong NymID (should be same "
1297 "as RecipientUserID.)\n";
1300 else if ((
nullptr != pMERCHANT_NYM) &&
1302 otOut << __FUNCTION__ <<
": Merchant has wrong NymID (should be same "
1303 "as RecipientUserID.)\n";
1307 otOut << __FUNCTION__
1308 <<
": Payer has wrong NymID (should be same as SenderUserID.)\n";
1314 otOut << __FUNCTION__ <<
": Failure. You need at least 2 transaction "
1315 "numbers available to do this.\n";
1319 otOut << __FUNCTION__ <<
": Failure. (The merchant was supposed to "
1320 "attach 2 transaction numbers.)\n";
1327 if ((
nullptr != pMERCHANT_NYM) &&
1329 otOut << __FUNCTION__ <<
": Merchant's signature failed to verify.\n";
1346 int64_t lTransactionNumber = 0, lClosingTransactionNo = 0;
1350 lTransactionNumber)) {
1351 otErr << __FUNCTION__
1352 <<
": Error: Strangely unable to get a transaction number.\n";
1357 lClosingTransactionNo)) {
1358 otErr << __FUNCTION__ <<
": Error: Strangely unable to get a closing "
1359 "transaction number.\n";
1373 lClosingTransactionNo);
1384 otLog4 << __FUNCTION__ <<
"(): Success!\n";
1476 :
ot_super(SERVER_ID, ASSET_ID, SENDER_ACCT_ID, SENDER_USER_ID)
1498 m_RECIPIENT_ACCT_ID.
Release();
1499 m_RECIPIENT_USER_ID.
Release();
1528 int32_t nReturnVal = 0;
1540 if (!strcmp(
"agreement", xml->getNodeName())) {
1544 const OTString strCreation = xml->getAttributeValue(
"creationDate");
1545 int64_t tCreation = strCreation.
ToLong();
1549 const OTString str_valid_from = xml->getAttributeValue(
"validFrom");
1550 const OTString str_valid_to = xml->getAttributeValue(
"validTo");
1552 int64_t tValidFrom = str_valid_from.
ToLong();
1553 int64_t tValidTo = str_valid_to.
ToLong();
1558 const OTString strServerID(xml->getAttributeValue(
"serverID")),
1559 strAssetTypeID(xml->getAttributeValue(
"assetTypeID")),
1560 strSenderAcctID(xml->getAttributeValue(
"senderAcctID")),
1561 strSenderUserID(xml->getAttributeValue(
"senderUserID")),
1562 strRecipientAcctID(xml->getAttributeValue(
"recipientAcctID")),
1563 strRecipientUserID(xml->getAttributeValue(
"recipientUserID")),
1564 strCanceled(xml->getAttributeValue(
"canceled")),
1565 strCancelerUserID(xml->getAttributeValue(
"cancelerUserID"));
1567 if (strCanceled.Exists() && strCanceled.Compare(
"true")) {
1570 if (strCancelerUserID.Exists())
1579 const OTIdentifier SERVER_ID(strServerID), ASSET_ID(strAssetTypeID),
1580 SENDER_ACCT_ID(strSenderAcctID), SENDER_USER_ID(strSenderUserID),
1581 RECIPIENT_ACCT_ID(strRecipientAcctID),
1582 RECIPIENT_USER_ID(strRecipientUserID);
1594 otInfo <<
" Creation Date: " << tCreation
1595 <<
" Valid From: " << tValidFrom <<
"\n Valid To: " << tValidTo
1597 " AssetTypeID: " << strAssetTypeID
1598 <<
"\n ServerID: " << strServerID
1600 " senderAcctID: " << strSenderAcctID
1601 <<
"\n senderUserID: " << strSenderUserID
1603 " recipientAcctID: " << strRecipientAcctID
1604 <<
"\n recipientUserID: " << strRecipientUserID <<
"\n ";
1608 else if (!strcmp(
"consideration", xml->getNodeName())) {
1611 otErr <<
"Error in OTPaymentPlan::ProcessXMLNode: consideration "
1612 "field without value.\n";
1618 else if (!strcmp(
"merchantSignedCopy", xml->getNodeName())) {
1621 otErr <<
"Error in OTPaymentPlan::ProcessXMLNode: "
1622 "merchant_signed_copy field without value.\n";
1631 else if (!strcmp(
"closingRecipientNumber", xml->getNodeName())) {
1632 OTString strClosingNumber = xml->getAttributeValue(
"value");
1634 if (strClosingNumber.
Exists()) {
1635 const int64_t lClosingNumber = atol(strClosingNumber.
Get());
1640 otErr <<
"Error in OTAgreement::ProcessXMLNode: "
1641 "closingRecipientNumber field without value.\n";
virtual int64_t GetOpeningNumber(const OTIdentifier &theNymID) const
OTLOG_IMPORT OTLogStream otLog4
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
void SetRecipientUserID(const OTIdentifier &USER_ID)
EXPORT int32_t GetRecipientCountClosingNumbers() const
virtual void onRemovalFromCron()
const OTIdentifier & GetSenderUserID() const
EXPORT bool ClawbackTransactionNumber(const OTIdentifier &theServerID, const int64_t &lTransClawback, bool bSave=false, OTPseudonym *pSIGNER_NYM=nullptr)
EXPORT int64_t GetRecipientClosingTransactionNoAt(uint32_t nIndex) const
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool SetProposal(OTPseudonym &MERCHANT_NYM, const OTString &strConsideration, time64_t VALID_FROM=OT_TIME_ZERO, time64_t VALID_TO=OT_TIME_ZERO)
time64_t GetValidTo() const
void SetMerchantSignedCopy(const OTString &strMerchantCopy)
virtual void HarvestClosingNumbers(OTPseudonym &theNym)
void SetValidFrom(time64_t TIME_FROM)
virtual EXPORT bool VerifyAccount(const OTPseudonym &theNym)
int64_t GetTransactionNum() const
virtual bool IsValidOpeningNumber(const int64_t &lOpeningNum) const
virtual void HarvestOpeningNumber(OTPseudonym &theNym)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT bool SaveContract()
OTString m_strConsideration
int64_t m_lTransactionNum
EXPORT bool VerifyIssuedNum(const OTString &strServerID, const int64_t &lTransNum) const
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
EXPORT int64_t ToLong() const
void AddRecipientClosingTransactionNo(const int64_t &lClosingTransactionNo)
EXPORT bool GetNextTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, int64_t &lTransNum, bool bSave=true)
const OTIdentifier & GetAssetID() const
EXPORT bool AddTransaction(OTTransaction &theTransaction)
OTLOG_IMPORT OTLogStream otOut
virtual bool CanRemoveItemFromCron(OTPseudonym &theNym)
std::map< std::string, OTPseudonym * > mapOfNyms
EXPORT bool SendNoticeToAllParties(bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &theServerID, const int64_t &lNewTransactionNumber, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr) const
OTLOG_IMPORT OTLogStream otLog3
EXPORT void SetAttachment(const OTString &theStr)
EXPORT bool SaveContractRaw(OTString &strOutput) const
void SetValidTo(time64_t TIME_TO)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
void SetAssetID(const OTIdentifier &ASSET_ID)
EXPORT bool LoadSignedNymfile(OTPseudonym &SIGNER_NYM)
OTString m_strMerchantSignedCopy
void SetRecipientAcctID(const OTIdentifier &ACCT_ID)
virtual bool CanRemoveItemFromCron(OTPseudonym &theNym)
virtual bool CompareAgreement(const OTAgreement &rhs) const
virtual int64_t GetClosingNumber(const OTIdentifier &theAcctID) const
EXPORT bool VerifyCurrentDate()
EXPORT void SetNymboxHashServerSide(const OTIdentifier &theInput)
EXPORT int32_t GetTransactionNumCount(const OTIdentifier &theServerID) const
void SetCreationDate(const time64_t &CREATION_DATE)
EXPORT int64_t GetRecipientOpeningNum() const
EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const
EXPORT bool VerifyPseudonym() const
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
EXPORT void ReleaseSignatures()
EXPORT bool Exists() const
EXPORT void SetString(const char *szString)
EXPORT void SetIdentifier(const OTIdentifier &theIdentifier)
virtual void HarvestOpeningNumber(OTPseudonym &theNym)
const OTIdentifier & GetServerID() const
void SetStatus(const OTItem::itemStatus &theVal)
time64_t GetValidFrom() const
EXPORT bool LoadPublicKey()
EXPORT void SetReferenceString(const OTString &theStr)
bool DropFinalReceiptToInbox(const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, const int64_t &lNewTransactionNumber, const int64_t &lClosingNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTAccount *pActualAcct=nullptr)
EXPORT bool Compare(const char *compare) const
EXPORT int32_t GetCountClosingNumbers() const
EXPORT bool VerifyOwner(const OTPseudonym &candidate) const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
virtual bool ProcessCron()
EXPORT bool AddTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, int64_t lTransNum, bool bSave)
virtual bool SaveContractWallet(std::ofstream &ofs) const
EXPORT bool Confirm(OTPseudonym &PAYER_NYM, OTPseudonym *pMERCHANT_NYM=nullptr, const OTIdentifier *p_id_MERCHANT_NYM=nullptr)
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
EXPORT bool RemoveIssuedNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, const int64_t &lTransNum, bool bSave)
virtual bool ProcessCron()
void SetTransactionNum(int64_t lTransactionNum)
virtual bool HasTransactionNum(const int64_t &lInput) const
OTString m_strContractType
#define OT_ASSERT_MSG(x, s)
EXPORT int64_t GetRecipientClosingNum() const
static EXPORT OTLedger * GenerateLedger(const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
OTLOG_IMPORT OTLogStream otInfo
EXPORT bool CompareID(const OTIdentifier &theIdentifier) const
virtual void UpdateContents()
void SetSenderAcctID(const OTIdentifier &ACCT_ID)
EXPORT bool SaveNymbox(OTIdentifier *pNymboxHash=nullptr)
virtual bool VerifyNymAsAgent(OTPseudonym &theNym, OTPseudonym &theSignerNym, mapOfNyms *pmap_ALREADY_LOADED=nullptr) const
EXPORT void SetNote(const OTString &theStr)
EXPORT bool SaveBoxReceipt(int64_t lLedgerType)
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
void SetServerID(const OTIdentifier &SERVER_ID)
OTLOG_IMPORT OTLogStream otErr
virtual EXPORT int64_t GetOpeningNumber(const OTIdentifier &theNymID) const
virtual void onFinalReceipt(OTCronItem &theOrigCronItem, const int64_t &lNewTransactionNumber, OTPseudonym &theOriginator, OTPseudonym *pRemover)
EXPORT void SetReferenceToNum(int64_t lTransactionNum)
OTIdentifier * m_pCancelerNymID
EXPORT const OTIdentifier & GetConstID() const
virtual EXPORT void HarvestClosingNumbers(OTPseudonym &theNym)
OTPseudonym * GetServerNym() const
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
const OTIdentifier & GetRecipientUserID() const
const OTIdentifier & GetSenderAcctID() const
virtual bool IsValidOpeningNumber(const int64_t &lOpeningNum) const
std::set< int64_t > & GetSetOpenCronItems()
virtual void GetAllTransactionNumbers(OTNumList &numlistOutput) const
const OTIdentifier & GetRecipientAcctID() const
std::deque< int64_t > m_dequeRecipientClosingNumbers
bool DropFinalReceiptToNymbox(const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
void SetSenderUserID(const OTIdentifier &USER_ID)
static EXPORT bool DropServerNoticeToNymbox(bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const int64_t &lInReferenceTo, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
int64_t OTTimeGetSecondsFromTime(time64_t time)
EXPORT void AddClosingTransactionNo(const int64_t &lClosingTransactionNo)
std::deque< int64_t > m_dequeClosingNumbers
virtual EXPORT void Release()
virtual int64_t GetClosingNumber(const OTIdentifier &theAcctID) const
virtual bool VerifyNymAsAgentForAccount(OTPseudonym &theNym, OTAccount &theAccount) const
virtual EXPORT void Release()
EXPORT void AddItem(OTItem &theItem)
EXPORT bool SaveSignedNymfile(OTPseudonym &SIGNER_NYM)