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(
2414 OTString strIsCopyProvided =
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";
2430 OTParty* pParty =
new OTParty(
2431 strName.Exists() ? strName.Get() :
"PARTY_ERROR_NAME",
2432 strOwnerType.Compare(
"nym") ?
true :
false,
2433 strOwnerID.Get(), strAuthAgent.Get());
2436 pParty->SetOpeningTransNo(
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(
2463 OTString strAgentRepSelf =
2464 xml->getAttributeValue(
2465 "doesAgentRepresentHimself");
2472 OTString strAgentIndividual =
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;
2529 OTAgent* pExistingAgent =
2532 if (
nullptr != pExistingAgent)
2536 <<
": Error loading agent named "
2538 <<
", since one was "
2539 "already there on party "
2540 << strName <<
".\n";
2552 OTAgent* pAgent =
new OTAgent(
2553 bRepsHimself, bIsIndividual, strAgentName,
2554 strNymID, strRoleID, strGroupName);
2557 if (!pParty->AddAgent(*pAgent)) {
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(
2608 OTString strAssetTypeID =
2609 xml->getAttributeValue(
2611 OTString strAgentName = xml->getAttributeValue(
2614 OTString strClosingTransNo =
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";
2655 OTPartyAccount* pAcct =
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";
2707 OTString strTextExpected;
2711 xml, strTextExpected, pElementExpected)) {
2712 otErr << szFunc <<
": Expected " << pElementExpected
2713 <<
" element with text field.\n";
2720 pParty->SetMySignedCopy(strTextExpected);
2725 <<
": Loaded Party: " << pParty->GetPartyName()
2728 otErr << szFunc <<
": Failed loading Party: "
2729 << pParty->GetPartyName() <<
"\n";
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(
2771 new OTBylaw(strName.Get(), strLanguage.Get());
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() ||
2809 !strVarType.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());
2899 bAddedVar = pBylaw->AddVariable(
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
2919 bAddedVar = pBylaw->AddVariable(
2920 str_var_name, bVarValue,
2925 <<
": No value found for bool "
2926 "variable: " << strVarName
2937 if (strVarValue.Exists() &&
2938 strVarValue.Compare(
"exists")) {
2939 strVarValue.Release();
2943 xml, strVarValue)) {
2945 <<
": No value found for "
2947 << strVarName <<
"\n";
2955 strVarValue.Release();
2962 const std::string str_var_value =
2964 bAddedVar = pBylaw->AddVariable(
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";
3004 OTString strTextExpected;
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() ||
3128 !strClause.Exists()) {
3129 otErr << szFunc <<
": Expected missing "
3130 "name or clause while "
3138 pBylaw->AddHook(strHookName.Get(),
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()))) {
3175 OTString strCallbackName =
3176 xml->getAttributeValue(
3180 OTString strClause = xml->getAttributeValue(
3185 if (!strCallbackName.Exists() ||
3186 !strClause.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";
3226 pBylaw->AddCallback(strCallbackName.Get(),
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";
std::map< std::string, std::string > Map
static bool ValidateName(std::string str_name)
virtual EXPORT bool AddParty(OTParty &theParty)
OTLOG_IMPORT OTLogStream otOut
EXPORT OTClause * GetClause(std::string str_clause_name) const
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
OTClause * GetCallback(std::string str_CallbackName)
OTVariable * GetVariable(std::string str_VarName)
OTLOG_IMPORT OTLogStream otInfo
static bool SkipToElement(irr::io::IrrXMLReader *&xml)
OTLOG_IMPORT OTLogStream otErr
OTAgent * GetAgent(std::string str_agent_name) const
OTPartyAccount * GetPartyAccount(std::string str_acct_name) const
virtual EXPORT bool AddBylaw(OTBylaw &theBylaw)
static bool LoadEncodedTextFieldByName(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)