145 #include <irrxml/irrXML.hpp>
147 #ifdef OT_USE_SCRIPT_CHAI
149 #include <chaiscript/chaiscript.hpp>
150 #ifdef OT_USE_CHAI_STDLIB
151 #include <chaiscript/chaiscript_stdlib.hpp>
165 #ifndef SCRIPTABLE_CALLBACK_PARTY_MAY_EXECUTE
166 #define SCRIPTABLE_CALLBACK_PARTY_MAY_EXECUTE \
167 "callback_party_may_execute_clause"
175 static char buf[45] =
"";
178 otErr << __FUNCTION__ <<
": Failure: Input string is empty.\n";
187 otErr << __FUNCTION__ <<
": Input string apparently was encoded and "
188 "then failed decoding. Contents: \n"
199 bool bGotLine = strContract.
sgets(buf, 40);
201 if (!bGotLine)
return nullptr;
213 if (!strFirstLine.
Exists() || strFirstLine.
Contains(
"- -"))
return nullptr;
219 "-----BEGIN SIGNED SMARTCONTRACT-----"))
227 if (
nullptr == pItem)
return nullptr;
241 m_strLabel = (
nullptr != pstrLabel) ? pstrLabel->c_str() :
"";
251 return !(isalnum(c) || (c ==
'_'));
257 if (str_name.size() <= 0) {
258 otErr <<
"OTScriptable::ValidateName: Name has zero size.\n";
261 else if (find_if(str_name.begin(), str_name.end(),
263 otErr <<
"OTScriptable::ValidateName: Name fails validation testing: "
276 #ifdef OT_USE_SCRIPT_CHAI
277 using namespace chaiscript;
282 OTScriptChai* pScript =
dynamic_cast<OTScriptChai*
>(&theScript);
284 if (
nullptr != pScript) {
290 "party_may_execute_clause");
293 #endif // OT_USE_SCRIPT_CHAI
295 otErr <<
"OTScriptable::RegisterOTNativeCallsWithScript: Failed "
296 "dynamic casting OTScript to OTScriptChai \n";
308 strTime.
Format(
"%lld", lTime);
309 return strTime.
Get();
323 std::string str_clause_name)
328 if (
nullptr == pParty) {
329 otOut <<
"OTScriptable::CanExecuteClause: Unable to find this party: "
330 << (str_party_name.size() > 0 ? str_party_name.c_str() :
"")
335 if (
nullptr == pClause) {
336 otOut <<
"OTScriptable::CanExecuteClause: Unable to find this clause: "
337 << (str_clause_name.size() > 0 ? str_clause_name.c_str() :
"")
404 if (str_clause_name.compare(0, 5,
"cron_") == 0)
406 otOut <<
"OTScriptable::CanExecuteClause: Parties may not directly "
407 "trigger clauses beginning in cron_\n";
411 if (str_clause_name.compare(0, 5,
"hook_") == 0)
413 otOut <<
"OTScriptable::CanExecuteClause: Parties may not directly "
414 "trigger clauses beginning in hook_\n";
418 if (str_clause_name.compare(0, 9,
"callback_") == 0)
420 otOut <<
"OTScriptable::CanExecuteClause: Parties may not directly "
421 "trigger clauses beginning in callback_\n";
442 if (
nullptr != pCallbackClause)
444 otOut <<
"OTScriptable::CanExecuteClause: Found script for: "
454 OTVariable param1(
"param_party_name", str_party_name,
456 OTVariable param2(
"param_clause_name", str_clause_name,
462 theParameters.insert(
463 std::pair<std::string, OTVariable*>(
"param_party_name", ¶m1));
464 theParameters.insert(
465 std::pair<std::string, OTVariable*>(
"param_clause_name", ¶m2));
469 *pCallbackClause, theParameters,
472 otErr <<
"OTScriptable::CanExecuteClause: Error while running "
473 "callback script " << SCRIPTABLE_CALLBACK_PARTY_MAY_EXECUTE
474 <<
", clause " << str_clause_name <<
" \n";
478 otOut <<
"OTScriptable::CanExecuteClause: Success executing "
479 "callback script " << SCRIPTABLE_CALLBACK_PARTY_MAY_EXECUTE
480 <<
", clause: " << str_clause_name <<
".\n\n";
487 otOut <<
"OTScriptable::CanExecuteClause: Unable to find script for: "
489 <<
". Therefore, default return value is: TRUE.\n";
529 const std::string str_clause_name = theCallbackClause.
GetName().
Exists()
540 const std::string str_code =
542 const std::string str_language =
545 std::shared_ptr<OTScript> pScript =
OTScriptFactory(str_language, str_code);
559 const std::string str_party_name = it.first;
561 OT_ASSERT((
nullptr != pParty) && (str_party_name.size() > 0));
563 pScript->AddParty(str_party_name, *pParty);
567 for (
auto& it : theParameters) {
568 const std::string str_var_name = it.first;
570 OT_ASSERT((
nullptr != pVar) && (str_var_name.size() > 0));
589 if (!pScript->ExecuteScript(&varReturnVal)) {
590 otErr <<
"OTScriptable::ExecuteCallback: Error while running "
591 "callback on scriptable: " <<
m_strLabel <<
"\n";
594 otOut <<
"OTScriptable::ExecuteCallback: Successfully executed "
595 "callback on scriptable: " <<
m_strLabel <<
"\n\n";
600 otErr <<
"OTScriptable::ExecuteCallback: Error instantiating script!\n";
659 const OTIdentifier& theServerID,
const int64_t& lNewTransactionNumber,
690 theServerNym, theServerID, lNewTransactionNumber,
693 strReference, pstrNote, pstrAttachment, pActualNym))
708 bool bIsDirty =
false;
728 bool bIsDirty =
false;
769 std::string str_agent_name)
const
771 int32_t nReturnVal = 0;
774 if (
nullptr == pAgent)
801 otErr <<
"OTScriptable::GetPartyAccount: Error: invalid name.\n";
809 if (
nullptr != pAcct)
824 if (
nullptr != pAcct)
877 if (pParty->
HasAgent(theNym, ppAgent))
return pParty;
901 if (pParty->
HasAccount(theAccount, ppPartyAccount)) {
978 const bool bBurnTransNo)
991 const bool bNeedToCleanup = (
nullptr == pmap_NEWLY_LOADED) ?
true :
false;
996 otOut << __FUNCTION__ <<
": Unable to find party's signed copy of this "
997 "contract. Has it been executed?\n";
1010 OTAgent* pAuthorizingAgent =
nullptr;
1013 std::unique_ptr<OTPseudonym> theAgentNymAngel;
1019 if (
nullptr != pmap_ALREADY_LOADED) {
1022 mapOfNyms& map_Nyms_Already_Loaded = (*pmap_ALREADY_LOADED);
1024 for (
auto& it : map_Nyms_Already_Loaded) {
1029 pAuthAgentsNym = pNym;
1047 bool bHadToLoadItMyself = (
nullptr == pAuthorizingAgent) ?
true :
false;
1051 if (bHadToLoadItMyself) {
1061 if (
nullptr != pAuthAgentsNym)
1067 <<
": I just had to load "
1068 "the authorizing agent's Nym for a party ("
1071 "so I guess it wasn't already available on the list of "
1072 "Nyms that were already loaded.\n";
1079 theAgentNymAngel.reset(pAuthAgentsNym);
1081 const std::string str_agent_name =
1084 mapOfNyms& map_Nyms_Newly_Loaded = (*pmap_NEWLY_LOADED);
1085 map_Nyms_Newly_Loaded.insert(
1086 map_Nyms_Newly_Loaded.begin(),
1087 std::pair<std::string, OTPseudonym*>(
1093 otErr << __FUNCTION__ <<
": Error: Strange, unable to load "
1094 "authorizing agent's Nym (to verify his "
1124 otErr << __FUNCTION__ <<
": Opening trans number " << lOpeningNo
1126 "verify for the nym listed as the authorizing agent for "
1128 if (bHadToLoadItMyself && bNeedToCleanup)
1140 else if (bBurnTransNo) {
1144 otErr << __FUNCTION__ <<
": Opening trans number " << lOpeningNo
1146 "verify as available for use, for the "
1147 "nym listed as the authorizing agent "
1149 if (bHadToLoadItMyself && bNeedToCleanup)
1169 lOpeningNo, strServerID, theSignerNym,
true);
1174 else if (bBurnTransNo)
1177 otOut << __FUNCTION__ <<
": FAILURE. On Party "
1179 <<
", expected to burn a legitimate opening transaction "
1180 "number, but got this instead: " << lOpeningNo <<
"\n";
1181 if (bHadToLoadItMyself && bNeedToCleanup)
1213 std::unique_ptr<OTScriptable> theCopyAngel;
1215 if (
nullptr == pPartySignedCopy) {
1216 otErr << __FUNCTION__ <<
": Error loading party's signed copy of "
1217 "agreement. Has it been executed?\n";
1218 if (bHadToLoadItMyself && bNeedToCleanup)
1223 theCopyAngel.reset(pPartySignedCopy);
1226 const bool bSigVerified =
1228 bool bContentsVerified =
false;
1241 if (!bContentsVerified)
1242 otOut << __FUNCTION__
1243 <<
": Though the signature verifies, the contract "
1245 <<
") doesn't match this contract. (Failed comparison.)\n";
1248 otOut << __FUNCTION__ <<
": Signature failed to verify for party: "
1251 if (bHadToLoadItMyself && bNeedToCleanup)
1259 return bContentsVerified;
1312 if (
nullptr == pParty) {
1313 otOut <<
"OTScriptable::VerifyNymAsAgent: Unable to find party based "
1314 "on Nym as agent.\n";
1322 otOut <<
"OTScriptable::VerifyNymAsAgent: Unable to find party's ("
1324 <<
") signed copy of this contract. Has it been executed?\n";
1337 OTAgent* pAuthorizingAgent =
nullptr;
1339 std::unique_ptr<OTPseudonym> theAgentNymAngel;
1344 (
nullptr != pmap_ALREADY_LOADED)) {
1349 mapOfNyms& map_Nyms_Already_Loaded = (*pmap_ALREADY_LOADED);
1350 for (
auto& it : map_Nyms_Already_Loaded) {
1355 pAuthAgentsNym = pNym;
1364 if (
nullptr == pAuthorizingAgent) {
1374 if (
nullptr != pAuthAgentsNym)
1379 otLog3 <<
"OTScriptable::VerifyNymAsAgent: I just had to load the "
1380 "authorizing agent's Nym for a party ("
1382 <<
"), so I guess it wasn't already available "
1383 "on the list of Nyms that were already loaded.\n";
1384 theAgentNymAngel.reset(pAuthAgentsNym);
1387 otErr <<
"OTScriptable::VerifyNymAsAgent: Error: Strange, unable "
1388 "to load authorizing "
1390 <<
" (to verify his signature.)\n";
1428 std::unique_ptr<OTScriptable> theCopyAngel;
1430 if (
nullptr == pPartySignedCopy) {
1431 otErr <<
"OTScriptable::VerifyNymAsAgent: Error loading party's ("
1433 <<
") signed copy of agreement. Has it been executed?\n";
1438 theCopyAngel.reset(pPartySignedCopy);
1440 const bool bSigVerified =
1442 bool bContentsVerified =
false;
1450 bContentsVerified =
Compare(*pPartySignedCopy);
1452 if (!bContentsVerified)
1453 otOut <<
"OTScriptable::VerifyNymAsAgent: Though the signature "
1454 "verifies, the contract "
1456 <<
") doesn't match this contract. (Failed comparison.)\n";
1459 otOut <<
"OTScriptable::VerifyNymAsAgent: Signature failed to verify "
1473 return bContentsVerified;
1497 const bool bBurnTransNo)
1509 if (
nullptr == pParty) {
1510 otErr <<
"OTScriptable::" << __FUNCTION__
1511 <<
": Unable to find party for acct: " << thePartyAcct.
GetName()
1518 if (
nullptr == pAuthorizedAgent) {
1519 otOut <<
"OTScriptable::" << __FUNCTION__
1520 <<
": Unable to find authorized agent ("
1522 <<
") for acct: " << thePartyAcct.
GetName() <<
" \n";
1540 otOut <<
"OTScriptable::" << __FUNCTION__
1541 <<
": Unable to verify party's (" << pParty->
GetPartyName()
1542 <<
") ownership of acct: " << thePartyAcct.
GetName() <<
" \n";
1552 otOut <<
"OTScriptable::" << __FUNCTION__
1553 <<
": Unable to verify agent's ("
1555 <<
") rights re: acct: " << thePartyAcct.
GetName() <<
" \n";
1581 otOut <<
"OTScriptable::" << __FUNCTION__
1582 <<
": Closing trans number " << lClosingNo
1584 "verify for the nym listed as the authorized agent for "
1585 "account " << thePartyAcct.
GetName() <<
".\n";
1593 else if (bBurnTransNo) {
1597 otOut <<
"OTScriptable::" << __FUNCTION__
1598 <<
": Closing trans number " << lClosingNo
1600 "verify as available for use, for the "
1601 "nym listed as the authorized agent for "
1602 "acct: " << thePartyAcct.
GetName() <<
".\n";
1614 lClosingNo, strServerID, theSignerNym,
true);
1619 else if (bBurnTransNo)
1622 otOut <<
"OTScriptable::" << __FUNCTION__ <<
": FAILURE. On Acct "
1624 <<
", expected to burn a legitimate closing transaction "
1625 "number, but got this instead: " << lClosingNo <<
"\n";
1648 if (
nullptr == pParty) {
1650 otOut <<
"OTScriptable::VerifyNymAsAgentForAccount: Unable to find "
1651 "party based on account.\n";
1659 otOut <<
"OTScriptable::VerifyNymAsAgentForAccount: pParty is not the "
1660 "owner of theAccount.\n";
1665 const std::string str_acct_agent_name = pPartyAcct->
GetAgentName().
Get();
1670 if (
nullptr == pAgent) {
1671 otOut <<
"OTScriptable::VerifyNymAsAgentForAccount: Unable to find the "
1672 "right agent for this account.\n";
1690 otOut <<
"OTScriptable::VerifyNymAsAgentForAccount: theNym is not a "
1691 "valid signer for pAgent.\n";
1696 otOut <<
"OTScriptable::VerifyNymAsAgentForAccount: theNym is not a "
1697 "valid agent for theAccount.\n";
1850 otErr << __FUNCTION__ <<
": Error: invalid name.\n";
1860 if (
nullptr != pClause)
1871 otErr << __FUNCTION__ <<
": Error: invalid name.\n";
1881 if (
nullptr != pAgent)
1892 otErr << __FUNCTION__ <<
": Error: invalid name.\n";
1913 otErr << __FUNCTION__ <<
": Error: invalid name.\n";
1932 if ((nIndex < 0) || (nIndex >= static_cast<int64_t>(
m_mapParties.size()))) {
1933 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
1937 int32_t nLoopIndex = -1;
1945 if (nLoopIndex == nIndex)
return pParty;
1953 if ((nIndex < 0) || (nIndex >= static_cast<int64_t>(
m_mapBylaws.size()))) {
1954 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
1958 int32_t nLoopIndex = -1;
1966 if (nLoopIndex == nIndex)
return pBylaw;
1986 const std::string current_party_name = it.first;
1993 std::unique_ptr<OTScriptable> theCopyAngel;
1995 if (
nullptr == pPartySignedCopy) {
1996 otErr << __FUNCTION__ <<
": Error loading party's ("
1997 << current_party_name
1998 <<
") signed copy of agreement. Has it been executed?\n";
2002 theCopyAngel.reset(pPartySignedCopy);
2004 if (!
Compare(*pPartySignedCopy))
2008 otErr << __FUNCTION__ <<
": Party's (" << current_party_name
2009 <<
") signed copy of agreement doesn't match *this.\n";
2035 const std::string str_party_name = theParty.
GetPartyName();
2039 otErr <<
"OTScriptable::ConfirmParty: Error: invalid name.\n";
2071 OTParty* pParty = it_delete->second;
2074 if (!pParty->
Compare(theParty))
2077 otOut <<
"OTScriptable::ConfirmParty: Party (" << str_party_name
2078 <<
") doesn't match the one it's confirming.\n";
2093 std::pair<std::string, OTParty*>(str_party_name, &theParty));
2126 otOut <<
"OTScriptable::ConfirmParty: Failed attempt to confirm "
2127 "non-existent party: " << str_party_name <<
" \n ";
2137 const std::string str_party_name = theParty.
GetPartyName();
2141 otErr <<
"OTScriptable::AddParty: Error: invalid name.\n";
2149 std::pair<std::string, OTParty*>(str_party_name, &theParty));
2156 otOut <<
"OTScriptable::AddParty: Failed attempt: party already exists "
2164 const std::string str_name = theBylaw.
GetName().
Get();
2168 otErr <<
"OTScriptable::AddBylaw: Error: invalid name.\n";
2176 std::pair<std::string, OTBylaw*>(str_name, &theBylaw));
2183 otOut <<
"OTScriptable::AddBylaw: Failed attempt: bylaw already exists "
2208 const char* szFunc =
"OTScriptable::Compare";
2217 otOut << szFunc <<
": The number of parties does not match.\n";
2221 otOut << szFunc <<
": The number of bylaws does not match.\n";
2226 const std::string str_bylaw_name = it.first;
2232 if (
nullptr == p2) {
2233 otOut << szFunc <<
": Unable to find bylaw " << str_bylaw_name
2237 else if (!pBylaw->
Compare(*p2)) {
2238 otOut << szFunc <<
": Bylaws don't match: " << str_bylaw_name
2245 const std::string str_party_name = it.first;
2251 if (
nullptr == p2) {
2252 otOut << szFunc <<
": Unable to find party " << str_party_name
2256 else if (!pParty->
Compare(*p2)) {
2257 otOut << szFunc <<
": Parties don't match: " << str_party_name
2286 bool bCalculatingID)
const
2289 strAppend.
Concatenate(
"<scriptableContract\n specifyAssetID=\"%s\"\n "
2290 "specifyParties=\"%s\"\n"
2291 " numParties=\"%d\"\n numBylaws=\"%d\" >\n\n",
2314 pBylaw->
Serialize(strAppend, bCalculatingID);
2317 strAppend.
Concatenate(
"</scriptableContract>\n\n");
2334 int32_t nReturnVal = 0;
2353 const OTString strNodeName(xml->getNodeName());
2358 if (strNodeName.Compare(
"scriptableContract")) {
2359 const char* szFunc =
"OTScriptable::ProcessXMLNode";
2360 const OTString strSpecify1 = xml->getAttributeValue(
"specifyAssetID");
2361 const OTString strSpecify2 = xml->getAttributeValue(
"specifyParties");
2363 OTString strNumParties = xml->getAttributeValue(
"numParties");
2364 OTString strNumBylaws = xml->getAttributeValue(
"numBylaws");
2377 int32_t nPartyCount =
2378 strNumParties.
Exists() ? atoi(strNumParties.
Get()) : 0;
2379 if (nPartyCount > 0) {
2380 while (nPartyCount-- > 0) {
2383 otOut << szFunc <<
": Failure: Unable to find expected "
2384 "element for party. \n";
2391 if ((!strcmp(
"party", xml->getNodeName()))) {
2392 OTString strName = xml->getAttributeValue(
2394 OTString strOwnerType = xml->getAttributeValue(
2396 OTString strOwnerID = xml->getAttributeValue(
2400 OTString strOpeningTransNo = xml->getAttributeValue(
2404 OTString strAuthAgent = xml->getAttributeValue(
2405 "authorizingAgent");
2409 OTString strNumAgents = xml->getAttributeValue(
2411 OTString strNumAccounts = xml->getAttributeValue(
2415 xml->getAttributeValue(
"signedCopyProvided");
2417 bool bIsCopyProvided =
false;
2419 if (strIsCopyProvided.
Compare(
"true"))
2420 bIsCopyProvided =
true;
2422 int64_t lOpeningTransNo = 0;
2424 if (strOpeningTransNo.
Exists())
2425 lOpeningTransNo = atol(strOpeningTransNo.
Get());
2428 <<
"s: Expected openingTransNo in party.\n";
2431 strName.
Exists() ? strName.
Get() :
"PARTY_ERROR_NAME",
2432 strOwnerType.
Compare(
"nym") ?
true :
false,
2433 strOwnerID.
Get(), strAuthAgent.
Get());
2443 int32_t nAgentCount =
2444 strNumAgents.
Exists() ? atoi(strNumAgents.
Get()) : 0;
2445 if (nAgentCount > 0) {
2446 while (nAgentCount-- > 0) {
2450 otOut << szFunc <<
": Failure: Unable to find "
2451 "expected element for "
2458 if ((xml->getNodeType() == irr::io::EXN_ELEMENT) &&
2459 (!strcmp(
"agent", xml->getNodeName()))) {
2460 OTString strAgentName = xml->getAttributeValue(
2464 xml->getAttributeValue(
2465 "doesAgentRepresentHimself");
2473 xml->getAttributeValue(
2474 "isAgentAnIndividual");
2481 OTString strNymID = xml->getAttributeValue(
2485 OTString strRoleID = xml->getAttributeValue(
2487 OTString strGroupName = xml->getAttributeValue(
2491 if (!strAgentName.
Exists() ||
2492 !strAgentRepSelf.
Exists() ||
2493 !strAgentIndividual.
Exists()) {
2494 otErr << szFunc <<
": Error loading agent: "
2495 "Either the name, or "
2497 "variables was EMPTY.\n";
2504 strAgentName.
Get())) {
2506 <<
": Failed loading agent due to "
2507 "Invalid name: " << strAgentName
2514 bool bRepsHimself =
true;
2516 if (strAgentRepSelf.
Compare(
"false"))
2517 bRepsHimself =
false;
2519 bool bIsIndividual =
true;
2521 if (strAgentIndividual.
Compare(
"false"))
2522 bIsIndividual =
false;
2532 if (
nullptr != pExistingAgent)
2536 <<
": Error loading agent named "
2538 <<
", since one was "
2539 "already there on party "
2540 << strName <<
".\n";
2553 bRepsHimself, bIsIndividual, strAgentName,
2554 strNymID, strRoleID, strGroupName);
2564 <<
": Failed adding agent to party.\n";
2577 <<
": Expected agent element in party.\n";
2587 int32_t nAcctCount = strNumAccounts.
Exists()
2588 ? atoi(strNumAccounts.
Get())
2590 if (nAcctCount > 0) {
2591 while (nAcctCount-- > 0) {
2593 otErr << szFunc <<
": Error finding expected "
2594 "next element for party "
2601 if ((xml->getNodeType() == irr::io::EXN_ELEMENT) &&
2602 (!strcmp(
"assetAccount", xml->getNodeName()))) {
2603 OTString strAcctName = xml->getAttributeValue(
2606 OTString strAcctID = xml->getAttributeValue(
2609 xml->getAttributeValue(
2611 OTString strAgentName = xml->getAttributeValue(
2615 xml->getAttributeValue(
2620 int64_t lClosingTransNo = 0;
2622 if (strClosingTransNo.
Exists())
2624 atol(strClosingTransNo.
Get());
2626 otErr << szFunc <<
": Expected "
2627 "closingTransNo in "
2638 if (!strAcctName.
Exists() ||
2640 !strAssetTypeID.
Exists())) {
2641 otErr << szFunc <<
": Expected missing "
2642 "AcctID or AssetTypeID "
2643 "or Name or AgentName "
2644 "in partyaccount.\n";
2662 <<
": Error loading partyacct named "
2664 <<
", since one was "
2665 "already there on party "
2666 << strName <<
".\n";
2680 strAgentName, strAcctName, strAcctID,
2681 strAssetTypeID, lClosingTransNo)) {
2682 otErr << szFunc <<
": Failed adding "
2683 "account to party.\n";
2696 otErr << szFunc <<
": Expected assetAccount "
2697 "element in party.\n";
2705 if (bIsCopyProvided) {
2706 const char* pElementExpected =
"mySignedCopy";
2711 xml, strTextExpected, pElementExpected)) {
2712 otErr << szFunc <<
": Expected " << pElementExpected
2713 <<
" element with text field.\n";
2728 otErr << szFunc <<
": Failed loading Party: "
2736 otErr << szFunc <<
": Expected party element.\n";
2744 int32_t nBylawCount =
2745 strNumBylaws.
Exists() ? atoi(strNumBylaws.
Get()) : 0;
2746 if (nBylawCount > 0) {
2747 while (nBylawCount-- > 0) {
2749 otOut << szFunc <<
": Failure: Unable to find expected "
2750 "element for bylaw. \n";
2754 if (!strcmp(
"bylaw", xml->getNodeName())) {
2756 xml->getAttributeValue(
"name");
2757 OTString strLanguage = xml->getAttributeValue(
2760 OTString strNumVariable = xml->getAttributeValue(
2762 OTString strNumClauses = xml->getAttributeValue(
2764 OTString strNumHooks = xml->getAttributeValue(
2766 OTString strNumCallbacks = xml->getAttributeValue(
2777 int32_t nCount = strNumVariable.
Exists()
2778 ? atoi(strNumVariable.
Get())
2781 while (nCount-- > 0) {
2783 otErr << szFunc <<
": Error finding expected "
2791 if ((xml->getNodeType() == irr::io::EXN_ELEMENT) &&
2792 (!strcmp(
"variable", xml->getNodeName()))) {
2793 OTString strVarName = xml->getAttributeValue(
2796 OTString strVarValue = xml->getAttributeValue(
2802 OTString strVarType = xml->getAttributeValue(
2804 OTString strVarAccess = xml->getAttributeValue(
2808 if (!strVarName.
Exists() ||
2810 !strVarAccess.
Exists()) {
2811 otErr << szFunc <<
": Expected missing "
2812 "name, type, or access "
2813 "type in variable.\n";
2831 <<
": Error loading variable named "
2833 <<
", since one was "
2834 "already there on one of the "
2852 if (strVarType.
Compare(
"integer"))
2854 else if (strVarType.
Compare(
"string"))
2856 else if (strVarType.
Compare(
"bool"))
2859 otErr << szFunc <<
": Bad variable type: "
2860 << strVarType <<
".\n";
2865 if (strVarAccess.
Compare(
"constant"))
2867 else if (strVarAccess.
Compare(
"persistent"))
2869 else if (strVarAccess.
Compare(
"important"))
2873 <<
": Bad variable access type: "
2874 << strVarAccess <<
".\n";
2881 <<
": Error loading variable to "
2882 "bylaw: bad type (" << strVarType
2883 <<
") or access type ("
2884 << strVarAccess <<
").\n";
2890 bool bAddedVar =
false;
2891 const std::string str_var_name =
2894 switch (theVarType) {
2896 if (strVarValue.
Exists()) {
2897 const int32_t nVarValue =
2898 atoi(strVarValue.
Get());
2900 str_var_name, nVarValue,
2905 <<
": No value found for integer "
2906 "variable: " << strVarName
2915 if (strVarValue.
Exists()) {
2916 const bool bVarValue =
2917 strVarValue.
Compare(
"true") ?
true
2920 str_var_name, bVarValue,
2925 <<
": No value found for bool "
2926 "variable: " << strVarName
2937 if (strVarValue.
Exists() &&
2938 strVarValue.
Compare(
"exists")) {
2943 xml, strVarValue)) {
2945 <<
": No value found for "
2947 << strVarName <<
"\n";
2962 const std::string str_var_value =
2965 str_var_name, str_var_value,
2970 <<
": Wrong variable type... "
2971 "somehow AFTER I should have "
2972 "already detected it...\n";
2979 otErr << szFunc <<
": Failed adding "
2980 "variable to bylaw.\n";
2988 otErr << szFunc <<
": Expected variable "
2989 "element in bylaw.\n";
3000 strNumClauses.
Exists() ? atoi(strNumClauses.
Get()) : 0;
3002 while (nCount-- > 0) {
3003 const char* pElementExpected =
"clause";
3016 temp_MapAttributes.insert(
3017 std::pair<std::string, std::string>(
"name",
3020 xml, strTextExpected, pElementExpected,
3021 &temp_MapAttributes))
3023 otErr << szFunc <<
": Error: Expected "
3025 <<
" element with text field.\n";
3038 auto it = temp_MapAttributes.find(
"name");
3040 if ((it != temp_MapAttributes.end()))
3043 std::string& str_name = it->second;
3045 if (str_name.size() > 0)
3061 <<
": Error loading clause named "
3063 <<
", since one was already "
3064 "there on one of the bylaws.\n";
3072 strTextExpected.
Get())) {
3073 otErr << szFunc <<
": Failed adding "
3074 "clause to bylaw.\n";
3086 <<
": Expected clause name.\n";
3093 otErr << szFunc <<
": Strange error: couldn't "
3094 "find name AT ALL.\n";
3104 nCount = strNumHooks.
Exists() ? atoi(strNumHooks.
Get()) : 0;
3106 while (nCount-- > 0) {
3109 otOut << szFunc <<
": Failure: Unable to find "
3110 "expected element.\n";
3116 if ((xml->getNodeType() == irr::io::EXN_ELEMENT) &&
3117 (!strcmp(
"hook", xml->getNodeName()))) {
3118 OTString strHookName = xml->getAttributeValue(
3122 OTString strClause = xml->getAttributeValue(
3127 if (!strHookName.
Exists() ||
3129 otErr << szFunc <<
": Expected missing "
3130 "name or clause while "
3141 <<
": Failed adding hook to bylaw.\n";
3149 <<
": Expected hook element in bylaw.\n";
3159 nCount = strNumCallbacks.
Exists()
3160 ? atoi(strNumCallbacks.
Get())
3163 while (nCount-- > 0) {
3166 otOut << szFunc <<
": Failure: Unable to find "
3167 "expected element.\n";
3173 if ((xml->getNodeType() == irr::io::EXN_ELEMENT) &&
3174 (!strcmp(
"callback", xml->getNodeName()))) {
3176 xml->getAttributeValue(
3180 OTString strClause = xml->getAttributeValue(
3185 if (!strCallbackName.
Exists() ||
3188 <<
": Expected, yet nevertheless "
3189 "missing, name or clause while "
3191 "callback for bylaw " << strName
3210 <<
": Error loading callback "
3212 <<
", since one was already there on "
3213 "one of the other bylaws.\n";
3229 <<
": Failed adding callback ("
3230 << strCallbackName <<
") to bylaw ("
3231 << strName <<
").\n";
3238 otErr << szFunc <<
": Expected callback "
3239 "element in bylaw.\n";
3249 <<
": Loaded Bylaw: " << pBylaw->
GetName()
3254 <<
": Failed loading Bylaw: " << pBylaw->
GetName()
3262 otErr << szFunc <<
": Expected bylaw element.\n";
3282 otErr <<
"OTScriptable::GetVariable: Error: invalid name.\n";
3292 if (
nullptr != pVar)
3305 (str_CallbackName.compare(0, 9,
"callback_") != 0))
3307 otErr <<
"OTScriptable::GetCallback: Error: invalid name: "
3308 << str_CallbackName <<
"\n";
3318 if (
nullptr != pClause)
3330 ((str_HookName.compare(0, 5,
"cron_") != 0) &&
3331 (str_HookName.compare(0, 5,
"hook_") != 0)))
3333 otErr <<
"OTScriptable::GetHooks: Error: invalid name.\n";
3337 bool bReturnVal =
false;
3345 if (pBylaw->
GetHooks(str_HookName, theResults)) bReturnVal =
true;
OTParty * FindPartyBasedOnNymIDAsAgent(const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
bool HasAgentByNymID(const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
EXPORT bool CanExecuteClause(std::string str_party_name, std::string str_clause_name)
std::map< std::string, std::string > Map
static bool ValidateName(std::string str_name)
bool SignContract(OTContract &theInput) const
EXPORT bool AddClause(OTClause &theClause)
bool AddAgent(OTAgent &theAgent)
bool is_ot_namechar_invalid(char c)
virtual EXPORT bool AddParty(OTParty &theParty)
EXPORT std::string GetPartyName(bool *pBoolSuccess=nullptr) const
EXPORT bool CalculateDigest(const OTData &dataInput)
EXPORT void RegisterForExecution(OTScript &theScript)
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 VerifyThisAgainstAllPartiesSignedCopies()
void ClearTemporaryPointers()
EXPORT OTAgent * GetAgent(const std::string &str_agent_name) const
bool VerifySignature(const OTContract &theContract) const
EXPORT OTParty * FindPartyBasedOnNymAsAuthAgent(OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
void SetOwnerAgreement(OTScriptable &theOwner)
EXPORT void RegisterVariablesForExecution(OTScript &theScript)
void ClearTemporaryPointers()
EXPORT bool SaveContract()
static EXPORT OTScriptable * InstantiateScriptable(const OTString &strInput)
void ClearTemporaryPointers()
EXPORT bool AllPartiesHaveSupposedlyConfirmed()
EXPORT const OTString & GetName() const
virtual bool SaveContractWallet(std::ofstream &ofs) const
EXPORT OTBylaw * GetBylaw(std::string str_bylaw_name) const
bool SendNoticeToParty(bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &theServerID, const int64_t &lNewTransactionNumber, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
EXPORT OTClause * GetCallback(std::string str_CallbackName)
int32_t GetCountAuthorizedAccts()
std::map< std::string, OTVariable * > mapOfVariables
virtual EXPORT void CalculateContractID(OTIdentifier &newID) const
virtual EXPORT void RegisterOTNativeCallsWithScript(OTScript &theScript)
EXPORT int32_t GetCountTransNumsNeededForAgent(std::string str_agent_name) const
OTLOG_IMPORT OTLogStream otOut
bool VerifyTransactionNumber(const int64_t &lNumber, const OTString &strServerID)
std::map< std::string, OTPseudonym * > mapOfNyms
virtual EXPORT bool Compare(OTScriptable &rhs) const
bool VerifyOwnershipOfAccount(const OTAccount &theAccount) const
EXPORT bool Compare(OTBylaw &rhs)
OTLOG_IMPORT OTLogStream otLog3
bool CopyValueBool() const
EXPORT bool GetHooks(std::string str_HookName, mapOfClauses &theResults)
EXPORT bool SaveContractRaw(OTString &strOutput) const
std::map< std::string, OTClause * > mapOfClauses
EXPORT bool IsDirty() const
static std::string GetTime()
bool AddAccount(OTPartyAccount &thePartyAcct)
EXPORT const OTString & GetName() const
EXPORT void Concatenate(const char *arg,...)
EXPORT OTAgent * GetAuthorizedAgent()
bool VerifyPartyAcctAuthorization(OTPartyAccount &thePartyAcct, OTPseudonym &theSignerNym, const OTString &strServerID, bool bBurnTransNo=false)
#define SCRIPTABLE_CALLBACK_PARTY_MAY_EXECUTE
mapOfParties m_mapParties
EXPORT bool DecodeIfArmored(bool escapedIsAllowed=true)
EXPORT void ReleaseSignatures()
EXPORT bool Exists() const
EXPORT OTClause * GetClause(std::string str_Name) const
EXPORT OTClause * GetClause(std::string str_clause_name) const
EXPORT bool IsValidSigner(OTPseudonym &theNym)
EXPORT void Format(const char *fmt,...)
int32_t GetBylawCount() const
bool HasAccount(OTAccount &theAccount, OTPartyAccount **ppPartyAccount=nullptr) const
void Release_Scriptable()
EXPORT bool Compare(const char *compare) const
bool ExecuteCallback(OTClause &theCallbackClause, mapOfVariables &theParameters, OTVariable &varReturnVal)
int32_t GetPartyCount() const
EXPORT const OTString & GetName()
void SetMySignedCopy(const OTString &strMyCopy)
bool VerifyPartyAuthorization(OTParty &theParty, OTPseudonym &theSignerNym, const OTString &strServerID, mapOfNyms *pmap_ALREADY_LOADED=nullptr, mapOfNyms *pmap_NEWLY_LOADED=nullptr, bool bBurnTransNo=false)
bool Compare(const OTParty &rhs) const
time64_t OTTimeGetCurrentTime()
void UpdateContentsToString(OTString &strAppend, bool bCalculatingID) const
bool VerifyIssuedNumber(const int64_t &lNumber, const OTString &strServerID)
EXPORT bool AddVariable(OTVariable &theVariable)
OTPseudonym * LoadAuthorizingAgentNym(OTPseudonym &theSignerNym, OTAgent **ppAgent=nullptr)
EXPORT void SetOwnerAgreement(OTScriptable &theOwner)
EXPORT const char * GetCode() const
OTParty * FindPartyBasedOnAccountID(const OTIdentifier &theAcctID, OTPartyAccount **ppPartyAccount=nullptr) const
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
bool sgets(char *buffer, uint32_t size)
virtual EXPORT void SetDisplayLabel(const std::string *pstrLabel=nullptr)
void RetrieveNymPointers(mapOfNyms &map_Nyms_Already_Loaded)
OTParty * FindPartyBasedOnAccount(OTAccount &theAccount, OTPartyAccount **ppPartyAccount=nullptr) const
EXPORT bool IsDirtyImportant() const
OTClause * GetCallback(std::string str_CallbackName)
OTVariable * GetVariable(std::string str_VarName)
bool HasAuthorizingAgentByNymID(const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
OTLOG_IMPORT OTLogStream otInfo
EXPORT OTParty * GetParty(std::string str_party_name) const
const OTString & GetAgentName() const
bool HasAgent(OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
EXPORT void Serialize(OTString &strAppend, bool bCalculatingID=false) const
EXPORT OTPartyAccount * GetAccountByID(const OTIdentifier &theAcctID) const
bool HasAccountByID(const OTIdentifier &theAcctID, OTPartyAccount **ppPartyAccount=nullptr) const
virtual void UpdateContents()
OTParty * GetParty() const
EXPORT OTVariable * GetVariable(std::string str_Name)
OTStringXML m_xmlUnsigned
EXPORT bool AddCallback(std::string str_CallbackName, std::string str_ClauseName)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT const char * Get() const
static bool SkipToElement(irr::io::IrrXMLReader *&xml)
OTLOG_IMPORT OTLogStream otErr
EXPORT OTPartyAccount * GetAccount(const std::string &str_acct_name) const
OTBylaw * GetBylaw() const
void Serialize(OTString &strAppend, bool bCalculatingID=false, bool bSpecifyAssetID=false, bool bSpecifyParties=false) const
bool VerifyAgencyOfAccount(const OTAccount &theAccount) const
EXPORT const OTString & GetName() const
EXPORT const char * GetLanguage() const
virtual EXPORT void Release()
bool VerifyOwnership() const
virtual EXPORT bool VerifyNymAsAgent(OTPseudonym &theNym, OTPseudonym &theSignerNym, mapOfNyms *pmap_ALREADY_LOADED=nullptr) const
const OTString & GetMySignedCopy()
virtual EXPORT bool VerifyNymAsAgentForAccount(OTPseudonym &theNym, OTAccount &theAccount) const
bool RemoveTransactionNumber(const int64_t &lNumber, const OTString &strServerID, OTPseudonym &SIGNER_NYM, bool bSave=true)
bool IsDirtyImportant() const
EXPORT bool Contains(const char *compare) const
int64_t GetOpeningTransNo() const
int64_t GetClosingTransNo() const
EXPORT OTParty * FindPartyBasedOnNymAsAgent(OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
EXPORT bool AddHook(std::string str_HookName, std::string str_ClauseName)
int64_t OTTimeGetSecondsFromTime(time64_t time)
OTAgent * GetAgent(std::string str_agent_name) const
void SetOpeningTransNo(const int64_t &theNumber)
EXPORT OTParty * GetPartyByIndex(int32_t nIndex) const
EXPORT bool LoadContractFromString(const OTString &theStr)
bool GetHooks(std::string str_HookName, mapOfClauses &theResults)
OTParty * FindPartyBasedOnNymIDAsAuthAgent(const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
OTPartyAccount * GetPartyAccountByID(const OTIdentifier &theAcctID) const
EXPORT OTBylaw * GetBylawByIndex(int32_t nIndex) const
OTPartyAccount * GetPartyAccount(std::string str_acct_name) const
virtual EXPORT bool ConfirmParty(OTParty &theParty)
bool IsAuthorizingAgentForParty()
virtual EXPORT void Release()
EXPORT std::shared_ptr< OTScript > OTScriptFactory(const std::string &script_type="")
virtual EXPORT bool AddBylaw(OTBylaw &theBylaw)
bool HasAuthorizingAgent(OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
void RetrieveNymPointers(mapOfNyms &map_Nyms_Already_Loaded)
static bool LoadEncodedTextFieldByName(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)