Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTOffer Class Reference

#include <OTOffer.hpp>

Inheritance diagram for opentxs::OTOffer:
Collaboration diagram for opentxs::OTOffer:

Public Member Functions

EXPORT bool MakeOffer (bool bBuyingOrSelling, const int64_t &lPriceLimit, const int64_t &lTotalAssetsOffer, const int64_t &lMinimumIncrement, const int64_t &lTransactionNum, const time64_t &VALID_FROM=OT_TIME_ZERO, const time64_t &VALID_TO=OT_TIME_ZERO)
 
void IncrementFinishedSoFar (const int64_t &lFinishedSoFar)
 
int64_t GetAmountAvailable () const
 
const int64_t & GetTransactionNum () const
 
const int64_t & GetPriceLimit () const
 
const int64_t & GetTotalAssetsOnOffer () const
 
const int64_t & GetFinishedSoFar () const
 
const int64_t & GetMinimumIncrement ()
 
const int64_t & GetScale () const
 
const OTIdentifierGetCurrencyID () const
 
void SetCurrencyID (const OTIdentifier &CURRENCY_ID)
 
bool IsBid ()
 
bool IsAsk ()
 
bool IsMarketOrder () const
 
bool IsLimitOrder () const
 
OTTradeGetTrade ()
 
void SetTrade (const OTTrade &theTrade)
 
EXPORT time64_t GetDateAddedToMarket () const
 
EXPORT void SetDateAddedToMarket (time64_t tDate)
 
EXPORT OTOffer ()
 
EXPORT OTOffer (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &CURRENCY_ID, const int64_t &MARKET_SCALE)
 
virtual EXPORT ~OTOffer ()
 
virtual void GetIdentifier (OTIdentifier &theIdentifier) const
 
void InitOffer ()
 
virtual void Release ()
 
void Release_Offer ()
 
virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
virtual void UpdateContents ()
 
virtual bool SaveContractWallet (std::ofstream &ofs) const
 
- Public Member Functions inherited from opentxs::OTInstrument
EXPORT OTInstrument ()
 
