本文整理汇总了C++中OTPseudonym类的典型用法代码示例。如果您正苦于以下问题:C++ OTPseudonym类的具体用法?C++ OTPseudonym怎么用?C++ OTPseudonym使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OTPseudonym类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HarvestClosingNumbers
// Used for adding transaction numbers back to a Nym, after deciding not to use this agreement
// or failing in trying to use it. Client side.
//
void OTAgreement::HarvestClosingNumbers(OTPseudonym & theNym)
{
// since we overrode the parent, we give it a chance to harvest also.
//
OTCronItem::HarvestClosingNumbers(theNym);
// The Nym is the original recipient. (If Compares true).
// FYI, if Nym is the original sender, then the above call will handle him.
//
// GetTransactionNum() is burned, but we can harvest the closing
// numbers from the "Closing" list, which is only for the sender's numbers.
// Subclasses will have to override this function for recipients, etc.
//
if (theNym.CompareID(GetRecipientUserID()))
{
const OTString strServerID(GetServerID());
for (int i = 0; i < GetRecipientCountClosingNumbers(); i++)
{
if (theNym.VerifyIssuedNum(strServerID, GetRecipientClosingTransactionNoAt(i))) // we only "add it back" if it was really there in the first place.
theNym.AddTransactionNum(theNym, strServerID, GetRecipientClosingTransactionNoAt(i),
(i == (GetRecipientCountClosingNumbers()-1) ? true : false)); // bSave=true only on the last iteration.
}
}
}
示例2: HarvestOpeningNumber
// You usually wouldn't want to use this, since if the transaction failed, the opening number
// is already burned and gone. But there might be cases where it's not, and you want to retrieve it.
// So I added this function.
//
void OTAgreement::HarvestOpeningNumber(OTPseudonym & theNym)
{
// since we overrode the parent, we give it a chance to harvest also.
// IF theNym is the original sender, the opening number will be harvested
// inside this call.
//
OTCronItem::HarvestOpeningNumber(theNym);
// The Nym is the original recipient. (If Compares true).
// IN CASES where GetTransactionNum() isn't already burned, we can harvest it here.
//
if (theNym.CompareID(GetRecipientUserID()))
{
// This function will only "add it back" if it was really there in the first place.
// (Verifies it is on issued list first, before adding to available list.)
//
theNym.ClawbackTransactionNumber(GetServerID(), GetRecipientOpeningNum(), true); //bSave=true
}
// NOTE: if the message failed (transaction never actually ran) then the sender AND recipient
// can both reclaim their opening numbers. But if the message SUCCEEDED and the transaction FAILED,
// then only the recipient can claim his opening number -- the sender's is already burned. So then,
// what if you mistakenly call this function and pass the sender, when that number is already burned?
// There's nothing this function can do, because we have no way of telling, from inside here,
// whether the message succeeded or not, and whether the transaction succeeded or not. Therefore,
// ==> we MUST rely on the CALLER to know this, and to avoid calling this function in the first place,
// if he's sitting on a sender with a failed transaction.
}
示例3: CanRemoveItemFromCron
/// See if theNym has rights to remove this item from Cron.
///
bool OTAgreement::CanRemoveItemFromCron(OTPseudonym & theNym)
{
// You don't just go willy-nilly and remove a cron item from a market unless you check first
// and make sure the Nym who requested it actually has said number (or a related closing number)
// signed out to him on his last receipt...
//
if (true == OTCronItem::CanRemoveItemFromCron(theNym))
return true;
const OTString strServerID(GetServerID());
// Usually the Nym is the originator. (Meaning GetTransactionNum() on this agreement
// is still verifiable as an issued number on theNum, and belongs to him.) In that case,
// the above call will discover this, and return true.
// In other cases, theNym has the right to Remove the item even though theNym didn't originate it.
// (Like if he is the recipient -- not the sender -- in a payment plan.) We check such things
// HERE in this function (see below.)
//
if (false == theNym.CompareID(GetRecipientUserID()))
{
OTLog::Output(0, "OTAgreement::CanRemoveItemFromCron Weird: Nym tried to remove agreement (payment plan), even "
"though he apparently wasn't the sender OR recipient.\n");
return false;
}
else if (this->GetRecipientCountClosingNumbers() < 2)
{
OTLog::vOutput(0, "OTAgreement::CanRemoveItemFromCron Weird: Recipient tried to remove agreement "
"(or payment plan); expected 2 closing numbers to be available--that weren't. (Found %d).\n",
this->GetRecipientCountClosingNumbers());
return false;
}
if (false == theNym.VerifyIssuedNum(strServerID, this->GetRecipientClosingNum()))
{
OTLog::Output(0, "OTAgreement::CanRemoveItemFromCron: Recipient Closing number didn't verify (for removal from cron).\n");
return false;
}
// By this point, we KNOW theNym is the sender, and we KNOW there are the proper number of transaction
// numbers available to close. We also know that this cron item really was on the cron object, since
// that is where it was looked up from, when this function got called! So I'm pretty sure, at this point,
// to authorize removal, as long as the transaction num is still issued to theNym (this check here.)
//
return theNym.VerifyIssuedNum(strServerID, this->GetRecipientOpeningNum());
// Normally this will be all we need to check. The originator will have the transaction
// number signed-out to him still, if he is trying to close it. BUT--in some cases, someone
// who is NOT the originator can cancel. Like in a payment plan, the sender is also the depositor,
// who would normally be the person cancelling the plan. But technically, the RECIPIENT should
// also have the ability to cancel that payment plan. BUT: the transaction number isn't signed
// out to the RECIPIENT... In THAT case, the below VerifyIssuedNum() won't work! In those cases,
// expect that the special code will be in the subclasses override of this function. (OTPaymentPlan::CanRemoveItem() etc)
// P.S. If you override this function, MAKE SURE to call the parent (OTCronItem::CanRemoveItem) first,
// for the VerifyIssuedNum call above. Only if that fails, do you need to dig deeper...
}
示例4: Seal
bool OTEnvelope::Seal(const OTPseudonym & theRecipient, const OTString & theInput)
{
OTString strNymID;
mapOfAsymmetricKeys theKeys;
theRecipient.GetIdentifier(strNymID);
theKeys.insert(std::pair<std::string, OTAsymmetricKey *>
(strNymID.Get(), const_cast<OTAsymmetricKey *>(&(theRecipient.GetPublicEncrKey()))));
// -----------------------------
return this->Seal(theKeys, theInput);
}
示例5: FOR_EACH
FOR_EACH(mapOfNyms, m_mapNyms)
{
OTPseudonym * pNym = (*it).second;
OT_ASSERT_MSG((NULL != pNym), "NULL pseudonym pointer in OTWallet::GetNymByID.");
OTIdentifier id_CurrentNym;
pNym->GetIdentifier(id_CurrentNym);
if (id_CurrentNym == NYM_ID)
return pNym;
}
示例6: strServerID
// This is a good implementation. Dots all the i's, so to speak.
// client-side.
// The basket ONLY stores closing numbers, so this means "harvest 'em all."
//
void OTBasket::HarvestClosingNumbers(OTPseudonym & theNym, const OTIdentifier & theServerID, const bool bSave/*=true*/)
{
const OTString strServerID(theServerID);
bool bNeedToSave = false;
// *************************************************************************
// The SUB-CURRENCIES first...
//
const unsigned int nCount = static_cast<unsigned int>(this->Count());
for (unsigned int i = 0; i < nCount; i++)
{
BasketItem * pRequestItem = this->At(i);
OT_ASSERT(NULL != pRequestItem);
// --------------------------------
const long lClosingTransNo = pRequestItem->lClosingTransactionNo;
// --------------------------------
// This function will only "add it back" if it was really there in the first place.
// (Verifies it is on issued list first, before adding to available list.)
//
const bool bClawedBack = theNym.ClawbackTransactionNumber(theServerID, lClosingTransNo, false); // bSave=false
if (bClawedBack)
bNeedToSave = true;
// else
// OTLog::vError("OTBasket::HarvestClosingNumbers: Number (%ld) failed as issued. (Thus didn't bother 'adding it back'.)\n",
// lClosingTransNo);
} // for
// *************************************************************************
// Then the BASKET currency itself...
//
const long lClosingTransNo = this->GetClosingNum();
// --------------------------------
// This function will only "add it back" if it was really there in the first place.
// (Verifies it is on issued list first, before adding to available list.)
//
const bool bClawedBack = theNym.ClawbackTransactionNumber(theServerID, lClosingTransNo, false); // bSave=false
if (bClawedBack)
bNeedToSave = true;
// *************************************************************************
// Until I put this down here, there were subtle cases where the Nym wouldn't get saved.
// Therefore another vote for my "dirty instances" theory.
//
if (bSave && bNeedToSave)
{
OTPseudonym * pSignerNym = &theNym;// probably unnecessary.
theNym.SaveSignedNymfile(*pSignerNym);
}
}
示例7: FOR_EACH
bool OTEnvelope::Seal(setOfNyms & theRecipients, const OTString & theInput)
{
mapOfAsymmetricKeys RecipPubKeys;
// Loop through theRecipients, and add the public key of each one to a set of keys.
//
FOR_EACH(setOfNyms, theRecipients)
{
OTPseudonym * pNym = *it;
OT_ASSERT_MSG(NULL != pNym, "OTEnvelope::Seal: Assert: NULL pseudonym pointer.");
// ------------------------------
OTString strNymID;
pNym->GetIdentifier(strNymID);
RecipPubKeys.insert(std::pair<std::string, OTAsymmetricKey *>
(strNymID.Get(), const_cast<OTAsymmetricKey *>(&(pNym->GetPublicEncrKey()))));
}
示例8: CreateBasket
// Normally, Asset Contracts do NOT update / rewrite their contents, since their
// primary goal is for the signature to continue to verify. But when first creating
// a basket contract, we have to rewrite the contents, which is done here.
bool OTAssetContract::CreateBasket(OTBasket & theBasket, OTPseudonym & theSigner)
{
Release();
// Grab a string copy of the basket information.
theBasket.SaveContractRaw(m_strBasketInfo);
// -------------------------------
// Insert the server's public key as the "contract" key for this basket currency.
OTString strPubKey, strKeyName("contract"); // todo stop hardcoding
theSigner.GetPublicKey().GetPublicKey(strPubKey);
InsertNym(strKeyName, strPubKey);
// todo check the above two return values.
OTASCIIArmor theBasketArmor(m_strBasketInfo);
// -------------------------------
m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
m_xmlUnsigned.Concatenate("<basketContract version=\"%s\">\n\n", m_strVersion.Get());
m_xmlUnsigned.Concatenate("<basketInfo>\n%s</basketInfo>\n\n", theBasketArmor.Get());
m_xmlUnsigned.Concatenate("<key name=\"%s\">\n%s</key>\n\n", strKeyName.Get(), strPubKey.Get());
m_xmlUnsigned.Concatenate("</basketContract>\n");
// This function assumes that m_xmlUnsigned is ready to be processed.
// This function only processes that portion of the contract.
bool bLoaded = LoadContractXML();
if (bLoaded)
{
OTString strTemp;
SignContract(theSigner);
RewriteContract(strTemp); // this trims
// This is probably redundant...
// std::string str_Trim(strTemp.Get());
// std::string str_Trim2 = OTString::trim(str_Trim);
// strTemp.Set(str_Trim2.c_str());
// -----------------------------------
Release();
LoadContractFromString(strTemp);
SaveContract();
OTIdentifier NEW_ID;
CalculateContractID(NEW_ID);
m_ID = NEW_ID;
return true;
}
return false;
}
示例9: HarvestOpeningNumber
// You usually wouldn't want to use this, since if the transaction failed, the opening number
// is already burned and gone. But there might be cases where it's not, and you want to retrieve it.
// So I added this function.
//
void OTAgreement::HarvestOpeningNumber(OTPseudonym & theNym)
{
// since we overrode the parent, we give it a chance to harvest also.
//
OTCronItem::HarvestOpeningNumber(theNym);
// The Nym is the original sender. (If Compares true).
// IN CASES where GetTransactionNum() isn't already burned, we can harvest it here.
// Subclasses will have to override this function for recipients, etc.
//
if (theNym.CompareID(GetRecipientUserID()))
{
const OTString strServerID(GetServerID());
if (theNym.VerifyIssuedNum(strServerID, GetRecipientOpeningNum())) // we only "add it back" if it was really there in the first place.
theNym.AddTransactionNum(theNym, strServerID, GetRecipientOpeningNum(), true); // bSave=true
}
}
示例10: VerifyOwner
// Verify Contract ID first, THEN Verify Owner.
// Because we use the ID in this function, so make sure that it is verified before calling this.
//
bool OTAccount::VerifyOwner(const OTPseudonym & theCandidate) const
{
OTIdentifier ID_CANDIDATE;
theCandidate.GetIdentifier(ID_CANDIDATE); // ID_CANDIDATE now contains the ID of the Nym we're testing.
if (m_AcctUserID == ID_CANDIDATE)
{
return true;
}
return false;
}
示例11: VerifyOwner
// Verify Contract ID first, THEN Verify Owner.
// Because we use the ID in this function, so make sure that it is verified before calling this.
bool OTAccount::VerifyOwner(OTPseudonym & theCandidate)
{
OTIdentifier ID_CANDIDATE;
theCandidate.GetIdentifier(ID_CANDIDATE); // ID_CANDIDATE now contains the ID of the Nym we're testing.
if (m_AcctUserID == ID_CANDIDATE) // There's an op== function, but no != ... So I used == since it exists.
{
return true;
}
return false;
}
示例12: HarvestClosingNumbers
// Used for adding transaction numbers back to a Nym, after deciding not to use this agreement
// or failing in trying to use it. Client side.
//
void OTAgreement::HarvestClosingNumbers(OTPseudonym & theNym)
{
// Since we overrode the parent, we give it a chance to harvest also.
// If theNym is the sender, then his closing numbers will be harvested
// inside here. But what if the transaction was a success? The numbers
// will still be harvested, since they are still on the sender's issued
// list, but they should not have been harvested, regardless, since the
// transaction was a success and the server therefore has them marked as
// "used." So clearly you cannot just blindly call this function unless
// you know beforehand whether the message and transaction were a success.
//
OTCronItem::HarvestClosingNumbers(theNym);
// The Nym is the original recipient. (If Compares true).
// FYI, if Nym is the original sender, then the above call will handle him.
//
// GetTransactionNum() is burned, but we can harvest the closing
// numbers from the "Closing" list, which is only for the sender's numbers.
// Subclasses will have to override this function for recipients, etc.
//
if (theNym.CompareID(GetRecipientUserID()))
{
for (int i = 0; i < GetRecipientCountClosingNumbers(); i++)
{
// This function will only "add it back" if it was really there in the first place.
// (Verifies it is on issued list first, before adding to available list.)
//
const bool bClawedBack =
theNym.ClawbackTransactionNumber(GetServerID(),
GetRecipientClosingTransactionNoAt(i),
(i == (GetRecipientCountClosingNumbers()-1) ? true : false)); // bSave=true only on the last iteration.
if (!bClawedBack)
{
// OTLog::vError("OTAgreement::HarvestClosingNumbers: Number (%ld) failed as issued. (Thus didn't bother 'adding it back'.)\n",
// GetRecipientClosingTransactionNoAt(i));
}
}
}
}
示例13: main
//.........这里部分代码省略.........
"have reached 10000. You will have to change the source code of this\n"
"program in order to continue. Sorry.\n\n");
return 0;
}
// ---------------------------------------------------------------------
// nSeries now contains the number we need to use for the next series.
// and strMintPath now contains the correct file path.
OTMint * pMint = new OTMint(strServerID, strServerNymID, strAssetTypeID);
OT_ASSERT(NULL != pMint);
OTString strSeries; strSeries.Format("%s%d", ".", nSeries);
if (pMint->LoadMint(strSeries.Get()))
{
OTLog::Output(0, "\n\nSorry, that mint already exists. Delete it first if you wish to re-create it.\n\n");
}
else
{
OTLog::vOutput(0, "\n\nMint file does not (yet) exist for series %d and asset type:\n%s\n Creating......\n\n",
nSeries, strAssetTypeID.Get());
// TODO: read the denominations out of the asset contract itself, instead of hardcoding them here.
// Calculate FROM as Today, Now,
// then calculate TO as 6 months from now,
// and EXPIRATION as 3 months from now.
//
// TODO: Let these numbers be configured either in server operator contract, or issuer contract.
// In the meantime, 3 and 6 months are good enough.
OTPseudonym theNym;
theNym.SetIdentifier(strServerNymID);
// 1 hour == 3600 Seconds
// 1 day == 86400 Seconds
// 30 days == 2592000 Seconds
// 3 months == 7776000 Seconds
// 6 months == 15552000 Seconds
// This part requires the server operator to enter his passphrase.
// Which is why the server can't just fire it off automatically and
// make a mint available to the client. The client has to wait a day or
// until the operator is able to run this script and type the passphrase.
if (theNym.Loadx509CertAndPrivateKey())
{
const time_t CURRENT_TIME = time(NULL),
VALID_TO = CURRENT_TIME + 15552000, // Tokens generated by this mint are valid from today until 6 months from today
MINT_EXPIRATION = CURRENT_TIME + 7776000; // The mint itself will expire in 3 months from today, and be replaced with a new one.
pMint->GenerateNewMint(nSeries, CURRENT_TIME, VALID_TO, MINT_EXPIRATION, ASSET_TYPE_ID, SERVER_ID,
// penny, nickel, dime, quarter, $1, $5, $10, $20, $100, $1000
theNym, 1, 5, 10, 25, 100, 500, 1000, 2000, 10000, 100000);
// should be: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536
// ---------------------------------------
// OTString strFilename;// strPUBLICFilename;
// strFilename. Format("%s%s%s", strServerID.Get(), OTLog::PathSeparator(), strAssetTypeID.Get());
// strPUBLICFilename. Format("%s%s%s%sPUBLIC",strServerID.Get(), OTLog::PathSeparator(), strAssetTypeID.Get(), ".");
if (!OTDataFolder::IsInitialized()) { OT_ASSERT(false); };
示例14: AddDenomination
// The mint has a different key pair for each denomination.
// Pass the actual denomination such as 5, 10, 20, 50, 100...
bool OTMint_Lucre::AddDenomination(OTPseudonym & theNotary, int64_t lDenomination, int32_t nPrimeLength/*=1024*/)
{
OT_ASSERT(NULL != m_pKeyPublic);
bool bReturnValue = false;
// Let's make sure it doesn't already exist
OTASCIIArmor theArmor;
if (GetPublic(theArmor, lDenomination))
{
// it already exists.
OTLog::Error("Error: Denomination public already exists in OTMint::AddDenomination\n");
return false;
}
if (GetPrivate(theArmor, lDenomination))
{
// it already exists.
OTLog::Error("Error: Denomination private already exists in OTMint::AddDenomination\n");
return false;
}
// OTLog::Error("%s <size of bank prime in bits> <bank data file> <bank public data file>\n",
if ((nPrimeLength/8) < (MIN_COIN_LENGTH+DIGEST_LENGTH))
{
OTLog::vError("Prime must be at least %d bits\n",
(MIN_COIN_LENGTH+DIGEST_LENGTH)*8);
return false;
}
if (nPrimeLength%8)
{
OTLog::Error("Prime length must be a multiple of 8\n");
return false;
}
#ifdef _WIN32
SetMonitor("openssl.dump");
#else
SetMonitor(stderr);
#endif
OpenSSL_BIO bio = BIO_new(BIO_s_mem());
OpenSSL_BIO bioPublic = BIO_new(BIO_s_mem());
// Generate the mint private key information
Bank bank(nPrimeLength/8);
bank.WriteBIO(bio);
// Generate the mint public key information
PublicBank pbank(bank);
pbank.WriteBIO(bioPublic);
// Copy from BIO back to a normal OTString or Ascii-Armor
char privateBankBuffer[4096], publicBankBuffer[4096]; // todo stop hardcoding these string lengths
int32_t privatebankLen = BIO_read(bio, privateBankBuffer, 4000); // cutting it a little short on purpose, with the buffer.
int32_t publicbankLen = BIO_read(bioPublic, publicBankBuffer, 4000); // Just makes me feel more comfortable for some reason.
if (privatebankLen && publicbankLen)
{
// With this, we have the Lucre public and private bank info converted to OTStrings
OTString strPublicBank; strPublicBank.Set(publicBankBuffer, publicbankLen);
OTString strPrivateBank; strPrivateBank.Set(privateBankBuffer, privatebankLen);
OTASCIIArmor * pPublic = new OTASCIIArmor();
OTASCIIArmor * pPrivate = new OTASCIIArmor();
OT_ASSERT(NULL != pPublic);
OT_ASSERT(NULL != pPrivate);
// Set the public bank info onto pPublic
pPublic->SetString(strPublicBank, true); // linebreaks = true
// Seal the private bank info up into an encrypted Envelope
// and set it onto pPrivate
OTEnvelope theEnvelope;
theEnvelope.Seal(theNotary, strPrivateBank); // Todo check the return values on these two functions
theEnvelope.GetAsciiArmoredData(*pPrivate);
// Add the new key pair to the maps, using denomination as the key
m_mapPublic[lDenomination] = pPublic;
m_mapPrivate[lDenomination] = pPrivate;
// Grab the Server Nym ID and save it with this Mint
theNotary.GetIdentifier(m_ServerNymID);
// ---------------------------
// Grab the Server's public key and save it with this Mint
//
const OTAsymmetricKey & theNotaryPubKey = theNotary.GetPublicSignKey();
delete m_pKeyPublic;
m_pKeyPublic = theNotaryPubKey.ClonePubKey();
// ---------------------------
m_nDenominationCount++;
// ---------------------------
// Success!
bReturnValue = true;
OTLog::vOutput(1, "Successfully added denomination: %lld\n", lDenomination);
}
//.........这里部分代码省略.........
示例15:
OTString::OTString(OTPseudonym & theValue)
{
Initialize();
theValue.SavePseudonym(*this);
}