Skip to content

Instantly share code, notes, and snippets.

@imylomylo
Last active March 31, 2019 03:56
Show Gist options
  • Save imylomylo/1caa171709f43967cf7245d00deb779d to your computer and use it in GitHub Desktop.
Save imylomylo/1caa171709f43967cf7245d00deb779d to your computer and use it in GitHub Desktop.
CORS anywhere and KMDICE

Start & Sync KMDICE

Using komodo-in-a-box admin interface

Still in beta, the repo is komodo-in-a-box.

Using cli to start komodod

If you don't have a data directory or configuration First syncing the chain with this configuration and creating a data dir for wallet if one doesn't exist, otherwise just skip these commands.

mkdir ~/.komodo/KMDICE
cd ~/.komodo/KMDICE
cat > KMDICE.conf <<EOF
rpcuser=XX_RPCUSER_XX
rpcpassword=XX_RPCPASS_XX
rpcport=30177
server=1
txindex=1
rpcworkqueue=256
rpcallowip=127.0.0.1
EOF

If you don't have a pubkey sync the chain whilst you prepare to use it.

komodod -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232

If you have a pubkey you are ready to start using it.

komodod -pubkey=<your pubkey> -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232

Checking the blockchain is synced to the chain tip

komodo-cli -ac_name=KMDICE getinfo

The blocks and the longestchain will be the same when synced.

...
  "blocks": 230640,
  "longestchain": 230640,
...

Using the Custom Consensus of KMDICE

Any blockchain created with Komodo that uses custom consensus needs a public key. Public key looks like

02XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
03XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

It doesn't matter if the alpha numeric characters are uppercase or lowercase, they are used as a hex string, and hex strings don't discriminate.

To get a pubkey, just use validateaddress on the address in your wallet. If you don't have an address in your wallet, use getnewaddress and then validateaddress. Also don't forget to get your private key for your new address using dumpprivkey

Once the blockchain is synced you will need to restart it with your public key if you haven't done so. Simply stop the chain and restart. To stop komodo-cli -ac_name=KMDICE stop. To restart it please use the command in the section above If you have a pubkey.

CORS Anywhere

Starting CORS Anywhere to use with KMDICE RPC

In a tmux session

git clone https://github.com/cakeshopclouddev/cors-anywhere.git
cd cors-anywhere
npm install
PORT=1234 node server.js

And that is the CORS Anywhere running, detach from tmux.

Keeping up to date with upstream

For instance on my repo, I sync with the original author.

cd cors-anywhere
git remote add upstream https://github.com/Rob--W/cors-anywhere.git
git fetch upstream
git merge upstream/master

If everything works, the cakeshopclouddev stuff can pull from imylomylo in a similar way or from whoever does real work on it in the future, maybe even Rob--W

Network Information

At some point you may need to know any of the next information, this is how you get it. Open port for connections Use the netstat or equivalent command

$ netstat -ptan
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:1234            0.0.0.0:*               LISTEN      1566/node
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      - 
tcp        0      0 0.0.0.0:30176           0.0.0.0:*               LISTEN      32056/komodod
...

You will see a lot of komodod remote addresses, these are p2p connections connecting on tcp/30176. tcp/22 is ssh and the tcp/1234 listening on any address running the node command is our CORS-Anywhere server.

Starting the cakeshop web interface

Cloning the web repo

git clone https://github.com/cakeshopclouddev/kmdice-cakeshop.git
cd kmdice-cakeshop
npm install
npm run dev

Ensure apache (or nginx) is using proxy pass to the kmdice cakeshop

sudo a2enmod proxy
sudo a2enmod proxy_http

The configuration of your <VirtualHost> should have these two lines

ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

Then restart apache

sudo systemctl restart apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment