blockchain/init

35 lines
874 B
Bash
Executable File

#!/bin/bash
function register_nodes() {
http POST localhost:5001/nodes/register \
nodes:='["http://localhost:5002"]'
http POST localhost:5002/nodes/register \
nodes:='["http://localhost:5001"]'
}
function synchronise_nodes() {
http POST localhost:5001/nodes/resolve
http POST localhost:5002/nodes/resolve
}
NODE1_ID=$(http localhost:5001/identifier | jq -r ".identifier")
NODE2_ID=$(http localhost:5002/identifier | jq -r ".identifier")
register_nodes >/dev/null
# Mine a few initial blocks
http POST localhost:5001/mine
http POST localhost:5001/mine
synchronise_nodes >/dev/null
http POST localhost:5001/transactions sender=$NODE1_ID recipient=$NODE2_ID amount=1.3
http POST localhost:5001/mine
synchronise_nodes >/dev/null
http localhost:5001/nodes/$NODE1_ID/balance
http localhost:5001/nodes/$NODE2_ID/balance
echo node1: $NODE1_ID
echo node2: $NODE2_ID