add verify command
This commit is contained in:
parent
a66fb691e4
commit
8c4ec3ebc1
|
|
@ -179,3 +179,15 @@ class Blockchain:
|
||||||
self.writeBlocks()
|
self.writeBlocks()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def isChainValid(self):
|
||||||
|
"""
|
||||||
|
Method to verify integrity of blockchain
|
||||||
|
"""
|
||||||
|
for i in range(1, len(self.chain)):
|
||||||
|
eachBlock = self.chain[i]
|
||||||
|
if eachBlock.hash != eachBlock.calculateHash():
|
||||||
|
return i
|
||||||
|
if eachBlock.previousHash != self.chain[i-1].hash:
|
||||||
|
return i
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
|
||||||
11
bscli.py
11
bscli.py
|
|
@ -27,6 +27,7 @@ SUPPORTED_COMMANDS = [
|
||||||
'getblock',
|
'getblock',
|
||||||
'help',
|
'help',
|
||||||
'modify',
|
'modify',
|
||||||
|
'verify',
|
||||||
]
|
]
|
||||||
|
|
||||||
def printLogo():
|
def printLogo():
|
||||||
|
|
@ -161,6 +162,16 @@ def modify(args):
|
||||||
else:
|
else:
|
||||||
throwError("Block modification failed!")
|
throwError("Block modification failed!")
|
||||||
|
|
||||||
|
def verify(cmd):
|
||||||
|
"""
|
||||||
|
Method to verify the validity of blockchain.
|
||||||
|
"""
|
||||||
|
chain_valid = coin.isChainValid()
|
||||||
|
if chain_valid == 0:
|
||||||
|
printSuccess("Blockchain is valid!")
|
||||||
|
else:
|
||||||
|
throwError(f"Blockchain is not valid! Error on block {chain_valid}. Altered Chain!")
|
||||||
|
|
||||||
def throwError(msg):
|
def throwError(msg):
|
||||||
"""
|
"""
|
||||||
Method to throw an error from Blockshell.
|
Method to throw an error from Blockshell.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue