Quick and dirty -- build jormungandr piblic testnet node ###################
# HERE BE FUN DRAGONS -- last updated ~ Sat Oct 19 13:46:44 UTC 2019
###################

# *NOTE*
# these instructions have only been tested on linux machines

# Get pre-reqs (Ubuntu)
sudo apt-get install build-essential pkg-config git curl libssl-dev

# install rust the easy way
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustup install stable
rustup default stable

# get the source, checkout a working commit hash/tag or master
# - NOTE latest stable is tag v0.6.5 checkout master if you're a cowboy
git clone https://github.com/input-output-hk/jormungandr.git
cd jormungandr
git pull # for good measure
git submodule update --init --recursive
git checkout v0.6.5

# build the binaries (force will be reqired if you've built before)
cargo install --path jcli --force;cargo install --path jormungandr --force

# create a working dir to play in, and a var
mkdir -p ~/pub_testnet01/storage
cd ~/pub_testnet01
APIURL="http://127.0.0.1:3101/api"

# create your node trusted ids
jcli key generate --type Ed25519 | tee private.id

# if you want to allow someone to use your peer they need your public id
cat private.id | jcli key to-public > public.id

# create your node config
# PRIVATE_ID == contents of the private.id file
# X.X.X.X == needs to be changed to your public facing IP address
# - run curl ifconfig.me if unsure of your public ip
# - if you are behind a NAT (home router/firewall) you will need to port forward
# /path-to == needs to be changed as ~ is not recognized
cat > ~/pub_testnet01/node_config.yaml << EOL
log:
  format: "plain"
  level: "info"
  output: "stderr"
p2p:
  private_id: "ed25519_sk1PRIVATE ID"
  listen_address: "/ip4/0.0.0.0/tcp/3100"
  public_address: "/ip4/X.X.X.X/tcp/3100"
  topics_of_interest:
    blocks: "high"
    messages: "high"
  trusted_peers:
    - address: "/ip4/3.115.194.22/tcp/3000"
      id: ed25519_pk1npsal4j9p9nlfs0fsmfjyga9uqk5gcslyuvxy6pexxr0j34j83rsf98wl2
    - address: "/ip4/13.113.10.64/tcp/3000"
      id: ed25519_pk16pw2st5wgx4558c6temj8tzv0pqc37qqjpy53fstdyzwxaypveys3qcpfl
    - address: "/ip4/52.57.214.174/tcp/3000"
      id: ed25519_pk1v4cj0edgmp8f2m5gex85jglrs2ruvu4z7xgy8fvhr0ma2lmyhtyszxtejz
    - address: "/ip4/3.120.96.93/tcp/3000"
      id: ed25519_pk10gmg0zkxpuzkghxc39n3a646pdru6xc24rch987cgw7zq5pmytmszjdmvh
    - address: "/ip4/52.28.134.8/tcp/3000"
      id: ed25519_pk1unu66eej6h6uxv4j4e9crfarnm6jknmtx9eknvq5vzsqpq6a9vxqr78xrw
    - address: "/ip4/13.52.208.132/tcp/3000"
      id: ed25519_pk15ppd5xlg6tylamskqkxh4rzum26w9acph8gzg86w4dd9a88qpjms26g5q9
    - address: "/ip4/54.153.19.202/tcp/3000"
      id: ed25519_pk1j9nj2u0amlg28k27pw24hre0vtyp3ge0xhq6h9mxwqeur48u463s0crpfk
rest:
  listen: "127.0.0.1:3101"
storage: "/path-to/pub_testnet01/storage"
*hit enter here -- at the > prompt type EOL as below*
> EOL


# start your node in the foreground
jormungandr --config ~/pub_testnet01/node_config.yaml --genesis-block-hash adbdd5ede31637f6c9bad5c271eec0bc3d0cb9efb86a5b913bb55cba549d0770


# start your node in the background
# - required if you want to exit the shell and leave the node running
nohup jormungandr --config ~/pub_testnet01/node_config.yaml --genesis-block-hash adbdd5ede31637f6c9bad5c271eec0bc3d0cb9efb86a5b913bb55cba549d0770 >> /path-to/pub_testnet01/node.out 2>&1 &
# to watch the output of the node run tail -f node.out


# you should see the files in the ~/pub_testnet01/storage start increasing in size
# - current size of sqlite file is around 30mb
ls -la ~/pub_testnet01/storage
total 29568
drwxrwxr-x 2 myuser myuser 4096 Sep 29 00:23 .
drwxrwxr-x 5 myuser myuser 4096 Sep 29 20:09 ..
-rw-r--r-- 1 myuser myuser 26066944 Sep 29 20:05 blocks.sqlite
-rw-r--r-- 1 myuser myuser 32768 Sep 29 20:09 blocks.sqlite-shm
-rw-r--r-- 1 myuser myuser 4165352 Sep 29 20:09 blocks.sqlite-wal


# to check to see if you're receiving new blocks:
# - if lastBlockTime value is blank you might be running into THIS ISSUE
# - some say if you wait long enough it will start to sync
# - others think getting someone to add your node to their node_config.yaml trusted_peers list fixes it
jcli rest v0 node stats get -h ${APIURL}
---
blockRecvCnt: 1009
lastBlockDate: "219.22133"
lastBlockFees: 0
lastBlockHash: cd6eb35ead45a42c7befea3aa5f2a89b0dc71ff2bc3306a962b8aeb24748a305
lastBlockHeight: "24562"
lastBlockSum: 0
lastBlockTime: "2019-09-29T20:11:21+00:00"
lastBlockTx: 0
txRecvCnt: 16
uptime: 9293

# once you see the blockRecvCnt incrementing your node is online -- Enjoy!

# NEXT STEP: Create an account and request funds from the faucet

# The Lovelace Community Pool is a no fee staking pool run by @kyleo
# Join us on Telegram

# If this was useful and you can/want to support us, our donation address is:
Ae2tdPwUPEYw3rz8KGHbnTusd9QWQ8ePhogEWkm1agugTtW51skA59DrKe8