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

#include <Token.hpp>

Inheritance diagram for opentxs::Token:
Collaboration diagram for opentxs::Token:

Public Types

enum  tokenState {
  blankToken, protoToken, signedToken, spendableToken,
  verifiedToken, errorToken
}
 

Public Member Functions

virtual EXPORT ~Token ()
 
EXPORT void Release_Token ()
 
virtual void Release ()
 
EXPORT void ReleasePrototokens ()
 
virtual void UpdateContents ()
 
void SetSavePrivateKeys ()
 
EXPORT bool ReassignOwnership (OTNym_or_SymmetricKey &oldOwner, OTNym_or_SymmetricKey &newOwner)
 
const OTASCIIArmorGetSpendable () const
 
void SetSpendable (const OTASCIIArmor &theArmor)
 
EXPORT bool GetSpendableString (OTNym_or_SymmetricKey theOwner, OTString &theString) const
 
Token::tokenState GetState () const
 
int32_t GetSeries () const
 
void SetSeriesAndExpiration (int32_t nSeries, time64_t VALID_FROM, time64_t VALID_TO)
 
virtual EXPORT bool ProcessToken (const OTPseudonym &theNym, Mint &theMint, Token &theRequest)=0
 
EXPORT bool VerifyToken (OTPseudonym &theNotary, Mint &theMint)
 
EXPORT bool IsTokenAlreadySpent (OTString &theCleartextToken)
 
EXPORT bool RecordTokenAsSpent (OTString &theCleartextToken)
 
EXPORT void SetSignature (const OTASCIIArmor &theSignature, int32_t nTokenIndex)
 
EXPORT bool GetSignature (OTASCIIArmor &theSignature) const
 
int64_t GetDenomination () const
 
void SetDenomination (int64_t lVal)
 
EXPORT bool GetPrototoken (OTASCIIArmor &ascPrototoken, int32_t nTokenIndex)
 
