133 #include "../core/stdafx.hpp"
138 #include "../core/crypto/OTAsymmetricKey.hpp"
139 #include "../core/OTAccount.hpp"
140 #include "../core/util/OTFolders.hpp"
141 #include "../core/OTLog.hpp"
142 #include "../core/OTMessage.hpp"
143 #include "../core/OTStorage.hpp"
145 #include <irrxml/irrXML.hpp>
147 #if defined(OT_CASH_USING_LUCRE)
156 Mint* pMint =
nullptr;
158 #if defined(OT_CASH_USING_LUCRE)
160 #elif defined(OT_CASH_USING_MAGIC_MONEY)
162 otErr << __FUCNTION__ <<
": Open-Transactions doesn't support Magic Money "
163 "by Pr0duct Cypher (yet), "
164 <<
"so it's impossible to instantiate a mint.\n";
168 <<
": Open-Transactions isn't built with any digital cash algorithms, "
169 <<
"so it's impossible to instantiate a mint.\n";
178 Mint* pMint =
nullptr;
180 #if defined(OT_CASH_USING_LUCRE)
181 pMint =
new MintLucre(strServerID, strAssetTypeID);
182 #elif defined(OT_CASH_USING_MAGIC_MONEY)
184 otErr << __FUNCTION__ <<
": Open-Transactions doesn't support Magic Money "
185 "by Pr0duct Cypher (yet), "
186 <<
"so it's impossible to instantiate a mint.\n";
190 <<
": Open-Transactions isn't built with any digital cash algorithms, "
191 <<
"so it's impossible to instantiate a mint.\n";
201 Mint* pMint =
nullptr;
203 #if defined(OT_CASH_USING_LUCRE)
204 pMint =
new MintLucre(strServerID, strServerNymID, strAssetTypeID);
205 #elif defined(OT_CASH_USING_MAGIC_MONEY)
207 otErr << __FUNCTION__ <<
": Open-Transactions doesn't support Magic Money "
208 "by Pr0duct Cypher (yet), "
209 <<
"so it's impossible to instantiate a mint.\n";
213 <<
": Open-Transactions isn't built with any digital cash algorithms, "
214 <<
"so it's impossible to instantiate a mint.\n";
221 #if defined(OT_CASH_USING_MAGIC_MONEY)
223 #endif // Magic Money
291 otErr << __FUNCTION__ <<
": the logic: if (nullptr != m_pKeyPublic) "
292 "failed, though it NEVER should. "
293 "(That pointer should never be nullptr.)\n";
319 , m_ServerID(strServerID)
320 , m_ServerNymID(strServerNymID)
322 , m_AssetID(strAssetTypeID)
323 , m_nDenominationCount(0)
324 , m_bSavePrivateKeys(false)
329 , m_pReserveAcct(nullptr)
333 strAssetTypeID.
Get());
340 , m_ServerID(strServerID)
342 , m_AssetID(strAssetTypeID)
343 , m_nDenominationCount(0)
344 , m_bSavePrivateKeys(false)
349 , m_pReserveAcct(nullptr)
353 strAssetTypeID.
Get());
361 , m_nDenominationCount(0)
362 , m_bSavePrivateKeys(false)
367 , m_pReserveAcct(nullptr)
374 otOut <<
"Mint::LoadContract OVERRIDE.\n";
388 if (
nullptr != szAppend)
392 strAssetTypeID.
Get(), szAppend);
396 strAssetTypeID.
Get());
400 if (
nullptr != szAppend)
401 strFilename.
Format(
"%s%s", strAssetTypeID.
Get(),
404 strFilename = strAssetTypeID.
Get();
407 const char* szFolder2name = strServerID.Get();
408 const char* szFilename =
411 if (!
OTDB::Exists(szFolder1name, szFolder2name, szFilename)) {
412 otOut <<
"Mint::LoadMint: File does not exist: " << szFolder1name
418 std::string strFileContents(
422 if (strFileContents.length() < 2) {
423 otErr <<
"Mint::LoadMint: Error reading file: " << szFolder1name
432 OTString strRawFile(strFileContents.c_str());
447 if (
nullptr != szAppend)
450 strAssetTypeID.
Get(), szAppend);
454 strAssetTypeID.
Get());
458 if (
nullptr != szAppend)
459 strFilename.
Format(
"%s%s", strAssetTypeID.
Get(), szAppend);
461 strFilename = strAssetTypeID.
Get();
464 const char* szFolder2name = strServerID.Get();
465 const char* szFilename = strFilename.
Get();
470 otErr <<
"Mint::SaveMint: Error saving Mintfile (to string):\n"
481 otErr <<
"Mint::SaveMint: Error saving mint (failed writing armored "
491 if (
nullptr != szAppend)
492 otErr <<
"Mint::SaveMint: Error writing to file: " << szFolder1name
496 otErr <<
"Mint::SaveMint: Error writing to file: " << szFolder1name
513 otErr <<
"Error comparing Mint ID to Asset Contract ID in "
514 "Mint::VerifyMint\n";
518 otErr <<
"Error verifying signature on mint in Mint::VerifyMint.\n";
522 otLog3 <<
"\nWe now know that...\n"
523 "1) The Asset Contract ID matches the Mint ID loaded from the "
525 "2) The SIGNATURE VERIFIED.\n\n";
542 otErr <<
"\nMint ID does NOT match Asset Type ID in "
543 "Mint::VerifyContractID.\n" << str1 <<
"\n" << str2 <<
"\n";
549 otInfo <<
"\nMint ID *SUCCESSFUL* match to Asset Contract ID:\n" << str1
562 "nullptr mint pointer in Mint::GetPrivate.\n");
564 if (it.first == lDenomination) {
565 theArmor.
Set(*pArmor);
579 "nullptr mint pointer in Mint::GetPublic.\n");
581 if (it.first == lDenomination) {
582 theArmor.
Set(*pArmor);
601 if (lDenom <= lAmount)
return lDenom;
617 int32_t nIterateIndex = 0;
620 ++it, nIterateIndex++) {
623 "nullptr mint pointer in Mint::GetDenomination.\n");
625 if (nIndex == nIterateIndex)
return it->first;
653 " serverNymID=\"%s\"\n"
654 " assetTypeID=\"%s\"\n"
655 " cashAcctID=\"%s\"\n"
657 " expiration=\"%" PRId64
"\"\n"
658 " validFrom=\"%" PRId64
"\"\n"
659 " validTo=\"%" PRId64
"\""
662 SERVER_NYM_ID.Get(), ASSET_ID.Get(),
669 armorPublicKey.
Get());
678 OT_ASSERT_MSG(
nullptr != pArmor,
"nullptr private mint pointer "
680 "Mint::UpdateContents.\n");
683 "<mintPrivateInfo denomination=\"%lld\">\n"
684 "%s</mintPrivateInfo>\n\n",
685 it.first, pArmor->
Get());
692 "nullptr public mint pointer in Mint::UpdateContents.\n");
695 "%s</mintPublicInfo>\n\n",
696 it.first, pArmor->
Get());
708 int32_t nReturnVal = 0;
710 const OTString strNodeName(xml->getNodeName());
723 if (strNodeName.Compare(
"mint")) {
724 OTString strServerID, strServerNymID, strAssetID, strCashAcctID;
727 strServerID = xml->getAttributeValue(
"serverID");
728 strServerNymID = xml->getAttributeValue(
"serverNymID");
729 strAssetID = xml->getAttributeValue(
"assetTypeID");
730 strCashAcctID = xml->getAttributeValue(
"cashAcctID");
732 m_nSeries = atoi(xml->getAttributeValue(
"series"));
736 const OTString str_valid_from = xml->getAttributeValue(
"validFrom");
737 const OTString str_valid_to = xml->getAttributeValue(
"validTo");
754 if (strCashAcctID.
Exists())
765 <<
"\n Server ID: " << strServerID
766 <<
"\n Asset Type ID: " << strAssetID
767 <<
"\n Cash Acct ID: " << strCashAcctID <<
"\n"
770 <<
" loading Cash Account into memory for pointer: "
771 "Mint::m_pReserveAcct\n"
772 " Series: " <<
m_nSeries <<
"\n Expiration: " << nExpiration
773 <<
"\n Valid From: " << nValidFrom <<
"\n Valid To: " << nValidTo
778 else if (strNodeName.Compare(
"mintPublicKey")) {
782 !armorPublicKey.
Exists()) {
783 otErr <<
"Error in Mint::ProcessXMLNode: mintPublicKey field "
794 else if (strNodeName.Compare(
"mintPrivateInfo")) {
795 int64_t lDenomination = atol(xml->getAttributeValue(
"denomination"));
803 otErr <<
"Error in Mint::ProcessXMLNode: mintPrivateInfo field "
817 else if (strNodeName.Compare(
"mintPublicInfo")) {
818 int64_t lDenomination = atol(xml->getAttributeValue(
"denomination"));
826 otErr <<
"Error in Mint::ProcessXMLNode: mintPublicInfo field "
884 int64_t nDenom2, int64_t nDenom3, int64_t nDenom4,
885 int64_t nDenom5, int64_t nDenom6, int64_t nDenom7,
886 int64_t nDenom8, int64_t nDenom9, int64_t nDenom10)
921 otOut <<
"Successfully created cash reserve account for new mint.\n";
924 otErr <<
"Error creating cash reserve account for new mint.\n";
static EXPORT const OTString & Mint()
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
void ReleaseDenominations()
static EXPORT Mint * MintFactory()
OTAccount * m_pReserveAcct
bool GetPrivate(OTASCIIArmor &theArmor, int64_t lDenomination)
virtual bool AddDenomination(OTPseudonym &theNotary, int64_t lDenomination, int32_t nPrimeLength=1024)=0
EXPORT bool Expired() const
EXPORT void GenerateNewMint(int32_t nSeries, time64_t VALID_FROM, time64_t VALID_TO, time64_t MINT_EXPIRATION, const OTIdentifier &theAssetID, const OTIdentifier &theServerID, OTPseudonym &theNotary, int64_t nDenom1=0, int64_t nDenom2=0, int64_t nDenom3=0, int64_t nDenom4=0, int64_t nDenom5=0, int64_t nDenom6=0, int64_t nDenom7=0, int64_t nDenom8=0, int64_t nDenom9=0, int64_t nDenom10=0)
EXPORT int64_t ToLong() const
static EXPORT OTAccount * GenerateNewAccount(const OTIdentifier &userId, const OTIdentifier &serverId, const OTPseudonym &serverNym, const OTMessage &message, AccountType acctType=simple, int64_t stashTransNum=0)
static EXPORT const char * PathSeparator()
EXPORT bool VerifyMint(const OTPseudonym &theOperator)
virtual bool SaveContractWallet(std::ofstream &ofs) const
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool SaveContractRaw(OTString &strOutput) const
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
virtual void UpdateContents()
OTIdentifier m_ServerNymID
EXPORT void Concatenate(const char *arg,...)
EXPORT bool WriteArmoredString(OTString &strOutput, const std::string str_type, bool bEscaped=false) const
EXPORT bool SaveMint(const char *szAppend=nullptr)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT bool Exists() const
EXPORT void SetString(const char *szString)
EXPORT int64_t GetLargestDenomination(int64_t lAmount)
EXPORT bool SetPublicKey(const OTASCIIArmor &strKey)
EXPORT void Format(const char *fmt,...)
bool GetPublic(OTASCIIArmor &theArmor, int64_t lDenomination)
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
virtual bool LoadContract()
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool GetPublicKey(OTASCIIArmor &strKey) const
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
OTIdentifier m_CashAccountID
int32_t GetDenominationCount() const
OTString m_strContractType
#define OT_ASSERT_MSG(x, s)
OTLOG_IMPORT OTLogStream otInfo
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
OTAsymmetricKey * m_pKeyPublic
OTStringXML m_xmlUnsigned
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
int32_t m_nDenominationCount
OTLOG_IMPORT OTLogStream otErr
virtual EXPORT void Release()
virtual bool VerifyContractID() const
EXPORT void GetString(OTString &theStr) const
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
int64_t OTTimeGetSecondsFromTime(time64_t time)
EXPORT bool LoadContractFromString(const OTString &theStr)
EXPORT bool LoadMint(const char *szAppend=nullptr)
virtual EXPORT void Release()
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
virtual EXPORT void Release()
int64_t GetDenomination(int32_t nIndex)