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

#include <OTAssetContract.hpp>

Inheritance diagram for opentxs::OTAssetContract:
Collaboration diagram for opentxs::OTAssetContract:

Public Member Functions

EXPORT OTAssetContract ()
 
EXPORT OTAssetContract (OTString &name, OTString &foldername, OTString &filename, OTString &strID)
 
virtual EXPORT ~OTAssetContract ()
 
virtual EXPORT void CreateContents ()
 
EXPORT bool IsShares () const
 
EXPORT bool AddAccountRecord (const OTAccount &theAccount) const
 
EXPORT bool EraseAccountRecord (const OTIdentifier &theAcctID) const
 
EXPORT bool VisitAccountRecords (AccountVisitor &visitor) const
 
EXPORT bool FormatAmount (int64_t amount, std::string &str_output) const
 
EXPORT bool StringToAmount (int64_t &amount, const std::string &str_input) const
 
EXPORT const OTString & GetBasketInfo () const
 
EXPORT const OTString & GetCurrencyName () const
 
EXPORT const OTString & GetCurrencyFraction () const
 
EXPORT const OTString & GetCurrencySymbol () const
 
EXPORT const OTString & GetCurrencyTLA () const
 
virtual EXPORT bool SaveContractWallet (OTString &strContents) const
 
virtual EXPORT bool SaveContractWallet (std::ofstream &ofs) const
 
virtual EXPORT bool DisplayStatistics (OTString &strContents) const
 
- 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 ()
 
virtual EXPORT void Release ()
 
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 (OTIdentifier &theIdentifier) const
 
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 UpdateContents ()
 
EXPORT void CreateInnerContents ()
 
virtual EXPORT bool SaveContents (std::ofstream &ofs) 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 void CalculateContractID (OTIdentifier &newID) 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 OTAsymmetricKey * GetContractPublicKey () const
 
EXPORT const OTPseudonym * GetContractPublicNym () const
 

Static Public Member Functions

static EXPORT std::string formatLongAmount (int64_t lValue, int32_t nFactor=100, int32_t nPower=2, const char *szCurrencySymbol="", const char *szThousandSeparator=",", const char *szDecimalPoint=".")
 
static EXPORT bool ParseFormatted (int64_t &lResult, const std::string &str_input, int32_t nFactor=100, int32_t nPower=2, const char *szThousandSeparator=",", const char *szDecimalPoint=".")
 
- 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)
 

Protected Member Functions

virtual EXPORT int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Protected Attributes

OTString m_strBasketInfo
 
OTString m_strIssueCompany
 
OTString m_strIssueEmail
 
OTString m_strIssueContractURL
 
OTString m_strIssueType
 
OTString m_strIssueDate
 
OTString m_strCurrencyName
 
OTString m_strCurrencyType
 
OTString m_strCurrencySymbol
 
OTString m_strCurrencyTLA
 
OTString m_strCurrencyFactor
 
OTString m_strCurrencyDecimalPower
 
OTString m_strCurrencyFraction
 
bool m_bIsCurrency
 
bool m_bIsShares
 
- 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
 

Detailed Description

Definition at line 147 of file OTAssetContract.hpp.

Constructor & Destructor Documentation

opentxs::OTAssetContract::OTAssetContract ( )

Definition at line 433 of file OTAssetContract.cpp.

434  : OTContract()
435  , m_bIsCurrency(true)
436  , m_bIsShares(false)
437 {
438 }
opentxs::OTAssetContract::OTAssetContract ( OTString &  name,
OTString &  foldername,
OTString &  filename,
OTString &  strID 
)

Definition at line 440 of file OTAssetContract.cpp.

442  : OTContract(name, foldername, filename, strID)
443  , m_bIsCurrency(true)
444  , m_bIsShares(false)
445 {
446 }
opentxs::OTAssetContract::~OTAssetContract ( )
virtual

Definition at line 448 of file OTAssetContract.cpp.

449 {
450 }

Member Function Documentation

bool opentxs::OTAssetContract::AddAccountRecord ( const OTAccount &  theAccount) const

Definition at line 598 of file OTAssetContract.cpp.

