python BlockChain(三)注册多节点
2018-06-30 本文已影响4人
ab64fd4eaee3
http://127.0.0.1:5000/node/register
def __init__(self):
self.chain = []
self.current_transactions = []
self.new_block(proof=100, previous_hash=1)
self.nodes = set()
def register_node(self,address:str):
# http://127.0.0.1:500
parsed_url = urlparse(address)
print(parsed_url.netloc)
self.nodes.add(parsed_url.netloc)
@app.route("/node/register", methods=["POST"])
def register_node():
values = request.get_json()
nodes = values["nodes"]
if nodes is None:
return "Error :please a vaild list of nodes", 400
for node in nodes:
blockchain.register_node(node)
reponse = {
'message': "New nodes haved added",
'total_nodes': list(blockchain.nodes)
}
return jsonify(reponse), 200