From d091425ada42bd9c4008cc42dbfb0a0fccb56d6e Mon Sep 17 00:00:00 2001 From: Saeid Nasiri Date: Thu, 25 Mar 2021 10:43:24 +0430 Subject: [PATCH 1/2] change interpolation to format --- blockchain.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blockchain.py b/blockchain.py index 937d3521..4752b238 100644 --- a/blockchain.py +++ b/blockchain.py @@ -47,8 +47,8 @@ def valid_chain(self, chain): while current_index < len(chain): block = chain[current_index] - print(f'{last_block}') - print(f'{block}') + print('{}'.format(last_block)) + print('{}'.format(block)) print("\n-----------\n") # Check that the hash of the block is correct last_block_hash = self.hash(last_block) @@ -80,7 +80,7 @@ def resolve_conflicts(self): # Grab and verify the chains from all the nodes in our network for node in neighbours: - response = requests.get(f'http://{node}/chain') + response = requests.get('http://{}/get_chain'.format(node)) if response.status_code == 200: length = response.json()['length'] @@ -186,7 +186,7 @@ def valid_proof(last_proof, proof, last_hash): """ - guess = f'{last_proof}{proof}{last_hash}'.encode() + guess = '{1}{2}{3}'.format(last_proof,proof,last_hash) guess_hash = hashlib.sha256(guess).hexdigest() return guess_hash[:4] == "0000" @@ -241,7 +241,7 @@ def new_transaction(): # Create a new Transaction index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount']) - response = {'message': f'Transaction will be added to Block {index}'} + response = {'message :Transaction will be added to Block {}'.format(index)} return jsonify(response), 201 From 88f902f0ee29ab27fd471cdcbe68cdd119787b18 Mon Sep 17 00:00:00 2001 From: Saeid Nasiri Date: Thu, 25 Mar 2021 18:21:35 +0430 Subject: [PATCH 2/2] resolve some bug --- blockchain.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/blockchain.py b/blockchain.py index 4752b238..d4a2b851 100644 --- a/blockchain.py +++ b/blockchain.py @@ -80,8 +80,7 @@ def resolve_conflicts(self): # Grab and verify the chains from all the nodes in our network for node in neighbours: - response = requests.get('http://{}/get_chain'.format(node)) - + response = requests.get('http://{0}/chain'.format(node)) if response.status_code == 200: length = response.json()['length'] chain = response.json()['chain'] @@ -186,7 +185,7 @@ def valid_proof(last_proof, proof, last_hash): """ - guess = '{1}{2}{3}'.format(last_proof,proof,last_hash) + guess = '{0}{1}{2}'.format(last_proof,proof,last_hash).encode() guess_hash = hashlib.sha256(guess).hexdigest() return guess_hash[:4] == "0000" @@ -241,7 +240,7 @@ def new_transaction(): # Create a new Transaction index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount']) - response = {'message :Transaction will be added to Block {}'.format(index)} + response = {'message' :'Transaction will be added to Block {}'.format(index)} return jsonify(response), 201