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

#include <OTPartyAccount.hpp>

Public Member Functions

EXPORT void RegisterForExecution (OTScript &theScript)
 
OTPartyGetParty () const
 
void SetParty (OTParty &theOwnerParty)
 
EXPORT const OTStringGetName () const
 
const OTStringGetAgentName () const
 
const OTStringGetAcctID () const
 
const OTStringGetAssetTypeID () const
 
void SetAgentName (const OTString &strAgentName)
 
void SetAcctID (const OTString &strAccountID)
 
EXPORT OTAgentGetAuthorizedAgent ()
 
OTAccountLoadAccount (OTPseudonym &theSignerNym, const OTString &strServerID)
 
bool IsAccount (OTAccount &theAccount)
 
bool IsAccountByID (const OTIdentifier &theAcctID) const
 
bool VerifyOwnership () const
 
bool VerifyAgency ()
 
int64_t GetClosingTransNo () const
 
void SetClosingTransNo (int64_t lTransNo)
 
bool Compare (const OTPartyAccount &rhs) const
 
bool DropFinalReceiptToInbox (mapOfNyms *pNymMap, const OTString &strServerID, OTPseudonym &theServerNym, OTSmartContract &theSmartContract, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr)
 
 OTPartyAccount ()
 
 OTPartyAccount (std::string str_account_name, const OTString &strAgentName, OTAccount &theAccount, int64_t lClosingTransNo)
 
 OTPartyAccount (const OTString &strName, const OTString &strAgentName, const OTString &strAcctID, const OTString &strAssetTypeID, int64_t lClosingTransNo)
 
virtual ~OTPartyAccount ()
 
void Serialize (OTString &strAppend, bool bCalculatingID=false, bool bSpecifyAssetID=false) const
 
void ClearTemporaryPointers ()
 

Detailed Description

Definition at line 185 of file OTPartyAccount.hpp.

Constructor & Destructor Documentation

opentxs::OTPartyAccount::OTPartyAccount ( )

Definition at line 153 of file OTPartyAccount.cpp.

154  : m_pForParty(nullptr)
155  , m_pAccount(nullptr)
156  , m_lClosingTransNo(0)
157 {
158 }
opentxs::OTPartyAccount::OTPartyAccount ( std::string  str_account_name,
const OTString strAgentName,
OTAccount theAccount,
int64_t  lClosingTransNo 
)

Definition at line 164 of file OTPartyAccount.cpp.

167  : m_pForParty(nullptr)
168  , // This gets set when this partyaccount is added to its party.
169  m_pAccount(&theAccount)
170  , m_lClosingTransNo(lClosingTransNo)
171  , m_strName(str_account_name.c_str())
172  , m_strAcctID(theAccount.GetRealAccountID())
173  , m_strAssetTypeID(theAccount.GetAssetTypeID())
174  , m_strAgentName(strAgentName)
175 {
176 }
opentxs::OTPartyAccount::OTPartyAccount ( const OTString strName,
const OTString strAgentName,
const OTString strAcctID,
const OTString strAssetTypeID,
int64_t  lClosingTransNo 
)

Definition at line 178 of file OTPartyAccount.cpp.

183  : m_pForParty(nullptr)
184  , // This gets set when this partyaccount is added to its party.
185  m_pAccount(nullptr)
186  , m_lClosingTransNo(lClosingTransNo)
187  , m_strName(strName)
188  , m_strAcctID(strAcctID)
189  , m_strAssetTypeID(strAssetTypeID)
190  , m_strAgentName(strAgentName)
191 {
192 }
opentxs::OTPartyAccount::~OTPartyAccount ( )
virtual

Definition at line 222 of file OTPartyAccount.cpp.

223 {
224  // m_pForParty and m_pAccount NOT cleaned up here. pointer is only for
225  // convenience.
226  m_pForParty = nullptr;
227  m_pAccount = nullptr;
228 }

Member Function Documentation

void opentxs::OTPartyAccount::ClearTemporaryPointers ( )
inline

