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

#include <OTAgent.hpp>

Public Member Functions

 OTAgent ()
 
 OTAgent (std::string str_agent_name, OTPseudonym &theNym, bool bNymRepresentsSelf=true)
 
 OTAgent (bool bNymRepresentsSelf, bool bIsAnIndividual, const OTString &strName, const OTString &strNymID, const OTString &strRoleID, const OTString &strGroupName)
 
virtual ~OTAgent ()
 
void Serialize (OTString &strAppend) const
 
void ClearTemporaryPointers ()
 
bool VerifyIssuedNumber (const int64_t &lNumber, const OTString &strServerID)
 
bool VerifyTransactionNumber (const int64_t &lNumber, const OTString &strServerID)
 
bool RemoveIssuedNumber (const int64_t &lNumber, const OTString &strServerID, bool bSave=false, OTPseudonym *pSignerNym=nullptr)
 
bool RemoveTransactionNumber (const int64_t &lNumber, const OTString &strServerID, OTPseudonym &SIGNER_NYM, bool bSave=true)
 
bool HarvestTransactionNumber (const int64_t &lNumber, const OTString &strServerID, bool bSave=false, OTPseudonym *pSignerNym=nullptr)
 
bool ReserveOpeningTransNum (const OTString &strServerID)
 
bool ReserveClosingTransNum (const OTString &strServerID, OTPartyAccount &thePartyAcct)
 
EXPORT bool SignContract (OTContract &theInput) const
 
bool VerifyAgencyOfAccount (const OTAccount &theAccount) const
 
bool VerifySignature (const OTContract &theContract) const
 
void SetParty (OTParty &theOwnerParty)
 
void SetNymPointer (OTPseudonym &theNym)
 
EXPORT bool IsValidSigner (OTPseudonym &theNym)
 
EXPORT bool IsValidSignerID (const OTIdentifier &theNymID)
 
bool IsAuthorizingAgentForParty ()
 
int32_t GetCountAuthorizedAccts ()
 
bool DoesRepresentHimself () const
 
bool DoesRepresentAnEntity () const
 
EXPORT bool IsAnIndividual () const
 
bool IsAGroup () const
 
EXPORT bool GetNymID (OTIdentifier &theOutput) const
 
bool GetRoleID (OTIdentifier &theOutput) const
 
bool GetSignerID (OTIdentifier &theOutput) const
 
bool GetEntityID (OTIdentifier &theOutput) const
 
EXPORT const OTStringGetName ()
 
bool GetGroupName (OTString &strGroupName)
 
bool GetPartyID (OTIdentifier &theOutput) const
 
OTPartyGetParty () const
 
void RetrieveNymPointer (mapOfNyms &map_Nyms_Already_Loaded)
 
OTPseudonymLoadNym (OTPseudonym &theServerNym)
 
