缺少一个必需的位置参数

fcg9iug3  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(555)

我在做一个区块链项目。在我添加挖掘功能之前,它似乎没有出现任何问题。然后它指出了两个错误,即缺少位置参数。第一个是第45行的主函数,第二个是if name是主函数。从那以后。这与挖掘功能有关。代码有点长,很难理解,所以我保留了必要的部分。

from hashlib import sha3_512

## some hashing stuff

class Block():

## the variables thrown into the function

    def __init__(self, txdata, number):
         #initialize function.
    # More hashing stuff
class blockchain:
    difficulty = 4
    def __init__(self, chain=[]):
        #Initialize function. Sets up the blockchain
    def add(self,Block):
        #lables adding stuff to the chain
    def mine(self,Block):
        try:
            block.prev = self.chain[-1].get('hash')
        except IndexError:
            pass
        while True:
            if Block.hash()[:blockchain.difficulty] == "0"*blockchain.difficulty:
                self.add(Block)
                break
            else:
                Block.nonce +=1
def main():
    blockchain()
    bchain = ["Nice day stack overflow", "Once again I need help with my bad code"]
    Num = 0
    for txdata in bchain:
        Num += 1
        blockchain.mine(Block(Block.txdata, Num)) #the error popped up here. I don't get it. I tried fiddling around with it, nothing.
if __name__ == '__main__':
    main()

你能帮我解决这个错误吗。如果不修复,它可能会毁掉整个项目。错误

Traceback(most recent call last)
 File "blockchain.py", line 47 in <module>
   main()
 File "blockchain.py", line 45, in main()
   blockchain.mine(Block(Block.txdata, Num))
Type error: mine missing one positional argument: Block
mftmpeh8

mftmpeh81#

您需要保留的示例 blockchain() .

def main():
    b = blockchain()  # keep hold of the instance in b
    bchain = ["Nice day stack overflow", "Once again I need help with my bad code"]
    Num = 0
    for txdata in bchain:
        Num += 1
        b.mine(Block(Block.txdata, Num))   # Use the instance here
if __name__ == '__main__':
    main()

相关问题