Definition at line 297 of file OTPartyAccount.hpp.

298  {
299  m_pAccount = nullptr;
300  }
bool opentxs::OTPartyAccount::Compare ( const OTPartyAccount rhs) const

Definition at line 464 of file OTPartyAccount.cpp.

465 {
466  if (!(GetName().Compare(rhs.GetName()))) {
467  otOut << "OTPartyAccount::Compare: Names don't match: " << GetName()
468  << " / " << rhs.GetName() << " \n";
469  return false;
470  }
471 
472  if ((GetClosingTransNo() > 0) && (rhs.GetClosingTransNo() > 0) &&
473  (GetClosingTransNo() != rhs.GetClosingTransNo())) {
474  otOut << "OTPartyAccount::Compare: Closing transaction numbers don't "
475  "match: " << GetName() << " \n";
476  return false;
477  }
478 
479  if ((GetAcctID().Exists()) && (rhs.GetAcctID().Exists()) &&
480  (!GetAcctID().Compare(rhs.GetAcctID()))) {
481  otOut << "OTPartyAccount::Compare: Asset account numbers don't match "
482  "for party account " << GetName() << ".\n( " << GetAcctID()
483  << " / " << rhs.GetAcctID() << " ) \n";
484  return false;
485  }
486 
487  if ((GetAgentName().Exists()) && (rhs.GetAgentName().Exists()) &&
488  (!GetAgentName().Compare(rhs.GetAgentName()))) {
489  otOut << "OTPartyAccount::Compare: Agent names don't match for party "
490  "account " << GetName() << ".\n( " << GetAgentName() << " / "
491  << rhs.GetAgentName() << " ) \n";
492  return false;
493  }
494 
495  if (!(GetAssetTypeID().Exists()) || !(rhs.GetAssetTypeID().Exists()) ||
496  !(GetAssetTypeID().Compare(rhs.GetAssetTypeID()))) {
497  otOut << "OTPartyAccount::Compare: Asset Type IDs don't exist, or "
498  "don't match ( " << GetAssetTypeID() << " / "
499  << rhs.GetAssetTypeID() << " ) for party's account: " << GetName()
500  << " \n";
501  return false;
502  }
503 
504  return true;
505 }
EXPORT const OTString & GetName() const
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
bool Compare(const OTPartyAccount &rhs) const
const OTString & GetAgentName() const
const OTString & GetAcctID() const
const OTString & GetAssetTypeID() const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
int64_t GetClosingTransNo() const
bool opentxs::OTPartyAccount::DropFinalReceiptToInbox ( mapOfNyms pNymMap,
const OTString strServerID,
OTPseudonym theServerNym,
OTSmartContract theSmartContract,
const int64_t &  lNewTransactionNumber,
const OTString strOrigCronItem,
OTString pstrNote = nullptr,
OTString pstrAttachment = nullptr 
)

Definition at line 345 of file OTPartyAccount.cpp.

350 {
351  const char* szFunc = "OTPartyAccount::DropFinalReceiptToInbox";
352 
353  if (nullptr == m_pForParty) {
354  otErr << szFunc << ": nullptr m_pForParty.\n";
355  return false;
356  }
357  else if (!m_strAcctID.Exists()) {
358  otErr << szFunc << ": Empty Acct ID.\n";
359  return false;
360  }
361  else if (!m_strAgentName.Exists()) {
362  otErr << szFunc << ": No agent named for this account.\n";
363  return false;
364  }
365 
366  // TODO: When entites and roles are added, this function may change a bit to
367  // accommodate them.
368 
369  const std::string str_agent_name(m_strAgentName.Get());
370 
371  OTAgent* pAgent = m_pForParty->GetAgent(str_agent_name);
372 
373  if (nullptr == pAgent)
374  otErr << szFunc << ": named agent wasn't found on party.\n";
375  else {
376  const OTIdentifier theAccountID(m_strAcctID);
377 
378  return pAgent->DropFinalReceiptToInbox(
379  pNymMap, strServerID, theServerNym, theSmartContract,
380  theAccountID, // acct ID from this.
381  lNewTransactionNumber, m_lClosingTransNo, // closing_no from this.
382  strOrigCronItem, pstrNote, pstrAttachment);
383  }
384 
385  return false;
386 }
EXPORT OTAgent * GetAgent(const std::string &str_agent_name) const
Definition: OTParty.cpp:609
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
const OTString& opentxs::OTPartyAccount::GetAcctID ( ) const
inline

