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

#include <TokenLucre.hpp>

Inheritance diagram for opentxs::Token_Lucre:
Collaboration diagram for opentxs::Token_Lucre:

Public Member Functions

virtual EXPORT bool ProcessToken (const OTPseudonym &theNym, Mint &theMint, Token &theRequest)
 
virtual EXPORT ~Token_Lucre ()
 
- Public Member Functions inherited from opentxs::Token
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)
 
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
 

Protected Member Functions

EXPORT Token_Lucre ()
 
EXPORT Token_Lucre (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
EXPORT Token_Lucre (const Purse &thePurse)
 
virtual EXPORT bool GenerateTokenRequest (const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())
 
- Protected Member Functions inherited from opentxs::Token
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)
 
- 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 ()
 

Friends

class Token
 

Additional Inherited Members

- Public Types inherited from opentxs::Token
enum  tokenState {
  blankToken, protoToken, signedToken, spendableToken,
  verifiedToken, errorToken
}
 
- Static Public Member Functions inherited from opentxs::Token
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 Attributes inherited from opentxs::Token
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 TokenLucre.hpp.

Constructor & Destructor Documentation

opentxs::Token_Lucre::Token_Lucre ( )
protected

Definition at line 159 of file TokenLucre.cpp.

160  : ot_super()
161 {
162 }
opentxs::Token_Lucre::Token_Lucre ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
)
protected

Definition at line 164 of file TokenLucre.cpp.

166  : ot_super(SERVER_ID, ASSET_ID)
167 {
168 }
opentxs::Token_Lucre::Token_Lucre ( const Purse thePurse)
protected

Definition at line 170 of file TokenLucre.cpp.

171  : ot_super(thePurse)
172 {
173 }
opentxs::Token_Lucre::~Token_Lucre ( )
virtual

Definition at line 175 of file TokenLucre.cpp.

176 {
177 }

Member Function Documentation

bool opentxs::Token_Lucre::GenerateTokenRequest ( const OTPseudonym theNym,
Mint theMint,
int64_t  lDenomination,
int32_t  nTokenCount = Token::GetMinimumPrototokenCount() 
)
protectedvirtual

Implements opentxs::Token.

Definition at line 183 of file TokenLucre.cpp.