bool DropFinalReceiptToNymbox (OTSmartContract &theSmartContract, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
 
bool DropFinalReceiptToInbox (mapOfNyms *pNymMap, const OTString &strServerID, OTPseudonym &theServerNym, OTSmartContract &theSmartContract, const OTIdentifier &theAccountID, const int64_t &lNewTransactionNumber, const int64_t &lClosingNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr)
 
bool DropServerNoticeToNymbox (bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &theServerID, const int64_t &lNewTransactionNumber, const int64_t &lInReferenceTo, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
 

Detailed Description

Definition at line 164 of file OTAgent.hpp.

Constructor & Destructor Documentation

opentxs::OTAgent::OTAgent ( )

Definition at line 266 of file OTAgent.cpp.

267  : m_bNymRepresentsSelf(false)
268  , m_bIsAnIndividual(false)
269  , m_pNym(nullptr)
270  , m_pForParty(nullptr)
271 {
272 }
opentxs::OTAgent::OTAgent ( std::string  str_agent_name,
OTPseudonym theNym,
bool  bNymRepresentsSelf = true 
)

Definition at line 288 of file OTAgent.cpp.

291  : m_bNymRepresentsSelf(bNymRepresentsSelf),
292  m_bIsAnIndividual(true),
293  m_pNym(&theNym),
294  m_pForParty(nullptr),
295  m_strName(str_agent_name.c_str())
296 {
297  // Grab m_strNymID
298  OTIdentifier theNymID;
299  theNym.GetIdentifier(theNymID);
300  theNymID.GetString(m_strNymID);
301 
302  //
303 
304  if (!bNymRepresentsSelf) {
305  // Todo: if the Nym represents an Entity, then RoleID should
306  // be passed in, and set here. I WILL PROBABLY make that part into a
307  // SEPARATE CONSTRUCTOR.
308  // (Once I get around to adding Entities.)
309  //
310  otErr << "OTAgent::OTAgent: THIS HASN'T BEEN WRITTEN YET!!\n";
311  }
312 }
OTLOG_IMPORT OTLogStream otErr
opentxs::OTAgent::OTAgent ( bool  bNymRepresentsSelf,
bool  bIsAnIndividual,
const OTString strName,
const OTString strNymID,
const OTString strRoleID,
const OTString strGroupName 
)

Definition at line 274 of file OTAgent.cpp.

277  : m_bNymRepresentsSelf(bNymRepresentsSelf)
278  , m_bIsAnIndividual(bIsAnIndividual)
279  , m_pNym(nullptr)
280  , m_pForParty(nullptr)
281  , m_strName(strName)
282  , m_strNymID(strNymID)
283  , m_strRoleID(strRoleID)
284  , m_strGroupName(strGroupName)
285 {
286 }
opentxs::OTAgent::~OTAgent ( )
virtual

Definition at line 351 of file OTAgent.cpp.

352 {
353  m_pNym =
354  nullptr; // this pointer is not owned by this object, and is here for
355  // convenience only.
356  m_pForParty =
357  nullptr; // The agent probably has a pointer to the party it acts
358  // on behalf of.
359 }

Member Function Documentation

void opentxs::OTAgent::ClearTemporaryPointers ( )
inline

Definition at line 231 of file OTAgent.hpp.

232  {
233  m_pNym = nullptr;
234  } /* Someday clear entity/role ptr here? And do NOT
bool opentxs::OTAgent::DoesRepresentAnEntity ( ) const

Definition at line 375 of file OTAgent.cpp.

376 {
377  return !m_bNymRepresentsSelf;
378 }
bool opentxs::OTAgent::DoesRepresentHimself ( ) const

Definition at line 365 of file OTAgent.cpp.

366 {
367 
368  return m_bNymRepresentsSelf;
369 }
bool opentxs::OTAgent::DropFinalReceiptToInbox ( mapOfNyms pNymMap,
const OTString strServerID,
OTPseudonym theServerNym,
OTSmartContract theSmartContract,
const OTIdentifier theAccountID,
const int64_t &  lNewTransactionNumber,
const int64_t &  lClosingNumber,
const OTString strOrigCronItem,
OTString pstrNote = nullptr,
OTString pstrAttachment = nullptr 
)

Definition at line 717 of file OTAgent.cpp.

723 {
724  // TODO: When entites and ROLES are added, this function may change a bit to
725  // accommodate them.
726  const char* szFunc = "OTAgent::DropFinalReceiptToInbox";
727 
728  OTIdentifier theAgentNymID;
729  bool bNymID = GetNymID(theAgentNymID);
730 
731  // Not all agents have Nyms. (Might be a voting group.)
732  // But in the case of Inboxes for asset accounts, shouldn't the agent be a
733  // Nym?
734  // Perhaps not... perhaps not... we shall see.
735 
736  if (true == bNymID) // therefore IsAnIndividual() is definitely true.
737  {
738  OTPseudonym* pNym = nullptr;
739  std::unique_ptr<OTPseudonym> theNymAngel;
740 
741  // If a list of pre-loaded Nyms was passed in, see if one of them is
742  // ours.
743  //
744  if (nullptr != pNymMap) {
745  const OTString strNymID(theAgentNymID);
746  OT_ASSERT(strNymID.Exists());
747 
748  auto ittt = pNymMap->find(strNymID.Get());
749 
750  if (pNymMap->end() != ittt) // found it!
751  {
752  pNym = ittt->second;
753  OT_ASSERT(nullptr != pNym);
754  }
755  }
756 
757  if (nullptr ==
758  pNym) // It wasn't on the list of already-loaded nyms that
759  // was passed in, so we have to load it.
760  {
761  // By this point we also know that pNym is NOT the server Nym, nor
762  // is it the
763  // Originator, nor pActingNym, nor pPartyNym, as they were all
764  // loaded already and
765  // were added to pNymMap, yet we didn't find the Nym we were looking
766  // for among them.
767  //
768  // (Therefore this is some new Nym, and doesn't need to be verified
769  // against those Nyms again,
770  // before loading it. Let's load it up!)
771  //
772  if (nullptr == (pNym = LoadNym(theServerNym)))
773  otErr << szFunc << ": Failed loading Nym.\n";
774  else
775  theNymAngel.reset(pNym); // CLEANUP :-)
776  }
777 
778  // I call this because LoadNym sets my internal Nym pointer to pNym, and
779  // then
780  // it goes out of scope before the end of this function and gets
781  // cleaned-up.
782  // Therefore, no point in letting this agent continue to point to bad
783  // memory...
784  //
786 
787  if ((nullptr != pNym) && (lClosingNumber > 0) &&
788  pNym->VerifyIssuedNum(strServerID,
789  lClosingNumber)) // <====================
790  {
791  return theSmartContract.DropFinalReceiptToInbox(
792  theAgentNymID, theAccountID, lNewTransactionNumber,
793  lClosingNumber, strOrigCronItem, pstrNote,
794  pstrAttachment); // pActualAcct=nullptr here. (This call will
795  // load
796  // the acct up and update its inbox hash.)
797  }
798  else
799  otErr << szFunc
800  << ": Error: pNym is nullptr, or lClosingNumber <=0, "
801  "or pNym->VerifyIssuedNum(strServerID, "
802  "lClosingNumber)) failed to verify.\n";
803  }
804  else
805  otErr << szFunc << ": No NymID available for this agent...\n";
806 
807  return false;
808 }
void ClearTemporaryPointers()
Definition: OTAgent.hpp:231
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
OTPseudonym * LoadNym(OTPseudonym &theServerNym)
Definition: OTAgent.cpp:224
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::DropFinalReceiptToNymbox ( OTSmartContract theSmartContract,
const int64_t &  lNewTransactionNumber,
const OTString strOrigCronItem,
OTString pstrNote = nullptr,
OTString pstrAttachment = nullptr,
OTPseudonym pActualNym = nullptr 
)

Definition at line 810 of file OTAgent.cpp.

819 {
820  OTIdentifier theAgentNymID;
821  bool bNymID = GetNymID(theAgentNymID);
822 
823  // Not all agents have Nyms. (Might be a voting group.)
824 
825  if (true == bNymID) {
826  OTPseudonym* pToActualNym = nullptr;
827 
828  if ((nullptr != pActualNym) && pActualNym->CompareID(theAgentNymID))
829  pToActualNym = pActualNym;
830 
831  return theSmartContract.DropFinalReceiptToNymbox(
832  theAgentNymID, lNewTransactionNumber, strOrigCronItem, pstrNote,
833  pstrAttachment, pToActualNym);
834  }
835 
836  // TODO: When entites and roles are added, this function may change a bit to
837  // accommodate them.
838 
839  return false;
840 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
bool opentxs::OTAgent::DropServerNoticeToNymbox ( bool  bSuccessMsg,
OTPseudonym theServerNym,
const OTIdentifier theServerID,
const int64_t &  lNewTransactionNumber,
const int64_t &  lInReferenceTo,
const OTString strReference,
OTString pstrNote = nullptr,
OTString pstrAttachment = nullptr,
OTPseudonym pActualNym = nullptr 
)

Definition at line 842 of file OTAgent.cpp.

849 {
850  OTIdentifier theAgentNymID;
851  bool bNymID = GetNymID(theAgentNymID);
852 
853  // Not all agents have Nyms. (Might be a voting group.)
854 
855  if (true == bNymID) {
856  OTPseudonym* pToActualNym = nullptr;
857 
858  if ((nullptr != pActualNym) && pActualNym->CompareID(theAgentNymID))
859  pToActualNym = pActualNym;
860  else if ((nullptr != m_pNym) && m_pNym->CompareID(theAgentNymID))
861  pToActualNym = m_pNym;
862 
864  bSuccessMsg, theServerNym, theServerID, theAgentNymID,
865  lNewTransactionNumber, lInReferenceTo, strReference, pstrNote,
866  pstrAttachment, pToActualNym);
867  }
868 
869  // TODO: When entites and roles are added, this function may change a bit to
870  // accommodate them.
871 
872  return false;
873 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
EXPORT bool CompareID(const OTIdentifier &theIdentifier) const
static EXPORT bool DropServerNoticeToNymbox(bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const int64_t &lInReferenceTo, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
int32_t opentxs::OTAgent::GetCountAuthorizedAccts ( )

Definition at line 636 of file OTAgent.cpp.

637 {
638  if (nullptr == m_pForParty) {
639  otErr << "OTAgent::CountAuthorizedAccts: Error: m_pForParty was "
640  "nullptr.\n";
641  return 0; // Maybe should log here...
642  }
643 
644  return m_pForParty->GetAccountCount(m_strName.Get());
645 }
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
int32_t GetAccountCount() const
Definition: OTParty.hpp:400
bool opentxs::OTAgent::GetEntityID ( OTIdentifier theOutput) const

Definition at line 601 of file OTAgent.cpp.

602 {
603  // IF represents an entity, then this is its ID. Else fail.
604  //
605  if (DoesRepresentAnEntity() && (nullptr != m_pForParty) &&
606  m_pForParty->IsEntity()) {
607  bool bSuccessEntityID = false;
608  std::string str_entity_id = m_pForParty->GetEntityID(&bSuccessEntityID);
609 
610  if (bSuccessEntityID && (str_entity_id.size() > 0)) {
611  OTString strEntityID(str_entity_id.c_str());
612  theOutput.SetString(strEntityID);
613 
614  return true;
615  }
616  }
617 
618  return false;
619 }
bool DoesRepresentAnEntity() const
Definition: OTAgent.cpp:375
bool IsEntity() const
Definition: OTParty.cpp:532
std::string GetEntityID(bool *pBoolSuccess=nullptr) const
Definition: OTParty.cpp:556
bool opentxs::OTAgent::GetGroupName ( OTString strGroupName)

Definition at line 650 of file OTAgent.cpp.

651 {
652  if (IsAGroup()) {
653  strGroupName.Set(m_strGroupName);
654 
655  return true;
656  }
657 
658  return false;
659 }
bool IsAGroup() const
Definition: OTAgent.cpp:399
EXPORT const OTString& opentxs::OTAgent::GetName ( )
inline

Definition at line 388 of file OTAgent.hpp.

389  {
390  return m_strName;
391  } // agent's name as used in a script.
bool opentxs::OTAgent::GetNymID ( OTIdentifier theOutput) const

Definition at line 473 of file OTAgent.cpp.

474 {
475  if (IsAnIndividual()) {
476  theOutput.SetString(m_strNymID);
477 
478  return true;
479  }
480 
481  return false;
482 }
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTParty* opentxs::OTAgent::GetParty ( ) const
inline

Definition at line 414 of file OTAgent.hpp.

415  {
416  return m_pForParty;
417  }
bool opentxs::OTAgent::GetPartyID ( OTIdentifier theOutput) const

Definition at line 663 of file OTAgent.cpp.

664 {
665  if (DoesRepresentHimself()) return GetNymID(theOutput);
666 
667  return GetEntityID(theOutput);
668 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
bool GetEntityID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:601
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
bool opentxs::OTAgent::GetRoleID ( OTIdentifier theOutput) const

Definition at line 488 of file OTAgent.cpp.

489 {
491  theOutput.SetString(m_strRoleID);
492 
493  return true;
494  }
495 
496  return false;
497 }
bool DoesRepresentAnEntity() const
Definition: OTAgent.cpp:375
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
bool opentxs::OTAgent::GetSignerID ( OTIdentifier theOutput) const

Definition at line 514 of file OTAgent.cpp.

515 {
516  // If IsIndividual() and DoesRepresentAnEntity() then this returns
517  // GetRoleID().
518  // else if Individual() and DoesRepresentHimself() then this returns
519  // GetNymID().
520  // else (if IsGroup()) then return false;
521 
522  if (IsAnIndividual()) {
523  if (DoesRepresentAnEntity()) {
524  return GetRoleID(theOutput);
525  }
526  else // DoesRepresentHimself()
527  {
528  return GetNymID(theOutput);
529  }
530  }
531 
532  // else IsGroup()... unable to sign directly; must hold votes instead.
533  //
534  return false;
535 }
bool DoesRepresentAnEntity() const
Definition: OTAgent.cpp:375
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
bool GetRoleID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:488
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
bool opentxs::OTAgent::HarvestTransactionNumber ( const int64_t &  lNumber,
const OTString strServerID,
bool  bSave = false,
OTPseudonym pSignerNym = nullptr 
)

Definition at line 933 of file OTAgent.cpp.

939 {
940 
941  // Todo: this function may change when entities / roles are added.
942  //
943  if (!IsAnIndividual() || !DoesRepresentHimself()) {
944  otErr << __FUNCTION__
945  << ": Error: Entities and Roles are not yet supported. Agent: "
946  << m_strName << "\n";
947  return false;
948  }
949 
950  if (nullptr != m_pNym) {
951  // If a signer wasn't passed in (the server-side uses server nym to
952  // sign)
953  // then we use the Nym himself as his own signer (common to
954  // client-side.)
955  //
956  if (nullptr == pSignerNym) pSignerNym = m_pNym;
957 
958  const OTIdentifier theServerID(strServerID);
959 
960  // This won't "add it back" unless we're SURE he had it in the first
961  // place...
962  //
963  const bool bSuccess = m_pNym->ClawbackTransactionNumber(
964  theServerID, lNumber, bSave, pSignerNym);
965 
966  if (bSuccess) {
967  // The transaction is being removed from play, so we will remove it
968  // from this list.
969  // That is, when we called RemoveTransactionNumber, the number was
970  // being put into play
971  // until RemoveIssuedNumber is called to close it out. But now
972  // RemoveIssuedNumber won't
973  // ever be called, since we are harvesting it back for future use.
974  // Therefore the number
975  // is currently no longer in play, therefore we remove it from the
976  // list of open cron numbers.
977  //
978  std::set<int64_t>& theIDSet = m_pNym->GetSetOpenCronItems();
979  auto theSetIT = theIDSet.find(lNumber);
980 
981  if (theIDSet.end() != theSetIT) // IF it was there, THEN remove it.
982  // (Client doesn't even track these,
983  // though server does.)
984  theIDSet.erase(lNumber);
985 
986  return true;
987  }
988  else
989  otErr << __FUNCTION__ << ": Number (" << lNumber
990  << ") failed to verify for agent: " << m_strName
991  << " (Thus didn't bother 'adding it back'.)\n";
992  }
993  else
994  otErr << __FUNCTION__
995  << ": Error: m_pNym was nullptr. For agent: " << m_strName
996  << "\n";
997 
998  return false;
999 }
EXPORT bool ClawbackTransactionNumber(const OTIdentifier &theServerID, const int64_t &lTransClawback, bool bSave=false, OTPseudonym *pSIGNER_NYM=nullptr)
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
std::set< int64_t > & GetSetOpenCronItems()
bool opentxs::OTAgent::IsAGroup ( ) const

Definition at line 399 of file OTAgent.cpp.

400 {
401  return !m_bIsAnIndividual;
402 }
bool opentxs::OTAgent::IsAnIndividual ( ) const

Definition at line 390 of file OTAgent.cpp.

391 {
392  return m_bIsAnIndividual;
393 }
bool opentxs::OTAgent::IsAuthorizingAgentForParty ( )

Definition at line 623 of file OTAgent.cpp.

624 {
625  if (nullptr == m_pForParty) return false;
626 
627  if (m_strName.Compare(m_pForParty->GetAuthorizingAgentName().c_str()))
628  return true;
629 
630  return false;
631 }
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
const std::string & GetAuthorizingAgentName() const
Definition: OTParty.hpp:353
bool opentxs::OTAgent::IsValidSigner ( OTPseudonym theNym)

Definition at line 553 of file OTAgent.cpp.

554 {
555  OTIdentifier theAgentNymID;
556  bool bNymID = GetNymID(theAgentNymID);
557 
558  // If there's a NymID on this agent, and it matches theNym's ID...
559  //
560  if (bNymID && theNym.CompareID(theAgentNymID)) {
561  // That means theNym *is* the Nym for this agent!
562  // We'll save his pointer, for future reference...
563  //
564  SetNymPointer(theNym);
565 
566  return true;
567  }
568 
569  // TODO Entity: Perhaps the original Nym was fired from his role... another
570  // Nym has now
571  // taken his place. In which case, the original Nym should be refused as a
572  // valid
573  // signer, and the new Nym should be allowed to sign in his place!
574  //
575  // This means if DoesRepresentAnEntity(), then I have to load the Role, and
576  // verify
577  // the Nym against that Role (which contains the updated status). Since I
578  // haven't
579  // coded Entities/Roles yet, then I don't have to do this just yet...
580  // Might even update the NymID on this agent, for updated copies of the
581  // agreement.
582  // (Obviously the original can't be changed...)
583  //
584 
585  return false;
586 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
void SetNymPointer(OTPseudonym &theNym)
Definition: OTAgent.hpp:277
bool opentxs::OTAgent::IsValidSignerID ( const OTIdentifier theNymID)

Definition at line 537 of file OTAgent.cpp.

538 {
539  OTIdentifier theAgentNymID;
540  bool bNymID = GetNymID(theAgentNymID);
541 
542  // If there's a NymID on this agent, and it matches theNymID...
543  //
544  if (bNymID && (theNymID == theAgentNymID)) return true;
545 
546  // TODO Entities...
547  //
548  return false;
549 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
OTPseudonym * opentxs::OTAgent::LoadNym ( OTPseudonym theServerNym)

Definition at line 224 of file OTAgent.cpp.

225 {
226  OTIdentifier theAgentNymID;
227  bool bNymID = GetNymID(theAgentNymID);
228 
229  if (bNymID) {
230  OTPseudonym* pNym = new OTPseudonym;
231  OT_ASSERT(nullptr != pNym);
232 
233  pNym->SetIdentifier(theAgentNymID);
234 
235  if (!pNym->LoadPublicKey()) {
236  OTString strNymID(theAgentNymID);
237  otErr << "OTAgent::LoadNym: Failure loading "
238  "agent's public key:\n" << strNymID << "\n";
239  delete pNym;
240  pNym = nullptr;
241  }
242  else if (pNym->VerifyPseudonym() &&
243  pNym->LoadSignedNymfile(theServerNym)) {
245  *pNym); // set this pointer in case I need it for later.
246  // also remember, caller is responsible to delete, so there's no
247  // guarantee the pointer
248  return pNym; // is any good. Then again, caller is also responsible
249  // to call ClearTemporaryPointers().
250  }
251  else {
252  OTString strNymID(theAgentNymID);
253  otErr << "OTAgent::LoadNym: Failure verifying agent's public key "
254  "or loading signed nymfile: " << strNymID << "\n";
255  delete pNym;
256  pNym = nullptr;
257  }
258  }
259  else
260  otErr << "OTAgent::LoadNym: Failure. Are you sure this agent IS a Nym "
261  "at all? \n";
262 
263  return nullptr;
264 }
EXPORT bool GetNymID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:473
void SetNymPointer(OTPseudonym &theNym)
Definition: OTAgent.hpp:277
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::RemoveIssuedNumber ( const int64_t &  lNumber,
const OTString strServerID,
bool  bSave = false,
OTPseudonym pSignerNym = nullptr 
)

Definition at line 1051 of file OTAgent.cpp.

1054 {
1055  // Todo: this function may change when entities / roles are added.
1056  if (!IsAnIndividual() || !DoesRepresentHimself()) {
1057  otErr << "OTAgent::" << __FUNCTION__
1058  << ": Error: Entities and Roles are not yet supported. Agent: "
1059  << m_strName << "\n";
1060  return false;
1061  }
1062 
1063  if (nullptr != m_pNym) {
1064  std::set<int64_t>& theIDSet =
1065  m_pNym->GetSetOpenCronItems(); // The transaction is being removed
1066  // from play, so we will remove it
1067  // from this list.
1068  const bool bSuccess =
1069  m_pNym->RemoveIssuedNum(strServerID, lNumber); // Doesn't save.
1070 
1071  if (bSuccess) {
1072  if (nullptr == pSignerNym) pSignerNym = m_pNym;
1073 
1074  // Since the Trans# is now out of play, the server removes it as an
1075  // open cron item.
1076  //
1077  auto theSetIT = theIDSet.find(lNumber);
1078 
1079  if (theIDSet.end() != theSetIT) // IF it was there, THEN remove it.
1080  // (Client doesn't even track these,
1081  // though server does.)
1082  theIDSet.erase(lNumber);
1083 
1084  if (bSave) m_pNym->SaveSignedNymfile(*pSignerNym);
1085  }
1086  else
1087  otErr << "OTAgent::" << __FUNCTION__
1088  << ": Error, should never happen. (I'd assume you aren't "
1089  "removing issued numbers without verifying first if "
1090  "they're there.)\n";
1091  return bSuccess;
1092  }
1093  else
1094  otErr << "OTAgent::" << __FUNCTION__
1095  << ": Error: m_pNym was nullptr. For agent: " << m_strName
1096  << "\n";
1097 
1098  return false;
1099 }
EXPORT bool RemoveIssuedNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, const int64_t &lTransNum, bool bSave)
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
std::set< int64_t > & GetSetOpenCronItems()
EXPORT bool SaveSignedNymfile(OTPseudonym &SIGNER_NYM)
bool opentxs::OTAgent::RemoveTransactionNumber ( const int64_t &  lNumber,
const OTString strServerID,
OTPseudonym SIGNER_NYM,
bool  bSave = true 
)

Definition at line 1006 of file OTAgent.cpp.

1009 {
1010  // Todo: this function may change when entities / roles are added.
1011  if (!IsAnIndividual() || !DoesRepresentHimself()) {
1012  otErr << "OTAgent::" << __FUNCTION__
1013  << ": Error: Entities and Roles are not yet supported. Agent: "
1014  << m_strName << "\n";
1015  return false;
1016  }
1017 
1018  if (nullptr != m_pNym) {
1019  std::set<int64_t>& theIDSet =
1020  m_pNym->GetSetOpenCronItems(); // The transaction is now in play, so
1021  // we are going to add it to this
1022  // list.
1023  const bool bSuccess =
1024  m_pNym->RemoveTransactionNum(strServerID, lNumber); // Doesn't save.
1025 
1026  if (bSuccess) {
1027  theIDSet.insert(lNumber); // Since the Trans# is now in play, the
1028  // server records it as an open cron item.
1029 
1030  if (bSave) m_pNym->SaveSignedNymfile(SIGNER_NYM);
1031  }
1032  else
1033  otErr << "OTAgent::" << __FUNCTION__
1034  << ": Error, should never happen. (I'd assume you aren't "
1035  "removing numbers without verifying first if they're "
1036  "there.)\n";
1037  return bSuccess;
1038  }
1039  else
1040  otErr << "OTAgent::" << __FUNCTION__
1041  << ": Error: m_pNym was nullptr. For agent: " << m_strName
1042  << "\n";
1043 
1044  return false;
1045 }
EXPORT bool RemoveTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, const int64_t &lTransNum)
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
std::set< int64_t > & GetSetOpenCronItems()
EXPORT bool SaveSignedNymfile(OTPseudonym &SIGNER_NYM)
bool opentxs::OTAgent::ReserveClosingTransNum ( const OTString strServerID,
OTPartyAccount thePartyAcct 
)

Definition at line 1102 of file OTAgent.cpp.

1104 {
1105  if (IsAnIndividual() && DoesRepresentHimself() && (nullptr != m_pNym)) {
1106  int64_t lTransactionNumber = 0;
1107  if (thePartyAcct.GetClosingTransNo() > 0) {
1108  otOut << "OTAgent::ReserveClosingTransNum: Failure: The account "
1109  "ALREADY has a closing transaction number "
1110  "set on it. Don't you want to save that first, before "
1111  "overwriting it?\n";
1112  return false;
1113  }
1114 
1115  if (m_pNym->GetTransactionNumCount(strServerID) <
1116  1) // Need a closing number...
1117  {
1118  otOut << "OTAgent::ReserveClosingTransNum: *** Failure *** Nym "
1119  "needs at least 1 transaction number available in order "
1120  "to do this.\n";
1121  return false;
1122  }
1123  else if (false ==
1124  m_pNym->GetNextTransactionNum(*m_pNym, strServerID,
1125  lTransactionNumber)) {
1126  otErr << "OTAgent::ReserveClosingTransNum: Error: Strangely, "
1127  "unable to get a transaction number, even though "
1128  "supposedly one was there.\n";
1129  return false;
1130  }
1131 
1132  // BELOW THIS POINT, TRANSACTION # HAS BEEN RESERVED, AND MUST BE
1133  // SAVED...
1134  // Any errors below this point will require this call before returning:
1135  // HarvestAllTransactionNumbers(strServerID);
1136  //
1137  thePartyAcct.SetClosingTransNo(lTransactionNumber);
1138  thePartyAcct.SetAgentName(m_strName);
1139 
1140  return true;
1141  }
1142  else // todo: when entities and roles are added... this function will
1143  // change.
1144  {
1145  otErr << "OTAgent::ReserveClosingTransNum: Either the Nym pointer "
1146  "isn't set properly, "
1147  "or you tried to use Entities when they haven't been coded "
1148  "yet. Agent: " << m_strName << " \n";
1149  }
1150 
1151  return false;
1152 }
EXPORT bool GetNextTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, int64_t &lTransNum, bool bSave=true)
OTLOG_IMPORT OTLogStream otOut
EXPORT int32_t GetTransactionNumCount(const OTIdentifier &theServerID) const
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::ReserveOpeningTransNum ( const OTString strServerID)

Definition at line 1155 of file OTAgent.cpp.

1156 {
1157  if (IsAnIndividual() && DoesRepresentHimself() && (nullptr != m_pNym)) {
1158  int64_t lTransactionNumber = 0;
1159  if (nullptr == m_pForParty) {
1160  otErr << "OTAgent::ReserveOpeningTransNum: Error: Party pointer "
1161  "was nullptr. SHOULD NEVER HAPPEN!!\n";
1162  return false;
1163  }
1164  if (m_pForParty->GetOpeningTransNo() > 0) {
1165  otOut << "OTAgent::ReserveOpeningTransNum: Failure: Party ALREADY "
1166  "had an opening transaction number "
1167  "set on it. Don't you want to save that first, before "
1168  "overwriting it?\n";
1169  return false;
1170  }
1171 
1172  if (m_pNym->GetTransactionNumCount(strServerID) <
1173  1) // Need opening number...
1174  {
1175  otOut << "OTAgent::ReserveOpeningTransNum: *** Failure *** Nym "
1176  "needs at least 1 transaction number available in order "
1177  "to do this.\n";
1178  return false;
1179  }
1180  else if (false ==
1181  m_pNym->GetNextTransactionNum(*m_pNym, strServerID,
1182  lTransactionNumber)) {
1183  otErr << "OTAgent::ReserveOpeningTransNum: Error: Strangely, "
1184  "unable to get a transaction number, even though "
1185  "supposedly one was there.\n";
1186  return false;
1187  }
1188 
1189  // BELOW THIS POINT, TRANSACTION # HAS BEEN RESERVED, AND MUST BE
1190  // SAVED...
1191  // Any errors below this point will require this call before returning:
1192  // HarvestAllTransactionNumbers(strServerID);
1193  //
1194  m_pForParty->SetOpeningTransNo(lTransactionNumber);
1195  m_pForParty->SetAuthorizingAgentName(m_strName.Get());
1196 
1197  return true;
1198  }
1199  else // todo: when entities and roles are added... this function will
1200  // change.
1201  {
1202  otErr << "OTAgent::ReserveOpeningTransNum: Either the Nym pointer "
1203  "isn't set properly, "
1204  "or you tried to use Entities when they haven't been coded "
1205  "yet. Agent: " << m_strName << " \n";
1206  }
1207 
1208  return false;
1209 }
EXPORT bool GetNextTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, int64_t &lTransNum, bool bSave=true)
void SetAuthorizingAgentName(std::string str_agent_name)
Definition: OTParty.hpp:357
OTLOG_IMPORT OTLogStream otOut
EXPORT int32_t GetTransactionNumCount(const OTIdentifier &theServerID) const
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT const char * Get() const
Definition: OTString.cpp:1045
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
int64_t GetOpeningTransNo() const
Definition: OTParty.hpp:295
void SetOpeningTransNo(const int64_t &theNumber)
Definition: OTParty.hpp:299
void opentxs::OTAgent::RetrieveNymPointer ( mapOfNyms map_Nyms_Already_Loaded)

Definition at line 670 of file OTAgent.cpp.

671 {
672  const std::string str_agent_name(m_strName.Get());
673 
674  // We actually have a Nym pointer on this agent somehow (so let's add it to
675  // the list.)
676  //
677  if (nullptr != m_pNym) {
678  if (!m_strName.Exists()) // Whoaa!! Can't add it without the agent's
679  // name for the map!
680  {
681  otErr << "OTAgent::RetrieveNymPointers: Failed: m_strName is "
682  "empty!\n";
683  }
684  else if (map_Nyms_Already_Loaded.end() ==
685  map_Nyms_Already_Loaded.insert(
686  map_Nyms_Already_Loaded.begin(),
687  std::pair<std::string, OTPseudonym*>(str_agent_name,
688  m_pNym)))
689  otErr << "OTAgent::RetrieveNymPointer: Failed on insertion, as "
690  "though another nym were already "
691  "there with the same agent name! (" << m_strName << ")\n";
692  // (else it was inserted successfully.)
693  }
694  // else nothing, since it's normal that most of them are nullptr, even when
695  // one
696  // is goood.
697 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTAgent::Serialize ( OTString strAppend) const

Definition at line 1211 of file OTAgent.cpp.

1212 {
1213  // strAppend.Concatenate("<agent>\n\n");
1214 
1215  strAppend.Concatenate(
1216  "<agent\n name=\"%s\"\n"
1217  " doesAgentRepresentHimself=\"%s\"\n"
1218  " isAgentAnIndividual=\"%s\"\n"
1219  " nymID=\"%s\"\n"
1220  " roleID=\"%s\"\n"
1221  " groupName=\"%s\" />\n\n",
1222  m_strName.Get(), m_bNymRepresentsSelf ? "true" : "false",
1223  m_bIsAnIndividual ? "true" : "false", m_strNymID.Get(),
1224  m_strRoleID.Get(), m_strGroupName.Get());
1225 
1226  // strAppend.Concatenate("</agent>\n");
1227 }
EXPORT const char * Get() const
Definition: OTString.cpp:1045
void opentxs::OTAgent::SetNymPointer ( OTPseudonym theNym)
inline

Definition at line 277 of file OTAgent.hpp.

278  {
279  m_pNym = &theNym;
280  }
void opentxs::OTAgent::SetParty ( OTParty theOwnerParty)

Definition at line 314 of file OTAgent.cpp.

316 {
317  m_pForParty = &theOwnerParty;
318 
319  // A Nym can only act as agent for himself or for an entity
320  // (never for another Nym. Start an entity if you want that.)
321  // If the owner party is a Nym, therefore this agent IS the Nym acting for
322  // himself.
323  // Whereas if the owner party were an entity, then this agent could be a Nym
324  // or a voting group.
325  // Since inside this block the owner party IS a Nym, not an entity, then the
326  // agent can therefore
327  // only be THAT Nym, acting as an agent for himself. Remember, a Nym cannot
328  // act as agent for
329  // another Nym. That is only possible by an agreement between them, and that
330  // agreement becomes
331  // the entity (therefore it's only possible using an entity.)
332  //
333  if (theOwnerParty.IsNym()) // Thus, this basically means the agent IS the
334  // party.
335  {
336  m_bNymRepresentsSelf = true;
337  m_bIsAnIndividual = true;
338 
339  bool bGetOwnerNymID = false;
340  const std::string str_owner_nym_id =
341  theOwnerParty.GetNymID(&bGetOwnerNymID);
342  m_strNymID.Set(bGetOwnerNymID ? str_owner_nym_id.c_str() : "");
343 
344  // Todo here, instead of copying the Owner's Nym ID like above, just
345  // make sure they match.
346  // Similarly, make sure that the RoleID or GroupName, whichever is
347  // relevant, is validated for the owner.
348  }
349 }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
bool opentxs::OTAgent::SignContract ( OTContract theInput) const

Definition at line 875 of file OTAgent.cpp.

876 {
877  if (!IsAnIndividual() || !DoesRepresentHimself()) {
878  otErr << "OTAgent::SignContract: Entities and roles are not yet "
879  "supported. Agent: " << m_strName << ".\n";
880  return false;
881  } // todo: when adding entities, this will change.
882 
883  if (nullptr == m_pNym) {
884  otErr << "OTAgent::SignContract: Nym was nullptr while trying to sign "
885  "contract. Agent: " << m_strName << ".\n";
886  return false;
887  } // todo: when adding entities, this will change.
888 
889  return theInput.SignContract(*m_pNym);
890 }
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::VerifyAgencyOfAccount ( const OTAccount theAccount) const

Definition at line 699 of file OTAgent.cpp.

700 {
701  OTIdentifier theSignerID;
702 
703  if (!GetSignerID(theSignerID)) {
704  otErr << "OTAgent::VerifyAgencyOfAccount: ERROR: Entities and roles "
705  "haven't been coded yet.\n";
706  return false;
707  }
708 
709  return theAccount.VerifyOwnerByID(theSignerID); // todo when entities and
710  // roles come, won't this
711  // "just work", or do I also
712  // have to warn the acct
713  // whether it's a Nym or a
714  // Role being passed?
715 }
bool GetSignerID(OTIdentifier &theOutput) const
Definition: OTAgent.cpp:514
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::VerifyIssuedNumber ( const int64_t &  lNumber,
const OTString strServerID 
)

Definition at line 892 of file OTAgent.cpp.

894 {
895  // Todo: this function may change when entities / roles are added.
896  if (!IsAnIndividual() || !DoesRepresentHimself()) {
897  otErr << "OTAgent::VerifyIssuedNumber: Error: Entities and Roles are "
898  "not yet supported. Agent: " << m_strName << "\n";
899  return false;
900  }
901 
902  if (nullptr != m_pNym)
903  return m_pNym->VerifyIssuedNum(strServerID, lNumber);
904  else
905  otErr << "OTAgent::VerifyIssuedNumber: Error: m_pNym was nullptr. For "
906  "agent: " << m_strName << "\n";
907 
908  return false;
909 }
EXPORT bool VerifyIssuedNum(const OTString &strServerID, const int64_t &lTransNum) const
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::VerifySignature ( const OTContract theContract) const

Definition at line 159 of file OTAgent.cpp.

160 {
161  // Only individual agents can sign for things, not groups (groups vote, they
162  // don't sign.)
163  // Thus, an individual can verify a signature, whereas a voting group would
164  // verify an election result (or whatever.)
165  //
166  if (!IsAnIndividual() || !DoesRepresentHimself()) {
167  otErr << "OTAgent::VerifySignature: Entities and roles are not yet "
168  "supported. Agent: " << m_strName << ".\n";
169  return false;
170  } // todo: when adding entities, this will change.
171 
172  // if (DoesRepresentAnEntity)
173  // {
174  // // The original version of a smartcontract might show that Frank,
175  // the Sales Director, signed it.
176  // // Years later, Frank is fired, and Jim is appointed to his former
177  // Role of sales director, in the same entity.
178  // // The original copy of the smart contract still contains Frank's
179  // signature, and thus we still need to load Frank
180  // // in order to verify that original signature. That's why we load
181  // Frank by the NymID stored there. He was the Nym
182  // // at the time, so that's the key we load.
183  // //
184  // // NEXT: What if JIM tries to verify the signature on the
185  // contract, even though FRANK was the original signer?
186  // // Should OTAgent be smart enough here to substitute Frank
187  // whenever Jim tries to verify? I argue no: this function is
188  // // too low-level. Plus it's backwards. If Jim tries to DO an
189  // action, THEN OT should be smart enough to verify that Jim
190  // // is in the proper Role and that Jim's signature is good enough
191  // to authorize actions. But if OT is verifying Frank's
192  // // signature on some old copy of something that Frank formerly
193  // signed, then this function should clearly tell me if Frank's
194  // // sig verified... or not.
195  // //
196  // // Therefore the "DoesRepresentAnEntity()" option is useless here,
197  // since we are verifying the same Nym's signature whether
198  // // he represents an entity or not.
199  // //
200  // }
201  // else
202  if (nullptr == m_pNym) {
203  OTString strTemp(theContract);
204  otErr << "OTAgent::VerifySignature: Attempted to verify signature on "
205  "contract, "
206  "but no Nym had ever been loaded for this agent:\n\n"
207  << strTemp << "\n\n";
208  return false;
209  }
210 
211  return theContract.VerifySignature(*m_pNym);
212 }
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAgent::VerifyTransactionNumber ( const int64_t &  lNumber,
const OTString strServerID 
)

Definition at line 911 of file OTAgent.cpp.

913 {
914  // Todo: this function may change when entities / roles are added.
915  if (!IsAnIndividual() || !DoesRepresentHimself()) {
916  otErr << "OTAgent::VerifyTransactionNumber: Error: Entities and Roles "
917  "are not yet supported. Agent: " << m_strName << "\n";
918  return false;
919  }
920 
921  if (nullptr != m_pNym)
922  return m_pNym->VerifyTransactionNum(strServerID, lNumber);
923  else
924  otErr << "OTAgent::VerifyTransactionNumber: Error: m_pNym was nullptr. "
925  "For agent: " << m_strName << "\n";
926 
927  return false;
928 }
bool DoesRepresentHimself() const
Definition: OTAgent.cpp:365
EXPORT bool IsAnIndividual() const
Definition: OTAgent.cpp:390
OTLOG_IMPORT OTLogStream otErr
EXPORT bool VerifyTransactionNum(const OTString &strServerID, const int64_t &lTransNum) const

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