Definition at line 239 of file OTPartyAccount.hpp.

240  {
241  return m_strAcctID;
242  } // account's ID as used internal to OT.
const OTString& opentxs::OTPartyAccount::GetAgentName ( ) const
inline

Definition at line 235 of file OTPartyAccount.hpp.

236  {
237  return m_strAgentName;
238  } // agent's name as used in a script.
const OTString& opentxs::OTPartyAccount::GetAssetTypeID ( ) const
inline

Definition at line 243 of file OTPartyAccount.hpp.

244  {
245  return m_strAssetTypeID;
246  } // asset type ID for the account.
OTAgent * opentxs::OTPartyAccount::GetAuthorizedAgent ( )

Definition at line 198 of file OTPartyAccount.cpp.

199 {
200  OT_ASSERT(nullptr != m_pForParty);
201 
202  if (!m_strAgentName.Exists()) {
203  otErr << "OTPartyAccount::GetAuthorizedAgent: Error: Authorized agent "
204  "name (for this account) is blank!\n";
205  return nullptr;
206  }
207 
208  const std::string str_agent_name = m_strAgentName.Get();
209 
210  OTAgent* pAgent = m_pForParty->GetAgent(str_agent_name);
211 
212  return pAgent;
213 }
EXPORT OTAgent * GetAgent(const std::string &str_agent_name) const
Definition: OTParty.cpp:609
EXPORT bool Exists() const
Definition: OTString.cpp:1035
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
int64_t opentxs::OTPartyAccount::GetClosingTransNo ( ) const
inline

Definition at line 267 of file OTPartyAccount.hpp.

268  {
269  return m_lClosingTransNo;
270  }
EXPORT const OTString& opentxs::OTPartyAccount::GetName ( ) const
inline

Definition at line 231 of file OTPartyAccount.hpp.

232  {
233  return m_strName;
234  } // account's name as used in a script.
OTParty* opentxs::OTPartyAccount::GetParty ( ) const
inline

Definition at line 223 of file OTPartyAccount.hpp.

224  {
225  return m_pForParty;
226  }
bool opentxs::OTPartyAccount::IsAccount ( OTAccount theAccount)

Definition at line 255 of file OTPartyAccount.cpp.

256 {
257  if (!m_strAcctID.Exists()) {
258  otErr << "OTPartyAccount::IsAccount: Error: Empty m_strAcctID.\n";
259  return false;
260  }
261 
262  if (!m_strAssetTypeID.Exists()) {
263  otErr << "OTPartyAccount::IsAccount: Error: Empty m_strAssetTypeID.\n";
264  return false;
265  }
266 
267  const OTIdentifier theAcctID(m_strAcctID);
268  if (!(theAccount.GetRealAccountID() == theAcctID)) {
269  OTString strRHS(theAccount.GetRealAccountID());
270  otLog4 << "OTPartyAccount::IsAccount: Account IDs don't match: "
271  << m_strAcctID << " / " << strRHS
272  << " \n"; // I set output to 4 because it's normal to call
273  // IsAccount() even when they don't match.
274  return false;
275  }
276 
277  const OTIdentifier theAssetTypeID(m_strAssetTypeID);
278  if (!(theAccount.GetAssetTypeID() == theAssetTypeID)) {
279  OTString strRHS(theAccount.GetAssetTypeID());
280  otOut << "OTPartyAccount::IsAccount: Asset Type IDs don't match ( "
281  << m_strAssetTypeID << " / " << strRHS
282  << " ) for Acct ID: " << m_strAcctID << " \n";
283  return false;
284  }
285 
286  m_pAccount = &theAccount;
287  return true;
288 }
OTLOG_IMPORT OTLogStream otLog4
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Exists() const
Definition: OTString.cpp:1035
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTPartyAccount::IsAccountByID ( const OTIdentifier theAcctID) const