607 {
608  // Load up account list StringMap. Create it if doesn't already exist.
609  // See if account is already there in the map. Add it otherwise.
610  // Save the StringMap back again. (The account records list for a given
611  // asset type.)
612 
613  const char* szFunc = "OTAssetContract::AddAccountRecord";
614 
615  if (theAccount.GetAssetTypeID() != m_ID) {
616  otErr << szFunc << ": Error: theAccount doesn't have the same asset "
617  "type ID as *this does.\n";
618  return false;
619  }
620 
621  const OTIdentifier theAcctID(theAccount);
622  const OTString strAcctID(theAcctID);
623 
624  OTString strAssetTypeID, strAcctRecordFile;
625  GetIdentifier(strAssetTypeID);
626  strAcctRecordFile.Format("%s.a", strAssetTypeID.Get());
627 
628  OTDB::Storable* pStorable = nullptr;
629  std::unique_ptr<OTDB::Storable> theAngel;
630  OTDB::StringMap* pMap = nullptr;
631 
632  if (OTDB::Exists(OTFolders::Contract().Get(),
633  strAcctRecordFile.Get())) // the file already exists; let's
634  // try to load it up.
636  OTFolders::Contract().Get(),
637  strAcctRecordFile.Get());
638  else // the account records file (for this asset type) doesn't exist.
639  pStorable = OTDB::CreateObject(
640  OTDB::STORED_OBJ_STRING_MAP); // this asserts already, on failure.
641 
642  theAngel.reset(pStorable);
643  pMap = (nullptr == pStorable) ? nullptr
644  : dynamic_cast<OTDB::StringMap*>(pStorable);
645 
646  // It exists.
647  //
648  if (nullptr == pMap) {
649  otErr << szFunc
650  << ": Error: failed trying to load or create the account records "
651  "file for asset type: " << strAssetTypeID << "\n";
652  return false;
653  }
654 
655  auto& theMap = pMap->the_map;
656  auto map_it = theMap.find(strAcctID.Get());
657 
658  if (theMap.end() != map_it) // we found it.
659  { // We were ADDING IT, but it was ALREADY THERE.
660  // (Thus, we're ALREADY DONE.)
661  // Let's just make sure the right asset type ID is associated with this
662  // account
663  // (it better be, since we loaded the account records file based on the
664  // asset type ID as its filename...)
665  //
666  const std::string& str2 =
667  map_it->second; // Containing the asset type ID. (Just in case
668  // someone copied the wrong file here,
669  // -------------------------------- // every account should map
670  // to the SAME asset ID.)
671 
672  if (false ==
673  strAssetTypeID.Compare(str2.c_str())) // should never happen.
674  {
675  otErr << szFunc
676  << ": Error: wrong asset type found in account records "
677  "file...\n For asset type: " << strAssetTypeID
678  << "\n "
679  "For account: " << strAcctID
680  << "\n Found wrong asset type: " << str2 << "\n";
681  return false;
682  }
683 
684  return true; // already there (no need to add.) + the asset type ID
685  // matches.
686  }
687 
688  // it wasn't already on the list...
689 
690  // ...so add it.
691  //
692  theMap[strAcctID.Get()] = strAssetTypeID.Get();
693 
694  // Then save it back to local storage:
695  //
696  if (!OTDB::StoreObject(*pMap, OTFolders::Contract().Get(),
697  strAcctRecordFile.Get())) {
698  otErr << szFunc
699  << ": Failed trying to StoreObject, while saving updated "
700  "account records file for asset type: " << strAssetTypeID
701  << "\n to contain account ID: " << strAcctID << "\n";
702  return false;
703  }
704 
705  // Okay, we saved the updated file, with the account added. (done, success.)
706  //
707  return true;
708 }
EXPORT Storable * CreateObject(StoredObjectType eType)
Definition: OTStorage.cpp:530
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
EXPORT Storable * QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:788
OTIdentifier m_ID
Definition: OTContract.hpp:172
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
EXPORT bool StoreObject(Storable &theContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:759
void opentxs::OTAssetContract::CreateContents ( )
virtual

Reimplemented from opentxs::OTContract.

Reimplemented in opentxs::BasketContract.

Definition at line 787 of file OTAssetContract.cpp.

788 {
789  m_strVersion = "2.0"; // 2.0 since adding credentials.
790 
792  m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n", "1.0");
793 
794  m_xmlUnsigned.Concatenate("<%s version=\"%s\">\n\n", "digitalAssetContract",
795  m_strVersion.Get());
796 
797  // Entity
798  m_xmlUnsigned.Concatenate("<entity shortname=\"%s\"\n"
799  " longname=\"%s\"\n"
800  " email=\"%s\"/>\n\n",
804 
805  // Issue
806  m_xmlUnsigned.Concatenate("<issue company=\"%s\"\n"
807  " email=\"%s\"\n"
808  " contractUrl=\"%s\"\n"
809  " type=\"%s\"/>\n\n",
812  m_strIssueType.Get());
813 
814  // [currency|shares]
815  if (m_bIsCurrency)
817  "<currency name=\"%s\" tla=\"%s\" symbol=\"%s\" type=\"%s\" "
818  "factor=\"%s\" decimal_power=\"%s\" fraction=\"%s\" />\n\n",
823  else if (m_bIsShares)
825  "<shares name=\"%s\" symbol=\"%s\" type=\"%s\" "
826  "issuedate=\"%s\" />\n\n",
829 
830  // This is where OTContract scribes m_xmlUnsigned with its keys, conditions,
831  // etc.
833 
834  m_xmlUnsigned.Concatenate("</%s>\n", "digitalAssetContract");
835 }
EXPORT void CreateInnerContents()
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
OTString m_strEntityShortName
Definition: OTContract.hpp:207
OTString m_strEntityLongName
Definition: OTContract.hpp:208
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTString m_strEntityEmail
Definition: OTContract.hpp:209
virtual EXPORT void Release()
Definition: OTString.cpp:765
bool opentxs::OTAssetContract::DisplayStatistics ( OTString &  strContents) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 452 of file OTAssetContract.cpp.

453 {
454  const OTString strID(m_ID);
455 
456  strContents.Concatenate(" Asset Type: %s\n"
457  " AssetTypeID: %s\n"
458  "\n",
459  m_strName.Get(), strID.Get());
460  return true;
461 }
OTIdentifier m_ID
Definition: OTContract.hpp:172
EXPORT const char * Get() const
Definition: OTString.cpp:1045
bool opentxs::OTAssetContract::EraseAccountRecord ( const OTIdentifier &  theAcctID) const

Definition at line 710 of file OTAssetContract.cpp.

713 {
714  // Load up account list StringMap. Create it if doesn't already exist.
715  // See if account is already there in the map. Erase it, if it is.
716  // Save the StringMap back again. (The account records list for a given
717  // asset type.)
718 
719  const char* szFunc = "OTAssetContract::EraseAccountRecord";
720 
721  const OTString strAcctID(theAcctID);
722 
723  OTString strAssetTypeID, strAcctRecordFile;
724  GetIdentifier(strAssetTypeID);
725  strAcctRecordFile.Format("%s.a", strAssetTypeID.Get());
726 
727  OTDB::Storable* pStorable = nullptr;
728  std::unique_ptr<OTDB::Storable> theAngel;
729  OTDB::StringMap* pMap = nullptr;
730 
731  if (OTDB::Exists(OTFolders::Contract().Get(),
732  strAcctRecordFile.Get())) // the file already exists; let's
733  // try to load it up.
735  OTFolders::Contract().Get(),
736  strAcctRecordFile.Get());
737  else // the account records file (for this asset type) doesn't exist.
738  pStorable = OTDB::CreateObject(
739  OTDB::STORED_OBJ_STRING_MAP); // this asserts already, on failure.
740 
741  theAngel.reset(pStorable);
742  pMap = (nullptr == pStorable) ? nullptr
743  : dynamic_cast<OTDB::StringMap*>(pStorable);
744 
745  // It exists.
746  //
747  if (nullptr == pMap) {
748  otErr << szFunc
749  << ": Error: failed trying to load or create the account records "
750  "file for asset type: " << strAssetTypeID << "\n";
751  return false;
752  }
753 
754  // Before we can erase it, let's see if it's even there....
755  //
756  auto& theMap = pMap->the_map;
757  auto map_it = theMap.find(strAcctID.Get());
758 
759  // we found it!
760  if (theMap.end() != map_it) // Acct ID was already there...
761  {
762  theMap.erase(map_it); // remove it
763  }
764 
765  // it wasn't already on the list...
766  // (So it's like success, since the end result is, acct ID will not appear
767  // on this list--whether
768  // it was there or not beforehand, it's definitely not there now.)
769 
770  // Then save it back to local storage:
771  //
772  if (!OTDB::StoreObject(*pMap, OTFolders::Contract().Get(),
773  strAcctRecordFile.Get())) {
774  otErr << szFunc
775  << ": Failed trying to StoreObject, while saving updated "
776  "account records file for asset type: " << strAssetTypeID
777  << "\n to erase account ID: " << strAcctID << "\n";
778  return false;
779  }
780 
781  // Okay, we saved the updated file, with the account removed. (done,
782  // success.)
783  //
784  return true;
785 }
EXPORT Storable * CreateObject(StoredObjectType eType)
Definition: OTStorage.cpp:530
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
EXPORT Storable * QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:788
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
EXPORT bool StoreObject(Storable &theContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:759
bool opentxs::OTAssetContract::FormatAmount ( int64_t  amount,
std::string &  str_output 
) const

Definition at line 348 of file OTAssetContract.cpp.

351 {
352  int32_t nFactor = atoi(
353  m_strCurrencyFactor.Get()); // default is 100 (100 cents in a dollar)
354  if (nFactor < 1) nFactor = 1;
355  OT_ASSERT(nFactor > 0); // should be 1, 10, 100, etc.
356 
357  int32_t nPower = atoi(m_strCurrencyDecimalPower.Get()); // default is 2.
358  // ($5.05 is moved 2
359  // decimal places.)
360  if (nPower < 0) nPower = 0;
361  OT_ASSERT(nPower >= 0); // should be 0, 1, 2, etc.
362 
363  // Lookup separator and decimal point symbols based on locale.
364 
365  // Get a moneypunct facet from the global ("C") locale
366  //
367  // NOTE: Turns out moneypunct kind of sucks.
368  // As a result, for internationalization purposes,
369  // these values have to be set here before compilation.
370  //
371  static OTString strSeparator(OT_THOUSANDS_SEP);
372  static OTString strDecimalPoint(OT_DECIMAL_POINT);
373 
374  // NOTE: from web searching, I've determined that locale / moneypunct has
375  // internationalization problems. Therefore it looks like if you want to
376  // build OT for various languages / regions, you're just going to have to
377  // edit stdafx.hpp and change the OT_THOUSANDS_SEP and OT_DECIMAL_POINT
378  // variables.
379  //
380  // The best improvement I can think on that is to check locale and then use
381  // it to choose from our own list of hardcoded values. Todo.
382 
384  amount, nFactor, nPower, m_strCurrencySymbol.Get(), strSeparator.Get(),
385  strDecimalPoint.Get());
386  return true;
387 }
static EXPORT std::string formatLongAmount(int64_t lValue, int32_t nFactor=100, int32_t nPower=2, const char *szCurrencySymbol="", const char *szThousandSeparator=",", const char *szDecimalPoint=".")
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const char * Get() const
Definition: OTString.cpp:1045
#define OT_DECIMAL_POINT
Definition: stdafx.hpp:46
#define OT_THOUSANDS_SEP
Definition: stdafx.hpp:45
std::string opentxs::OTAssetContract::formatLongAmount ( int64_t  lValue,
int32_t  nFactor = 100,
int32_t  nPower = 2,
const char *  szCurrencySymbol = "",
const char *  szThousandSeparator = ",",
const char *  szDecimalPoint = "." 
)
static

Definition at line 312 of file OTAssetContract.cpp.

317 {
318  std::stringstream sss;
319 
320  // Handle negative values
321  if (lValue < 0) {
322  sss << "-";
323  lValue = -lValue;
324  }
325 
326  sss << szCurrencySymbol << " ";
327 
328  // For example, if 506 is supposed to be $5.06, then dividing by a factor of
329  // 100 results in 5 dollars (integer value) and 6 cents (fractional value).
330 
331  // Handle integer value with thousand separaters
332  separateThousands(sss, lValue / nFactor, szThousandSeparator);
333 
334  // Handle fractional value
335  if (1 < nFactor) {
336  sss << szDecimalPoint << std::setfill('0') << std::setw(nPower)
337  << (lValue % nFactor);
338  }
339 
340  return sss.str();
341 }
void separateThousands(std::stringstream &sss, int64_t value, const char *szSeparator)
EXPORT const OTString& opentxs::OTAssetContract::GetBasketInfo ( ) const
inline

Definition at line 199 of file OTAssetContract.hpp.

200  {
201  return m_strBasketInfo;
202  }
EXPORT const OTString& opentxs::OTAssetContract::GetCurrencyFraction ( ) const
inline

Definition at line 208 of file OTAssetContract.hpp.

209  {
210  return m_strCurrencyFraction;
211  } // "cents" (for example)
EXPORT const OTString& opentxs::OTAssetContract::GetCurrencyName ( ) const
inline

Definition at line 204 of file OTAssetContract.hpp.

205  {
206  return m_strCurrencyName;
207  } // "dollars" (for example)
EXPORT const OTString& opentxs::OTAssetContract::GetCurrencySymbol ( ) const
inline

Definition at line 212 of file OTAssetContract.hpp.

213  {
214  return m_strCurrencySymbol;
215  } // "$" (for example)
EXPORT const OTString& opentxs::OTAssetContract::GetCurrencyTLA ( ) const
inline

Definition at line 216 of file OTAssetContract.hpp.

217  {
218  return m_strCurrencyTLA;
219  } // "USD"" (for example)
EXPORT bool opentxs::OTAssetContract::IsShares ( ) const
inline

Definition at line 163 of file OTAssetContract.hpp.

164  {
165  return m_bIsShares;
166  }
bool opentxs::OTAssetContract::ParseFormatted ( int64_t &  lResult,
const std::string &  str_input,
int32_t  nFactor = 100,
int32_t  nPower = 2,
const char *  szThousandSeparator = ",",
const char *  szDecimalPoint = "." 
)
static

Definition at line 154 of file OTAssetContract.cpp.

159 {
160  OT_ASSERT(nullptr != szThousandSeparator);
161  OT_ASSERT(nullptr != szDecimalPoint);
162 
163  lResult = 0;
164 
165  char theSeparator = szThousandSeparator[0];
166  char theDecimalPoint = szDecimalPoint[0];
167 
168  int64_t lDollars = 0;
169  int64_t lCents = 0;
170  int64_t lOutput = 0;
171  int64_t lSign = 1;
172 
173  bool bHasEnteredDollars = false;
174  bool bHasEnteredCents = false;
175 
176  int32_t nDigitsCollectedBeforeDot = 0;
177  int32_t nDigitsCollectedAfterDot = 0;
178 
179  // BUG: &mp isn't used.
180  // const std::moneypunct<char, false> &mp = std::use_facet<
181  // std::moneypunct<char, false> >(std::locale ());
182 
183  std::deque<int64_t> deque_cents;
184 
185  for (uint32_t uIndex = 0; uIndex < str_input.length(); ++uIndex) {
186  char theChar = str_input[uIndex];
187 
188  if (iscntrl(theChar)) // Break at any newline or other control
189  // character.
190  break;
191 
192  if (0 == isdigit(theChar)) // if it's not a numerical digit.
193  {
194  if (theSeparator == theChar) continue;
195 
196  if (theDecimalPoint == theChar) {
197  if (bHasEnteredCents) {
198  // There shouldn't be ANOTHER decimal point if we are
199  // already in the cents.
200  // Therefore, we're done here. Break.
201  //
202  break;
203  }
204 
205  // If we HAVEN'T entered the cents yet, then this decimal point
206  // marks the spot where we DO.
207  //
208  bHasEnteredDollars = true;
209  bHasEnteredCents = true;
210  continue;
211  } // theChar is the decimal point
212 
213  // Once a negative sign appears, it's negative, period.
214  // If you put two or three negative signs in a row, it's STILL
215  // negative.
216 
217  if ('-' == theChar) {
218  lSign = -1;
219  continue;
220  }
221 
222  // Okay, by this point, we know it's not numerical, and it's not a
223  // separator or decimal point, or
224  // sign.
225  // We allow letters and symbols BEFORE the numbers start, but not
226  // AFTER (that would terminate the
227  // number.) Therefore we need to see if the dollars or cents have
228  // started yet. If they have, then
229  // this is the end, and we break. Otherwise if they haven't, then
230  // we're still at the beginning, so
231  // we continue.
232  //
233  if (bHasEnteredDollars || bHasEnteredCents)
234  break;
235  else
236  continue;
237  } // not numerical
238 
239  // By this point, we KNOW that it's a numeric digit.
240  // Are we collecting cents yet? How about dollars?
241  // Also, if nPower is 2, then we only collect 2 digits
242  // after the decimal point. If we've already collected
243  // those, then we need to break.
244  //
245  if (bHasEnteredCents) {
246  ++nDigitsCollectedAfterDot;
247 
248  // If "cents" occupy 2 digits after the decimal point,
249  // and we are now on the THIRD digit -- then we're done.
250  if (nDigitsCollectedAfterDot > nPower) break;
251 
252  // Okay, we're in the cents, so let's add this digit...
253  //
254  deque_cents.push_back(static_cast<int64_t>(theChar - '0'));
255 
256  continue;
257  }
258 
259  // Okay, it's a digit, and we haven't started processing cents yet.
260  // How about dollars?
261  //
262  if (!bHasEnteredDollars) bHasEnteredDollars = true;
263 
264  ++nDigitsCollectedBeforeDot;
265 
266  // Let's add this digit...
267  //
268  lDollars *=
269  10; // Multiply existing dollars by 10, and then add the new digit.
270  lDollars += static_cast<int64_t>(theChar - '0');
271  }
272 
273  // Time to put it all together...
274  //
275  lOutput += lDollars;
276  lOutput *= static_cast<int64_t>(nFactor); // 1 dollar becomes 100 cents.
277 
278  int32_t nTempPower = nPower;
279 
280  while (nTempPower > 0) {
281  --nTempPower;
282 
283  if (deque_cents.size() > 0) {
284  lCents += deque_cents.front();
285  deque_cents.pop_front();
286  }
287 
288  lCents *= 10;
289  }
290  lCents /= 10; // There won't be any rounding errors here, since the last
291  // thing we did in the loop was multiply by 10.
292 
293  lOutput += lCents;
294 
295  lResult = (lOutput * lSign);
296 
297  return true;
298 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t opentxs::OTAssetContract::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
protectedvirtual

Reimplemented from opentxs::OTContract.

Reimplemented in opentxs::BasketContract.

Definition at line 839 of file OTAssetContract.cpp.

840 {
841  int32_t nReturnVal = OTContract::ProcessXMLNode(xml);
842 
843  // Here we call the parent class first.
844  // If the node is found there, or there is some error,
845  // then we just return either way. But if it comes back
846  // as '0', then nothing happened, and we'll continue executing.
847  //
848  // -- Note you can choose not to call the parent if
849  // you don't want to use any of those xml tags.
850 
851  if (nReturnVal == 1 || nReturnVal == (-1)) return nReturnVal;
852 
853  const OTString strNodeName(xml->getNodeName());
854 
855  if (strNodeName.Compare("digitalAssetContract")) {
856  m_strVersion = xml->getAttributeValue("version");
857 
858  otWarn << "\n"
859  "===> Loading XML portion of asset contract into memory "
860  "structures...\n\n"
861  "Digital Asset Contract: " << m_strName
862  << "\nContract version: " << m_strVersion << "\n----------\n";
863  nReturnVal = 1;
864  }
865  else if (strNodeName.Compare("issue")) {
866  m_strIssueCompany = xml->getAttributeValue("company");
867  m_strIssueEmail = xml->getAttributeValue("email");
868  m_strIssueContractURL = xml->getAttributeValue("contractUrl");
869  m_strIssueType = xml->getAttributeValue("type");
870 
871  otInfo << "Loaded Issue company: " << m_strIssueCompany
872  << "\nEmail: " << m_strIssueEmail
873  << "\nContractURL: " << m_strIssueContractURL
874  << "\nType: " << m_strIssueType << "\n----------\n";
875  nReturnVal = 1;
876  }
877  // TODO security validation: validate all the above and below values.
878  else if (strNodeName.Compare("currency")) {
879  m_bIsCurrency = true; // silver grams
880  m_bIsShares = false;
881 
882  m_strName = xml->getAttributeValue("name");
883  m_strCurrencyName = xml->getAttributeValue("name");
884  m_strCurrencySymbol = xml->getAttributeValue("symbol");
885  m_strCurrencyType = xml->getAttributeValue("type");
886 
887  m_strCurrencyTLA = xml->getAttributeValue("tla");
888  m_strCurrencyFactor = xml->getAttributeValue("factor");
889  m_strCurrencyDecimalPower = xml->getAttributeValue("decimal_power");
890  m_strCurrencyFraction = xml->getAttributeValue("fraction");
891 
892  otInfo << "Loaded " << strNodeName << ", Name: " << m_strCurrencyName
893  << ", TLA: " << m_strCurrencyTLA
894  << ", Symbol: " << m_strCurrencySymbol
895  << "\n"
896  "Type: " << m_strCurrencyType
897  << ", Factor: " << m_strCurrencyFactor
898  << ", Decimal Power: " << m_strCurrencyDecimalPower
899  << ", Fraction: " << m_strCurrencyFraction << "\n----------\n";
900  nReturnVal = 1;
901  }
902 
903  // share_type some type, for example, A or B, or NV (non voting)
904  //
905  // share_name this is the int64_t legal name of the company
906  //
907  // share_symbol this is the trading name (8 chars max), as it might be
908  // displayed in a market contect, and should be unique within some
909  // given market
910  //
911  // share_issue_date date of start of this share item (not necessarily IPO)
912  else if (strNodeName.Compare("shares")) {
913  m_bIsShares = true; // shares of pepsi
914  m_bIsCurrency = false;
915 
916  m_strName = xml->getAttributeValue("name");
917  m_strCurrencyName = xml->getAttributeValue("name");
918  m_strCurrencySymbol = xml->getAttributeValue("symbol");
919  m_strCurrencyType = xml->getAttributeValue("type");
920 
921  m_strIssueDate = xml->getAttributeValue("issuedate");
922 
923  otInfo << "Loaded " << strNodeName << ", Name: " << m_strCurrencyName
924  << ", Symbol: " << m_strCurrencySymbol
925  << "\n"
926  "Type: " << m_strCurrencyType
927  << ", Issue Date: " << m_strIssueDate << "\n----------\n";
928  nReturnVal = 1;
929  }
930 
931  return nReturnVal;
932 }
OTLOG_IMPORT OTLogStream otInfo
OTLOG_IMPORT OTLogStream otWarn
virtual EXPORT int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
bool opentxs::OTAssetContract::SaveContractWallet ( OTString &  strContents) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 463 of file OTAssetContract.cpp.

464 {
465  const OTString strID(m_ID);
466 
467  OTASCIIArmor ascName;
468 
469  if (m_strName.Exists()) // name is in the clear in memory, and base64 in
470  // storage.
471  {
472  ascName.SetString(m_strName, false); // linebreaks == false
473  }
474 
475  strContents.Concatenate("<assetType name=\"%s\"\n"
476  " assetTypeID=\"%s\" />\n\n",
477  m_strName.Exists() ? ascName.Get() : "",
478  strID.Get());
479 
480  return true;
481 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
OTIdentifier m_ID
Definition: OTContract.hpp:172
bool opentxs::OTAssetContract::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Implements opentxs::OTContract.

Definition at line 483 of file OTAssetContract.cpp.

484 {
485  OTString strOutput;
486 
487  if (SaveContractWallet(strOutput)) {
488  ofs << strOutput;
489  return true;
490  }
491 
492  return false;
493 }
virtual EXPORT bool SaveContractWallet(OTString &strContents) const
bool opentxs::OTAssetContract::StringToAmount ( int64_t &  amount,
const std::string &  str_input 
) const

Definition at line 394 of file OTAssetContract.cpp.

397 {
398  int32_t nFactor = atoi(
399  m_strCurrencyFactor.Get()); // default is 100 (100 cents in a dollar)
400  if (nFactor < 1) nFactor = 1;
401  OT_ASSERT(nFactor > 0); // should be 1, 10, 100, etc.
402 
403  int32_t nPower = atoi(m_strCurrencyDecimalPower.Get()); // default is 2.
404  // ($5.05 is moved 2
405  // decimal places.)
406  if (nPower < 0) nPower = 0;
407  OT_ASSERT(nPower >= 0); // should be 0, 1, 2, etc.
408 
409  // Lookup separator and decimal point symbols based on locale.
410 
411  // Get a moneypunct facet from the global ("C") locale
412  //
413 
414  // NOTE: from web searching, I've determined that locale / moneypunct has
415  // internationalization problems. Therefore it looks like if you want to
416  // build OT for various languages / regions, you're just going to have to
417  // edit stdafx.hpp and change the OT_THOUSANDS_SEP and OT_DECIMAL_POINT
418  // variables.
419  //
420  // The best improvement I can think on that is to check locale and then use
421  // it to choose from our own list of hardcoded values. Todo.
422 
423  static OTString strSeparator(",");
424  static OTString strDecimalPoint(".");
425 
426  bool bSuccess = OTAssetContract::ParseFormatted(amount, str_input, nFactor,
427  nPower, strSeparator.Get(),
428  strDecimalPoint.Get());
429 
430  return bSuccess;
431 }
static EXPORT bool ParseFormatted(int64_t &lResult, const std::string &str_input, int32_t nFactor=100, int32_t nPower=2, const char *szThousandSeparator=",", const char *szDecimalPoint=".")
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const char * Get() const
Definition: OTString.cpp:1045
bool opentxs::OTAssetContract::VisitAccountRecords ( AccountVisitor &  visitor) const

Definition at line 498 of file OTAssetContract.cpp.

499 {
500  OTString strAssetTypeID, strAcctRecordFile;
501  GetIdentifier(strAssetTypeID);
502  strAcctRecordFile.Format("%s.a", strAssetTypeID.Get());
503 
504  std::unique_ptr<OTDB::Storable> pStorable(OTDB::QueryObject(
506  strAcctRecordFile.Get()));
507 
508  OTDB::StringMap* pMap = dynamic_cast<OTDB::StringMap*>(pStorable.get());
509 
510  // There was definitely a StringMap loaded from local storage.
511  // (Even an empty one, possibly.) This is the only block that matters in
512  // this function.
513  //
514  if (nullptr != pMap) {
515  OTIdentifier* pServerID = visitor.GetServerID();
516  OT_ASSERT_MSG(nullptr != pServerID,
517  "Assert: nullptr Server ID on functor. "
518  "(How did you even construct the "
519  "thing?)");
520 
521  auto& theMap = pMap->the_map;
522 
523  // todo: optimize: will probably have to use a database for this,
524  // int64_t term.
525  // (What if there are a million acct IDs in this flat file? Not
526  // scaleable.)
527  //
528  for (auto& it : theMap) {
529  const std::string& str_acct_id =
530  it.first; // Containing the account ID.
531  const std::string& str_asset_id =
532  it.second; // Containing the asset type ID. (Just in case
533  // someone copied the wrong file here...)
534 
535  if (!strAssetTypeID.Compare(str_asset_id.c_str())) {
536  otErr << "OTAssetContract::VisitAccountRecords: Error: wrong "
537  "asset type ID (" << str_asset_id
538  << ") when expecting: " << strAssetTypeID << "\n";
539  }
540  else {
541  OTAccount* pAccount = nullptr;
542  std::unique_ptr<OTAccount> theAcctAngel;
543 
544  const OTIdentifier theAccountID(str_acct_id.c_str());
545 
546  // Before loading it from local storage, let's first make sure
547  // it's not already loaded.
548  // (visitor functor has a list of 'already loaded' accounts,
549  // just in case.)
550  //
551  mapOfAccounts* pLoadedAccounts = visitor.GetLoadedAccts();
552 
553  if (nullptr !=
554  pLoadedAccounts) // there are some accounts already loaded,
555  { // let's see if the one we're looking for is there...
556  auto found_it = pLoadedAccounts->find(str_acct_id);
557 
558  if (pLoadedAccounts->end() != found_it) // FOUND IT.
559  {
560  pAccount = found_it->second;
561  OT_ASSERT(nullptr != pAccount);
562 
563  if (theAccountID != pAccount->GetPurportedAccountID()) {
564  otErr << "Error: the actual account didn't have "
565  "the ID that the std::map SAID it had! "
566  "(Should never happen.)\n";
567  pAccount = nullptr;
568  }
569  }
570  }
571 
572  // I guess it wasn't already loaded...
573  // Let's try to load it.
574  //
575  if (nullptr == pAccount) {
576  pAccount = OTAccount::LoadExistingAccount(theAccountID,
577  *pServerID);
578  theAcctAngel.reset(pAccount);
579  }
580 
581  bool bSuccessLoadingAccount =
582  ((pAccount != nullptr) ? true : false);
583  if (bSuccessLoadingAccount) {
584  bool bTriggerSuccess = visitor.Trigger(*pAccount);
585  if (!bTriggerSuccess)
586  otErr << __FUNCTION__ << ": Error: Trigger Failed.";
587  }
588  else {
589  otErr << __FUNCTION__ << ": Error: Failed Loading Account!";
590  }
591  }
592  }
593  return true;
594  }
595  return true;
596 }
static EXPORT const OTString & Contract()
Definition: OTFolders.cpp:303
EXPORT Storable * QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:788
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
std::map< std::string, OTAccount * > mapOfAccounts
Definition: OTWallet.hpp:157
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
Definition: OTAccount.cpp:480

Member Data Documentation

bool opentxs::OTAssetContract::m_bIsCurrency
protected

Definition at line 259 of file OTAssetContract.hpp.

bool opentxs::OTAssetContract::m_bIsShares
protected

Definition at line 260 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strBasketInfo
protected

Definition at line 231 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyDecimalPower
protected

Definition at line 253 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyFactor
protected

Definition at line 251 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyFraction
protected

Definition at line 257 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyName
protected

Definition at line 243 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencySymbol
protected

Definition at line 246 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyTLA
protected

Definition at line 249 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strCurrencyType
protected

Definition at line 245 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strIssueCompany
protected

Definition at line 234 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strIssueContractURL
protected

Definition at line 236 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strIssueDate
protected

Definition at line 240 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strIssueEmail
protected

Definition at line 235 of file OTAssetContract.hpp.

OTString opentxs::OTAssetContract::m_strIssueType
protected

Definition at line 237 of file OTAssetContract.hpp.


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