Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
hashlib在python中编写区块链_Python - Fatal编程技术网

hashlib在python中编写区块链

hashlib在python中编写区块链,python,Python,我正在尝试创建一个区块链。运行时,我收到以下错误: " File "<ipython-input-3-7d6dab8d7cb5>", line 50 content_hash= hashlib.sha256(content).hexdigest() ^ SyntaxError: invalid syntax" 错误实际上是前几行的结果。它们没有正确关闭(您忘记了结束括号“}”)…因此解释器试图将下一行包含在它们中,并且不知道如何执行 更正:

我正在尝试创建一个区块链。运行时,我收到以下错误:

"  File "<ipython-input-3-7d6dab8d7cb5>", line 50
    content_hash= hashlib.sha256(content).hexdigest()
               ^
SyntaxError: invalid syntax"

错误实际上是前几行的结果。它们没有正确关闭(您忘记了结束括号“}”)…因此解释器试图将下一行包含在它们中,并且不知道如何执行

更正:

def valid_proof(self, index, hash_of_previous_block, transactions, nonce):
    #create a string containing the hash of the previous block and the block content, including the nonce 
    content ={
              f'{index}{hash_of_previous_block}{transactions}{nonce}'.encode()
              }
    #hash using sha256
    content_hash = hashlib.sha256(content).hexdigest()

您从未关闭过花括号
content={
,直到
返回后,您才可以这样做
def valid_proof(self, index, hash_of_previous_block, transactions, nonce):
    #create a string containing the hash of the previous block and the block content, including the nonce 
    content ={
              f'{index}{hash_of_previous_block}{transactions}{nonce}'.encode()
              }
    #hash using sha256
    content_hash = hashlib.sha256(content).hexdigest()