A Deep Look at the Company Blockstream & Their Bitcoin ...

Advice on memory management

Hi guys, I'm studying C ++ for my project, the part I'm working on now focuses on bitcoin-core deserialization in json, that is, each blk.dat file will be converted to blk.json.

And now I'm finding myself preparing the alpha version of the project and so I'm putting my mind to work in the best possible way also because there are so many files and I wouldn't want to saturate the memory when the alpha version is launched.

I would like to ask you some opinions on the way in which I managed the memory also because I am studying C ++ and therefore I am a novice in this field, I am native in java.

I used the DAO pattern to create a simple way to decouple the components.

I put the code of the method involved and I would like to ask you what I am wrong, and if the things I do are right, drought you are experts in C ++ I believe there is no better way to learn, thank you.

Excuse my English but I'm learning

The method principal, saveBlock
bool DAOFileBlkJson::saveBlock(string inputPath, string outputPath) { if (inputPath.empty() || outputPath.empty()) { LOG(ERROR) << "The argument function is null"; throw DAOException("The argument function loadBlocks from DAOBlockchain is Empity"); } bool result = false; if (fs::exists(inputPath)) { if(fs::is_directory(inputPath)) { LOG(WARNING) << "Path exits and the path is the directory, the path is: " << inputPath; string pathFile = nameFileSearched(inputPath); while(!pathFile.empty()) { LOG(WARNING) << "The file examinad is: " << pathFile; LOG_IF(ERROR, counterBlock < 0) << "The counter block are negative, this is not possible, the attual value is" << counterBlock; string nameFile = getNameFile(pathFile); vector> vectorBlockFileBlk = readBlock(pathFile, counterBlock); if (!vectorBlockFileBlk.empty()) { LOG(INFO) << "I added block readed in this file " << inputPath; result = convertVectorBlockIntoJson(vectorBlockFileBlk, outputPath, nameFile); if(!result) { LOG(ERROR) << "Error into convert vector blocks readed into json file"; vectorBlockFileBlk.clear(); return result; } } currentFile++; vectorBlockFileBlk.clear(); pathFile = nameFileSearched(inputPath); } return result; } LOG(ERROR) << "The path not is a directory"; throw DAOException("The path not is a directory"); } LOG(ERROR) << "The path not exist"; throw DAOException("The path not exist"); } 
The method readBlock
vector> DAOFileBlkJson::readBlock(string path, int &conuterBlock) { if (!isBlockFileBlk(path)) { LOG(INFO) << "This path not contain a file blk"; return vector>(); } if(!fs::exists(path)){ LOG(ERROR) << "File " << path << " not exist"; return vector>(); } ifstream stream(path); //unique_ptr stream(new ifstream(path)); if (stream.is_open()) { LOG(INFO) << "File in this path " << path << " is open"; //vector *blocksFile = new vector(); // unique_ptr> blocksFile(new vector()); vector> blocksFile; while (!stream.eof()) { //Block *block = new Block(); unique_ptr block(new Block()); block->decode(stream); block->setHeightBlock(counterBlock); counterBlock++; LOG(WARNING) << "The numbar blocks readed are: " << counterBlock; blocksFile.push_back(move(block)); delete block.release(); } fileBlkReaded++; stream.close(); LOG(WARNING) << "Readed a " << blocksFile.size() << " files"; return blocksFile; } LOG(ERROR) << "File not open"; throw DAOException("File not open"); } 
The method convertVectorBlockIntoJson whit library https://github.com/nlohmann/json
bool DAOFileBlkJson::convertVectorBlockIntoJson(vector> &blockFileBlk, string outputPath, string nameFile) { if(blockFileBlk.empty() || outputPath.empty() || nameFile.empty()) { LOG(ERROR) << "The imput parameter is null"; throw DAOException("Input is null"); } json jsonBlocksFile;//TODO convert vector into json. json listBlocksConvert; for(int i = 0; i < static_cast(blockFileBlk.size()); i++) { listBlocksConvert.push_back(blockFileBlk.at(i)->toJsonFat()); } blockFileBlk.clear(); jsonBlocksFile = {"blocks", listBlocksConvert}; string nameFileJson = outputPath; nameFileJson += nameFile + ".json"; ofstream streamOutput(nameFileJson); if(streamOutput.is_open()) { streamOutput << jsonBlocksFile; streamOutput.close(); return true; } LOG(ERROR) << "ERROR the file is not open into this directory " << outputPath; return false; } 
The service method
bool DAOFileBlkJson::isBlockFileBlk(string path) { string tmpPathFile(path); LOG(INFO) << "The path in string is: " << path; string nameFile = tmpPathFile.substr(tmpPathFile.size() - 12, tmpPathFile.size()); LOG(INFO) << "The name file in path is " << nameFile; bool containsBlk = nameFile.find("blk") != string::npos; bool containsExstension = nameFile.find(".dat") != string::npos; return containsBlk && containsExstension; } string DAOFileBlkJson::getNameFile(string path) { LOG(INFO) << "Path File is " << path; string nameFile = path.substr((path.size() - 12), 8); LOG(WARNING) << "Name file analized is " << nameFile << "and creating file json whit this name"; LOG_IF(ERROR, nameFile.empty()) << "Name file empity"; return nameFile; } 
submitted by crazyjoker96 to cpp_questions [link] [comments]

What the CPU usage depends on and how to optimize it

hello guys
I created a bitcoin parser that read from a file and deserializes parserized information in json, uses the rapidjson library for decryption in json and the bitcoin library to read the information from the bitcoin file.
My parser, for now, has been thought to be single thread, when I launch the app everything works, I have optimized thanks to this also communicated the use of ram but I have noticed that I use the core of the processor to the maximum and now I would like to understand from what is due in general this problem and what is possible to optimize this.
This is the code portion where I perform the decoding and serialization operation in json
void SpyCBlock::convertBlkIntoJson(string locationBitcoinCore, string destinationBitcoinCoreJson) { int height = 0; string pathInput = nameFileSearched(locationBitcoinCore); while(pathInput != "") { string fileNameOutput = getNameFile(pathInput); DAOJson dao; string pathOutput = destinationBitcoinCoreJson + fileNameOutput + ".json"; dao.saveBlock(pathInput, pathOutput, height); currentFile++; pathInput = nameFileSearched(locationBitcoinCore); } } //method dao.saveBlock(..) bool DAOJson::saveBlock(string inputPath, string outputPath, int &height) { if (fs::exists(inputPath)) { if(!fs::is_directory(inputPath)) { ifstream loadFileDat(inputPath); ofstream saveBlkToJson(outputPath); OStreamWrapper streamWrapper(saveBlkToJson); Writer writer(streamWrapper); if(loadFileDat.is_open()) { writer.StartObject(); writer.Key("blocks"); writer.StartArray(); Block block; while(!loadFileDat.eof()) { block.decode(loadFileDat); height++; block.setHeightBlock(height); block.toJson(writer); } writer.EndArray(); writer.EndObject(); saveBlkToJson.close(); return true; } } } } 
Sorry for the stupid question, I'm a student and I'm programming simple program with java and I don't have experience with the optimizing code
submitted by crazyjoker96 to cpp_questions [link] [comments]

Verify that there are at least n bits in an input stream

I'm reading the file that generates bitcoin cores, the files are serialized in hexadecimal and above all my program reads the information based on the size of the type of data to be decoded, but bitcoin core in some cases can add junk information for example the end of a block can end with some indormations that are not appropriate for the information I have to extract, so I wanted to know how I can do in C ++ reading this raw bitcoin core file but with a further check on the actual size of input to be parsed that advances.

An example
with this code
ifstream loadFileDat("blk00000.dat") vector> blockFileBlk; while(!loadFileDat.eof()) { auto block = make_unique(); block->decode(loadFileDat); blockFileBlk.push_back(move(block)); } 
I create a block that does not exist if the end of the file contains junk information, since I know the size of the block I will read, I can check the actual existence of that block in the block. So as to be able to stop if that information is garbage for my purpose

This is the question of the reference on stackoverflow
submitted by crazyjoker96 to cpp_questions [link] [comments]

High Limit Coin Pusher full of Bitcoins! I came out a ... Test Stream 2 of 3 - Bitcoin Moon Boy on Deck - YouTube bitcoin banned countries , bitcoin price ( due to banning ... Bitcoin Trading Robots - YouTube What Is Bitcoin and How Does It Work? - YouTube

From a Stream, if you Read(buffer, offset, count) you'll get a non-positive result, and if you Peek() you'll get a negative result.. With a BinaryReader, the documentation suggests that PeekChar() should return negative:. Return Value. Type: System.Int32 The next available character, or -1 if no more characters are available or the stream does not support seeking. Auf der Spiele-Plattform Steam konntet ihr eure Games früher auch mit der Internet-Währung Bitcoin bezahlen. Aufgrund von Wertschwankungen und Gebühren hat Stream diese Option aber wieder ... The WisdomTree Bitcoin ETP (BTCW) is listed on the SIX Swiss Exchange with a total expense ratio (TER) of 0.95%, the cheapest crypto ETP on the market. The firm said the reason for listing in Switzerland is the regulatory requirements for cryptocurrencies are more favourable than other exchanges in Europe. WisdomTree is targeting professional investors with this product, however, added this ... Bitcoin Ticker - Tick by tick, real time updates. All data is indicative. Options Last Updated: seconds : Time between graph updates : ms: Play sound on each trade . Round Bids/Asks to 0.500 . Animate Depth Movements . Highlight BTC bids/asks above : Alert if price falls below: Alert if price climbs above: Alert if price change +/- : Sound Alert . Desktop Alert . Show Personalized Content ... eof() checks the eofbit in the stream state. On each read operation, if the position is at the end of stream and more data has to be read, eofbit is set to true. Therefore you're going to get an extra character before you get eofbit=1.

[index] [10041] [27154] [26834] [49816] [40582] [44994] [42854] [22265] [18539] [50229]

High Limit Coin Pusher full of Bitcoins! I came out a ...

BTC, ETC, LTC, XRP, bitcoin, etherium, litecoin, ripple, bitcoin cash, free bitcoin, free etherium, free ripple, crypto bot, trading bot, free bot, free CRYP... https://introtocryptos.ca/discord Bitcoin Liquidation Watch Livestream: Center Chart is 10second bars. Along right side are the significant trades, with audi... 👇🏽 More Bitcoin Links below👇🏽 _____ Please follow me on Lbry.TV: http://lbry.davincij15.com Also, Subsc... BITCOIN CHART LIVESTREAM - Wird die 7100$ Marke halten?! Youtube Alternativen wie DTube im Talk - Duration: 1:31:36. Finanzielle Freiheit dank Kryptowährungen 1,053 views STREAM - ako zničiť Bitcoin - fork vs. spoon ... Žraloci sobě . Loading... Unsubscribe from Žraloci sobě? Cancel Unsubscribe. Working... Subscribe Subscribed Unsubscribe 4.11K. Loading ...