Definition at line 230 of file OTPartyAccount.cpp.

231 {
232  if (!m_strAcctID.Exists()) {
233  return false;
234  }
235 
236  if (!m_strAssetTypeID.Exists()) {
237  return false;
238  }
239 
240  const OTIdentifier theMemberAcctID(m_strAcctID);
241  if (!(theAcctID == theMemberAcctID)) {
242  OTString strRHS(theAcctID);
243  otLog4 << "OTPartyAccount::IsAccountByID: Account IDs don't match: "
244  << m_strAcctID << " / " << strRHS << " \n";
245  // I set output to 4 because it's normal to call IsAccountByID() even
246  // when they don't match.
247  return false;
248  }
249 
250  // They match!
251 
252  return true;
253 }
OTLOG_IMPORT OTLogStream otLog4
EXPORT bool Exists() const
Definition: OTString.cpp:1035
OTAccount * opentxs::OTPartyAccount::LoadAccount ( OTPseudonym theSignerNym,
const OTString strServerID 
)

Definition at line 394 of file OTPartyAccount.cpp.

396 {
397  if (!m_strAcctID.Exists()) {
398  otOut << "OTPartyAccount::LoadAccount: Bad: Acct ID is blank for "
399  "account: " << m_strName << " \n";
400  return nullptr;
401  }
402 
403  const OTIdentifier theAcctID(m_strAcctID), theServerID(strServerID);
404 
405  OTAccount* pAccount =
406  OTAccount::LoadExistingAccount(theAcctID, theServerID);
407 
408  if (nullptr == pAccount) {
409  otOut << "OTPartyAccount::LoadAccount: Failed trying to load account: "
410  << m_strName << ", with AcctID: " << m_strAcctID << " \n";
411  return nullptr;
412  }
413  // BELOW THIS POINT, You must delete pAccount if you don't return it!!
414  //
415  else if (!pAccount->VerifyAccount(theSignerNym)) {
416  otOut
417  << "OTPartyAccount::LoadAccount: Failed trying to verify account: "
418  << m_strName << ", with AcctID: " << m_strAcctID << " \n";
419  delete pAccount;
420  return nullptr;
421  }
422 
423  // This compares asset type ID, AND account ID on the actual loaded account,
424  // to what is expected.
425  else if (!IsAccount(*pAccount)) // It also sets the internal pointer
426  // m_pAccount... FYI.
427  {
428  // IsAccount has plenty of logging already.
429  delete pAccount;
430  return nullptr;
431  }
432  // BELOW THIS POINT, pAccount is loaded and validated, in-and-of-itself, and
433  // against the PartyAcct.
434  // (But not against the party ownership and agent rights.)
435  // It must be deleted or will leak.
436 
437  // (No need to set m_pAccount, as that happened already in IsAccount().)
438 
439  return pAccount;
440 }
OTLOG_IMPORT OTLogStream otOut
EXPORT bool Exists() const
Definition: OTString.cpp:1035
bool IsAccount(OTAccount &theAccount)
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
Definition: OTAccount.cpp:480
void opentxs::OTPartyAccount::RegisterForExecution ( OTScript theScript)

Definition at line 457 of file OTPartyAccount.cpp.

458 {
459  const std::string str_acct_name = m_strName.Get();
460  theScript.AddAccount(str_acct_name, *this);
461 }
EXPORT const char * Get() const
Definition: OTString.cpp:1045
void opentxs::OTPartyAccount::Serialize ( OTString strAppend,
bool  bCalculatingID = false,
bool  bSpecifyAssetID = false 
) const

Definition at line 442 of file OTPartyAccount.cpp.