EXPORT OTInstrument (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
virtual EXPORT ~OTInstrument ()
 
void Release_Instrument ()
 
EXPORT bool VerifyCurrentDate ()
 
EXPORT bool IsExpired ()
 
time64_t GetValidFrom () const
 
time64_t GetValidTo () const
 
const OTIdentifierGetAssetID () const
 
const OTIdentifierGetServerID () const
 
void InitInstrument ()
 
- Public Member Functions inherited from opentxs::OTScriptable
virtual EXPORT void SetDisplayLabel (const std::string *pstrLabel=nullptr)
 
int32_t GetPartyCount () const
 
int32_t GetBylawCount () const
 
virtual EXPORT bool AddParty (OTParty &theParty)
 
virtual EXPORT bool AddBylaw (OTBylaw &theBylaw)
 
virtual EXPORT bool ConfirmParty (OTParty &theParty)
 
EXPORT OTPartyGetParty (std::string str_party_name) const
 
EXPORT OTBylawGetBylaw (std::string str_bylaw_name) const
 
EXPORT OTClauseGetClause (std::string str_clause_name) const
 
EXPORT OTPartyGetPartyByIndex (int32_t nIndex) const
 
EXPORT OTBylawGetBylawByIndex (int32_t nIndex) const
 
EXPORT OTPartyFindPartyBasedOnNymAsAgent (OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
 
EXPORT OTPartyFindPartyBasedOnNymAsAuthAgent (OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnAccount (OTAccount &theAccount, OTPartyAccount **ppPartyAccount=nullptr) const
 
OTPartyFindPartyBasedOnNymIDAsAgent (const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnNymIDAsAuthAgent (const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnAccountID (const OTIdentifier &theAcctID, OTPartyAccount **ppPartyAccount=nullptr) const
 
OTAgentGetAgent (std::string str_agent_name) const
 
OTPartyAccountGetPartyAccount (std::string str_acct_name) const
 
OTPartyAccountGetPartyAccountByID (const OTIdentifier &theAcctID) const
 
EXPORT int32_t GetCountTransNumsNeededForAgent (std::string str_agent_name) const
 
virtual EXPORT bool VerifyNymAsAgent (OTPseudonym &theNym, OTPseudonym &theSignerNym, mapOfNyms *pmap_ALREADY_LOADED=nullptr) const
 
virtual EXPORT bool VerifyNymAsAgentForAccount (OTPseudonym &theNym, OTAccount &theAccount) const
 
bool VerifyPartyAuthorization (OTParty &theParty, OTPseudonym &theSignerNym, const OTString &strServerID, mapOfNyms *pmap_ALREADY_LOADED=nullptr, mapOfNyms *pmap_NEWLY_LOADED=nullptr, bool bBurnTransNo=false)
 
bool VerifyPartyAcctAuthorization (OTPartyAccount &thePartyAcct, OTPseudonym &theSignerNym, const OTString &strServerID, bool bBurnTransNo=false)
 
EXPORT bool VerifyThisAgainstAllPartiesSignedCopies ()
 
EXPORT bool AllPartiesHaveSupposedlyConfirmed ()
 
void RetrieveNymPointers (mapOfNyms &map_Nyms_Already_Loaded)
 
void ClearTemporaryPointers ()
 
bool GetHooks (std::string str_HookName, mapOfClauses &theResults)
 
OTClauseGetCallback (std::string str_CallbackName)
 
OTVariableGetVariable (std::string str_VarName)
 
bool IsDirty () const
 
bool IsDirtyImportant () const
 
void SetAsClean ()
 
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
 
EXPORT bool CanExecuteClause (std::string str_party_name, std::string str_clause_name)
 
bool ExecuteCallback (OTClause &theCallbackClause, mapOfVariables &theParameters, OTVariable &varReturnVal)
 
virtual EXPORT void RegisterOTNativeCallsWithScript (OTScript &theScript)
 
virtual EXPORT bool Compare (OTScriptable &rhs) const
 
 OTScriptable ()
 
virtual ~OTScriptable ()
 
void UpdateContentsToString (OTString &strAppend, bool bCalculatingID) const
 
virtual EXPORT void CalculateContractID (OTIdentifier &newID) const
 
void Release_Scriptable ()
 
- Public Member Functions inherited from opentxs::OTContract
const char * GetHashType () const
 
void SetIdentifier (const OTIdentifier &theID)
 
EXPORT OTContract ()
 
EXPORT OTContract (const OTString &name, const OTString &foldername, const OTString &filename, const OTString &strID)
 
EXPORT OTContract (const OTString &strID)
 
EXPORT OTContract (const OTIdentifier &theID)
 
void Initialize ()
 
virtual EXPORT ~OTContract ()
 
EXPORT void Release_Contract ()
 
EXPORT void ReleaseSignatures ()
 
virtual EXPORT bool CreateContract (const OTString &strContract, const OTPseudonym &theSigner)
 
EXPORT bool InsertNym (const OTString &strKeyName, const OTString &strKeyValue)
 
EXPORT void GetName (OTString &strName) const
 
EXPORT void SetName (const OTString &strName)
 
virtual EXPORT bool VerifyContract ()
 
virtual EXPORT void GetIdentifier (OTString &theIdentifier) const
 
EXPORT void GetFilename (OTString &strFilename) const
 
EXPORT void GetFoldername (OTString &strFoldername) const
 
virtual EXPORT bool LoadContract ()
 
EXPORT bool LoadContract (const char *szFoldername, const char *szFilename)
 
EXPORT bool LoadContractFromString (const OTString &theStr)
 
bool LoadContractRawFile ()
 
EXPORT bool ParseRawFile ()
 
EXPORT bool SaveToContractFolder ()
 
EXPORT bool SaveContractRaw (OTString &strOutput) const
 
EXPORT bool RewriteContract (OTString &strOutput) const
 
EXPORT bool SaveContract ()
 
EXPORT bool SaveContract (const char *szFoldername, const char *szFilename)
 
virtual EXPORT void CreateContents ()
 
EXPORT void CreateInnerContents ()
 
virtual EXPORT bool SaveContents (std::ofstream &ofs) const
 
virtual EXPORT bool SaveContractWallet (OTString &strContents) const
 
virtual EXPORT bool DisplayStatistics (OTString &strContents) const
 
virtual EXPORT bool SaveContents (OTString &strContents) const
 
virtual EXPORT bool SignContract (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const char *szFoldername, const char *szFilename, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
virtual EXPORT bool VerifyContractID () const
 
virtual EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
virtual EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifyWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const char *szFoldername, const char *szFilename, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT const OTAsymmetricKeyGetContractPublicKey () const
 
EXPORT const OTPseudonymGetContractPublicNym () const
 

Protected Member Functions

void SetTransactionNum (const int64_t &lTransactionNum)
 
void SetPriceLimit (const int64_t &lPriceLimit)
 
void SetTotalAssetsOnOffer (const int64_t &lTotalAssets)
 
void SetFinishedSoFar (const int64_t &lFinishedSoFar)
 
void SetMinimumIncrement (const int64_t &lMinIncrement)
 
void SetScale (const int64_t &lScale)
 
- Protected Member Functions inherited from opentxs::OTInstrument
void SetValidFrom (time64_t TIME_FROM)
 
void SetValidTo (time64_t TIME_TO)
 
void SetAssetID (const OTIdentifier &ASSET_ID)
 
void SetServerID (const OTIdentifier &SERVER_ID)
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Protected Attributes

OTTradem_pTrade
 
OTIdentifier m_CURRENCY_TYPE_ID
 
bool m_bSelling
 
int64_t m_lPriceLimit
 
int64_t m_lTransactionNum
 
int64_t m_lTotalAssetsOffer
 
int64_t m_lFinishedSoFar
 
int64_t m_lScale
 
int64_t m_lMinimumIncrement
 
- Protected Attributes inherited from opentxs::OTInstrument
OTIdentifier m_AssetTypeID
 
OTIdentifier m_ServerID
 
time64_t m_VALID_FROM
 
time64_t m_VALID_TO
 
- Protected Attributes inherited from opentxs::OTScriptable
mapOfParties m_mapParties
 
mapOfBylaws m_mapBylaws
 
bool m_bCalculatingID
 
bool m_bSpecifyAssetID
 
bool m_bSpecifyParties
 
OTString m_strLabel
 
- Protected Attributes inherited from opentxs::OTContract
OTString m_strName
 
OTString m_strFoldername
 
OTString m_strFilename
 
OTIdentifier m_ID
 
OTStringXML m_xmlUnsigned
 
OTString m_strRawFile
 
OTString m_strSigHashType
 
OTString m_strContractType
 
mapOfNyms m_mapNyms
 
listOfSignatures m_listSignatures
 
OTString m_strVersion
 
OTString m_strEntityShortName
 
OTString m_strEntityLongName
 
OTString m_strEntityEmail
 
OTString::Map m_mapConditions
 

Additional Inherited Members

- Static Public Member Functions inherited from opentxs::OTScriptable
static EXPORT OTScriptableInstantiateScriptable (const OTString &strInput)
 
static bool ValidateName (std::string str_name)
 
static std::string GetTime ()
 
- Static Public Member Functions inherited from opentxs::OTContract
static EXPORT bool DearmorAndTrim (const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
 
static bool AddBookendsAroundContent (OTString &strOutput, const OTString &strContents, const OTString &strContractType, const OTString &strHashType, const listOfSignatures &listSignatures)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTString &strOutput)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTString &strOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool SkipToElement (irr::io::IrrXMLReader *&xml)
 
static bool SkipToTextField (irr::io::IrrXMLReader *&xml)
 
static bool SkipAfterLoadingField (irr::io::IrrXMLReader *&xml)
 
static EXPORT bool SignFlatText (OTString &strFlatText, const OTString &strContractType, const OTPseudonym &theSigner, OTString &strOutput)
 

Detailed Description

Definition at line 167 of file OTOffer.hpp.

Constructor & Destructor Documentation

opentxs::OTOffer::OTOffer ( )

Definition at line 510 of file OTOffer.cpp.

511  : ot_super()
512  , m_tDateAddedToMarket(OT_TIME_ZERO)
513  , m_pTrade(nullptr)
514  , // No need to free m_pTrade, not responsible. Only here for convenience.
515  m_bSelling(false)
516  , m_lPriceLimit(0)
517  , m_lTransactionNum(0)
519  , m_lFinishedSoFar(0)
520  , m_lScale(1)
521  , // This must be 1 or greater. CANNOT be zero. Enforced.
523  1) // This must be 1 or greater. CANNOT be zero. Enforced.
524 {
525  InitOffer();
526 }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
void InitOffer()
Definition: OTOffer.cpp:574
OTTrade * m_pTrade
Definition: OTOffer.hpp:198
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
int64_t m_lScale
Definition: OTOffer.hpp:219
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
#define OT_TIME_ZERO
Definition: Common.hpp:180
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
opentxs::OTOffer::OTOffer ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID,
const OTIdentifier CURRENCY_ID,
const int64_t &  MARKET_SCALE 
)

Definition at line 528 of file OTOffer.cpp.

530  : ot_super(SERVER_ID, ASSET_ID)
531  , m_tDateAddedToMarket(OT_TIME_ZERO)
532  , m_pTrade(nullptr)
533  , // No need to free m_pTrade, not responsible. Only here for convenience.
534  m_bSelling(false)
535  , m_lPriceLimit(0)
536  , m_lTransactionNum(0)
538  , m_lFinishedSoFar(0)
539  , m_lScale(1)
540  , // This must be 1 or greater. CANNOT be zero. Enforced.
542  1) // This must be 1 or greater. CANNOT be zero. Enforced.
543 {
544  InitOffer();
545 
546  SetScale(lScale);
547 
548  m_CURRENCY_TYPE_ID = CURRENCY_ID;
549 }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
void InitOffer()
Definition: OTOffer.cpp:574
OTTrade * m_pTrade
Definition: OTOffer.hpp:198
void SetScale(const int64_t &lScale)
Definition: OTOffer.hpp:249
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
int64_t m_lScale
Definition: OTOffer.hpp:219
OTIdentifier m_CURRENCY_TYPE_ID
Definition: OTOffer.hpp:201
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
#define OT_TIME_ZERO
Definition: Common.hpp:180
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
opentxs::OTOffer::~OTOffer ( )
virtual

Definition at line 551 of file OTOffer.cpp.

552 {
553  Release_Offer();
554 }
void Release_Offer()
Definition: OTOffer.cpp:556

Member Function Documentation

int64_t opentxs::OTOffer::GetAmountAvailable ( ) const
inline

Definition at line 273 of file OTOffer.hpp.

274  {
276  }
const int64_t & GetTotalAssetsOnOffer() const
Definition: OTOffer.hpp:286
const int64_t & GetFinishedSoFar() const
Definition: OTOffer.hpp:290
const OTIdentifier& opentxs::OTOffer::GetCurrencyID ( ) const
inline

Definition at line 304 of file OTOffer.hpp.

305  {
306  return m_CURRENCY_TYPE_ID;
307  }
OTIdentifier m_CURRENCY_TYPE_ID
Definition: OTOffer.hpp:201
time64_t opentxs::OTOffer::GetDateAddedToMarket ( ) const

Definition at line 498 of file OTOffer.cpp.

500 {
501  return m_tDateAddedToMarket;
502 }
const int64_t& opentxs::OTOffer::GetFinishedSoFar ( ) const
inline

Definition at line 290 of file OTOffer.hpp.

291  {
292  return m_lFinishedSoFar;
293  }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
void opentxs::OTOffer::GetIdentifier ( OTIdentifier theIdentifier) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 206 of file OTOffer.cpp.

207 {
208  OTString strTemp, strAsset(GetAssetID()), strCurrency(GetCurrencyID());
209 
210  int64_t lScale = GetScale();
211 
212  // In this way we generate a unique ID that will always be consistent
213  // for the same asset ID, currency ID, and market scale.
214  strTemp.Format("ASSET TYPE:\n%s\nCURRENCY TYPE:\n%s\nMARKET SCALE:\n%lld\n",
215  strAsset.Get(), strCurrency.Get(), lScale);
216 
217  theIdentifier.CalculateDigest(strTemp);
218 }
const int64_t & GetScale() const
Definition: OTOffer.hpp:299
const OTIdentifier & GetAssetID() const
const OTIdentifier & GetCurrencyID() const
Definition: OTOffer.hpp:304
const int64_t& opentxs::OTOffer::GetMinimumIncrement ( )
inline

Definition at line 294 of file OTOffer.hpp.

295  {
297  return m_lMinimumIncrement;
298  }
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
const int64_t& opentxs::OTOffer::GetPriceLimit ( ) const
inline

Definition at line 282 of file OTOffer.hpp.

283  {
284  return m_lPriceLimit;
285  }
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
const int64_t& opentxs::OTOffer::GetScale ( ) const
inline

Definition at line 299 of file OTOffer.hpp.

300  {
301  return m_lScale;
302  }
int64_t m_lScale
Definition: OTOffer.hpp:219
const int64_t& opentxs::OTOffer::GetTotalAssetsOnOffer ( ) const
inline

Definition at line 286 of file OTOffer.hpp.

287  {
288  return m_lTotalAssetsOffer;
289  }
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
OTTrade* opentxs::OTOffer::GetTrade ( )
inline

Definition at line 328 of file OTOffer.hpp.

329  {
330  return m_pTrade;
331  }
OTTrade * m_pTrade
Definition: OTOffer.hpp:198
const int64_t& opentxs::OTOffer::GetTransactionNum ( ) const
inline

Definition at line 277 of file OTOffer.hpp.

278  {
279  return m_lTransactionNum;
280  }
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
void opentxs::OTOffer::IncrementFinishedSoFar ( const int64_t &  lFinishedSoFar)
inline

Definition at line 268 of file OTOffer.hpp.

269  {
270  m_lFinishedSoFar += lFinishedSoFar;
271  }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
void opentxs::OTOffer::InitOffer ( )

Definition at line 574 of file OTOffer.cpp.

575 {
577  "OFFER"); // in practice should never appear. BID/ASK will overwrite.
578 
579  // This pointer will get wiped anytime Release() is called... which means
580  // anytime LoadContractFromString()
581  // is called. For some objects, that screws them up because suddenly the
582  // pointer went nullptr when they needed it.
583  // In the case of this object, the pointer is reset whenever Cron processes,
584  // so this is safe. But in
585  // the case of other objects, it's better not to initialize the pointer
586  // here, but in the constructor instead.
587  // FYI. For example, OTCron has a pointer to m_pServerNym. LoadCron() and
588  // the pointer is nullptr. Can't have that!
589  // So I moved it to the constructor in that case.
590 
591  m_bSelling = false;
592  m_lPriceLimit = 0;
593  m_lTransactionNum = 0;
595  m_lFinishedSoFar = 0;
596  m_lMinimumIncrement = 1; // This must be 1 or greater. Enforced.
597  SetScale(1); // This must be 1 or greater. Enforced.
598 }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
OTString m_strContractType
Definition: OTContract.hpp:178
void SetScale(const int64_t &lScale)
Definition: OTOffer.hpp:249
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
bool opentxs::OTOffer::IsAsk ( )
inline

Definition at line 318 of file OTOffer.hpp.

319  {
320  return m_bSelling;
321  }
bool opentxs::OTOffer::IsBid ( )
inline

Definition at line 314 of file OTOffer.hpp.

315  {
316  return !m_bSelling;
317  }
bool opentxs::OTOffer::IsLimitOrder ( ) const

Definition at line 225 of file OTOffer.cpp.

226 {
227  return (0 != GetPriceLimit());
228 }
const int64_t & GetPriceLimit() const
Definition: OTOffer.hpp:282
bool opentxs::OTOffer::IsMarketOrder ( ) const

Definition at line 220 of file OTOffer.cpp.

221 {
222  return (0 == GetPriceLimit());
223 }
const int64_t & GetPriceLimit() const
Definition: OTOffer.hpp:282
bool opentxs::OTOffer::MakeOffer ( bool  bBuyingOrSelling,
const int64_t &  lPriceLimit,
const int64_t &  lTotalAssetsOffer,
const int64_t &  lMinimumIncrement,
const int64_t &  lTransactionNum,
const time64_t VALID_FROM = OT_TIME_ZERO,
const time64_t VALID_TO = OT_TIME_ZERO 
)

Definition at line 434 of file OTOffer.cpp.

446 {
447  m_bSelling = bBuyingOrSelling; // Bid or Ask?
448  SetTransactionNum(lTransactionNum);
449  SetTotalAssetsOnOffer(lTotalAssetsOffer); // 500 bushels for sale.
450 
451  m_strContractType.Set((m_bSelling ? "ASK" : "BID"));
452 
453  // Make sure minimum increment isn't bigger than total Assets.
454  // (If you pass them into this function as the same value, it's functionally
455  // a "FILL OR KILL" order.)
456  int64_t lRealMinInc = lMinimumIncrement;
457  if (lMinimumIncrement > lTotalAssetsOffer) // Once the total, minus finish
458  // so far, is smaller than the
459  // minimum increment,
460  lRealMinInc = lTotalAssetsOffer; // then the OTTrade object I am linked
461  // to will expire and remove me from
462  // the market.
463  // OR it could set the minimum increment to the remainder. But then need to
464  // calc price.
465 
466  SetMinimumIncrement(lRealMinInc); // Must sell in 50 bushel increments.
467  // (Perhaps on the 10-bushel market it
468  // will sell in 5 increments of 10.)
469  SetPriceLimit(lPriceLimit); // Won't sell for any less than $10 per
470  // increment. (Always get best market price.)
471  SetFinishedSoFar(0); // So far have already sold 350 bushels. Actual amount
472  // available is (total - finished).
473 
474  time64_t REAL_VALID_FROM = VALID_FROM;
475  time64_t REAL_VALID_TO = VALID_TO;
476 
477  if (OT_TIME_ZERO >= VALID_FROM) {
478  REAL_VALID_FROM =
479  OTTimeGetCurrentTime(); // This time is set to TODAY NOW
480  }
481 
482  if (OT_TIME_ZERO >= VALID_TO) {
483  // (All offers default to a "DAY ORDER" if valid dates not specified.)
484  REAL_VALID_TO = OTTimeAddTimeInterval(
485  REAL_VALID_FROM,
487  }
488 
489  SetValidFrom(REAL_VALID_FROM);
490  SetValidTo(REAL_VALID_TO);
491 
492  return true;
493 }
void SetFinishedSoFar(const int64_t &lFinishedSoFar)
Definition: OTOffer.hpp:240
void SetValidFrom(time64_t TIME_FROM)
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
void SetTransactionNum(const int64_t &lTransactionNum)
Definition: OTOffer.hpp:228
void SetValidTo(time64_t TIME_TO)
int64_t time64_t
Definition: Common.hpp:209
#define OT_TIME_DAY_IN_SECONDS
Definition: Common.hpp:176
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
OTString m_strContractType
Definition: OTContract.hpp:178
void SetTotalAssetsOnOffer(const int64_t &lTotalAssets)
Definition: OTOffer.hpp:236
void SetMinimumIncrement(const int64_t &lMinIncrement)
Definition: OTOffer.hpp:244
void SetPriceLimit(const int64_t &lPriceLimit)
Definition: OTOffer.hpp:232
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
int32_t opentxs::OTOffer::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
virtual

Reimplemented from opentxs::OTInstrument.

Definition at line 231 of file OTOffer.cpp.

232 {
233  int32_t nReturnVal = 0;
234 
235  // Here we call the parent class first.
236  // If the node is found there, or there is some error,
237  // then we just return either way. But if it comes back
238  // as '0', then nothing happened, and we'll continue executing.
239  //
240  // -- Note you can choose not to call the parent if
241  // you don't want to use any of those xml tags.
242  // As I do below, in the case of OTAccount.
243  // if (nReturnVal = OTContract::ProcessXMLNode(xml))
244  // return nReturnVal;
245 
246  if (!strcmp("marketOffer", xml->getNodeName())) {
247  m_strVersion = xml->getAttributeValue("version");
248 
249  OTString strIsSelling;
250  strIsSelling = xml->getAttributeValue("isSelling");
251  if (strIsSelling.Compare("true"))
252  m_bSelling = true;
253  else
254  m_bSelling = false;
255 
256  m_strContractType.Set((m_bSelling ? "ASK" : "BID"));
257 
258  const OTString strServerID(xml->getAttributeValue("serverID")),
259  strAssetTypeID(xml->getAttributeValue("assetTypeID")),
260  strCurrencyTypeID(xml->getAttributeValue("currencyTypeID"));
261 
262  const OTIdentifier SERVER_ID(strServerID), ASSET_ID(strAssetTypeID),
263  CURRENCY_TYPE_ID(strCurrencyTypeID);
264 
265  SetServerID(SERVER_ID);
266  SetAssetID(ASSET_ID);
267  SetCurrencyID(CURRENCY_TYPE_ID);
268 
269  const OTString strScale = xml->getAttributeValue("marketScale");
270  const int64_t lScale = strScale.Exists() ? atol(strScale.Get())
271  : 0; // if it doesn't exist,
272  // the 0 here causes the
273  // below error to fire.
274 
275  if (!isPowerOfTen(lScale)) {
276  otOut << "OTOffer::ProcessXMLNode: Failure: marketScale *must* be "
277  "1, or a power of 10. Instead I got: " << lScale << ".\n";
278  return (-1);
279  }
280  else
281  SetScale(lScale);
282 
283  const OTString strPriceLimit = xml->getAttributeValue("priceLimit");
284  const int64_t lPriceLimit = strPriceLimit.Exists()
285  ? atol(strPriceLimit.Get())
286  : 0; // if it doesn't exist, the 0 here
287  // causes the below error to fire.
288 
289  // NOTE: Market Orders (new) have a 0 price, so this error condition was
290  // changed.
291  if (!strPriceLimit.Exists())
292  // if (lPriceLimit < 1)
293  {
294  otOut << "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be "
295  "provided(" << lPriceLimit << ").\n";
296  return (-1);
297  }
298  else
299  SetPriceLimit(lPriceLimit);
300 
301  const OTString strTotal = xml->getAttributeValue("totalAssetsOnOffer");
302  const int64_t lTotal = strTotal.Exists() ? atol(strTotal.Get())
303  : 0; // if it doesn't exist,
304  // the 0 here causes the
305  // below error to fire.
306  if (lTotal < 1) {
307  otOut << "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer "
308  "*must* be larger than 0. Instead I got: " << lTotal
309  << ".\n";
310  return (-1);
311  }
312  else
313  SetTotalAssetsOnOffer(lTotal);
314 
315  const OTString strFinished = xml->getAttributeValue("finishedSoFar");
316  const int64_t lFinished = strFinished.Exists()
317  ? atol(strFinished.Get())
318  : 0; // if it doesn't exist, the 0 here
319  // causes the below error to fire.
320  if (lFinished < 0) {
321  otOut << "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* "
322  "be 0 or larger. Instead I got: " << lFinished << ".\n";
323  return (-1);
324  }
325  else
326  SetFinishedSoFar(lFinished);
327 
328  const OTString strMinInc = xml->getAttributeValue("minimumIncrement");
329  const int64_t lMinInc = strMinInc.Exists() ? atol(strMinInc.Get())
330  : 0; // if it doesn't exist,
331  // the 0 here causes the
332  // below error to fire.
333  if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot
334  // logically be higher than the
335  // total assets on offer...
336  {
337  otOut << "OTOffer::ProcessXMLNode: Failure: minimumIncrement "
338  "*must* be 1 or larger, \n"
339  "and must also be less than the total assets on offer. "
340  "Instead I got: " << lMinInc << ".\n";
341  return (-1);
342  }
343  else
344  SetMinimumIncrement(lMinInc);
345 
346  const OTString strTransNum = xml->getAttributeValue("transactionNum");
347  const int64_t lTransNum =
348  strTransNum.Exists() ? atol(strTransNum.Get()) : 0;
349 
350  SetTransactionNum(lTransNum);
351 
352  const OTString str_valid_from = xml->getAttributeValue("validFrom");
353  const OTString str_valid_to = xml->getAttributeValue("validTo");
354 
355  int64_t tValidFrom =
356  str_valid_from.Exists() ? str_valid_from.ToLong() : 0;
357  int64_t tValidTo = str_valid_to.Exists() ? str_valid_to.ToLong() : 0;
358 
359  if ((tValidTo < tValidFrom) && (tValidTo != 0)) {
360  otOut << "OTOffer::" << __FUNCTION__ << ": Failure: validTo date ("
361  << tValidFrom << ") cannot be earlier than "
362  "validFrom date (" << tValidTo << ").\n";
363  return (-1);
364  }
365 
368 
369  otLog4 << "\n\nOffer. Transaction Number: " << m_lTransactionNum
370  << "\n Valid From: " << tValidFrom << "\n Valid To: " << tValidTo
371  << "\n"
372  " AssetTypeID: " << strAssetTypeID
373  << "\n CurrencyTypeID: " << strCurrencyTypeID
374  << "\n ServerID: " << strServerID
375  << "\n"
376  " Price Limit: " << GetPriceLimit()
377  << ", Total Assets on Offer: " << GetTotalAssetsOnOffer()
378  << ", " << (m_bSelling ? "sold" : "bought")
379  << " so far: " << GetFinishedSoFar() << "\n "
380  " Scale: " << GetScale()
381  << ". Minimum Increment: " << GetMinimumIncrement()
382  << ". This offer is a" << (m_bSelling ? "n ASK" : " BID")
383  << ".\n";
384 
385  nReturnVal = 1;
386  }
387 
388  return nReturnVal;
389 }
void SetFinishedSoFar(const int64_t &lFinishedSoFar)
Definition: OTOffer.hpp:240
const int64_t & GetMinimumIncrement()
Definition: OTOffer.hpp:294
OTLOG_IMPORT OTLogStream otLog4
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
void SetValidFrom(time64_t TIME_FROM)
const int64_t & GetScale() const
Definition: OTOffer.hpp:299
OTLOG_IMPORT OTLogStream otOut
void SetTransactionNum(const int64_t &lTransactionNum)
Definition: OTOffer.hpp:228
void SetCurrencyID(const OTIdentifier &CURRENCY_ID)
Definition: OTOffer.hpp:308
void SetValidTo(time64_t TIME_TO)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
Definition: Common.hpp:215
void SetAssetID(const OTIdentifier &ASSET_ID)
const int64_t & GetTotalAssetsOnOffer() const
Definition: OTOffer.hpp:286
const int64_t & GetFinishedSoFar() const
Definition: OTOffer.hpp:290
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
OTString m_strContractType
Definition: OTContract.hpp:178
bool isPowerOfTen(const int64_t &x)
Definition: OTOffer.cpp:149
void SetScale(const int64_t &lScale)
Definition: OTOffer.hpp:249
void SetServerID(const OTIdentifier &SERVER_ID)
void SetTotalAssetsOnOffer(const int64_t &lTotalAssets)
Definition: OTOffer.hpp:236
void SetMinimumIncrement(const int64_t &lMinIncrement)
Definition: OTOffer.hpp:244
void SetPriceLimit(const int64_t &lPriceLimit)
Definition: OTOffer.hpp:232
const int64_t & GetPriceLimit() const
Definition: OTOffer.hpp:282
void opentxs::OTOffer::Release ( void  )
virtual

Reimplemented from opentxs::OTInstrument.

Definition at line 562 of file OTOffer.cpp.

563 {
564  // If there were any dynamically allocated objects, clean them up here.
565  Release_Offer();
566 
567  ot_super::Release(); // since I've overridden the base class, I call it
568  // now...
569 
570  // Then I call this to re-initialize everything
571  InitOffer();
572 }
virtual EXPORT void Release()
void InitOffer()
Definition: OTOffer.cpp:574
void Release_Offer()
Definition: OTOffer.cpp:556
void opentxs::OTOffer::Release_Offer ( )

Definition at line 556 of file OTOffer.cpp.

557 {
558  // If there were any dynamically allocated objects, clean them up here.
560 }
OTIdentifier m_CURRENCY_TYPE_ID
Definition: OTOffer.hpp:201
virtual EXPORT void Release()
Definition: OTData.cpp:257
bool opentxs::OTOffer::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Reimplemented from opentxs::OTInstrument.

Definition at line 600 of file OTOffer.cpp.

601 {
602  return true;
603 }
void opentxs::OTOffer::SetCurrencyID ( const OTIdentifier CURRENCY_ID)
inline

Definition at line 308 of file OTOffer.hpp.

309  {
310  m_CURRENCY_TYPE_ID = CURRENCY_ID;
311  }
OTIdentifier m_CURRENCY_TYPE_ID
Definition: OTOffer.hpp:201
void opentxs::OTOffer::SetDateAddedToMarket ( time64_t  tDate)

Definition at line 504 of file OTOffer.cpp.

506 {
507  m_tDateAddedToMarket = tDate;
508 }
void opentxs::OTOffer::SetFinishedSoFar ( const int64_t &  lFinishedSoFar)
inlineprotected

Definition at line 240 of file OTOffer.hpp.

241  {
242  m_lFinishedSoFar = lFinishedSoFar;
243  }
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
void opentxs::OTOffer::SetMinimumIncrement ( const int64_t &  lMinIncrement)
inlineprotected

Definition at line 244 of file OTOffer.hpp.

245  {
246  m_lMinimumIncrement = lMinIncrement;
248  }
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
void opentxs::OTOffer::SetPriceLimit ( const int64_t &  lPriceLimit)
inlineprotected

Definition at line 232 of file OTOffer.hpp.

233  {
234  m_lPriceLimit = lPriceLimit;
235  }
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
void opentxs::OTOffer::SetScale ( const int64_t &  lScale)
inlineprotected

Definition at line 249 of file OTOffer.hpp.

250  {
251  m_lScale = lScale;
252  if (m_lScale < 1) m_lScale = 1;
253  }
int64_t m_lScale
Definition: OTOffer.hpp:219
void opentxs::OTOffer::SetTotalAssetsOnOffer ( const int64_t &  lTotalAssets)
inlineprotected

Definition at line 236 of file OTOffer.hpp.

237  {
238  m_lTotalAssetsOffer = lTotalAssets;
239  }
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
void opentxs::OTOffer::SetTrade ( const OTTrade theTrade)
inline

Definition at line 332 of file OTOffer.hpp.

333  {
334  m_pTrade = &((OTTrade&)theTrade);
335  }
OTTrade * m_pTrade
Definition: OTOffer.hpp:198
void opentxs::OTOffer::SetTransactionNum ( const int64_t &  lTransactionNum)
inlineprotected

Definition at line 228 of file OTOffer.hpp.

229  {
230  m_lTransactionNum = lTransactionNum;
231  }
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
void opentxs::OTOffer::UpdateContents ( )
virtual

Reimplemented from opentxs::OTScriptable.

Definition at line 391 of file OTOffer.cpp.

392 {
393  const OTString SERVER_ID(GetServerID()), ASSET_TYPE_ID(GetAssetID()),
394  CURRENCY_TYPE_ID(GetCurrencyID());
395 
396  const int64_t lFrom = OTTimeGetSecondsFromTime(GetValidFrom());
397  const int64_t lTo = OTTimeGetSecondsFromTime(GetValidTo());
398  const int64_t lPriceLimit = GetPriceLimit();
399  const int64_t lTotalAssetsOnOffer = GetTotalAssetsOnOffer();
400  const int64_t lFinishedSoFar = GetFinishedSoFar();
401  const int64_t lScale = GetScale();
402  const int64_t lMinimumIncrement = GetMinimumIncrement();
403  const int64_t lTransactionNum = GetTransactionNum();
404 
405  // I release this because I'm about to repopulate it.
407 
408  m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
409 
411  "<marketOffer\n version=\"%s\"\n"
412  " isSelling=\"%s\"\n" // true or false.
413  " serverID=\"%s\"\n"
414  " assetTypeID=\"%s\"\n"
415  " currencyTypeID=\"%s\"\n"
416  " priceLimit=\"%lld\"\n"
417  " totalAssetsOnOffer=\"%lld\"\n"
418  " finishedSoFar=\"%lld\"\n"
419  " marketScale=\"%lld\"\n"
420  " minimumIncrement=\"%lld\"\n"
421  " transactionNum=\"%lld\"\n"
422  " validFrom=\"%" PRId64 "\"\n"
423  " validTo=\"%" PRId64 "\""
424  " />\n\n", // <=== the tag ends here.
425  m_strVersion.Get(),
426  (IsBid() ? "false" : "true"), SERVER_ID.Get(), ASSET_TYPE_ID.Get(),
427  CURRENCY_TYPE_ID.Get(), lPriceLimit, lTotalAssetsOnOffer,
428  lFinishedSoFar, lScale, lMinimumIncrement, lTransactionNum, lFrom, lTo);
429 
430  // m_xmlUnsigned.Concatenate("</marketOffer>\n"); // ^^^ Tag already
431  // ended above.
432 }
const int64_t & GetMinimumIncrement()
Definition: OTOffer.hpp:294
time64_t GetValidTo() const
const int64_t & GetScale() const
Definition: OTOffer.hpp:299
const OTIdentifier & GetAssetID() const
const OTIdentifier & GetCurrencyID() const
Definition: OTOffer.hpp:304
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
const int64_t & GetTotalAssetsOnOffer() const
Definition: OTOffer.hpp:286
const OTIdentifier & GetServerID() const
time64_t GetValidFrom() const
const int64_t & GetFinishedSoFar() const
Definition: OTOffer.hpp:290
const int64_t & GetTransactionNum() const
Definition: OTOffer.hpp:277
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
EXPORT const char * Get() const
Definition: OTString.cpp:1045
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
virtual EXPORT void Release()
Definition: OTString.cpp:765
const int64_t & GetPriceLimit() const
Definition: OTOffer.hpp:282

Member Data Documentation

bool opentxs::OTOffer::m_bSelling
protected

Definition at line 203 of file OTOffer.hpp.

OTIdentifier opentxs::OTOffer::m_CURRENCY_TYPE_ID
protected

Definition at line 201 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lFinishedSoFar
protected

Definition at line 216 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lMinimumIncrement
protected

Definition at line 221 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lPriceLimit
protected

Definition at line 208 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lScale
protected

Definition at line 219 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lTotalAssetsOffer
protected

Definition at line 214 of file OTOffer.hpp.

int64_t opentxs::OTOffer::m_lTransactionNum
protected

Definition at line 213 of file OTOffer.hpp.

OTTrade* opentxs::OTOffer::m_pTrade
protected

Definition at line 198 of file OTOffer.hpp.


The documentation for this class was generated from the following files: