老师我挖矿的时候一直提示这个错误,帮我看一下吧
来源:3-8 挖矿接口实现

慕UI6354368
2018-05-25
#postman提示: #<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> #<title>500 Internal Server Error</title> #<h1>Internal Server Error</h1> #<p>The server encountered an internal error and was unable to complete your request. # Either the server is overloaded or there is an error in the application.</p> # 'previous_hash': previous_hash or self.hash(self.last_block[-1]), #KeyError: -1 #127.0.0.1 - - [25/May/2018 09:52:18] "GET /mine HTTP/1.1" 500 - def new_block(self,proof,previous_hash=None): block = { 'index': len(self.chain) + 1, 'timestamp': time(), 'transacations': self.current_transactions, 'proof': proof, 'previous_hash': previous_hash or self.hash(self.last_block[-1]), } self.current_transactions = [] self.chain.append(block) return block @app.route('/mine',methods=['GET']) def mine(): last_block = blockchain.last_block last_proof = last_block['proof'] proof=blockchain.proof_of_work(last_proof) blockchain.new_transaction(sender="0",recipient=node_identifier,amount=1,) block = blockchain.new_block(proof,None) response = { "message": "New Block Forged", "index": block['index'], "transaction": block['transactions'], "proof": block['proof'], "previous_hash": block['previous_hash'] } return jsonify(response),200
写回答
1回答
-
lastblock 应该是 chain吧?
012018-05-27
相似问题