444 {
445  strAppend.Concatenate(
446  "<assetAccount\n name=\"%s\"\n"
447  " acctID=\"%s\"\n"
448  " assetTypeID=\"%s\"\n"
449  " agentName=\"%s\"\n"
450  " closingTransNo=\"%lld\" />\n\n",
451  m_strName.Get(), bCalculatingID ? "" : m_strAcctID.Get(),
452  (bCalculatingID && !bSpecifyAssetID) ? "" : m_strAssetTypeID.Get(),
453  bCalculatingID ? "" : m_strAgentName.Get(),
454  bCalculatingID ? 0 : m_lClosingTransNo);
455 }
EXPORT const char * Get() const
Definition: OTString.cpp:1045
void opentxs::OTPartyAccount::SetAcctID ( const OTString strAccountID)
inline

Definition at line 252 of file OTPartyAccount.hpp.

253  {
254  m_strAcctID = strAccountID;
255  }
void opentxs::OTPartyAccount::SetAgentName ( const OTString strAgentName)
inline

Definition at line 248 of file OTPartyAccount.hpp.

249  {
250  m_strAgentName = strAgentName;
251  }
void opentxs::OTPartyAccount::SetClosingTransNo ( int64_t  lTransNo)
inline

Definition at line 271 of file OTPartyAccount.hpp.

272  {
273  m_lClosingTransNo = lTransNo;
274  }
void opentxs::OTPartyAccount::SetParty ( OTParty theOwnerParty)

Definition at line 217 of file OTPartyAccount.cpp.

218 {
219  m_pForParty = &theOwnerParty;
220 }
bool opentxs::OTPartyAccount::VerifyAgency ( )

Definition at line 317 of file OTPartyAccount.cpp.

318 {
319  if (nullptr == m_pAccount) {
320  otErr << "OTPartyAccount::VerifyAgency: Error: nullptr pointer to "
321  "account. (This function expects account to already be "
322  "loaded.) \n";
323  return false;
324  } // todo maybe turn the above into OT_ASSERT()s.
325 
326  OTAgent* pAgent = GetAuthorizedAgent();
327 
328  if (nullptr == pAgent) {
329  otOut
330  << "OTPartyAccount::VerifyAgency: Unable to find authorized agent ("
331  << GetAgentName() << ") for this account: " << GetName() << " \n";
332  return false;
333  }
334 
335  if (!pAgent->VerifyAgencyOfAccount(*m_pAccount)) {
336  otOut << "OTPartyAccount::VerifyAgency: Agent " << GetAgentName()
337  << " doesn't verify as ACTUALLY having rights over account "
338  << GetName() << " with ID: " << GetAcctID() << " \n";
339  return false;
340  }
341 
342  return true;
343 }
EXPORT const OTString & GetName() const
OTLOG_IMPORT OTLogStream otOut
EXPORT OTAgent * GetAuthorizedAgent()
const OTString & GetAgentName() const
OTLOG_IMPORT OTLogStream otErr
const OTString & GetAcctID() const
bool opentxs::OTPartyAccount::VerifyOwnership ( ) const

Definition at line 292 of file OTPartyAccount.cpp.

293 {
294  if (nullptr == m_pForParty) {
295  otErr << "OTPartyAccount::VerifyOwnership: Error: nullptr pointer to "
296  "owner party. \n";
297  return false;
298  }
299  if (nullptr == m_pAccount) {
300  otErr << "OTPartyAccount::VerifyOwnership: Error: nullptr pointer to "
301  "account. (This function expects account to already be "
302  "loaded.) \n";
303  return false;
304  } // todo maybe turn the above into OT_ASSERT()s.
305 
306  if (!m_pForParty->VerifyOwnershipOfAccount(*m_pAccount)) {
307  otOut << "OTPartyAccount::VerifyOwnership: Party %s doesn't verify as "
308  "the ACTUAL owner of account: " << m_strName << " \n";
309  return false;
310  }
311 
312  return true;
313 }
OTLOG_IMPORT OTLogStream otOut
bool VerifyOwnershipOfAccount(const OTAccount &theAccount) const
Definition: OTParty.cpp:934
OTLOG_IMPORT OTLogStream otErr

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