@@ -337,9 +337,6 @@ class ApplicationImp : public Application, public RootStoppable, public BasicApp
337337 int
338338 fdRequired () const override ;
339339
340- bool
341- loadSubChains ();
342-
343340 // --------------------------------------------------------------------------
344341
345342 Logs&
@@ -1101,9 +1098,6 @@ ApplicationImp::setup()
11011098 if (!schema_main->setup ())
11021099 return false ;
11031100
1104- // if (!loadSubChains())
1105- // return false;
1106-
11071101 {
11081102 try
11091103 {
@@ -1219,161 +1213,6 @@ ApplicationImp::fdRequired() const
12191213 return std::max (1024 , needed);
12201214}
12211215
1222- bool
1223- ApplicationImp::loadSubChains ()
1224- {
1225- // return;
1226- // 1 parse the schema_info
1227- // 2 create the sub chain
1228-
1229- boost::filesystem::path schemaPath = config_->SCHEMA_PATH ;
1230-
1231- if (schemaPath.empty () || !boost::filesystem::exists (schemaPath))
1232- {
1233- return true ;
1234- }
1235-
1236- std::string schemaInfo (" schema_info" );
1237-
1238- std::vector<boost::filesystem::path> paths;
1239-
1240- for (auto const & entry :
1241- boost::filesystem::recursive_directory_iterator (schemaPath))
1242- {
1243- std::string fileName = entry.path ().filename ().string ();
1244- if (boost::filesystem::is_regular_file (entry) && schemaInfo == fileName)
1245- {
1246- paths.emplace_back (entry.path ());
1247- // std::cout << entry.path().string()<< std::endl;
1248- }
1249- }
1250-
1251- for (auto item : paths)
1252- {
1253- boost::filesystem::ifstream file (item);
1254- std::string str;
1255- std::vector<std::string> filenames;
1256- while (getline (file, str))
1257- {
1258- filenames.push_back (str);
1259- }
1260-
1261- if (filenames.size () != 7 )
1262- Throw<std::runtime_error>(" Invalid info in schema_info" );
1263-
1264- std::string sSchemaId = filenames[0 ];
1265- auto schemaId = ripple::from_hex_text<ripple::uint256>(sSchemaId );
1266- SchemaParams params{};
1267- bool bShouldCreate = false ;
1268- // To Modify: use sle to judge if schema should be created.
1269- auto ledger = getLedgerMaster (beast::zero).getValidatedLedger ();
1270- if (ledger->seq () > 1 )
1271- {
1272- auto sle = ledger->read (Keylet (ltSCHEMA, schemaId));
1273- if (!sle)
1274- {
1275- JLOG (m_journal.warn ())
1276- << " Read sle for schema:" << to_string (schemaId)
1277- << " failed" ;
1278- continue ;
1279- }
1280- params.readFromSle (sle);
1281- for (auto validator : params.validator_list )
1282- {
1283- if (validator.first == getValidationPublicKey ())
1284- {
1285- bShouldCreate = true ;
1286- break ;
1287- }
1288- }
1289- }
1290- else
1291- {
1292- std::string sSchemaName = filenames[1 ];
1293- std::string sAcountID = filenames[2 ];
1294- std::string sStragegy = filenames[3 ];
1295-
1296- std::string sAnchorLedgerHash = filenames[4 ];
1297- std::string sValidatorInfo = filenames[5 ];
1298- std::string sPeerListInfo = filenames[6 ];
1299-
1300- params.account = *ripple::parseBase58<AccountID>(sAcountID );
1301- params.admin = params.account ;
1302- params.schema_id = schemaId;
1303- params.schema_name = sSchemaName ;
1304- params.anchor_ledger_hash =
1305- ripple::from_hex_text<ripple::uint256>(sAnchorLedgerHash );
1306- params.strategy = boost::iequals (sStragegy , " 1" )
1307- ? SchemaStragegy::new_chain
1308- : SchemaStragegy::with_state;
1309-
1310- boost::split (
1311- params.peer_list , sPeerListInfo , boost::is_any_of (" ;" ));
1312-
1313- std::vector<std::string> vValidatorInfo;
1314- boost::split (vValidatorInfo, sValidatorInfo , boost::is_any_of (" ;" ));
1315-
1316- for (auto item : vValidatorInfo)
1317- {
1318- std::vector<std::string> vValidator;
1319- boost::split (vValidator, item, boost::is_any_of (" " ));
1320-
1321- if (vValidator.size () != 2 )
1322- Throw<std::runtime_error>(
1323- " Invalid validator info in schema_info" );
1324-
1325- boost::optional<PublicKey> pk = parseBase58<PublicKey>(
1326- TokenType::NodePublic, vValidator[0 ]);
1327- bool bValid = boost::iequals (vValidator[0 ], " 1" ) ? true : false ;
1328-
1329- std::pair<PublicKey, bool > validator =
1330- std::make_pair (*pk, bValid);
1331- params.validator_list .push_back (validator);
1332-
1333- if (*pk == getValidationPublicKey ())
1334- bShouldCreate = true ;
1335- }
1336- }
1337- if (!bShouldCreate)
1338- {
1339- JLOG (m_journal.warn ())
1340- << " Schema:" << to_string (schemaId) << " will not be created." ;
1341- continue ;
1342- }
1343-
1344- JLOG (m_journal.info ())
1345- << " Schema:" << to_string (schemaId) << " begin create." ;
1346-
1347- auto config = std::make_shared<Config>();
1348- std::string config_path =
1349- (boost::format (" %1%/%2%/%3%" ) % config_->SCHEMA_PATH % sSchemaId %
1350- " chainsqld.cfg" )
1351- .str ();
1352- config->setup (
1353- config_path,
1354- config_->quiet (),
1355- config_->silent (),
1356- config->standalone ());
1357-
1358- auto newSchema = getSchemaManager ().createSchema (config, params);
1359- if (!newSchema->initBeforeSetup ())
1360- {
1361- getSchemaManager ().removeSchema (newSchema->schemaId ());
1362- return false ;
1363- }
1364-
1365- if (!newSchema->setup ())
1366- {
1367- getSchemaManager ().removeSchema (newSchema->schemaId ());
1368- return false ;
1369- }
1370-
1371- JLOG (m_journal.info ())
1372- << " Schema:" << to_string (schemaId) << " created." ;
1373- }
1374- return true ;
1375- }
1376-
13771216// ------------------------------------------------------------------------------
13781217
13791218bool
0 commit comments