Skip to content

Commit 44abb72

Browse files
committed
Fix block
1 parent b7ff4a9 commit 44abb72

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

backend/blockchain/block.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import time
22

33
from backend.util.crypto_hash import crypto_hash
4-
<<<<<<< HEAD
5-
=======
6-
from backend.util.hex_to_binary import hex_to_binary
7-
>>>>>>> a77fccd... Complete proof of work section
84
from backend.config import MINE_RATE
95

106
GENESIS_DATA = {
@@ -29,12 +25,6 @@ def __init__(self, timestamp, last_hash, hash, data, difficulty, nonce):
2925
self.difficulty = difficulty
3026
self.nonce = nonce
3127

32-
<<<<<<< HEAD
33-
def add_block(self, data):
34-
self.chain.append(Block(data))
35-
36-
=======
37-
>>>>>>> a77fccd... Complete proof of work section
3828
def __repr__(self):
3929
return (
4030
'Block('
@@ -58,7 +48,7 @@ def mine_block(last_block, data):
5848
nonce = 0
5949
hash = crypto_hash(timestamp, last_hash, data, difficulty, nonce)
6050

61-
while hex_to_binary(hash)[0:difficulty] != '0' * difficulty:
51+
while hash[0:difficulty] != '0' * difficulty:
6252
nonce += 1
6353
timestamp = time.time_ns()
6454
difficulty = Block.adjust_difficulty(last_block, timestamp)
@@ -77,8 +67,8 @@ def genesis():
7767
def adjust_difficulty(last_block, new_timestamp):
7868
"""
7969
Calculate the adjusted difficulty according to the MINE_RATE.
80-
Decrease the difficulty for slowly mined blocks.
8170
Increase the difficulty for quickly mined blocks.
71+
Decrease the difficulty for slowly mined blocks.
8272
"""
8373
if (new_timestamp - last_block.timestamp) < MINE_RATE:
8474
return last_block.difficulty + 1
@@ -91,14 +81,7 @@ def adjust_difficulty(last_block, new_timestamp):
9181
def main():
9282
genesis_block = Block.genesis()
9383
block = Block.mine_block(genesis_block, 'foo')
94-
<<<<<<< HEAD
95-
print(f'block: {block}')
96-
97-
if __name__ == '__main__':
98-
main()
99-
=======
10084
print(block)
10185

10286
if __name__ == '__main__':
10387
main()
104-
>>>>>>> a77fccd... Complete proof of work section

0 commit comments

Comments
 (0)