// return -1 if error, 0 if nothing, and 1 if the node was processed. int OTAgreement::ProcessXMLNode(irr::io::IrrXMLReader*& xml) { int nReturnVal = 0; // Here we call the parent class first. // If the node is found there, or there is some error, // then we just return either way. But if it comes back // as '0', then nothing happened, and we'll continue executing. // // -- Note you can choose not to call the parent if // you don't want to use any of those xml tags. // As I do below, in the case of OTAccount. if (0 != (nReturnVal = OTCronItem::ProcessXMLNode(xml))) return nReturnVal; // ------------------------------------------------- if (!strcmp("agreement", xml->getNodeName())) { m_strVersion = xml->getAttributeValue("version"); SetTransactionNum( atol(xml->getAttributeValue("transactionNum")) ); SetCreationDate( atoi(xml->getAttributeValue("creationDate"))); SetValidFrom( atoi(xml->getAttributeValue("validFrom"))); SetValidTo( atoi(xml->getAttributeValue("validTo"))); // --------------------- const OTString strServerID(xml->getAttributeValue("serverID")), strAssetTypeID(xml->getAttributeValue("assetTypeID")), strSenderAcctID(xml->getAttributeValue("senderAcctID")), strSenderUserID(xml->getAttributeValue("senderUserID")), strRecipientAcctID(xml->getAttributeValue("recipientAcctID")), strRecipientUserID(xml->getAttributeValue("recipientUserID")); const OTIdentifier SERVER_ID(strServerID), ASSET_ID(strAssetTypeID), SENDER_ACCT_ID(strSenderAcctID), SENDER_USER_ID(strSenderUserID), RECIPIENT_ACCT_ID(strRecipientAcctID), RECIPIENT_USER_ID(strRecipientUserID); SetServerID(SERVER_ID); SetAssetID(ASSET_ID); SetSenderAcctID(SENDER_ACCT_ID); SetSenderUserID(SENDER_USER_ID); SetRecipientAcctID(RECIPIENT_ACCT_ID); SetRecipientUserID(RECIPIENT_USER_ID); // --------------------- OTLog::vOutput(0, "\n\nAgreement. Transaction Number: %ld\n", m_lTransactionNum); OTLog::vOutput(1, " Creation Date: %d Valid From: %d\n Valid To: %d\n" " AssetTypeID: %s\n ServerID: %s\n" " senderAcctID: %s\n senderUserID: %s\n " " recipientAcctID: %s\n recipientUserID: %s\n ", GetCreationDate(), GetValidFrom(), GetValidTo(), strAssetTypeID.Get(), strServerID.Get(), strSenderAcctID.Get(), strSenderUserID.Get(), strRecipientAcctID.Get(), strRecipientUserID.Get()); nReturnVal = 1; } else if (!strcmp("consideration", xml->getNodeName())) { if (false == LoadEncodedTextField(xml, m_strConsideration)) { OTLog::Error("Error in OTPaymentPlan::ProcessXMLNode: consideration field without value.\n"); return (-1); // error condition } nReturnVal = 1; } else if (!strcmp("merchantSignedCopy", xml->getNodeName())) { if (false == LoadEncodedTextField(xml, m_strMerchantSignedCopy)) { OTLog::Error("Error in OTPaymentPlan::ProcessXMLNode: merchant_signed_copy field without value.\n"); return (-1); // error condition } nReturnVal = 1; } // ------------------------------------------- // std::deque<long> m_dequeRecipientClosingNumbers; // Numbers used for CLOSING a transaction. (finalReceipt.) else if (!strcmp("closingRecipientNumber", xml->getNodeName())) { OTString strClosingNumber = xml->getAttributeValue("value"); if (strClosingNumber.Exists()) { const long lClosingNumber = atol(strClosingNumber.Get()); this->AddRecipientClosingTransactionNo(lClosingNumber); } else { OTLog::Error("Error in OTAgreement::ProcessXMLNode: closingRecipientNumber field without value.\n"); return (-1); // error condition } nReturnVal = 1; } return nReturnVal; }
// return -1 if error, 0 if nothing, and 1 if the node was processed. int32_t OTOffer::ProcessXMLNode(irr::io::IrrXMLReader*& xml) { int32_t nReturnVal = 0; // Here we call the parent class first. // If the node is found there, or there is some error, // then we just return either way. But if it comes back // as '0', then nothing happened, and we'll continue executing. // // -- Note you can choose not to call the parent if // you don't want to use any of those xml tags. // As I do below, in the case of OTAccount. //if (nReturnVal = OTContract::ProcessXMLNode(xml)) // return nReturnVal; if (!strcmp("marketOffer", xml->getNodeName())) { m_strVersion = xml->getAttributeValue("version"); OTString strIsSelling; strIsSelling = xml->getAttributeValue("isSelling"); if (strIsSelling.Compare("true")) m_bSelling = true; else m_bSelling = false; m_strContractType.Set((m_bSelling ? "ASK" : "BID")); const OTString strServerID(xml->getAttributeValue("serverID")), strAssetTypeID(xml->getAttributeValue("assetTypeID")), strCurrencyTypeID(xml->getAttributeValue("currencyTypeID")); const OTIdentifier SERVER_ID(strServerID), ASSET_ID(strAssetTypeID), CURRENCY_TYPE_ID(strCurrencyTypeID); SetServerID(SERVER_ID); SetAssetID(ASSET_ID); SetCurrencyID(CURRENCY_TYPE_ID); // ------------------------------------ const OTString strScale = xml->getAttributeValue("marketScale"); const int64_t lScale = strScale.Exists() ? atol(strScale.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire. if (false == isPowerOfTen( lScale )) { OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: marketScale *must* be 1, or a power of 10. Instead I got: %lld.\n", lScale); return (-1); } else SetScale(lScale); // ------------------------------------ const OTString strPriceLimit = xml->getAttributeValue("priceLimit"); const int64_t lPriceLimit = strPriceLimit.Exists() ? atol(strPriceLimit.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire. // NOTE: Market Orders (new) have a 0 price, so this error condition was changed. if (!strPriceLimit.Exists()) // if (lPriceLimit < 1) { OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be provided.\n", lPriceLimit); return (-1); } else SetPriceLimit(lPriceLimit); // ------------------------------------ const OTString strTotal = xml->getAttributeValue("totalAssetsOnOffer"); const int64_t lTotal = strTotal.Exists() ? atol(strTotal.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire. if (lTotal < 1) { OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer *must* be larger than 0. Instead I got: %lld.\n", lTotal); return (-1); } else SetTotalAssetsOnOffer(lTotal); // ------------------------------------ const OTString strFinished = xml->getAttributeValue("finishedSoFar"); const int64_t lFinished = strFinished.Exists() ? atol(strFinished.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire. if (lFinished < 0) { OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* be 0 or larger. Instead I got: %lld.\n", lFinished); return (-1); } else SetFinishedSoFar(lFinished); // ------------------------------------ const OTString strMinInc = xml->getAttributeValue("minimumIncrement"); const int64_t lMinInc = strMinInc.Exists() ? atol(strMinInc.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire. if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot logically be higher than the total assets on offer... { OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: minimumIncrement *must* be 1 or larger, \n" "and must also be less than the total assets on offer. Instead I got: %lld.\n", lMinInc); return (-1); } else SetMinimumIncrement(lMinInc); // ----------------------------------- const OTString strTransNum = xml->getAttributeValue("transactionNum"); const int64_t lTransNum = strTransNum.Exists() ? atol(strTransNum.Get()) : 0; SetTransactionNum(lTransNum); // ---------------------------------------------------------------- const OTString str_valid_from = xml->getAttributeValue("validFrom"); const OTString str_valid_to = xml->getAttributeValue("validTo"); int64_t tValidFrom = str_valid_from.Exists() ? str_valid_from.ToLong() : 0; int64_t tValidTo = str_valid_to.Exists () ? str_valid_to.ToLong() : 0; if ((tValidTo < tValidFrom) && (tValidTo != 0)) { OTLog::vOutput(0, "OTOffer::%s: Failure: validTo date (%" PRId64") cannot be earlier than " "validFrom date (%" PRId64").\n", __FUNCTION__, tValidFrom, tValidTo); return (-1); } // ---------------------------------------------------------------- SetValidFrom(OTTimeGetTimeFromSeconds(tValidFrom)); SetValidTo(OTTimeGetTimeFromSeconds(tValidTo)); // ---------------------------------------------------------------- OTLog::vOutput(4, "\n\nOffer. Transaction Number: %lld\n Valid From: %" PRId64"\n Valid To: %" PRId64"\n" " AssetTypeID: %s\n CurrencyTypeID: %s\n ServerID: %s\n" " Price Limit: %lld, Total Assets on Offer: %lld, %s so far: %lld\n " " Scale: %lld. Minimum Increment: %lld. This offer is a%s.\n", m_lTransactionNum, tValidFrom, tValidTo, strAssetTypeID.Get(), strCurrencyTypeID.Get(), strServerID.Get(), GetPriceLimit(), GetTotalAssetsOnOffer(), (m_bSelling ? "sold" : "bought"), GetFinishedSoFar(), GetScale(), GetMinimumIncrement(), (m_bSelling ? "n ASK" : " BID")); // ---------------------------------------------------------------- nReturnVal = 1; } // ---------------- return nReturnVal; }