EXPORT bool GetPrivatePrototoken (OTASCIIArmor &ascPrototoken, int32_t nTokenIndex)
 
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 (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 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
 

Static Public Member Functions

static EXPORT int32_t GetMinimumPrototokenCount ()
 
static EXPORT TokenTokenFactory (OTString strInput)
 
static EXPORT TokenTokenFactory (OTString strInput, const Purse &thePurse)
 
static EXPORT TokenTokenFactory (OTString strInput, const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
static EXPORT TokenLowLevelInstantiate (const Purse &thePurse)
 
static EXPORT TokenLowLevelInstantiate (const OTString &strFirstLine)
 
static EXPORT TokenLowLevelInstantiate (const OTString &strFirstLine, const Purse &thePurse)
 
static EXPORT TokenLowLevelInstantiate (const OTString &strFirstLine, const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
static EXPORT TokenInstantiateAndGenerateTokenRequest (const Purse &thePurse, const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())
 
- 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)
 

Protected Member Functions

virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
void InitToken ()
 
bool ChooseIndex (int32_t nIndex)
 
EXPORT Token ()
 
EXPORT Tokenoperator= (const Token &rhs)
 
EXPORT Token (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
EXPORT Token (const Purse &thePurse)
 
virtual EXPORT bool GenerateTokenRequest (const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())=0
 
- 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

bool m_bPasswordProtected
 
OTASCIIArmor m_ascSpendable
 
OTASCIIArmor m_Signature
 
int64_t m_lDenomination
 
mapOfPrototokens m_mapPublic
 
mapOfPrototokens m_mapPrivate
 
int32_t m_nTokenCount
 
int32_t m_nChosenIndex
 
int32_t m_nSeries
 
tokenState m_State
 
bool m_bSavePrivateKeys
 
- 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
 

Detailed Description

Definition at line 196 of file Token.hpp.

Member Enumeration Documentation

Enumerator
blankToken 
protoToken 
signedToken 
spendableToken 
verifiedToken 
errorToken 

Definition at line 202 of file Token.hpp.

Constructor & Destructor Documentation

opentxs::Token::Token ( )
protected

Definition at line 219 of file Token.cpp.

220  : ot_super()
221  , m_bPasswordProtected(false)
222  , m_lDenomination(0)
223  , m_nTokenCount(0)
224  , m_nChosenIndex(0)
225  , m_nSeries(0)
227  , m_bSavePrivateKeys(false)
228 {
229  InitToken();
230 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
int32_t m_nSeries
Definition: Token.hpp:268
bool m_bSavePrivateKeys
Definition: Token.hpp:270
bool m_bPasswordProtected
Definition: Token.hpp:221
void InitToken()
Definition: Token.cpp:207
int32_t m_nTokenCount
Definition: Token.hpp:244
tokenState m_State
Definition: Token.hpp:269
int64_t m_lDenomination
Definition: Token.hpp:230
opentxs::Token::Token ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
)
protected

Definition at line 240 of file Token.cpp.

241  : ot_super(SERVER_ID, ASSET_ID)
242  , m_bPasswordProtected(false)
243  , m_lDenomination(0)
244  , m_nTokenCount(0)
245  , m_nChosenIndex(0)
246  , m_nSeries(0)
248  , m_bSavePrivateKeys(false)
249 {
250  InitToken();
251 
252  // m_ServerID and m_AssetTypeID are now in the parent class (OTInstrument)
253  // So they are initialized there now.
254 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
int32_t m_nSeries
Definition: Token.hpp:268
bool m_bSavePrivateKeys
Definition: Token.hpp:270
bool m_bPasswordProtected
Definition: Token.hpp:221
void InitToken()
Definition: Token.cpp:207
int32_t m_nTokenCount
Definition: Token.hpp:244
tokenState m_State
Definition: Token.hpp:269
int64_t m_lDenomination
Definition: Token.hpp:230
opentxs::Token::Token ( const Purse thePurse)
protected

Definition at line 256 of file Token.cpp.

257  : ot_super()
258  , m_bPasswordProtected(false)
259  , m_lDenomination(0)
260  , m_nTokenCount(0)
261  , m_nChosenIndex(0)
262  , m_nSeries(0)
264  , m_bSavePrivateKeys(false)
265 {
266  InitToken();
267 
268  // These are in the parent class, OTInstrument.
269  // I set them here because the "Purse" argument only exists
270  // in this subclass constructor, not the base.
271  m_ServerID = thePurse.GetServerID();
272  m_AssetTypeID = thePurse.GetAssetID();
273 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
int32_t m_nSeries
Definition: Token.hpp:268
bool m_bSavePrivateKeys
Definition: Token.hpp:270
bool m_bPasswordProtected
Definition: Token.hpp:221
void InitToken()
Definition: Token.cpp:207
int32_t m_nTokenCount
Definition: Token.hpp:244
OTIdentifier m_AssetTypeID
tokenState m_State
Definition: Token.hpp:269
int64_t m_lDenomination
Definition: Token.hpp:230
opentxs::Token::~Token ( )
virtual

Definition at line 294 of file Token.cpp.

295 {
296  Release_Token();
297 
298  m_bPasswordProtected = false;
299 
300  // todo: optimization (probably just remove these here.)
301  m_lDenomination = 0;
302  // m_nTokenCount = 0; // this happens in ReleasePrototokens. (Called
303  // by Release_Token above.)
304  m_nChosenIndex = 0;
305  m_nSeries = 0;
307  m_bSavePrivateKeys = false;
308 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
int32_t m_nSeries
Definition: Token.hpp:268
bool m_bSavePrivateKeys
Definition: Token.hpp:270
bool m_bPasswordProtected
Definition: Token.hpp:221
EXPORT void Release_Token()
Definition: Token.cpp:275
tokenState m_State
Definition: Token.hpp:269
int64_t m_lDenomination
Definition: Token.hpp:230

Member Function Documentation

bool opentxs::Token::ChooseIndex ( int32_t  nIndex)
inlineprotected

Definition at line 1107 of file Token.cpp.

1108 {
1109  if (nIndex > (m_nTokenCount - 1) || nIndex < 0)
1110  return false;
1111  else {
1112  m_nChosenIndex = nIndex;
1113  return true;
1114  }
1115 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
int32_t m_nTokenCount
Definition: Token.hpp:244
virtual EXPORT bool opentxs::Token::GenerateTokenRequest ( const OTPseudonym theNym,
Mint theMint,
int64_t  lDenomination,
int32_t  nTokenCount = Token::GetMinimumPrototokenCount() 
)
protectedpure virtual

Implemented in opentxs::Token_Lucre.

int64_t opentxs::Token::GetDenomination ( ) const
inline

Definition at line 409 of file Token.hpp.

410  {
411  return m_lDenomination;
412  }
int64_t m_lDenomination
Definition: Token.hpp:230
int32_t opentxs::Token::GetMinimumPrototokenCount ( )
static

Definition at line 180 of file Token.cpp.

181 {
183 }
const int32_t Token__nMinimumPrototokenCount
Definition: Token.cpp:178
bool opentxs::Token::GetPrivatePrototoken ( OTASCIIArmor ascPrototoken,
int32_t  nTokenIndex 
)

Definition at line 1062 of file Token.cpp.

1064 {
1065  // out of bounds. For a count 10 element array, index 10 is out of bounds.
1066  // thus if attempted index is equal or larger to the count, out of bounds.
1067  if (nTokenIndex >= m_nTokenCount) {
1068  return false;
1069  }
1070 
1071  for (auto& it : m_mapPrivate) {
1072  OTASCIIArmor* pPrototoken = it.second;
1073  OT_ASSERT(nullptr != pPrototoken);
1074 
1075  bool bSuccess = (nTokenIndex == it.first);
1076 
1077  if (bSuccess) {
1078  ascPrototoken.Set(*pPrototoken);
1079  return true;
1080  }
1081  }
1082  return false;
1083 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
mapOfPrototokens m_mapPrivate
Definition: Token.hpp:240
int32_t m_nTokenCount
Definition: Token.hpp:244
bool opentxs::Token::GetPrototoken ( OTASCIIArmor ascPrototoken,
int32_t  nTokenIndex 
)

Definition at line 1039 of file Token.cpp.

1040 {
1041  // out of bounds. For a count 10 element array, index 10 is out of bounds.
1042  // thus if attempted index is equal or larger to the count, out of bounds.
1043  if (nTokenIndex >= m_nTokenCount) {
1044  return false;
1045  }
1046 
1047  for (auto& it : m_mapPublic) {
1048  OTASCIIArmor* pPrototoken = it.second;
1049  OT_ASSERT(nullptr != pPrototoken);
1050 
1051  const bool bSuccess = (nTokenIndex == it.first);
1052 
1053  if (bSuccess) {
1054  ascPrototoken.Set(*pPrototoken);
1055 
1056  return true;
1057  }
1058  }
1059  return false;
1060 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t m_nTokenCount
Definition: Token.hpp:244
mapOfPrototokens m_mapPublic
Definition: Token.hpp:237
int32_t opentxs::Token::GetSeries ( ) const
inline

Definition at line 368 of file Token.hpp.

369  {
370  return m_nSeries;
371  }
int32_t m_nSeries
Definition: Token.hpp:268
bool opentxs::Token::GetSignature ( OTASCIIArmor theSignature) const

Definition at line 1148 of file Token.cpp.

1149 {
1150  theSignature = m_Signature;
1151 
1152  return true;
1153 }
OTASCIIArmor m_Signature
Definition: Token.hpp:227
const OTASCIIArmor& opentxs::Token::GetSpendable ( ) const
inline

Definition at line 329 of file Token.hpp.

330  {
331  return m_ascSpendable;
332  }
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
bool opentxs::Token::GetSpendableString ( OTNym_or_SymmetricKey  theOwner,
OTString theString 
) const

Definition at line 751 of file Token.cpp.

753 {
754  const char* szFunc = "Token::GetSpendableString";
755 
756  if (m_ascSpendable.Exists()) {
757  OTEnvelope theEnvelope(m_ascSpendable);
758 
759  // Decrypt the Envelope into strContents
760  const OTString strDisplay(szFunc);
761 
762  if (theOwner.Open_or_Decrypt(theEnvelope, theString, &strDisplay))
763  return true;
764  }
765  else
766  otErr << szFunc << ": m_ascSpendable is empty... (failure.)\n";
767 
768  return false;
769 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
OTLOG_IMPORT OTLogStream otErr
Token::tokenState opentxs::Token::GetState ( ) const
inline

Definition at line 347 of file Token.hpp.

348  {
349  return m_State;
350  }
tokenState m_State
Definition: Token.hpp:269
void opentxs::Token::InitToken ( )
protected

Definition at line 207 of file Token.cpp.

208 {
209  // m_lDenomination = 0;
210  // m_nTokenCount = 0;
211  // m_nChosenIndex = 0;
212  // m_nSeries = 0;
213  // m_State = blankToken;
214  // m_bSavePrivateKeys = false;
215 
216  m_strContractType.Set("CASH TOKEN"); // todo internationalization.
217 }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
OTString m_strContractType
Definition: OTContract.hpp:178
Token * opentxs::Token::InstantiateAndGenerateTokenRequest ( const Purse thePurse,
const OTPseudonym theNym,
Mint theMint,
int64_t  lDenomination,
int32_t  nTokenCount = Token::GetMinimumPrototokenCount() 
)
static

Definition at line 1086 of file Token.cpp.

1091 {
1092  Token* pToken = Token::LowLevelInstantiate(thePurse); // already asserts.
1093  OT_ASSERT(nullptr != pToken); // Just for good measure.
1094 
1095  const bool bGeneratedRequest = pToken->GenerateTokenRequest(
1096  theNym, theMint, lDenomination, nTokenCount);
1097 
1098  if (!bGeneratedRequest) {
1099  otErr << __FUNCTION__ << ": Failed trying to generate token request.\n";
1100  delete pToken;
1101  pToken = nullptr;
1102  }
1103 
1104  return pToken;
1105 }
static EXPORT Token * LowLevelInstantiate(const Purse &thePurse)
Definition: Token.cpp:418
EXPORT Token()
Definition: Token.cpp:219
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::Token::IsTokenAlreadySpent ( OTString theCleartextToken)

Definition at line 557 of file Token.cpp.

558 {
559  OTString strAssetID(GetAssetID());
560 
561  // Calculate the filename (a hash of the Lucre cleartext token ID)
562  OTIdentifier theTokenHash;
563  theTokenHash.CalculateDigest(theCleartextToken);
564 
565  // Grab the new hash into a string (for use as a filename)
566  OTString strTokenHash(theTokenHash);
567 
568  OTString strAssetFolder;
569  strAssetFolder.Format("%s.%d", strAssetID.Get(), GetSeries());
570 
571  bool bTokenIsPresent = OTDB::Exists(
572  OTFolders::Spent().Get(), strAssetFolder.Get(), strTokenHash.Get());
573 
574  if (bTokenIsPresent) {
575  otOut << "\nToken::IsTokenAlreadySpent: Token was already spent: "
576  << OTFolders::Spent() << OTLog::PathSeparator() << strAssetFolder
577  << OTLog::PathSeparator() << strTokenHash << "\n";
578  return true; // all errors must return true in this function.
579  // But this is not an error. Token really WAS already
580  } // spent, and this true is for real. The others are just
581  // for security reasons because of this one.
582 
583  // This is the ideal case: the token was NOT already spent, it was good,
584  // so we can return false and the depositor can be credited appropriately.
585  // IsTokenAlreadySpent? NO-it was NOT already spent. You can only POSSIBLY
586  // get a false out of this method if you actually reached the bottom (here.)
587  return false;
588 }
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
int32_t GetSeries() const
Definition: Token.hpp:368
const OTIdentifier & GetAssetID() const
OTLOG_IMPORT OTLogStream otOut
EXPORT const char * Get() const
Definition: OTString.cpp:1045
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
static EXPORT const OTString & Spent()
Definition: OTFolders.cpp:375
Token * opentxs::Token::LowLevelInstantiate ( const Purse thePurse)
static

Definition at line 418 of file Token.cpp.

419 {
420  Token* pToken = nullptr;
421 
422 #if defined(OT_CASH_USING_LUCRE)
423  pToken = new Token_Lucre(thePurse);
424  OT_ASSERT(nullptr != pToken);
425 #else
426  otErr << __FUNCTION__ << ": Open-Transactions is not built for any digital "
427  "cash algorithms. (Failure.)";
428 #endif // defined (OT_CASH_USING_LUCRE)
429 
430  return pToken;
431 }
EXPORT Token()
Definition: Token.cpp:219
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
Token * opentxs::Token::LowLevelInstantiate ( const OTString strFirstLine)
static

Definition at line 433 of file Token.cpp.

434 {
435  Token* pToken = nullptr;
436 
437 #if defined(OT_CASH_USING_LUCRE)
438  if (strFirstLine.Contains("-----BEGIN SIGNED CASH-----")) // this string is
439  // 27 chars long.
440  {
441  pToken = new Token_Lucre;
442  OT_ASSERT(nullptr != pToken);
443  }
444  else if (strFirstLine.Contains(
445  "-----BEGIN SIGNED CASH TOKEN-----")) // this string is 33
446  // chars long.
447  {
448  pToken = new Token_Lucre;
449  OT_ASSERT(nullptr != pToken);
450  }
451  else if (strFirstLine.Contains(
452  "-----BEGIN SIGNED LUCRE CASH TOKEN-----")) // this string is
453  // 39 chars long.
454  {
455  pToken = new Token_Lucre;
456  OT_ASSERT(nullptr != pToken);
457  }
458 #else
459  otErr << __FUNCTION__ << ": Open-Transactions is not built for any digital "
460  "cash algorithms. (Failure.)";
461 #endif // defined (OT_CASH_USING_LUCRE)
462 
463  return pToken;
464 }
EXPORT Token()
Definition: Token.cpp:219
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
Token * opentxs::Token::LowLevelInstantiate ( const OTString strFirstLine,
const Purse thePurse 
)
static

Definition at line 384 of file Token.cpp.

386 {
387  Token* pToken = nullptr;
388 
389 #if defined(OT_CASH_USING_LUCRE)
390  if (strFirstLine.Contains("-----BEGIN SIGNED CASH-----")) // this string is
391  // 27 chars long.
392  {
393  pToken = new Token_Lucre(thePurse);
394  OT_ASSERT(nullptr != pToken);
395  }
396  else if (strFirstLine.Contains(
397  "-----BEGIN SIGNED CASH TOKEN-----")) // this string is 33
398  // chars long.
399  {
400  pToken = new Token_Lucre(thePurse);
401  OT_ASSERT(nullptr != pToken);
402  }
403  else if (strFirstLine.Contains(
404  "-----BEGIN SIGNED LUCRE CASH TOKEN-----")) // this string is
405  // 39 chars long.
406  {
407  pToken = new Token_Lucre(thePurse);
408  OT_ASSERT(nullptr != pToken);
409  }
410 #else
411  otErr << __FUNCTION__ << ": Open-Transactions is not built for any digital "
412  "cash algorithms. (Failure.)";
413 #endif // defined (OT_CASH_USING_LUCRE)
414 
415  return pToken;
416 }
EXPORT Token()
Definition: Token.cpp:219
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
Token * opentxs::Token::LowLevelInstantiate ( const OTString strFirstLine,
const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
)
static

Definition at line 349 of file Token.cpp.

352 {
353  Token* pToken = nullptr;
354 
355 #if defined(OT_CASH_USING_LUCRE)
356  if (strFirstLine.Contains("-----BEGIN SIGNED CASH-----")) // this string is
357  // 27 chars long.
358  {
359  pToken = new Token_Lucre(SERVER_ID, ASSET_ID);
360  OT_ASSERT(nullptr != pToken);
361  }
362  else if (strFirstLine.Contains(
363  "-----BEGIN SIGNED CASH TOKEN-----")) // this string is 33
364  // chars long.
365  {
366  pToken = new Token_Lucre(SERVER_ID, ASSET_ID);
367  OT_ASSERT(nullptr != pToken);
368  }
369  else if (strFirstLine.Contains(
370  "-----BEGIN SIGNED LUCRE CASH TOKEN-----")) // this string is
371  // 39 chars long.
372  {
373  pToken = new Token_Lucre(SERVER_ID, ASSET_ID);
374  OT_ASSERT(nullptr != pToken);
375  }
376 #else
377  otErr << __FUNCTION__ << ": Open-Transactions is not built for any digital "
378  "cash algorithms. (Failure.)";
379 #endif // defined (OT_CASH_USING_LUCRE)
380 
381  return pToken;
382 }
EXPORT Token()
Definition: Token.cpp:219
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
EXPORT Token& opentxs::Token::operator= ( const Token rhs)
protected
virtual EXPORT bool opentxs::Token::ProcessToken ( const OTPseudonym theNym,
Mint theMint,
Token theRequest 
)
pure virtual

Implemented in opentxs::Token_Lucre.

int32_t opentxs::Token::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
protectedvirtual

Reimplemented from opentxs::OTInstrument.

Definition at line 871 of file Token.cpp.

872 {
873  static int32_t nPublicTokenCount = 0;
874  static int32_t nPrivateTokenCount = 0;
875 
876  int32_t nReturnVal = 0;
877 
878  const OTString strNodeName(xml->getNodeName());
879 
880  // Here we call the parent class first.
881  // If the node is found there, or there is some error,
882  // then we just return either way. But if it comes back
883  // as '0', then nothing happened, and we'll continue executing.
884  //
885  // -- Note you can choose not to call the parent if
886  // you don't want to use any of those xml tags.
887  // As I do below, in the case of OTAccount.
888  // if (nReturnVal = OTContract::ProcessXMLNode(xml))
889  // return nReturnVal;
890 
891  if (strNodeName.Compare("token")) {
892  OTString strState;
893 
894  m_strVersion = xml->getAttributeValue("version");
895  strState = xml->getAttributeValue("state");
896 
897  m_nSeries = atoi(xml->getAttributeValue("series"));
898 
899  const OTString str_from = xml->getAttributeValue("validFrom");
900  const OTString str_to = xml->getAttributeValue("validTo");
901 
902  int64_t tFrom = str_from.ToLong();
903  int64_t tTo = str_to.ToLong();
904 
907 
908  SetDenomination(atol(xml->getAttributeValue("denomination")));
909 
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"))
920  else
922 
924  m_strContractType.Set("CASH TOKEN");
925 
926  OTString strAssetTypeID(xml->getAttributeValue("assetTypeID")),
927  strServerID(xml->getAttributeValue("serverID"));
928 
929  m_AssetTypeID.SetString(strAssetTypeID);
930  m_ServerID.SetString(strServerID);
931 
932  otLog4 <<
933  // "\n===> Loading XML for token into memory structures..."
934  "\n\nToken State: " << strState
935  << "\n Denomination: " << GetDenomination()
936  << "\n"
937  " AssetTypeID: " << strAssetTypeID
938  << "\nServerID: " << strServerID << "\n";
939 
940  nReturnVal = 1;
941  }
942  else if (strNodeName.Compare("tokenID")) {
944  otErr << "Error in Token::ProcessXMLNode: token ID without "
945  "value.\n";
946  return (-1); // error condition
947  }
948 
949  return 1;
950  }
951  else if (strNodeName.Compare("tokenSignature")) {
953  otErr << "Error in Token::ProcessXMLNode: token Signature "
954  "without value.\n";
955  return (-1); // error condition
956  }
957 
958  return 1;
959  }
960  else if (strNodeName.Compare("protopurse")) { // TODO for security, if the
961  // count here doesn't match
962  // what's loaded up, that
963  // should be part of
964  // what is verified in each token when it's verified..
965  m_nTokenCount = atoi(xml->getAttributeValue("count"));
966  m_nChosenIndex = atoi(xml->getAttributeValue("chosenIndex"));
967 
968  nPublicTokenCount = 0;
969 
970  return 1;
971  }
972  else if (strNodeName.Compare("prototoken")) {
973  OTASCIIArmor* pArmoredPrototoken = new OTASCIIArmor;
974  OT_ASSERT(nullptr != pArmoredPrototoken);
975 
976  if (!OTContract::LoadEncodedTextField(xml, *pArmoredPrototoken) ||
977  !pArmoredPrototoken->Exists()) {
978  otErr << "Error in Token::ProcessXMLNode: prototoken field "
979  "without value.\n";
980 
981  delete pArmoredPrototoken;
982  pArmoredPrototoken = nullptr;
983 
984  return (-1); // error condition
985  }
986  else {
987  m_mapPublic[nPublicTokenCount] = pArmoredPrototoken;
988  nPublicTokenCount++;
989  }
990 
991  return 1;
992  }
993  else if (strNodeName.Compare("privateProtopurse")) {
994  nPrivateTokenCount = 0;
995 
996  return 1;
997  }
998  else if (strNodeName.Compare("privatePrototoken")) {
999  OTASCIIArmor* pArmoredPrototoken = new OTASCIIArmor;
1000  OT_ASSERT(nullptr != pArmoredPrototoken);
1001 
1002  if (!OTContract::LoadEncodedTextField(xml, *pArmoredPrototoken) ||
1003  !pArmoredPrototoken->Exists()) {
1004  otErr << "Error in Token::ProcessXMLNode: privatePrototoken "
1005  "field without value.\n";
1006 
1007  delete pArmoredPrototoken;
1008  pArmoredPrototoken = nullptr;
1009 
1010  return (-1); // error condition
1011  }
1012  else {
1013  m_mapPrivate[nPrivateTokenCount] = pArmoredPrototoken;
1014  nPrivateTokenCount++;
1015 
1016  otLog4 << "Loaded prototoken and adding to m_mapPrivate at index: "
1017  << nPrivateTokenCount - 1 << "\n";
1018  }
1019 
1020  return 1;
1021  }
1022 
1023  return nReturnVal;
1024 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
OTLOG_IMPORT OTLogStream otLog4
OTASCIIArmor m_Signature
Definition: Token.hpp:227
int32_t m_nSeries
Definition: Token.hpp:268
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
Definition: Common.hpp:215
void SetDenomination(int64_t lVal)
Definition: Token.hpp:413
EXPORT void SetString(const char *szString)
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
int64_t GetDenomination() const
Definition: Token.hpp:409
#define OT_ASSERT(x)
Definition: Assert.hpp:150
mapOfPrototokens m_mapPrivate
Definition: Token.hpp:240
OTString m_strContractType
Definition: OTContract.hpp:178
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
int32_t m_nTokenCount
Definition: Token.hpp:244
OTLOG_IMPORT OTLogStream otErr
mapOfPrototokens m_mapPublic
Definition: Token.hpp:237
OTIdentifier m_AssetTypeID
tokenState m_State
Definition: Token.hpp:269
bool opentxs::Token::ReassignOwnership ( OTNym_or_SymmetricKey oldOwner,
OTNym_or_SymmetricKey newOwner 
)

Definition at line 716 of file Token.cpp.

719 {
720  const char* szFunc = "Token::ReassignOwnership";
721  const OTString strDisplay(szFunc);
722 
723  bool bSuccess = true;
724 
725  if (!oldOwner.CompareID(newOwner)) // only re-assign if they don't ALREADY
726  // have the same owner.
727  {
728  OTEnvelope theEnvelope(m_ascSpendable);
729  OTString theString; // output from opening/decrypting (and eventually
730  // input for sealing/encrypting) envelope.
731 
732  // Remember, OTPurse can store its own internal symmetric key, for cases
733  // where the purse is "password protected" instead of belonging to a
734  // specific Nym.
735  // Therefore the old or new "owner" might actually be a symmetric key.
736  // Decrypt/Open the Envelope into theString
737  //
738  bSuccess =
739  oldOwner.Open_or_Decrypt(theEnvelope, theString, &strDisplay);
740  if (bSuccess) {
741  OTEnvelope theNewEnvelope;
742  bSuccess = newOwner.Seal_or_Encrypt(theNewEnvelope, theString,
743  &strDisplay);
744  if (bSuccess)
745  bSuccess = theNewEnvelope.GetAsciiArmoredData(m_ascSpendable);
746  }
747  }
748  return bSuccess;
749 }
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
bool opentxs::Token::RecordTokenAsSpent ( OTString theCleartextToken)

Definition at line 590 of file Token.cpp.

591 {
592  OTString strAssetID(GetAssetID());
593 
594  // Calculate the filename (a hash of the Lucre cleartext token ID)
595  OTIdentifier theTokenHash;
596  theTokenHash.CalculateDigest(theCleartextToken);
597 
598  // Grab the new hash into a string (for use as a filename)
599  OTString strTokenHash(theTokenHash);
600 
601  OTString strAssetFolder;
602  strAssetFolder.Format("%s.%d", strAssetID.Get(), GetSeries());
603 
604  // See if the spent token file ALREADY EXISTS...
605  bool bTokenIsPresent = OTDB::Exists(
606  OTFolders::Spent().Get(), strAssetFolder.Get(), strTokenHash.Get());
607 
608  // If so, we're trying to record a token that was already recorded...
609  if (bTokenIsPresent) {
610  otErr << "Token::RecordTokenAsSpent: Trying to record token as spent,"
611  " but it was already recorded: " << OTFolders::Spent()
612  << OTLog::PathSeparator() << strAssetFolder
613  << OTLog::PathSeparator() << strTokenHash << "\n";
614  return false;
615  }
616 
617  // FINISHED:
618  //
619  // We actually save the token itself into the file, which is named based
620  // on a hash of the Lucre data.
621  // The success of that operation is also now the success of this one.
622 
623  OTString strFinal;
624  OTASCIIArmor ascTemp(m_strRawFile);
625 
626  if (false ==
627  ascTemp.WriteArmoredString(strFinal, m_strContractType.Get())) {
628  otErr << "Token::RecordTokenAsSpent: Error recording token as "
629  "spent (failed writing armored string):\n"
630  << OTFolders::Spent() << OTLog::PathSeparator() << strAssetFolder
631  << OTLog::PathSeparator() << strTokenHash << "\n";
632  return false;
633  }
634 
635  const bool bSaved =
636  OTDB::StorePlainString(strFinal.Get(), OTFolders::Spent().Get(),
637  strAssetFolder.Get(), strTokenHash.Get());
638  if (!bSaved) {
639  otErr << "Token::RecordTokenAsSpent: Error saving file: "
640  << OTFolders::Spent() << OTLog::PathSeparator() << strAssetFolder
641  << OTLog::PathSeparator() << strTokenHash << "\n";
642  }
643 
644  return bSaved;
645 }
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:698
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
int32_t GetSeries() const
Definition: Token.hpp:368
const OTIdentifier & GetAssetID() const
OTString m_strContractType
Definition: OTContract.hpp:178
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
static EXPORT const OTString & Spent()
Definition: OTFolders.cpp:375
void opentxs::Token::Release ( )
virtual

Reimplemented from opentxs::OTInstrument.

Definition at line 286 of file Token.cpp.

287 {
288  Release_Token();
289 
290  ot_super::Release(); // since I've overridden the base class, I call it
291  // now...
292 }
virtual EXPORT void Release()
EXPORT void Release_Token()
Definition: Token.cpp:275
void opentxs::Token::Release_Token ( )

Definition at line 275 of file Token.cpp.

276 {
277 
280 
281  // InitToken();
282 
284 }
EXPORT void ReleasePrototokens()
Definition: Token.cpp:310
OTASCIIArmor m_Signature
Definition: Token.hpp:227
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
virtual EXPORT void Release()
Definition: OTString.cpp:765
void opentxs::Token::ReleasePrototokens ( )

Definition at line 310 of file Token.cpp.

311 {
312  for (auto& it : m_mapPublic) {
313  OTASCIIArmor* pPrototoken = it.second;
315  nullptr != pPrototoken,
316  "nullptr OTASCIIArmor pointer in Token::ReleasePrototokens.");
317 
318  delete pPrototoken;
319  pPrototoken = nullptr;
320  }
321 
322  for (auto& it : m_mapPrivate) {
323  OTASCIIArmor* pPrototoken = it.second;
325  nullptr != pPrototoken,
326  "nullptr OTASCIIArmor pointer in Token::ReleasePrototokens.");
327 
328  delete pPrototoken;
329  pPrototoken = nullptr;
330  }
331 
332  m_mapPublic.clear();
333  m_mapPrivate.clear();
334 
335  m_nTokenCount = 0;
336 }
mapOfPrototokens m_mapPrivate
Definition: Token.hpp:240
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
int32_t m_nTokenCount
Definition: Token.hpp:244
mapOfPrototokens m_mapPublic
Definition: Token.hpp:237
bool opentxs::Token::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Reimplemented from opentxs::OTInstrument.

Definition at line 339 of file Token.cpp.

340 {
341  // mapOfPrototokens m_mapPrivate; // The elements are accessed [0..N].
342  // mapPublic[2] corresponds to map_Private[2], etc.
343 
344  return true;
345 }
void opentxs::Token::SetDenomination ( int64_t  lVal)
inline

Definition at line 413 of file Token.hpp.

414  {
415  m_lDenomination = lVal;
416  }
int64_t m_lDenomination
Definition: Token.hpp:230
void opentxs::Token::SetSavePrivateKeys ( )
inline

Definition at line 309 of file Token.hpp.

310  {
311  m_bSavePrivateKeys = true;
312  }
bool m_bSavePrivateKeys
Definition: Token.hpp:270
void opentxs::Token::SetSeriesAndExpiration ( int32_t  nSeries,
time64_t  VALID_FROM,
time64_t  VALID_TO 
)
inline

Definition at line 373 of file Token.hpp.

374  {
375  m_nSeries = nSeries;
376  m_VALID_FROM = VALID_FROM;
377  m_VALID_TO = VALID_TO;
378  }
int32_t m_nSeries
Definition: Token.hpp:268
void opentxs::Token::SetSignature ( const OTASCIIArmor theSignature,
int32_t  nTokenIndex 
)

Definition at line 1119 of file Token.cpp.

1120 {
1121  // The server sets the signature, and then sends the token back to the
1122  // client. We release all these prototokens before doing so, because there's
1123  // no point in sending them all back to the client again, who already has
1124  // them anyway.
1125  // This is important because otherwise I wouldn't release, because the
1126  // client
1127  // still has to look up the private coin in order to unblind. But we're not
1128  // on the client if we're signing -- we're on the server -- who doesn't have
1129  // those private coins anyway.
1131 
1132  // We now officially have the bank's signature on this token.
1133  m_Signature.Set(theSignature);
1134 
1135  // otErr << "DEBUG Token::SetSignature. nTokenIndex is %d.\nm_Signature
1136  // is:\n%s\n"
1137  // "-------------------------------------\n",
1138  // nTokenIndex, m_Signature.Get());
1139 
1140  // We have to flag which index was signed by the mint, so that
1141  // the client knows which private coin to use for unblinding.
1142  // (Once the coin is unblinded, it will be ready to spend.)
1143  ChooseIndex(nTokenIndex);
1144 
1146 }
EXPORT void ReleasePrototokens()
Definition: Token.cpp:310
OTASCIIArmor m_Signature
Definition: Token.hpp:227
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
tokenState m_State
Definition: Token.hpp:269
bool ChooseIndex(int32_t nIndex)
Definition: Token.cpp:1107
void opentxs::Token::SetSpendable ( const OTASCIIArmor theArmor)
inline

Definition at line 333 of file Token.hpp.

334  {
335  m_ascSpendable.Set(theArmor);
336  }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
Token * opentxs::Token::TokenFactory ( OTString  strInput)
static

Definition at line 518 of file Token.cpp.

519 {
520  // const char * szFunc = "Token::TokenFactory";
521 
522  OTString strContract, strFirstLine; // output for the below function.
523  const bool bProcessed =
524  OTContract::DearmorAndTrim(strInput, strContract, strFirstLine);
525 
526  if (bProcessed) {
527  Token* pToken = Token::LowLevelInstantiate(strFirstLine);
528 
529  // The string didn't match any of the options in the factory.
530  if (nullptr == pToken) return nullptr;
531 
532  // Does the contract successfully load from the string passed in?
533  if (pToken->LoadContractFromString(strContract))
534  return pToken;
535  else
536  delete pToken;
537  }
538 
539  return nullptr;
540 }
static EXPORT bool DearmorAndTrim(const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
Definition: OTContract.cpp:158
static EXPORT Token * LowLevelInstantiate(const Purse &thePurse)
Definition: Token.cpp:418
EXPORT Token()
Definition: Token.cpp:219
Token * opentxs::Token::TokenFactory ( OTString  strInput,
const Purse thePurse 
)
static

Definition at line 494 of file Token.cpp.

495 {
496  // const char * szFunc = "Token::TokenFactory";
497 
498  OTString strContract, strFirstLine; // output for the below function.
499  const bool bProcessed =
500  OTContract::DearmorAndTrim(strInput, strContract, strFirstLine);
501 
502  if (bProcessed) {
503  Token* pToken = Token::LowLevelInstantiate(strFirstLine, thePurse);
504 
505  // The string didn't match any of the options in the factory.
506  if (nullptr == pToken) return nullptr;
507 
508  // Does the contract successfully load from the string passed in?
509  if (pToken->LoadContractFromString(strContract))
510  return pToken;
511  else
512  delete pToken;
513  }
514 
515  return nullptr;
516 }
static EXPORT bool DearmorAndTrim(const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
Definition: OTContract.cpp:158
static EXPORT Token * LowLevelInstantiate(const Purse &thePurse)
Definition: Token.cpp:418
EXPORT Token()
Definition: Token.cpp:219
Token * opentxs::Token::TokenFactory ( OTString  strInput,
const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
)
static

Definition at line 468 of file Token.cpp.

470 {
471  // const char * szFunc = "Token::TokenFactory";
472 
473  OTString strContract, strFirstLine; // output for the below function.
474  const bool bProcessed =
475  OTContract::DearmorAndTrim(strInput, strContract, strFirstLine);
476 
477  if (bProcessed) {
478  Token* pToken =
479  Token::LowLevelInstantiate(strFirstLine, SERVER_ID, ASSET_ID);
480 
481  // The string didn't match any of the options in the factory.
482  if (nullptr == pToken) return nullptr;
483 
484  // Does the contract successfully load from the string passed in?
485  if (pToken->LoadContractFromString(strContract))
486  return pToken;
487  else
488  delete pToken;
489  }
490 
491  return nullptr;
492 }
static EXPORT bool DearmorAndTrim(const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
Definition: OTContract.cpp:158
static EXPORT Token * LowLevelInstantiate(const Purse &thePurse)
Definition: Token.cpp:418
EXPORT Token()
Definition: Token.cpp:219
void opentxs::Token::UpdateContents ( )
virtual

Reimplemented from opentxs::OTScriptable.

Definition at line 771 of file Token.cpp.

772 {
773  if (m_State == Token::spendableToken) m_strContractType.Set("CASH TOKEN");
774 
775  OTString ASSET_TYPE_ID(m_AssetTypeID), SERVER_ID(m_ServerID);
776 
777  OTString strState;
778  switch (m_State) {
779  case Token::blankToken:
780  strState.Set("blankToken");
781  break;
782  case Token::protoToken:
783  strState.Set("protoToken");
784  break;
785  case Token::signedToken:
786  strState.Set("signedToken");
787  break;
789  strState.Set("spendableToken");
790  break;
792  strState.Set("verifiedToken");
793  break;
794  default:
795  strState.Set("errorToken");
796  break;
797  }
798 
799  int64_t lFrom = OTTimeGetSecondsFromTime(m_VALID_FROM);
800  int64_t lTo = OTTimeGetSecondsFromTime(m_VALID_TO);
801 
802  // I release this because I'm about to repopulate it.
804 
805  m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
806 
808  "<token\n version=\"%s\"\n state=\"%s\"\n denomination=\"%lld\"\n"
809  " assetTypeID=\"%s\"\n"
810  " serverID=\"%s\"\n"
811  " series=\"%d\"\n"
812  " validFrom=\"%" PRId64 "\"\n"
813  " validTo=\"%" PRId64 "\""
814  " >\n\n",
815  m_strVersion.Get(), strState.Get(), GetDenomination(),
816  ASSET_TYPE_ID.Get(), SERVER_ID.Get(), m_nSeries, lFrom, lTo);
817 
818  // signed tokens, as well as spendable tokens, both carry a TokenID
819  // (The spendable token contains the unblinded version.)
821  m_xmlUnsigned.Concatenate("<tokenID>\n%s</tokenID>\n\n",
822  m_ascSpendable.Get());
823  }
824 
825  // Only signedTokens carry the signature, which is discarded in spendable
826  // tokens.
827  // (Because it is not used past the unblinding stage anyway, and because it
828  // could
829  // be used to track the token.)
830  if (Token::signedToken == m_State) {
831  m_xmlUnsigned.Concatenate("<tokenSignature>\n%s</tokenSignature>\n\n",
832  m_Signature.Get());
833  }
834 
836  m_nTokenCount) {
838  "<protopurse count=\"%d\" chosenIndex=\"%d\">\n\n", m_nTokenCount,
840 
841  for (auto& it : m_mapPublic) {
842  OTASCIIArmor* pPrototoken = it.second;
843  OT_ASSERT(nullptr != pPrototoken);
844 
845  m_xmlUnsigned.Concatenate("<prototoken>\n%s</prototoken>\n\n",
846  pPrototoken->Get());
847  }
848  m_xmlUnsigned.Concatenate("</protopurse>\n\n");
849  }
850 
851  if (m_bSavePrivateKeys) {
852  m_bSavePrivateKeys = false; // set it back to false;
853 
854  m_xmlUnsigned.Concatenate("<privateProtopurse>\n\n");
855 
856  for (auto& it : m_mapPrivate) {
857  OTASCIIArmor* pPrototoken = it.second;
858  OT_ASSERT(nullptr != pPrototoken);
859 
861  "<privatePrototoken>\n%s</privatePrototoken>\n\n",
862  pPrototoken->Get());
863  }
864  m_xmlUnsigned.Concatenate("</privateProtopurse>\n\n");
865  }
866 
867  m_xmlUnsigned.Concatenate("</token>\n");
868 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
OTASCIIArmor m_Signature
Definition: Token.hpp:227
int32_t m_nSeries
Definition: Token.hpp:268
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
bool m_bSavePrivateKeys
Definition: Token.hpp:270
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
int64_t GetDenomination() const
Definition: Token.hpp:409
#define OT_ASSERT(x)
Definition: Assert.hpp:150
mapOfPrototokens m_mapPrivate
Definition: Token.hpp:240
OTString m_strContractType
Definition: OTContract.hpp:178
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
int32_t m_nTokenCount
Definition: Token.hpp:244
EXPORT const char * Get() const
Definition: OTString.cpp:1045
mapOfPrototokens m_mapPublic
Definition: Token.hpp:237
OTIdentifier m_AssetTypeID
tokenState m_State
Definition: Token.hpp:269
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
virtual EXPORT void Release()
Definition: OTString.cpp:765
bool opentxs::Token::VerifyToken ( OTPseudonym theNotary,
Mint theMint 
)

Definition at line 1162 of file Token.cpp.

1163 {
1164  // otErr << "%s <bank info> <coin>\n",argv[0]);
1165 
1166  if (Token::spendableToken != m_State) {
1167  otErr << "Expected spendable token in Token::VerifyToken\n";
1168 
1169  return false;
1170  }
1171 
1172  // _OT_Lucre_Dumper setDumper; // OTMint::VerifyToken already does this.
1173  // Unnecessary here?
1174 
1175  // load the bank and coin info into the bios
1176  // The Mint private info is encrypted in m_ascPrivate. So I need to extract
1177  // that
1178  // first before I can use it.
1179  OTEnvelope theEnvelope(m_ascSpendable);
1180 
1181  OTString strContents; // output from opening the envelope.
1182  // Decrypt the Envelope into strContents
1183  if (!theEnvelope.Open(theNotary, strContents))
1184  return false; // todo log error, etc.
1185 
1186  // Verify that the series is correct...
1187  // (Otherwise, someone passed us the wrong Mint and the
1188  // thing won't verify anyway, since we'd have the wrong keys.)
1189  if (m_nSeries != theMint.GetSeries() ||
1190  // Someone might, however, in a clever attack, choose to leave
1191  // the series intact, but change the expiration dates, so that the
1192  // mint keys continue to work properly for this token, but then
1193  // when we check the date, it APPEARS good, when really the dates
1194  // were altered! To prevent this, we explicitly verify the series
1195  // information on the token against the same info on the mint,
1196  // BEFORE checking the date.
1197  m_VALID_FROM != theMint.GetValidFrom() ||
1198  m_VALID_TO != theMint.GetValidTo()) {
1199  otOut << "Token series information doesn't match Mint series "
1200  "information!\n";
1201  return false;
1202  }
1203 
1204  // Verify whether token has expired...expiration date is validated here.
1205  // We know the series is correct or the key wouldn't verify below... and
1206  // we know that the dates are correct because we compared them against the
1207  // mint of that series above. So now we just make sure that the CURRENT date
1208  // and time is within the range described on the token.
1209  if (!VerifyCurrentDate()) {
1210  otOut << "Token is expired!\n";
1211  return false;
1212  }
1213 
1214  // pass the cleartext Lucre spendable coin data to the Mint to be verified.
1215  if (theMint.VerifyToken(theNotary, strContents,
1216  GetDenomination())) // Here's the boolean output:
1217  // coin is verified!
1218  {
1219  otOut << "Token verified!\n";
1220  return true;
1221  }
1222  else {
1223  otOut << "Bad coin!\n";
1224  return false;
1225  }
1226 }
int32_t m_nSeries
Definition: Token.hpp:268
OTLOG_IMPORT OTLogStream otOut
EXPORT bool VerifyCurrentDate()
int64_t GetDenomination() const
Definition: Token.hpp:409
OTASCIIArmor m_ascSpendable
Definition: Token.hpp:224
OTLOG_IMPORT OTLogStream otErr
tokenState m_State
Definition: Token.hpp:269

Member Data Documentation

OTASCIIArmor opentxs::Token::m_ascSpendable
protected

Definition at line 224 of file Token.hpp.

bool opentxs::Token::m_bPasswordProtected
protected

Definition at line 221 of file Token.hpp.

bool opentxs::Token::m_bSavePrivateKeys
protected

Definition at line 270 of file Token.hpp.

int64_t opentxs::Token::m_lDenomination
protected

Definition at line 230 of file Token.hpp.

mapOfPrototokens opentxs::Token::m_mapPrivate
protected

Definition at line 240 of file Token.hpp.

mapOfPrototokens opentxs::Token::m_mapPublic
protected

Definition at line 237 of file Token.hpp.

int32_t opentxs::Token::m_nChosenIndex
protected

Definition at line 246 of file Token.hpp.

int32_t opentxs::Token::m_nSeries
protected

Definition at line 268 of file Token.hpp.

int32_t opentxs::Token::m_nTokenCount
protected

Definition at line 244 of file Token.hpp.

OTASCIIArmor opentxs::Token::m_Signature
protected

Definition at line 227 of file Token.hpp.

tokenState opentxs::Token::m_State
protected

Definition at line 269 of file Token.hpp.


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