186 {
187  // otErr << "%s <bank public info> <coin request private output file>
188  // <coin request public output file>\n", argv[0]);
189  //
190  if (Token::blankToken != m_State) {
191  otErr << "Token_Lucre::GenerateTokenRequest: Blank token expected.\n";
192  return false;
193  }
194 
195  LucreDumper setDumper; // todo security.
196 
197  OpenSSL_BIO bioBank = BIO_new(
198  BIO_s_mem()); // Input. We must supply the bank's public lucre info
199 
200  // This version base64-DECODES the ascii-armored string passed in,
201  // and then sets the decoded plaintext string onto the string.
202  // OTString::OTString(const OTASCIIArmor & strValue)
203  OTASCIIArmor ascPublicMint;
204 
205  theMint.GetPublic(ascPublicMint, lDenomination);
206  // otErr << "DEBUG: OTToken public asc: \n%s\n", ascPublicMint.Get());
207 
208  OTString strPublicMint(ascPublicMint);
209  // otErr << "DEBUG: OTToken public str: \n%s\n", strPublicMint.Get());
210 
211  // Get the bank's public key (now decoded in strPublicMint)
212  // and put it into bioBank so we can use it with Lucre.
213  BIO_puts(bioBank, strPublicMint.Get());
214 
215  // Instantiate a PublicBank (Lucre) object.
216  // We will use it to generate all the prototokens in the loop below.
217  PublicBank bank;
218  bank.ReadBIO(bioBank);
219 
220  Release(); // note: why is this here? I guess to release the prototokens,
221  // the signature (is there one?) and m_ascSpendable (exists?
222  // doubt it.) This WAS also doing "InitToken" (no longer) which
223  // WAS setting series and expiration range back to 0 (no longer.)
224  // Which was causing problems for all series above 0. I'm leaving
225  // this call here, to do the stuff I guess it was put here for.
226  // But things such as the series, expiration date range, and
227  // token count, etc are no longer (inadvertantly) set to 0 here
228  // on this line. I'm also moving the SetSeriesAndExpiration call
229  // to be BELOW this line, since it's not apparently needed above
230  // this line anyway.
231 
232  // We are supposed to set these values here.
233  // The server actually sets them again, for security reasons.
234  // But we should still set them since server may choose to reject the
235  // request.
236  // Update: the series information on this token IS used by the server, since
237  // more than
238  // one mint may be currently valid, and since the server has to process the
239  // request using
240  // the proper mint, corresponding to the same mint that was used to GENERATE
241  // that request.
242  // So the server uses the series value from this token in order to choose
243  // which mint is loaded,
244  // on the server side. When this call WAS above the Release() call above,
245  // these values were
246  // getting wiped in Release back to 0. So I've moved it below the Release()
247  // call. (I've also
248  // stopped wiping them in Release.)
249  //
250  SetSeriesAndExpiration(theMint.GetSeries(), theMint.GetValidFrom(),
251  theMint.GetValidTo());
252 
253  const int32_t nFinalTokenCount =
254  (nTokenCount < Token::GetMinimumPrototokenCount())
256  : nTokenCount;
257 
258  // Token count is actually 1 (always) with Lucre, although this lib has
259  // potential to work with
260  // multiple proto-tokens, you can see this loop as though it always executes
261  // just once.
262  for (int32_t i = 0; i < nFinalTokenCount; i++) {
263  OpenSSL_BIO bioCoin = BIO_new(BIO_s_mem()); // These two are output. We
264  // must write these bios,
265  // after
266  OpenSSL_BIO bioPublicCoin = BIO_new(
267  BIO_s_mem()); // the operation, back into some form we can use
268 
269  CoinRequest req(bank);
270 
271  // write the private coin request to BIO
272  req.WriteBIO(bioCoin);
273 
274  // write the public coin request to BIO
275  ((PublicCoinRequest*)&req)->WriteBIO(bioPublicCoin);
276 
277  // Convert the two bios to our format
278  char privateCoinBuffer[4096],
279  publicCoinBuffer[4096]; // todo stop hardcoding these string lengths
280  int32_t privatecoinLen = BIO_read(bioCoin, privateCoinBuffer,
281  4000); // cutting it a little short on
282  // purpose, with the buffer.
283  // Just makes me feel more
284  // comfortable for some reason.
285  int32_t publiccoinLen = BIO_read(bioPublicCoin, publicCoinBuffer, 4000);
286 
287  if (privatecoinLen && publiccoinLen) {
288  // With this, we have the Lucre public and private bank info
289  // converted to OTStrings
290  OTString strPublicCoin;
291  strPublicCoin.Set(publicCoinBuffer, publiccoinLen);
292  OTString strPrivateCoin;
293  strPrivateCoin.Set(privateCoinBuffer, privatecoinLen);
294 
295  OTASCIIArmor* pArmoredPublic = new OTASCIIArmor(strPublicCoin);
296  OTASCIIArmor* pArmoredPrivate = new OTASCIIArmor();
297 
299  ((nullptr != pArmoredPublic) && (nullptr != pArmoredPrivate)),
300  "ERROR: Unable to allocate memory in "
301  "Token_Lucre::GenerateTokenRequest\n");
302 
303  // Change the state. It's no longer a blank token, but a prototoken.
305 
306  // Seal the private coin info up into an encrypted Envelope
307  // and set it onto pArmoredPrivate (which was just added to our
308  // internal map, above.)
309  OTEnvelope theEnvelope;
310  theEnvelope.Seal(theNym, strPrivateCoin); // Todo check the return
311  // values on these two
312  // functions
313  theEnvelope.GetAsciiArmoredData(*pArmoredPrivate);
314 
315  m_mapPublic[i] = pArmoredPublic;
316  m_mapPrivate[i] = pArmoredPrivate;
317 
318  m_nTokenCount = nFinalTokenCount;
319  SetDenomination(lDenomination);
320  }
321  else {
322  // Error condition todo
323  }
324  }
325 
326  return true;
327 }
static EXPORT int32_t GetMinimumPrototokenCount()
Definition: Token.cpp:180
void SetDenomination(int64_t lVal)
Definition: Token.hpp:413
void ReadBIO(BIO *bio)
virtual void Release()
Definition: Token.cpp:286
mapOfPrototokens m_mapPrivate
Definition: Token.hpp:240
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
void SetSeriesAndExpiration(int32_t nSeries, time64_t VALID_FROM, time64_t VALID_TO)
Definition: Token.hpp:373
int32_t m_nTokenCount
Definition: Token.hpp:244
OTLOG_IMPORT OTLogStream otErr
mapOfPrototokens m_mapPublic
Definition: Token.hpp:237
tokenState m_State
Definition: Token.hpp:269
bool opentxs::Token_Lucre::ProcessToken ( const OTPseudonym theNym,
Mint theMint,
Token theRequest 
)
virtual

Implements opentxs::Token.

Definition at line 332 of file TokenLucre.cpp.

