- Activate venv.
$ source server/myvenv/bin/activate
- At
__init__
inconnection_manager.py
, choose how many peers to connect.
class ConnectionManager:
def __init__(self, host, port, callback):
self.host = host
self.port = port
self.mm = MessageManager()
self.callback = callback
self.peers = set()
# connect to 2 peers
self.peers = [(host, 65001), (host, 65002)]
# connect to 3 peers
# self.peers = [(host, 65001), (host, 65002), (host, 65003)]
- Start node server.
$ python node1_server.py
- There are
node1_server.py
,node2_server.py
, andnode3_server.py
- Each node's port is
50082
,50083
, and50084
- There are
- Send HTTP GET
start
for every nodes - You can send any APIs 🎉
- node: node1, node2, node3
- account: aki, so, satoshi
- controller
The genesis block has these three transactions.
[ {"sender": None, "recipient": "aki", "value": 2},
{"sender": None, "recipient": "so", "value": 7},
{"sender": None, "recipient": "satoshi", "value": 5} ]
- https://$node-simulator-host:$port/$api
- eg.) curl -X GET http://localhost:10001/status
- activate node
- need to be used every time you start the program
- reset state
- clock is 0, tx pool is empty, and chain contains the Genesis block only.
- return status in JSON
- return value
{
"clock": 1,
"status": "idle"
}
- status type
- 1: idle
- 2: mining
- 3: broadcasting-block
- 4: broadcasting-tx
- 5: receiving-block
- 6: receiving-tx
block value
{
"id": 4,
"hash": "5234ab...",
"timestamp": "%Y/%m/%d %H:%M:%S",
"transactions": [{"sender": "aki", "recipient": "so", "value": 3}],
"previoud_block_hash": "d628e...",
"nonde": 46
}
- return a block for the given id in the node in JSON
- return block value
- return the latest block in the node in JSON
- return HTTP 200 with the block value, if it exists
- return HTTP 404, if not
- return all blocks in the node in JSON
- return value
{
"length": 2,
"blocks": [
{ "id": 0, "hash: ..." },
{ "id": 1, "hash: ..." }
]
}
- return all transactions in the tx pool of the node in JSON
- return value
{
"sender": "aki",
"recipient": "so",
"value": 3
}
- request the node to mine
- at the next clock, the status of the node becomes “mining”
- return HTTP 200, no body
- changes clock to the given value
- return HTTP 200, no body
- request to add a transaction to the tx pool
- POST data: tx value
- return value
{
"result": "success" // success | fail
}
- mining: 3
- broadcasting-block: 1
- broadcasting-transaction: 1
- receiving-block: 1
- receiving-transaction: 1
- respond to controller: 0
- socketで繋がっている
- blockchainにはgenesis blockが入っている
- tx poolは空
- akiに10コイン(genesis blockにtxが入っている)
- NEW_BLOCK
- NEW_TX