Steem Smart Contracts: save and load the blockchain

in #utopian-io6 years ago (edited)

Repository

https://github.com/harpagon210/steemsmartcontracts

Related commit: https://github.com/harpagon210/steemsmartcontracts/commit/7c534af75830d6909a40defd07e682ec40289072

What feature(s) did you add?

Before implementing this new feature the blockchain and its database were fully hosted in RAM. Although it was good for performances, this was leading to a major problem when you were closing the app; the entire blockchain and its database were being destroyed. When you were restarting the app again you had to rescan the Steem blockchain from the starting point defined in the config.json file.
With this commit, the blockchain and the database are now saved when the app is being closed so that it is possible to resume the blockchain from where it was when you reopen the app.

How did you implement it/them?

Two main methods have been added to the Blockchain class:

loadBlockchain:

This method first check if we have a blockchain.json file available, this file is used to store the blockchain, it is simply an array of Block objetcs.

  • If this file doesn't exist we create a folder called "data", this folder will be used later on to save the blockchain and the database.
  • If the file exists fs.pathExistsSync(this.blockchainFilePath), we then load the database this.state.database.loadDatabase, LokiJS offers an adapter (loki-fs-structured-adapter) that allows us to load a database from the filesystem to the RAM, once the database is loaded we call the main process to tell him that the blockchain is up and ready callback(null);. If an error happens, we tell the main process what happened callback(error);.

saveBlockchain:

This method will save the blockchain as a JSON file called blockchain.json. Before saving we make sure that the blockchain is not producing a block if (this.producing) this.saveBlockchain(callback);, once we are sure that the blockchain is not producing, we save the file s.writeJson(this.blockchainFilePath, this.chain,, the database is saved as well thanks to the LokiJS adapter "loki-fs-structured-adapter" (that we loaded during the loading part) this.state.database.saveDatabase

additional changes:

In addition to the above two methods, the app.js has been updated so that the streamer only starts streaming the Steem blockchain once the Steem Smart Contracts blockchain is ready. Also when the app is being closed, the process doesn't stop right away, the blockchain and its database are saved and once this is done, the process is finally killed. Finally, the tests were updated to conform with the new way of initializing the Blockchain class.

GitHub Account

https://github.com/harpagon210

Sort:  

Your project is not really clear for me to be honest. I don't really see its purpose.
Could you explain it in more details ? 2 lines in the readme.md is a little too much concise !

Also it would be better to use pull requests so that we can know what we are reviewing as well.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

I don't know what I can explain more about it, I already explained the purpose of this app in my previous utopian post: https://busy.org/@harpagon/steem-smart-contracts-the-sidechain-that-brings-the-power-of-smart-contracts-to-the-steem-blockchain

The read me is pretty brief but you can find a link to the wiki in it which is way more complete than a simple read me (https://github.com/harpagon210/steemsmartcontracts/wiki).

I added a link to the commit in the description.

Thanks for the review ;)

You should put this link in your readme.md because I try to understand your project only from the github information

Hey @harpagon
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hi @harpagon, apparently the bot thought this was a task request and used the wrong % - hopefully this will get fixed soon!

Hey @amosbastian, thanks for the heads up ;)

Congratulations @harpagon! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.24
TRX 0.21
JST 0.037
BTC 98347.06
ETH 3416.93
USDT 1.00
SBD 3.34