334 {
335  // otErr << "%s <bank public info> <private coin request> <signed coin
336  // request> <coin>\n",
337  bool bReturnValue = false;
338 
339  // When the Mint has signed a token and sent it back to the client,
340  // the client must unblind the token and set it as spendable. Thus,
341  // this function is only performed on tokens in the signedToken state.
342  if (Token::signedToken != m_State) {
343  otErr << "Signed token expected in Token_Lucre::ProcessToken\n";
344  return false;
345  }
346 
347  // Lucre
348  LucreDumper setDumper; // todo security.
349 
350  OpenSSL_BIO bioBank = BIO_new(BIO_s_mem()); // input
351  OpenSSL_BIO bioSignature = BIO_new(BIO_s_mem()); // input
352  OpenSSL_BIO bioPrivateRequest = BIO_new(BIO_s_mem()); // input
353  OpenSSL_BIO bioCoin = BIO_new(BIO_s_mem()); // output
354 
355  // Get the bank's public key (decoded into strPublicMint)
356  // and put it into bioBank so we can use it with Lucre.
357  //
358  OTASCIIArmor ascPublicMint;
359  theMint.GetPublic(ascPublicMint, GetDenomination());
360  OTString strPublicMint(ascPublicMint);
361  BIO_puts(bioBank, strPublicMint.Get());
362 
363  // Get the existing signature into a bio.
364  // otErr << "DEBUGGING, m_Signature: -------------%s--------------\n",
365  // m_Signature.Get());
366  OTString strSignature(m_Signature);
367  BIO_puts(bioSignature, strSignature.Get());
368 
369  // I need the Private coin request also. (Only the client has this private
370  // coin request data.)
371  OTASCIIArmor thePrototoken; // The server sets m_nChosenIndex when it signs
372  // the token.
373  bool bFoundToken =
374  theRequest.GetPrivatePrototoken(thePrototoken, m_nChosenIndex);
375 
376  if (bFoundToken) {
377  // otErr << "THE PRIVATE REQUEST ARMORED
378  // CONTENTS:\n------------------>%s<-----------------------\n",
379  // thePrototoken.Get());
380 
381  // Decrypt the prototoken
382  OTString strPrototoken;
383  OTEnvelope theEnvelope(thePrototoken);
384  theEnvelope.Open(theNym, strPrototoken); // todo check return value.
385 
386  // otErr << "THE PRIVATE REQUEST
387  // CONTENTS:\n------------------>%s<-----------------------\n",
388  // strPrototoken.Get());
389 
390  // copy strPrototoken to a BIO
391  BIO_puts(bioPrivateRequest, strPrototoken.Get());
392 
393  // ------- Okay, the BIOs are all loaded.... let's process...
394 
395  PublicBank bank(bioBank);
396  CoinRequest req(bioPrivateRequest);
397 
398  // TODO make sure I'm not leaking memory with these ReadNumbers
399  // Probably need to be calling some free function for each one.
400 
401  // Apparently reading the request id here and then just discarding it...
402  ReadNumber(bioSignature, "request=");
403 
404  // Versus the signature data, which is read into bnSignature apparently.
405  BIGNUM* bnSignature = ReadNumber(bioSignature, "signature=");
406  DumpNumber("signature=", bnSignature);
407 
408  // Produce the final unblinded token in Coin coin, and write it to
409  // bioCoin...
410  Coin coin; // Coin Request, processes into Coin, with Bank and Signature
411  // passed in.
412  req.ProcessResponse(&coin, bank, bnSignature); // Notice still
413  // apparently "request"
414  // info is discarded.
415  coin.WriteBIO(bioCoin);
416 
417  // convert bioCoin to a C-style string...
418  char CoinBuffer[1024]; // todo stop hardcoding these string lengths
419  int32_t coinLen =
420  BIO_read(bioCoin, CoinBuffer, 1000); // cutting it a little short on
421  // purpose, with the buffer.
422  // Just makes me feel more
423  // comfortable for some reason.
424 
425  if (coinLen) {
426  // ...to OTString...
427  OTString strCoin;
428  strCoin.Set(CoinBuffer, coinLen);
429 
430  // otErr << "Processing token...\n%s\n", strCoin.Get());
431 
432  // ...to Envelope stored in m_ascSpendable (encrypted and
433  // base64-encoded)
434  OTEnvelope theEnvelope;
435  theEnvelope.Seal(theNym, strCoin); // Todo check the return values
436  // on these two functions
437  theEnvelope.GetAsciiArmoredData(
438  m_ascSpendable); // Here's the final product.
439 
440  // otErr << "NEW SPENDABLE
441  // token...\n--------->%s<----------------\n",
442  // m_ascSpendable.Get());
443 
444  // Now the coin is encrypted from here on out, and otherwise
445  // ready-to-spend.
447  bReturnValue = true;
448 
449  // Lastly, we free the signature data, which is no longer needed,
450  // and which could be
451  // otherwise used to trace the token. (Which we don't want.)
453  }
454  }
455  // Todo log error here if the private prototoken is not found. (Very strange
456  // if so!!)
457  // else {}
458 
459  return bReturnValue;
460 }
int32_t m_nChosenIndex
Definition: Token.hpp:246
void WriteBIO(BIO *bio)
OTASCIIArmor m_Signature
Definition: Token.hpp:227
Definition: bank.h:185
void DumpNumber(BIO *out, const char *szTitle, const BIGNUM *bn, const char *szTrailer=_NL)
BIGNUM * ReadNumber(BIO *in, const char *szTitle)
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
virtual EXPORT void Release()
Definition: OTString.cpp:765

Friends And Related Function Documentation

friend class Token
friend

Definition at line 200 of file TokenLucre.hpp.


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