OTTrackable::OTTrackable(const OTIdentifier & SERVER_ID, const OTIdentifier & ASSET_ID, const OTIdentifier & ACCT_ID, const OTIdentifier & USER_ID) : ot_super(SERVER_ID, ASSET_ID), m_lTransactionNum(0) { InitTrackable(); SetSenderAcctID(ACCT_ID); SetSenderUserID(USER_ID); }
// Imagine that you are actually writing a cheque. // That's basically what this function does. // Make sure to sign it afterwards. bool Cheque::IssueCheque( const int64_t& lAmount, const int64_t& lTransactionNum, const time64_t& VALID_FROM, const time64_t& VALID_TO, // The expiration date (valid from/to dates) of // the cheque const Identifier& SENDER_ACCT_ID, // The asset account the cheque is drawn // on. const Identifier& SENDER_NYM_ID, // This ID must match the user ID on the // asset account, // AND must verify the cheque signature with that user's key. const String& strMemo, // Optional memo field. const Identifier* pRECIPIENT_NYM_ID) // Recipient optional. // (Might be a blank // cheque.) { m_lAmount = lAmount; m_strMemo = strMemo; SetValidFrom(VALID_FROM); SetValidTo(VALID_TO); SetTransactionNum(lTransactionNum); SetSenderAcctID(SENDER_ACCT_ID); SetSenderNymID(SENDER_NYM_ID); if (nullptr == pRECIPIENT_NYM_ID) { m_bHasRecipient = false; m_RECIPIENT_NYM_ID.Release(); } else { m_bHasRecipient = true; m_RECIPIENT_NYM_ID = *pRECIPIENT_NYM_ID; } m_bHasRemitter = false; // OTCheque::SetAsVoucher() will set this to true. if (m_lAmount < 0) m_strContractType.Set("INVOICE"); return true; }
// return -1 if error, 0 if nothing, and 1 if the node was processed. int32_t OTTrade::ProcessXMLNode(irr::io::IrrXMLReader*& xml) { int32_t returnVal = 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 != (returnVal = ot_super::ProcessXMLNode(xml))) return returnVal; if (!strcmp("trade", xml->getNodeName())) { m_strVersion = xml->getAttributeValue("version"); tradesAlreadyDone_ = atoi(xml->getAttributeValue("completedNoTrades")); SetTransactionNum( String::StringToLong(xml->getAttributeValue("transactionNum"))); const std::string creationStr = xml->getAttributeValue("creationDate"); const std::string validFromStr = xml->getAttributeValue("validFrom"); const std::string validToStr = xml->getAttributeValue("validTo"); int64_t creation = parseTimestamp(creationStr); int64_t validFrom = parseTimestamp(validFromStr); int64_t validTo = parseTimestamp(validToStr); SetCreationDate(OTTimeGetTimeFromSeconds(creation)); SetValidFrom(OTTimeGetTimeFromSeconds(validFrom)); SetValidTo(OTTimeGetTimeFromSeconds(validTo)); String activated(xml->getAttributeValue("hasActivated")); if (activated.Compare("true")) hasTradeActivated_ = true; else hasTradeActivated_ = false; const String notaryID(xml->getAttributeValue("notaryID")), nymID(xml->getAttributeValue("nymID")), instrumentDefinitionID( xml->getAttributeValue("instrumentDefinitionID")), assetAcctID(xml->getAttributeValue("assetAcctID")), currencyTypeID(xml->getAttributeValue("currencyTypeID")), currencyAcctID(xml->getAttributeValue("currencyAcctID")); const Identifier NOTARY_ID(notaryID), NYM_ID(nymID), INSTRUMENT_DEFINITION_ID(instrumentDefinitionID), ASSET_ACCT_ID(assetAcctID), CURRENCY_TYPE_ID(currencyTypeID), CURRENCY_ACCT_ID(currencyAcctID); SetNotaryID(NOTARY_ID); SetSenderNymID(NYM_ID); SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID); SetSenderAcctID(ASSET_ACCT_ID); SetCurrencyID(CURRENCY_TYPE_ID); SetCurrencyAcctID(CURRENCY_ACCT_ID); otLog3 << "\n\nTrade. Transaction Number: " << m_lTransactionNum << " Completed # of Trades: " << tradesAlreadyDone_ << "\n"; otWarn << " Creation Date: " << creation << " Valid From: " << validFrom << "\n Valid To: " << validTo << "\n" " instrumentDefinitionID: " << instrumentDefinitionID << "\n assetAcctID: " << assetAcctID << "\n" " NotaryID: " << notaryID << "\n NymID: " << nymID << "\n " " currencyTypeID: " << currencyTypeID << "\n currencyAcctID: " << currencyAcctID << "\n "; returnVal = 1; } if (!strcmp("stopOrder", xml->getNodeName())) { String sign(xml->getAttributeValue("sign")); if (sign.Compare("0")) { stopSign_ = 0; // Zero means it isn't a stop order. So why is the // tag in the file? otErr << "Strange: Stop order tag found in trade, but sign " "character set to 0.\n" "(Zero means: NOT a stop order.)\n"; return (-1); } else if (sign.Compare("<")) stopSign_ = '<'; else if (sign.Compare(">")) stopSign_ = '>'; else { stopSign_ = 0; otErr << "Unexpected or nonexistent value in stop order sign: " << sign << "\n"; return (-1); } // Now we know the sign is properly formed, let's grab the price value. stopPrice_ = String::StringToLong(xml->getAttributeValue("price")); String activated(xml->getAttributeValue("hasActivated")); if (activated.Compare("true")) stopActivated_ = true; else stopActivated_ = false; otLog3 << "\n\nStop order -- " << (stopActivated_ ? "Already activated" : "Will activate") << " when price " << (stopActivated_ ? "was" : "reaches") << " " << (('<' == stopSign_) ? "LESS THAN" : "GREATER THAN") << ": " << stopPrice_ << ".\n"; returnVal = 1; } else if (!strcmp("offer", xml->getNodeName())) { if (!Contract::LoadEncodedTextField(xml, marketOffer_)) { otErr << "Error in OTTrade::ProcessXMLNode: offer field without " "value.\n"; return (-1); // error condition } returnVal = 1; } return returnVal; }
// 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 Cheque::ProcessXMLNode(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("cheque", xml->getNodeName())) { String strHasRecipient = xml->getAttributeValue("hasRecipient"); m_bHasRecipient = strHasRecipient.Compare("true"); String strHasRemitter = xml->getAttributeValue("hasRemitter"); m_bHasRemitter = strHasRemitter.Compare("true"); m_strVersion = xml->getAttributeValue("version"); m_lAmount = String::StringToLong(xml->getAttributeValue("amount")); SetTransactionNum( String::StringToLong(xml->getAttributeValue("transactionNum"))); const std::string str_valid_from = xml->getAttributeValue("validFrom"); const std::string str_valid_to = xml->getAttributeValue("validTo"); SetValidFrom(parseTimestamp(str_valid_from)); SetValidTo(parseTimestamp(str_valid_to)); String strInstrumentDefinitionID( xml->getAttributeValue("instrumentDefinitionID")), strNotaryID(xml->getAttributeValue("notaryID")), strSenderAcctID(xml->getAttributeValue("senderAcctID")), strSenderNymID(xml->getAttributeValue("senderNymID")), strRecipientNymID(xml->getAttributeValue("recipientNymID")), strRemitterNymID(xml->getAttributeValue("remitterNymID")), strRemitterAcctID(xml->getAttributeValue("remitterAcctID")); Identifier INSTRUMENT_DEFINITION_ID(strInstrumentDefinitionID), NOTARY_ID(strNotaryID), SENDER_ACCT_ID(strSenderAcctID), SENDER_NYM_ID(strSenderNymID); SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID); SetNotaryID(NOTARY_ID); SetSenderAcctID(SENDER_ACCT_ID); SetSenderNymID(SENDER_NYM_ID); // Recipient ID if (m_bHasRecipient) m_RECIPIENT_NYM_ID.SetString(strRecipientNymID); else m_RECIPIENT_NYM_ID.Release(); // Remitter ID (for vouchers) if (m_bHasRemitter) { m_REMITTER_NYM_ID.SetString(strRemitterNymID); m_REMITTER_ACCT_ID.SetString(strRemitterAcctID); } else { m_REMITTER_NYM_ID.Release(); m_REMITTER_ACCT_ID.Release(); } otInfo << "\n\nCheque Amount: " << m_lAmount << ". Transaction Number: " << m_lTransactionNum << "\n Valid From: " << str_valid_from << "\n Valid To: " << str_valid_to << "\n InstrumentDefinitionID: " << strInstrumentDefinitionID << "\n NotaryID: " << strNotaryID << "\n" " senderAcctID: " << strSenderAcctID << "\n senderNymID: " << strSenderNymID << "\n " " Has Recipient? " << (m_bHasRecipient ? "Yes" : "No") << ". If yes, NymID of Recipient: " << strRecipientNymID << "\n" " Has Remitter? " << (m_bHasRemitter ? "Yes" : "No") << ". If yes, NymID/Acct of Remitter: " << strRemitterNymID << " / " << strRemitterAcctID << "\n"; nReturnVal = 1; } else if (!strcmp("memo", xml->getNodeName())) { if (!Contract::LoadEncodedTextField(xml, m_strMemo)) { otErr << "Error in OTCheque::ProcessXMLNode: memo field without " "value.\n"; return (-1); // error condition } return 1; } return nReturnVal; }