basics initializing a cx chain - SkycoinWikis/CXChains GitHub Wiki

CXCHAINS HOME » CX » CX CHAINS » INITIALIZING A CX CHAIN

Initializing a CX Chain

Currently, CX has the newcoin command as a dependency (located in cmd/newcoin). In order to initialize a new CX chain, newcoin needs to create the cxcoin command (located in cmd/cxcoin) using the parameters defined in ./fiber.toml. This process should be simplified by mimicking the process defined by cmd/cxcoin/cxcoin.go in cxgo/main.go. In other words, instead of having to call the process defined by cxcoin, we can embed the process in CX to eliminate the newcoin and cxcoin dependencies.

The workflow – which occurs when running, for example, cx --blockchain --secret-key $SECRET_KEY --public-key $PUBLIC_KEY examples/blockchain/counter-bc.cx – is as follows:

  1. newcoin is installed by running go install ./cmd/newcoin/...
  2. newcoin is run in order to create cxcoin

It is worthy to note that the name cxcoin could be changed to something else by using the --program-name flag, but this behavior has not been tested yet.

  1. cxcoin is installed by running go install ./cmd/cxcoin/...

  2. cxcoin is run to initialize the CX chain. This process involves:

    1. Running go run ./cmd/cxcoin/cxcoin.go --block-publisher=true --blockchain-secret-key=$SECRET_KEY.

    The data directory for the publisher node is stored in $HOME/.cxcoin/. Every time a new CX chain is initialized, its data directory is deleted first. The name of this directory can change, depending on the value of --program-name.

    1. As this is a new blockchain, the genesis block will be created and a genesis signature is generated. This genesis signature will be different for every blockchain, even if the blockchain private and public keys are the same.
    2. Using the genesis signature and the secret key, a CX chain creates the first transaction in the genesis block, which is a transaction without a transaction code and with an unspent output storing the initial program state, defined by running the blockchain code.
    3. fiber.toml's field genesis_signature_str is updated automatically with the new genesis signature.
    4. The genesis signature is printed to standard output, so the user can take note of it.

The diagram below illustrates how the different parts and processes that have been reviewed until now interact among them in order to generate the initial program state.

init-stage.png

NEXT ->