void OTOffer::UpdateContents() { const String NOTARY_ID(GetNotaryID()), INSTRUMENT_DEFINITION_ID(GetInstrumentDefinitionID()), CURRENCY_TYPE_ID(GetCurrencyID()); // I release this because I'm about to repopulate it. m_xmlUnsigned.Release(); Tag tag("marketOffer"); tag.add_attribute("version", m_strVersion.Get()); tag.add_attribute("isSelling", formatBool(!IsBid())); tag.add_attribute("notaryID", NOTARY_ID.Get()); tag.add_attribute("instrumentDefinitionID", INSTRUMENT_DEFINITION_ID.Get()); tag.add_attribute("currencyTypeID", CURRENCY_TYPE_ID.Get()); tag.add_attribute("priceLimit", formatLong(GetPriceLimit())); tag.add_attribute("totalAssetsOnOffer", formatLong(GetTotalAssetsOnOffer())); tag.add_attribute("finishedSoFar", formatLong(GetFinishedSoFar())); tag.add_attribute("marketScale", formatLong(GetScale())); tag.add_attribute("minimumIncrement", formatLong(GetMinimumIncrement())); tag.add_attribute("transactionNum", formatLong(GetTransactionNum())); tag.add_attribute("validFrom", formatTimestamp(GetValidFrom())); tag.add_attribute("validTo", formatTimestamp(GetValidTo())); std::string str_result; tag.output(str_result); m_xmlUnsigned.Concatenate("%s", str_result.c_str()); }
void OTOffer::UpdateContents() { const OTString SERVER_ID(GetServerID()), ASSET_TYPE_ID(GetAssetID()), CURRENCY_TYPE_ID(GetCurrencyID()); const int64_t lFrom = OTTimeGetSecondsFromTime(GetValidFrom()); const int64_t lTo = OTTimeGetSecondsFromTime(GetValidTo()); const int64_t lPriceLimit = GetPriceLimit(); const int64_t lTotalAssetsOnOffer = GetTotalAssetsOnOffer(); const int64_t lFinishedSoFar = GetFinishedSoFar(); const int64_t lScale = GetScale(); const int64_t lMinimumIncrement = GetMinimumIncrement(); const int64_t lTransactionNum = GetTransactionNum(); // I release this because I'm about to repopulate it. m_xmlUnsigned.Release(); m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0"); m_xmlUnsigned.Concatenate("<marketOffer\n version=\"%s\"\n" " isSelling=\"%s\"\n" // true or false. " serverID=\"%s\"\n" " assetTypeID=\"%s\"\n" " currencyTypeID=\"%s\"\n" " priceLimit=\"%lld\"\n" " totalAssetsOnOffer=\"%lld\"\n" " finishedSoFar=\"%lld\"\n" " marketScale=\"%lld\"\n" " minimumIncrement=\"%lld\"\n" " transactionNum=\"%lld\"\n" " validFrom=\"%" PRId64"\"\n" " validTo=\"%" PRId64"\"" " />\n\n", // <=== the tag ends here. m_strVersion.Get(), (IsBid() ? "false" : "true"), SERVER_ID.Get(), ASSET_TYPE_ID.Get(), CURRENCY_TYPE_ID.Get(), lPriceLimit, lTotalAssetsOnOffer, lFinishedSoFar, lScale, lMinimumIncrement, lTransactionNum, lFrom, lTo ); // m_xmlUnsigned.Concatenate("</marketOffer>\n"); // ^^^ Tag already ended above. }
inline int64_t GetAmountAvailable() const { return GetTotalAssetsOnOffer() - GetFinishedSoFar(); }
// 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; }
// 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 = Contract::ProcessXMLNode(xml)) // return nReturnVal; if (!strcmp("marketOffer", xml->getNodeName())) { m_strVersion = xml->getAttributeValue("version"); String strIsSelling; strIsSelling = xml->getAttributeValue("isSelling"); if (strIsSelling.Compare("true")) m_bSelling = true; else m_bSelling = false; m_strContractType.Set((m_bSelling ? "ASK" : "BID")); const String strNotaryID(xml->getAttributeValue("notaryID")), strInstrumentDefinitionID( xml->getAttributeValue("instrumentDefinitionID")), strCurrencyTypeID(xml->getAttributeValue("currencyTypeID")); const Identifier NOTARY_ID(strNotaryID), INSTRUMENT_DEFINITION_ID(strInstrumentDefinitionID), CURRENCY_TYPE_ID(strCurrencyTypeID); SetNotaryID(NOTARY_ID); SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID); SetCurrencyID(CURRENCY_TYPE_ID); const String strScale = xml->getAttributeValue("marketScale"); const int64_t lScale = strScale.Exists() ? strScale.ToLong() : 0; // if it doesn't exist, // the 0 here causes the // below error to fire. if (!isPowerOfTen(lScale)) { otOut << "OTOffer::ProcessXMLNode: Failure: marketScale *must* be " "1, or a power of 10. Instead I got: " << lScale << ".\n"; return (-1); } else SetScale(lScale); const String strPriceLimit = xml->getAttributeValue("priceLimit"); const int64_t lPriceLimit = strPriceLimit.Exists() ? strPriceLimit.ToLong() : 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) { otOut << "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be " "provided(" << lPriceLimit << ").\n"; return (-1); } else SetPriceLimit(lPriceLimit); const String strTotal = xml->getAttributeValue("totalAssetsOnOffer"); const int64_t lTotal = strTotal.Exists() ? strTotal.ToLong() : 0; // if it doesn't exist, // the 0 here causes the // below error to fire. if (lTotal < 1) { otOut << "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer " "*must* be larger than 0. Instead I got: " << lTotal << ".\n"; return (-1); } else SetTotalAssetsOnOffer(lTotal); const String strFinished = xml->getAttributeValue("finishedSoFar"); const int64_t lFinished = strFinished.Exists() ? strFinished.ToLong() : 0; // if it doesn't exist, the 0 here // causes the below error to fire. if (lFinished < 0) { otOut << "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* " "be 0 or larger. Instead I got: " << lFinished << ".\n"; return (-1); } else SetFinishedSoFar(lFinished); const String strMinInc = xml->getAttributeValue("minimumIncrement"); // if it doesn't exist, the 0 here causes the below error to fire. const int64_t lMinInc = strMinInc.Exists() ? strMinInc.ToLong() : 0; if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot // logically be higher than the // total assets on offer... { otOut << "OTOffer::ProcessXMLNode: Failure: minimumIncrement " "*must* be 1 or larger, \n" "and must also be less than the total assets on offer. " "Instead I got: " << lMinInc << ".\n"; return (-1); } else SetMinimumIncrement(lMinInc); const String strTransNum = xml->getAttributeValue("transactionNum"); const int64_t lTransNum = strTransNum.Exists() ? strTransNum.ToLong() : 0; SetTransactionNum(lTransNum); const String str_valid_from = xml->getAttributeValue("validFrom"); const String str_valid_to = xml->getAttributeValue("validTo"); int64_t tValidFrom = str_valid_from.Exists() ? parseTimestamp(str_valid_from.Get()) : 0; int64_t tValidTo = str_valid_to.Exists() ? parseTimestamp(str_valid_to.Get()) : 0; if ((tValidTo < tValidFrom) && (tValidTo != 0)) { otOut << "OTOffer::" << __FUNCTION__ << ": Failure: validTo date (" << tValidFrom << ") cannot be earlier than " "validFrom date (" << tValidTo << ").\n"; return (-1); } SetValidFrom(OTTimeGetTimeFromSeconds(tValidFrom)); SetValidTo(OTTimeGetTimeFromSeconds(tValidTo)); otLog4 << "\n\nOffer. Transaction Number: " << m_lTransactionNum << "\n Valid From: " << tValidFrom << "\n Valid To: " << tValidTo << "\n" " InstrumentDefinitionID: " << strInstrumentDefinitionID << "\n CurrencyTypeID: " << strCurrencyTypeID << "\n NotaryID: " << strNotaryID << "\n" " Price Limit: " << GetPriceLimit() << ", Total Assets on Offer: " << GetTotalAssetsOnOffer() << ", " << (m_bSelling ? "sold" : "bought") << " so far: " << GetFinishedSoFar() << "\n " " Scale: " << GetScale() << ". Minimum Increment: " << GetMinimumIncrement() << ". This offer is a" << (m_bSelling ? "n ASK" : " BID") << ".\n"; nReturnVal = 1; } return nReturnVal; }