133 #include "../core/stdafx.hpp"
139 #if defined(OT_CASH_USING_LUCRE)
143 #include "../core/crypto/OTEnvelope.hpp"
144 #include "../core/crypto/OTNymOrSymmetricKey.hpp"
145 #include "../core/util/OTFolders.hpp"
146 #include "../core/OTLog.hpp"
147 #include "../core/OTStorage.hpp"
149 #include <irrxml/irrXML.hpp>
221 , m_bPasswordProtected(false)
226 , m_State(blankToken)
227 , m_bSavePrivateKeys(false)
242 , m_bPasswordProtected(false)
247 , m_State(blankToken)
248 , m_bSavePrivateKeys(false)
258 , m_bPasswordProtected(false)
263 , m_State(blankToken)
264 , m_bSavePrivateKeys(false)
315 nullptr != pPrototoken,
316 "nullptr OTASCIIArmor pointer in Token::ReleasePrototokens.");
319 pPrototoken =
nullptr;
325 nullptr != pPrototoken,
326 "nullptr OTASCIIArmor pointer in Token::ReleasePrototokens.");
329 pPrototoken =
nullptr;
333 m_mapPrivate.clear();
353 Token* pToken =
nullptr;
355 #if defined(OT_CASH_USING_LUCRE)
356 if (strFirstLine.
Contains(
"-----BEGIN SIGNED CASH-----"))
363 "-----BEGIN SIGNED CASH TOKEN-----"))
370 "-----BEGIN SIGNED LUCRE CASH TOKEN-----"))
377 otErr << __FUNCTION__ <<
": Open-Transactions is not built for any digital "
378 "cash algorithms. (Failure.)";
379 #endif // defined (OT_CASH_USING_LUCRE)
385 const Purse& thePurse)
387 Token* pToken =
nullptr;
389 #if defined(OT_CASH_USING_LUCRE)
390 if (strFirstLine.
Contains(
"-----BEGIN SIGNED CASH-----"))
397 "-----BEGIN SIGNED CASH TOKEN-----"))
404 "-----BEGIN SIGNED LUCRE CASH TOKEN-----"))
411 otErr << __FUNCTION__ <<
": Open-Transactions is not built for any digital "
412 "cash algorithms. (Failure.)";
413 #endif // defined (OT_CASH_USING_LUCRE)
420 Token* pToken =
nullptr;
422 #if defined(OT_CASH_USING_LUCRE)
426 otErr << __FUNCTION__ <<
": Open-Transactions is not built for any digital "
427 "cash algorithms. (Failure.)";
428 #endif // defined (OT_CASH_USING_LUCRE)
435 Token* pToken =
nullptr;
437 #if defined(OT_CASH_USING_LUCRE)
438 if (strFirstLine.
Contains(
"-----BEGIN SIGNED CASH-----"))
445 "-----BEGIN SIGNED CASH TOKEN-----"))
452 "-----BEGIN SIGNED LUCRE CASH TOKEN-----"))
459 otErr << __FUNCTION__ <<
": Open-Transactions is not built for any digital "
460 "cash algorithms. (Failure.)";
461 #endif // defined (OT_CASH_USING_LUCRE)
474 const bool bProcessed =
482 if (
nullptr == pToken)
return nullptr;
499 const bool bProcessed =
506 if (
nullptr == pToken)
return nullptr;
523 const bool bProcessed =
530 if (
nullptr == pToken)
return nullptr;
566 OTString strTokenHash(theTokenHash);
574 if (bTokenIsPresent) {
575 otOut <<
"\nToken::IsTokenAlreadySpent: Token was already spent: "
599 OTString strTokenHash(theTokenHash);
609 if (bTokenIsPresent) {
610 otErr <<
"Token::RecordTokenAsSpent: Trying to record token as spent,"
628 otErr <<
"Token::RecordTokenAsSpent: Error recording token as "
629 "spent (failed writing armored string):\n"
637 strAssetFolder.
Get(), strTokenHash.
Get());
639 otErr <<
"Token::RecordTokenAsSpent: Error saving file: "
720 const char* szFunc =
"Token::ReassignOwnership";
723 bool bSuccess =
true;
754 const char* szFunc =
"Token::GetSpendableString";
766 otErr << szFunc <<
": m_ascSpendable is empty... (failure.)\n";
780 strState.
Set(
"blankToken");
783 strState.
Set(
"protoToken");
786 strState.
Set(
"signedToken");
789 strState.
Set(
"spendableToken");
792 strState.
Set(
"verifiedToken");
795 strState.
Set(
"errorToken");
808 "<token\n version=\"%s\"\n state=\"%s\"\n denomination=\"%lld\"\n"
809 " assetTypeID=\"%s\"\n"
812 " validFrom=\"%" PRId64
"\"\n"
813 " validTo=\"%" PRId64
"\""
816 ASSET_TYPE_ID.Get(), SERVER_ID.
Get(),
m_nSeries, lFrom, lTo);
838 "<protopurse count=\"%d\" chosenIndex=\"%d\">\n\n",
m_nTokenCount,
861 "<privatePrototoken>\n%s</privatePrototoken>\n\n",
873 static int32_t nPublicTokenCount = 0;
874 static int32_t nPrivateTokenCount = 0;
876 int32_t nReturnVal = 0;
878 const OTString strNodeName(xml->getNodeName());
891 if (strNodeName.Compare(
"token")) {
895 strState = xml->getAttributeValue(
"state");
897 m_nSeries = atoi(xml->getAttributeValue(
"series"));
899 const OTString str_from = xml->getAttributeValue(
"validFrom");
900 const OTString str_to = xml->getAttributeValue(
"validTo");
902 int64_t tFrom = str_from.ToLong();
903 int64_t tTo = str_to.
ToLong();
910 if (strState.
Compare(
"blankToken"))
912 else if (strState.
Compare(
"protoToken"))
914 else if (strState.
Compare(
"signedToken"))
916 else if (strState.
Compare(
"spendableToken"))
918 else if (strState.
Compare(
"verifiedToken"))
926 OTString strAssetTypeID(xml->getAttributeValue(
"assetTypeID")),
927 strServerID(xml->getAttributeValue(
"serverID"));
934 "\n\nToken State: " << strState
937 " AssetTypeID: " << strAssetTypeID
938 <<
"\nServerID: " << strServerID <<
"\n";
942 else if (strNodeName.Compare(
"tokenID")) {
944 otErr <<
"Error in Token::ProcessXMLNode: token ID without "
951 else if (strNodeName.Compare(
"tokenSignature")) {
953 otErr <<
"Error in Token::ProcessXMLNode: token Signature "
960 else if (strNodeName.Compare(
"protopurse")) {
968 nPublicTokenCount = 0;
972 else if (strNodeName.Compare(
"prototoken")) {
974 OT_ASSERT(
nullptr != pArmoredPrototoken);
977 !pArmoredPrototoken->
Exists()) {
978 otErr <<
"Error in Token::ProcessXMLNode: prototoken field "
981 delete pArmoredPrototoken;
982 pArmoredPrototoken =
nullptr;
987 m_mapPublic[nPublicTokenCount] = pArmoredPrototoken;
993 else if (strNodeName.Compare(
"privateProtopurse")) {
994 nPrivateTokenCount = 0;
998 else if (strNodeName.Compare(
"privatePrototoken")) {
1000 OT_ASSERT(
nullptr != pArmoredPrototoken);
1003 !pArmoredPrototoken->
Exists()) {
1004 otErr <<
"Error in Token::ProcessXMLNode: privatePrototoken "
1005 "field without value.\n";
1007 delete pArmoredPrototoken;
1008 pArmoredPrototoken =
nullptr;
1014 nPrivateTokenCount++;
1016 otLog4 <<
"Loaded prototoken and adding to m_mapPrivate at index: "
1017 << nPrivateTokenCount - 1 <<
"\n";
1051 const bool bSuccess = (nTokenIndex == it.first);
1054 ascPrototoken.
Set(*pPrototoken);
1063 int32_t nTokenIndex)
1075 bool bSuccess = (nTokenIndex == it.first);
1078 ascPrototoken.
Set(*pPrototoken);
1089 int64_t lDenomination,
1090 int32_t nTokenCount)
1096 theNym, theMint, lDenomination, nTokenCount);
1098 if (!bGeneratedRequest) {
1099 otErr << __FUNCTION__ <<
": Failed trying to generate token request.\n";
1167 otErr <<
"Expected spendable token in Token::VerifyToken\n";
1183 if (!theEnvelope.
Open(theNotary, strContents))
1199 otOut <<
"Token series information doesn't match Mint series "
1210 otOut <<
"Token is expired!\n";
1219 otOut <<
"Token verified!\n";
1223 otOut <<
"Bad coin!\n";
1230 #if defined(OT_CASH_USING_MAGIC_MONEY)
1232 #endif // Magic Money
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
OTLOG_IMPORT OTLogStream otLog4
virtual EXPORT void Release()
static EXPORT int32_t GetMinimumPrototokenCount()
EXPORT bool GetPrototoken(OTASCIIArmor &ascPrototoken, int32_t nTokenIndex)
EXPORT void ReleasePrototokens()
EXPORT bool CalculateDigest(const OTData &dataInput)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
static EXPORT bool DearmorAndTrim(const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
EXPORT bool GetSignature(OTASCIIArmor &theSignature) const
const int32_t Token__nMinimumPrototokenCount
EXPORT int64_t ToLong() const
static EXPORT const char * PathSeparator()
int32_t GetSeries() const
const OTIdentifier & GetAssetID() const
virtual bool SaveContractWallet(std::ofstream &ofs) const
OTLOG_IMPORT OTLogStream otOut
static EXPORT Token * LowLevelInstantiate(const Purse &thePurse)
virtual EXPORT bool VerifyToken(OTPseudonym &theNotary, OTString &theCleartextToken, int64_t lDenomination)=0
const OTIdentifier & GetAssetID() const
EXPORT bool GetSpendableString(OTNym_or_SymmetricKey theOwner, OTString &theString) const
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
EXPORT bool Open(const OTPseudonym &theRecipient, OTString &theOutput, const OTPasswordData *pPWData=nullptr)
EXPORT void Concatenate(const char *arg,...)
EXPORT bool VerifyCurrentDate()
EXPORT bool WriteArmoredString(OTString &strOutput, const std::string str_type, bool bEscaped=false) const
int32_t GetSeries() const
EXPORT bool GetPrivatePrototoken(OTASCIIArmor &ascPrototoken, int32_t nTokenIndex)
EXPORT bool Exists() const
void SetDenomination(int64_t lVal)
EXPORT void SetString(const char *szString)
EXPORT bool VerifyToken(OTPseudonym &theNotary, Mint &theMint)
EXPORT void Format(const char *fmt,...)
virtual void UpdateContents()
EXPORT bool Compare(const char *compare) const
static EXPORT Token * InstantiateAndGenerateTokenRequest(const Purse &thePurse, const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())
time64_t GetValidTo() const
EXPORT bool Seal_or_Encrypt(OTEnvelope &outputEnvelope, const OTString &strInput, const OTString *pstrDisplay=nullptr)
virtual EXPORT bool GenerateTokenRequest(const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())=0
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
EXPORT void SetSignature(const OTASCIIArmor &theSignature, int32_t nTokenIndex)
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
EXPORT bool GetAsciiArmoredData(OTASCIIArmor &theArmoredText, bool bLineBreaks=true) const
int64_t GetDenomination() const
EXPORT bool IsTokenAlreadySpent(OTString &theCleartextToken)
mapOfPrototokens m_mapPrivate
EXPORT bool RecordTokenAsSpent(OTString &theCleartextToken)
OTString m_strContractType
#define OT_ASSERT_MSG(x, s)
time64_t GetValidFrom() const
OTStringXML m_xmlUnsigned
bool m_bPasswordProtected
OTASCIIArmor m_ascSpendable
EXPORT const char * Get() const
EXPORT bool ReassignOwnership(OTNym_or_SymmetricKey &oldOwner, OTNym_or_SymmetricKey &newOwner)
OTLOG_IMPORT OTLogStream otErr
mapOfPrototokens m_mapPublic
OTIdentifier m_AssetTypeID
EXPORT void Release_Token()
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool CompareID(const OTNym_or_SymmetricKey &rhs) const
EXPORT bool Contains(const char *compare) const
static EXPORT Token * TokenFactory(OTString strInput)
int64_t OTTimeGetSecondsFromTime(time64_t time)
EXPORT bool LoadContractFromString(const OTString &theStr)
static EXPORT const OTString & Spent()
virtual EXPORT void Release()
bool ChooseIndex(int32_t nIndex)
EXPORT bool Open_or_Decrypt(const OTEnvelope &inputEnvelope, OTString &strOutput, const OTString *pstrDisplay=nullptr)
const OTIdentifier & GetServerID() const