Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6561ca1

Browse files
committed
Fixed sync between nodes
1 parent 51ebcab commit 6561ca1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

blockchain/blockchain.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,21 @@ def valid_chain(self, chain):
164164

165165
while current_index < len(chain):
166166
block = chain[current_index]
167-
print(last_block)
168-
print(block)
169-
print("\n-----------\n")
167+
#print(last_block)
168+
#print(block)
169+
#print("\n-----------\n")
170170
# Check that the hash of the block is correct
171171
if block['previous_hash'] != self.hash(last_block):
172172
return False
173173

174174
# Check that the Proof of Work is correct
175-
if not self.valid_proof(last_block['nonce'], block['nonce'], block['previous_hash']):
175+
#Delete the reward transaction
176+
transactions = block['transactions'][:-1]
177+
# Need to make sure that the dictionary is ordered. Otherwise we'll get a different hash
178+
transaction_elements = ['sender_address', 'recipient_address', 'value']
179+
transactions = [OrderedDict((k, transaction[k]) for k in transaction_elements) for transaction in transactions]
180+
181+
if not self.valid_proof(transactions, block['previous_hash'], block['nonce'], MINING_DIFFICULTY):
176182
return False
177183

178184
last_block = block

blockchain/templates/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ <h4 class="card-title">Transactions on the Blockchain &nbsp;&nbsp;&nbsp;
109109
type: 'GET',
110110
success: function(response){
111111

112-
console.log(response['transactions']);
113-
//Generate Transactions Table
114112
//Generate Transactions Table
115113
var transactions = [];
116114
count = 1;
@@ -150,7 +148,7 @@ <h4 class="card-title">Transactions on the Blockchain &nbsp;&nbsp;&nbsp;
150148
type: 'GET',
151149
success: function(response){
152150

153-
console.log(response);
151+
//console.log(response);
154152
//Generate Transactions Table
155153
var transactions = [];
156154
count = 1;

0 commit comments

Comments
 (0)