Closed GlenDC closed 5 years ago
Template files will have to be worked on and committed to https://github.com/threefoldtech/rivine-chain-template repo (master branch). The tool can be worked on from a local version, on the feat/rivinecg
branch.
For the CLI use https://github.com/spf13/cobra, we already use it for our other commands as well. For the blockchain config files I would say use https://github.com/spf13/viper, so we can support JSON/YAML/TOML with ease, and let's use YAML by default.
The tool should come under ./cmd/rivinecg
of this repo (under the feat/rivinecg
Git branch)
Tasks:
rivinecg version
and rivinecg generate seed
commands. The version should be the same version as we use for the rest of the codebase. That version command returns similar information as you get when returning rivinec version
(where relevant of course). The generate seed cmd has already been discussed in detail.rivinecg generate config
cmd . The config file command already has been discussed in detail on the other page. Ensure that the config file is fully validated when loaded into memory and that errors are reported clearly. Make sure it can support reading YAML/TOML/JSON automatically. rivinecg generate blockchain
, it should do the following:
--config
(or -c
) flag.todo
folder for now, that is the folder we keep in all files that you still need to move, and if needed templatify, to the root dir (in the same file structure as the todo folder) :
.template
suffix, just move as-is.template
suffix:
blockchain
config file object as the only argument on it, and write the file to the new location to the same path (be it in a directory or not, so following the same file structure), with the same filename, but remove the .template
suffix from it.todo
directory, and modifying them into .template
files if required. Don't copy blindly, you can probably improve a lot in these code files and be careful. After this task is done you should be able to launch a blockchain with 1, 2 or 3 networks, but not yet with the minting extension allowed.I completed the validation for the config struct, now writing some tests. Need to test following cases.
blockchain
propertyblockchain.name
propertyblockchain.repository
propertyblockchain.currency
propertyblockchain.ports
propertyblockchain.ports.api
and blockchain.ports.rpc
propertyminting
property in transactions
and without minting
property in a network
networks
propertynetworks
property (need to be atleast one)genesis
property in a network
single-sig
and/or multisig
values in network.genesis.coinOutputs
/ network.genesis.blockStakeOutputs
/network.genesis.minting
propertyMerged and ready to use. Might make some further improvements while I review the ThreefoldBonus Chain tomorrow, as ideally a generated rivine blockchain doesn't modify manually any generated files.
For the TFB chain ticket (#534) I already started creating a template Rivine chain repo at https://github.com/threefoldtech/rivine-chain-template. It still requires a lot of manual work however to replace all the stuff, with a lot of information to be replaced duplicate information. We cannot simply make a chain repo that is ready to compile simply be providing a config file that it reads on runtime. We can however go pretty close to that. That is where the
rivinecg
tool comes into the picture.Goal would be that the template repo is really files that are either already ready to use-as-is, or they end in the
.template
suffix and thus will be parsed using therivinecg
tool chain generation process injecting the variables provided by the chain config as is.Commands
Generation commands we would provide:
Other command that we would provide:
Blockchain Generation Config
The config used for the blockchain generation would look as follows:
Templates
For
.template
files we can simply use the template format as defined by the Go std package https://golang.org/pkg/text/template/, no need to go crazier, it has all we needs. This we can apply to all Go, JS, Documentation, Makefile, script and all other files that require templating, based on the config as defined in the "Blockchain Generation Config" section.How to create a chain
Creating a chain will than become very easy, and can be done as follows
myorg/awesomechain
(or however you want to name it)mkdir -p $GOPATH/github.com/myorg/awesomechain && cd $GOPATH/github.com/myorg/awesomechain
rivinecg
tool:go get -u github.com/threefoldtech/rivine/cmd/rivinecg
rivinecg generate config
vim blockchain.cfg
rivinecg generate blockchain
git init
git add -A && git commit -m "initial commit: blockchain codebase ready to be used"
dep
but you can any tool you wish. Fordep
you would do it as follows:dep init
git add -A && git commit -m "add all blockchain code dependencies"
git remote add git@github.com:myorg/awesomechain.git
git push origin master
You know have your blockchain codebase ready to be used by you and others, fully working out of the box.
To build in development mode (
DEBUG=TRUE
) you can usemake install
, to build in production mode you can usemake install-std
.Once you have your blockchain installed you can launch your daemon anywhere using:
You can control your daemon using the CLI client
awesomechainc
. Please consult the--help
flag for bothawesomechaind
andawesomechainc
for more information on how to use these binaries.Please also read the README generated for your awesome chain to know how to start playing with your blockchain on a local
devnet
.Conclusion
Creating a new Rivine-based blockchain becomes super easy and fast once we have this tool. I therefore recommend that we wait with task #534 (create TFB chain) and #533 (create FFT chain) until we have this tool. In fact I would wait until we have Rivine 1.2 in a stable and releasable state, so that we don't require any further updates to the TFB and FFT codebase once it is generated.