A distributed wallet with two operation DEPOSIT and WITHDRAW
Go 1.13+
go build main.goStart first node (create a new cluster)
./main -http 127.0.0.1:10000 -consensus 127.0.0.1:20000 -id NODE1 -bootstrap ./NODE1Wait for first node started then start second & third nodes
./main -http 127.0.0.1:10001 -consensus 127.0.0.1:20001 -id NODE2 -join 127.0.0.1:10000 ./NODE2
./main -http 127.0.0.1:10002 -consensus 127.0.0.1:20002 -id NODE3 -join 127.0.0.1:10001 ./NODE3Create a new node
./main -http 127.0.0.1:10003 -consensus 127.0.0.1:20003 -id NODE4 ./NODE4Bootstrap the newly created node into existing cluster
curl -i -X POST 127.0.0.1:10001/join -H 'Content-Type:application/json' -d '{"httpAddr":"127.0.0.1:10003", "consensusAddr": "127.0.0.1:20003", "id": "NODE4"}'Check the balance
curl -X GET 127.0.0.1:10000
curl -X GET 127.0.0.1:10001
curl -X GET 127.0.0.1:100025000
5000
5000deposit money into wallet
curl -i -X POST 127.0.0.1:10002/dw -H 'Content-Type:application/json' -d '{"op":"DEPOSIT", "amount": "525"}'Then the balance is change on all nodes too
curl -X GET 127.0.0.1:10000
curl -X GET 127.0.0.1:10001
curl -X GET 127.0.0.1:100025525
5525
5525withdraw money from wallet
curl -i -X POST 127.0.0.1:10002/dw -H 'Content-Type:application/json' -d '{"op":"WITHDRAW", "amount": "1725"}'Get new balance
curl -X GET 127.0.0.1:10000
curl -X GET 127.0.0.1:10001
curl -X GET 127.0.0.1:100023800
3800
3800go build main.go./main -http $HTTP_ADDR -consensus $CONSENSUS_ADDR -id $NODE_ID -bootstrap -join $OTHER_ADDR /path/to/store/dirwhile
-http $HTTP_ADDR
declares service http endpoint (e.g 127.0.0.1:10000)
-consensus $CONSENSUS_ADDR
declares consensus service endpoint (e.g 127.0.0.1:20000)
-id $NODE_ID
node id (ids in the same cluster must not be duplicated)
-bootstrap
to bootstrap new cluster.
- if
bootstrapis set then ignorejoinoption. - if
bootstrapandjoinis not set then create a new node (it will not functional)
-join $OTHER_ADDR
used to join this newly created node to an existed cluster.
(this could be http binding of any node inside cluster)
/path/to/store/dir
path to log store used to snapshot & restore if node is up