Remove Type Annotations
I have some reasons for this, but could be swayed to keep them: - For folks who are learning, it tends to get in the way—there are way too many questions about this. - It doesn’t bring much value if there are reasonable tests. - Not many folks are using `mypy` before run time.
This commit is contained in:
parent
5c6f5109c6
commit
3fa90ff8ba
|
@ -18,7 +18,7 @@ class Blockchain:
|
||||||
# Create the genesis block
|
# Create the genesis block
|
||||||
self.new_block(previous_hash='1', proof=100)
|
self.new_block(previous_hash='1', proof=100)
|
||||||
|
|
||||||
def register_node(self, address: str) -> None:
|
def register_node(self, address):
|
||||||
"""
|
"""
|
||||||
Add a new node to the list of nodes
|
Add a new node to the list of nodes
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class Blockchain:
|
||||||
parsed_url = urlparse(address)
|
parsed_url = urlparse(address)
|
||||||
self.nodes.add(parsed_url.netloc)
|
self.nodes.add(parsed_url.netloc)
|
||||||
|
|
||||||
def valid_chain(self, chain: List[Dict[str, Any]]) -> bool:
|
def valid_chain(self, chain):
|
||||||
"""
|
"""
|
||||||
Determine if a given blockchain is valid
|
Determine if a given blockchain is valid
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class Blockchain:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def resolve_conflicts(self) -> bool:
|
def resolve_conflicts(self):
|
||||||
"""
|
"""
|
||||||
This is our consensus algorithm, it resolves conflicts
|
This is our consensus algorithm, it resolves conflicts
|
||||||
by replacing our chain with the longest one in the network.
|
by replacing our chain with the longest one in the network.
|
||||||
|
@ -91,7 +91,7 @@ class Blockchain:
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def new_block(self, proof: int, previous_hash: Optional[str]) -> Dict[str, Any]:
|
def new_block(self, proof, previous_hash):
|
||||||
"""
|
"""
|
||||||
Create a new Block in the Blockchain
|
Create a new Block in the Blockchain
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class Blockchain:
|
||||||
self.chain.append(block)
|
self.chain.append(block)
|
||||||
return block
|
return block
|
||||||
|
|
||||||
def new_transaction(self, sender: str, recipient: str, amount: int) -> int:
|
def new_transaction(self, sender, recipient, amount):
|
||||||
"""
|
"""
|
||||||
Creates a new transaction to go into the next mined Block
|
Creates a new transaction to go into the next mined Block
|
||||||
|
|
||||||
|
@ -132,11 +132,11 @@ class Blockchain:
|
||||||
return self.last_block['index'] + 1
|
return self.last_block['index'] + 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_block(self) -> Dict[str, Any]:
|
def last_block(self):
|
||||||
return self.chain[-1]
|
return self.chain[-1]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def hash(block: Dict[str, Any]) -> str:
|
def hash(block):
|
||||||
"""
|
"""
|
||||||
Creates a SHA-256 hash of a Block
|
Creates a SHA-256 hash of a Block
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class Blockchain:
|
||||||
block_string = json.dumps(block, sort_keys=True).encode()
|
block_string = json.dumps(block, sort_keys=True).encode()
|
||||||
return hashlib.sha256(block_string).hexdigest()
|
return hashlib.sha256(block_string).hexdigest()
|
||||||
|
|
||||||
def proof_of_work(self, last_proof: int) -> int:
|
def proof_of_work(self, last_proof):
|
||||||
"""
|
"""
|
||||||
Simple Proof of Work Algorithm:
|
Simple Proof of Work Algorithm:
|
||||||
- Find a number p' such that hash(pp') contains leading 4 zeroes, where p is the previous p'
|
- Find a number p' such that hash(pp') contains leading 4 zeroes, where p is the previous p'
|
||||||
|
@ -161,7 +161,7 @@ class Blockchain:
|
||||||
return proof
|
return proof
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def valid_proof(last_proof: int, proof: int) -> bool:
|
def valid_proof(last_proof, proof):
|
||||||
"""
|
"""
|
||||||
Validates the Proof
|
Validates the Proof
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue