From f50bd347e0ef6e1e48c14702155b61e8253968b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= Date: Sat, 28 Oct 2017 13:29:35 +0200 Subject: [PATCH] Accept URLs without scheme (also includes #18 and #28) --- blockchain.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blockchain.py b/blockchain.py index f55b269..cbb95a8 100644 --- a/blockchain.py +++ b/blockchain.py @@ -26,7 +26,14 @@ class Blockchain: """ parsed_url = urlparse(address) - self.nodes.add(parsed_url.netloc) + if parsed_url.netloc: + self.nodes.add(parsed_url.netloc) + elif parsed_url.path: + # Accepts an URL without scheme like '192.168.0.5:5000'. + self.nodes.add(parsed_url.path) + else: + raise ValueError('Invalid URL') + def valid_chain(self, chain: List[Dict[str, Any]]) -> bool: """ @@ -132,7 +139,7 @@ class Blockchain: return self.last_block['index'] + 1 @property - def last_block(self) -> Dict[str: Any]: + def last_block(self) -> Dict[str, Any]: return self.chain[-1] @staticmethod @@ -201,7 +208,7 @@ def mine(): ) # Forge the new Block by adding it to the chain - block = blockchain.new_block(proof) + block = blockchain.new_block(proof, []) response = { 'message': "New Block Forged",