146 #include <irrxml/irrXML.hpp>
167 static char buf[45] =
"";
169 if (!strCronItem.
Exists()) {
170 otErr << __FUNCTION__
171 <<
": Empty string was passed in (returning nullptr.)\n";
178 otErr << __FUNCTION__ <<
": Input string apparently was encoded and "
179 "then failed decoding. Contents: \n"
180 << strCronItem <<
"\n";
186 bool bGotLine = strContract.
sgets(buf, 40);
188 if (!bGotLine)
return nullptr;
198 if (!strFirstLine.
Exists() || strFirstLine.
Contains(
"- -"))
return nullptr;
203 std::unique_ptr<OTCronItem> pItem;
205 if (strFirstLine.
Contains(
"-----BEGIN SIGNED PAYMENT PLAN-----")) {
209 else if (strFirstLine.
Contains(
"-----BEGIN SIGNED TRADE-----")) {
213 else if (strFirstLine.
Contains(
"-----BEGIN SIGNED SMARTCONTRACT-----")) {
221 if (pItem->LoadContractFromString(strContract)) {
222 return pItem.release();
230 strFilename.
Format(
"%lld.crn", lTransactionNum);
233 const char* szFilename = strFilename.
Get();
236 otErr <<
"OTCronItem::" << __FUNCTION__
237 <<
": File does not exist: " << szFoldername
243 szFoldername, szFilename));
246 otErr <<
"OTCronItem::" << __FUNCTION__
247 <<
": Error reading file: " << szFoldername
263 const int64_t& lTransactionNum,
266 OTString strFilename, strServerID(serverID);
267 strFilename.
Format(
"%lld.crn", lTransactionNum);
270 const char* szFilename = strFilename.
Get();
273 otErr <<
"OTCronItem::" << __FUNCTION__
274 <<
": File does not exist: " << szFoldername
276 << szFilename <<
"\n";
285 otErr <<
"OTCronItem::" << __FUNCTION__
286 <<
": Error reading file: " << szFoldername
288 << szFilename <<
"\n";
313 OTString strListFilename(nymID), strServerID(serverID);
314 strListFilename.Concatenate(
".lst");
316 if (
OTDB::Exists(szFoldername, strServerID.
Get(), strListFilename.Get())) {
320 szFoldername, strServerID.
Get(), strListFilename.Get()));
322 if (strNumlist.
Exists()) {
327 otErr << __FUNCTION__
328 <<
": List of recurring transactions; string apparently "
330 "and then failed decoding. Contents: \n" << strNumlist
335 output.Add(strNumlist);
348 OTString strFilename, strServerID(serverID);
349 strFilename.
Format(
"%lld.crn", lTransactionNum);
352 const char* szFilename = strFilename.
Get();
368 szFoldername, strServerID.
Get(), strListFilename.
Get()));
370 if (strNumlist.
Exists()) {
375 otErr << __FUNCTION__
376 <<
": List of recurring transactions; string apparently "
378 "and then failed decoding. Contents: \n" << strNumlist
382 numlist.Add(strNumlist);
387 if (numlist.
Count() > 0) numlist.
Remove(lTransactionNum);
389 if (0 == numlist.
Count()) {
391 strListFilename.
Get())) {
392 otOut <<
"OTCronItem::" << __FUNCTION__
393 <<
": FYI, failure erasing recurring IDs file: "
399 numlist.
Output(strNumlist);
406 strFinal,
"ACTIVE CRON ITEMS"))
408 otErr <<
"OTCronItem::" << __FUNCTION__
409 <<
": Error re-saving recurring IDs (failed writing "
410 "armored string): " << szFoldername
417 strFinal.
Get(), szFoldername, strServerID.
Get(),
418 strListFilename.
Get());
421 otErr <<
"OTCronItem::" << __FUNCTION__
422 <<
": Error re-saving recurring IDs: " << szFoldername
435 otErr <<
"OTCronItem::" << __FUNCTION__
436 <<
": File does not exist: " << szFoldername
438 << szFilename <<
"\n";
443 otErr <<
"OTCronItem::" << __FUNCTION__
444 <<
": Error erasing file: " << szFoldername
446 << szFilename <<
"\n";
459 strFilename.
Format(
"%lld.crn", lOpeningNum);
462 const char* szFilename = strFilename.
Get();
465 otInfo <<
"OTCronItem::" << __FUNCTION__
466 <<
": Cron Record already exists for transaction "
484 strListFilename.
Get())) {
488 szFoldername, strServerID.
Get(), strListFilename.
Get()));
490 if (strNumlist.
Exists()) {
495 otErr << __FUNCTION__
496 <<
": Input string apparently was encoded and then"
497 " failed decoding. Contents: \n" << strNumlist
501 numlist.Add(strNumlist);
505 numlist.Add(lOpeningNum);
509 if (numlist.
Output(strNumlist)) {
515 strFinal,
"ACTIVE CRON ITEMS"))
517 otErr <<
"OTCronItem::" << __FUNCTION__
518 <<
": Error saving recurring IDs (failed writing armored "
521 << strListFilename <<
"\n";
527 strListFilename.
Get());
530 otErr <<
"OTCronItem::" << __FUNCTION__
531 <<
": Error saving recurring IDs: " << szFoldername
544 otErr <<
"OTCronItem::" << __FUNCTION__
545 <<
": Error saving file (failed writing armored string): "
552 strServerID.
Get(), szFilename);
555 otErr <<
"OTCronItem::" << __FUNCTION__
556 <<
": Error saving file: " << szFoldername
558 << szFilename <<
"\n";
583 const char* szFilename = strFilename.
Get();
586 otErr <<
"OTCronItem::" << __FUNCTION__
587 <<
": Cron Record already exists for transaction "
591 "yet inexplicably attempted to record it again.\n";
600 otErr <<
"OTCronItem::" << __FUNCTION__
601 <<
": Error saving file (failed writing armored string): "
610 otErr <<
"OTCronItem::" << __FUNCTION__
611 <<
": Error saving file: " << szFoldername
651 otErr <<
"OTCronItem::" << __FUNCTION__ <<
": VALID_TO ("
652 << lValidTo <<
") is earlier than VALID_FROM (" << lValidFrom
663 otErr <<
"OTCronItem::" << __FUNCTION__
664 <<
": Negative value for valid_to: " << lValidTo <<
"\n";
684 otErr << __FUNCTION__ <<
": "
686 <<
" is equal or larger than m_dequeClosingNumbers.size()!\n";
709 otLog5 <<
"OTCronItem::CanRemoveItem: theNym is not the originator of "
711 "(He could be a recipient though, so this is normal.)\n";
717 otOut <<
"Weird: Sender tried to remove a cron item; expected at least "
718 "1 closing number to be available"
726 otOut <<
"OTCronItem::CanRemoveItemFromCron: Closing number didn't "
727 "verify (for removal from cron).\n";
798 bool bForTheFirstTime)
816 int64_t newTransactionNo)
823 const int64_t lNewTransactionNumber = newTransactionNo;
826 if (0 == lNewTransactionNumber) {
827 otErr <<
"OTCronItem::HookRemovalFromCron: ** ERROR Final receipt not "
828 "added to inbox, since no "
829 "transaction numbers were available!\n";
870 std::unique_ptr<OTCronItem> theCronItemAngel(pOrigCronItem);
879 if (!bValidSignture) {
880 otErr << __FUNCTION__ <<
": Failure verifying signature of "
881 "server on Cron Item!\n";
888 const OTString strOrigCronItem(*pOrigCronItem);
904 pOriginator = pServerNym;
914 else if ((
nullptr != pRemover) &&
917 pOriginator = pRemover;
932 if (
nullptr == pOriginator) {
944 otErr <<
"OTCronItem::HookRemovalFromCron: Failure loading "
945 "Sender's public key:\n" << strNymID <<
"\n";
952 pOriginator = &theOriginatorNym;
956 otErr <<
"OTCronItem::HookRemovalFromCron: Failure verifying "
958 " public key or loading signed nymfile: " << strNymID
968 if (
nullptr != pOriginator) {
973 onFinalReceipt(*pOrigCronItem, lNewTransactionNumber, *pOriginator,
977 otErr <<
"MAJOR ERROR in OTCronItem::HookRemovalFromCron!! Failed "
978 "loading Originator Nym for Cron Item.\n";
994 const int64_t& lNewTransactionNumber,
1006 OTString strUpdatedCronItem(*
this);
1007 OTString* pstrAttachment = &strUpdatedCronItem;
1009 const OTString strOrigCronItem(theOrigCronItem);
1020 const int64_t lOpeningNumber = theOrigCronItem.
GetOpeningNum();
1021 const int64_t lClosingNumber = theOrigCronItem.
GetClosingNum();
1034 if ((lOpeningNumber > 0) &&
1042 theIDSet.erase(lOpeningNumber);
1044 theOriginator.
RemoveIssuedNum(*pServerNym, strServerID, lOpeningNumber,
1060 if ((
nullptr != pServerNym) && pServerNym->
CompareID(ACTUAL_NYM_ID))
1061 pActualNym = pServerNym;
1062 else if (theOriginator.
CompareID(ACTUAL_NYM_ID))
1063 pActualNym = &theOriginator;
1064 else if ((
nullptr != pRemover) && pRemover->
CompareID(ACTUAL_NYM_ID))
1065 pActualNym = pRemover;
1078 otErr << __FUNCTION__
1079 <<
": Failure loading public key for Nym: " << strNymID
1080 <<
". (To update his NymboxHash.) \n";
1091 <<
": Loading actual Nym, since he wasn't already loaded. "
1092 "(To update his NymboxHash.)\n";
1093 pActualNym = &theActualNym;
1099 <<
": Failure loading or verifying Actual Nym public key: "
1100 << strNymID <<
". (To update his NymboxHash.)\n";
1105 strOrigCronItem,
nullptr,
1106 pstrAttachment, pActualNym)) {
1107 otErr << __FUNCTION__
1108 <<
": Failure dropping finalReceipt to Nymbox.\n";
1112 otErr << __FUNCTION__ <<
": Failed doing "
1113 "VerifyIssuedNum(theOrigCronItem."
1114 "GetTransactionNum())\n";
1117 if ((lClosingNumber > 0) &&
1125 strOrigCronItem,
nullptr,
1129 otErr << __FUNCTION__ <<
": Failure dropping receipt into inbox.\n";
1142 otErr << __FUNCTION__
1143 <<
": Failed verifying "
1144 "lClosingNumber=theOrigCronItem.GetClosingTransactionNoAt(0)>"
1146 "theOriginator.VerifyTransactionNum(lClosingNumber)\n";
1163 const int64_t& lNewTransactionNumber,
const int64_t& lClosingNumber,
1170 const char* szFunc =
"OTCronItem::DropFinalReceiptToInbox";
1172 std::unique_ptr<OTAccount> theDestAcctGuardian;
1178 bool bSuccessLoading = theInbox.
LoadInbox();
1182 if (
true == bSuccessLoading)
1185 otErr << szFunc <<
": ERROR loading inbox ledger.\n";
1191 if (!bSuccessLoading) {
1192 otErr << szFunc <<
": ERROR loading or generating an inbox. (FAILED "
1193 "WRITING RECEIPT!!) \n";
1256 if (
nullptr != pstrNote) {
1264 if (
nullptr != pstrAttachment) {
1292 if (
nullptr == pActualAcct)
1297 theDestAcctGuardian.reset(pActualAcct);
1302 if (
nullptr != pActualAcct) {
1313 <<
": Failed: pActualAcct->VerifyAccount(*pServerNym)\n";
1348 const int64_t& lNewTransactionNumber,
1357 const char* szFunc =
1358 "OTCronItem::DropFinalReceiptToNymbox";
1363 bool bSuccessLoading = theLedger.
LoadNymbox();
1367 if (
true == bSuccessLoading)
1370 otErr << szFunc <<
": Unable to load Nymbox.\n";
1375 if (!bSuccessLoading) {
1376 otErr << szFunc <<
": ERROR loading or generating a nymbox. (FAILED "
1377 "WRITING RECEIPT!!) \n";
1444 if (
nullptr != pstrNote) {
1452 if (
nullptr != pstrAttachment) {
1462 pTransaction->
AddItem(*pItem1);
1501 if (
nullptr == pActualNym) {
1502 if ((
nullptr != pServerNym) && pServerNym->
CompareID(ACTUAL_NYM_ID))
1503 pActualNym = pServerNym;
1516 otErr << szFunc <<
": Failure loading public key for Nym: "
1518 "(To update his NymboxHash.) \n";
1527 otLog3 << szFunc <<
": Loading actual Nym, since he wasn't "
1529 "(To update his NymboxHash.)\n";
1530 pActualNym = &theActualNym;
1534 otErr << szFunc <<
": Failure loading or verifying Actual "
1535 "Nym public key: " << strNymID
1537 "(To update his NymboxHash.)\n";
1546 if (
nullptr != pActualNym) {
1558 otErr << szFunc <<
": Failed trying to create finalReceipt.\n";
1678 , serverNym_(nullptr)
1679 , serverId_(nullptr)
1682 , m_PROCESS_INTERVAL(1)
1685 , m_bCanceled(false)
1686 , m_bRemovalFlag(false)
1695 , serverNym_(nullptr)
1696 , serverId_(nullptr)
1699 , m_PROCESS_INTERVAL(1)
1702 , m_bCanceled(false)
1703 , m_bRemovalFlag(false)
1711 :
ot_super(SERVER_ID, ASSET_ID, ACCT_ID, USER_ID)
1713 , serverNym_(nullptr)
1714 , serverId_(nullptr)
1717 , m_PROCESS_INTERVAL(1)
1720 , m_bCanceled(false)
1721 , m_bRemovalFlag(false)
1781 m_PROCESS_INTERVAL = 1;
1801 int32_t nReturnVal = 0;
1818 const OTString strNodeName(xml->getNodeName());
1820 if (strNodeName.Compare(
"closingTransactionNumber")) {
1821 OTString strClosingNumber = xml->getAttributeValue(
"value");
1823 if (strClosingNumber.
Exists()) {
1824 const int64_t lClosingNumber = atol(strClosingNumber.
Get());
1829 otErr <<
"Error in OTCronItem::ProcessXMLNode: "
1830 "closingTransactionNumber field without value.\n";
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
virtual int64_t GetOpeningNumber(const OTIdentifier &theNymID) const
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
EXPORT void SetNumberOfOrigin(int64_t lTransactionNum)
EXPORT bool IsCanceled() const
const OTIdentifier & GetSenderUserID() const
EXPORT bool ClawbackTransactionNumber(const OTIdentifier &theServerID, const int64_t &lTransClawback, bool bSave=false, OTPseudonym *pSIGNER_NYM=nullptr)
EXPORT bool SaveCronReceipt()
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 SaveActiveCronReceipt(const OTIdentifier &theNymID)
EXPORT bool SaveContract()
EXPORT bool VerifyIssuedNum(const OTString &strServerID, const int64_t &lTransNum) const
EXPORT bool Remove(const int64_t &theValue)
void HookRemovalFromCron(OTPseudonym *pRemover, int64_t newTransactionNo)
static EXPORT const char * PathSeparator()
static EXPORT OTCronItem * LoadCronReceipt(const int64_t &lTransactionNum)
bool IsFlaggedForRemoval() const
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT bool AddTransaction(OTTransaction &theTransaction)
OTLOG_IMPORT OTLogStream otOut
virtual bool CanRemoveItemFromCron(OTPseudonym &theNym)
OTLOG_IMPORT OTLogStream otLog3
EXPORT void SetAttachment(const OTString &theStr)
virtual void onFinalReceipt(OTCronItem &theOrigCronItem, const int64_t &lNewTransactionNumber, OTPseudonym &theOriginator, OTPseudonym *pRemover)
EXPORT uint32_t GetLength() const
void SetValidTo(time64_t TIME_TO)
EXPORT bool LoadSignedNymfile(OTPseudonym &SIGNER_NYM)
EXPORT void Concatenate(const char *arg,...)
EXPORT void SetNymboxHashServerSide(const OTIdentifier &theInput)
EXPORT bool WriteArmoredString(OTString &strOutput, const std::string str_type, bool bEscaped=false) const
void SetCreationDate(const time64_t &CREATION_DATE)
void ClearClosingNumbers()
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 bool DecodeIfArmored(bool escapedIsAllowed=true)
EXPORT void ReleaseSignatures()
EXPORT bool Exists() const
EXPORT void SetIdentifier(const OTIdentifier &theIdentifier)
const OTIdentifier & GetServerID() const
EXPORT void Format(const char *fmt,...)
void SetStatus(const OTItem::itemStatus &theVal)
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 int32_t GetCountClosingNumbers() const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
virtual bool ProcessCron()
EXPORT void SetClosingNum(int64_t lClosingNum)
EXPORT bool GetCancelerID(OTIdentifier &theOutput) const
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool Output(std::set< int64_t > &theOutput) const
EXPORT bool RemoveIssuedNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, const int64_t &lTransNum, bool bSave)
bool sgets(char *buffer, uint32_t size)
EXPORT bool SetDateRange(time64_t VALID_FROM=OT_TIME_ZERO, time64_t VALID_TO=OT_TIME_ZERO)
OTString m_strContractType
EXPORT bool EraseValueByKey(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
OTLOG_IMPORT OTLogStream otInfo
EXPORT bool CompareID(const OTIdentifier &theIdentifier) const
EXPORT int32_t Count() const
static EXPORT bool EraseActiveCronReceipt(const int64_t &lTransactionNum, const OTIdentifier &nymID, const OTIdentifier &serverID)
static EXPORT bool GetActiveCronTransNums(OTNumList &output, const OTIdentifier &nymID, const OTIdentifier &serverID)
EXPORT bool CancelBeforeActivation(OTPseudonym &theCancelerNym)
EXPORT bool SaveNymbox(OTIdentifier *pNymboxHash=nullptr)
EXPORT int64_t GetClosingNum() const
static EXPORT OTCronItem * LoadActiveCronReceipt(const int64_t &lTransactionNum, const OTIdentifier &serverID)
EXPORT void SetNote(const OTString &theStr)
EXPORT int64_t GetOpeningNum() const
EXPORT bool SaveBoxReceipt(int64_t lLedgerType)
EXPORT const char * Get() const
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
EXPORT bool SaveInbox(OTLedger &box, OTIdentifier *hash=nullptr)
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetPurportedAccountID() const
virtual bool VerifyAccount(const OTPseudonym &theNym)
EXPORT void SetReferenceToNum(int64_t lTransactionNum)
OTIdentifier * m_pCancelerNymID
EXPORT const OTIdentifier & GetConstID() const
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
const OTIdentifier & GetSenderAcctID() const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
static EXPORT const OTString & Cron()
EXPORT bool Contains(const char *compare) const
std::set< int64_t > & GetSetOpenCronItems()
bool DropFinalReceiptToNymbox(const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, 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()
EXPORT bool SaveAccount()
virtual int64_t GetClosingNumber(const OTIdentifier &theAcctID) const
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
void HookActivationOnCron(OTPseudonym *pActivator, bool bForTheFirstTime=false)
virtual EXPORT void Release()
static EXPORT OTCronItem * NewCronItem(const OTString &strCronItem)
EXPORT void AddItem(OTItem &theItem)
EXPORT bool SaveSignedNymfile(OTPseudonym &SIGNER_NYM)
virtual void onRemovalFromCron()
virtual void onActivate()
OTLOG_IMPORT OTLogStream otLog5
EXPORT bool SaveInbox(OTIdentifier *pInboxHash=nullptr)