WSGIRequest не является вызываемым "блокчейн-проектом

Я работаю над проектом блокчейна, но у меня возникла проблема, которую я не смог решить самостоятельно, и здесь я делюсь всеми деталями проекта.

Добыча нового блока

    def mine_block(request):
    if request.method == 'GET':
        previous_block = blockchain.get_last_block()
        previous_nonce = previous_block['nonce']
        nonce = blockchain.proof_of_work(previous_nonce)
        previous_hash = blockchain.hash(previous_block)
        blockchain.add_transaction(sender = root_node, receiver = node_address, amount = 1.15, time=str(datetime.datetime.now()))
        block = blockchain.create_block(nonce, previous_hash)
        response = render(request({'message': 'Congratulations, you just mined a block!',
                    'index': block['index'],
                    'timestamp': block['timestamp'],
                    'nonce': block['nonce'],
                    'previous_hash': block['previous_hash'],
                    'transactions': block['transactions']}))
    return render(JsonResponse(response))
‍```
# Getting the full Blockchain
‍‍‍‍‍```
def get_chain(request):
    if request.method == 'GET':
        response = render(request({'chain': blockchain.chain,
                    'length': len(blockchain.chain)}))
    return render(request,JsonResponse(response))

Проверка достоверности блокчейна

def is_valid(request):
    if request.method == 'GET':
        is_valid = blockchain.is_chain_valid(blockchain.chain)
        if is_valid:
            response = render(request({'message': 'All good. The Blockchain is valid.'}))
        else:
            response = render(request({'message': 'Houston, we have a problem. The Blockchain is not valid.'}))
    return render(request,JsonResponse(response))

Добавление новой транзакции в блокчейн



@csrf_exempt
def add_transaction(request): #New
    if request.method == 'POST':
        received_json = json.loads(request.body)
        transaction_keys = ['sender', 'receiver', 'amount','time']
        if not all(key in received_json for key in transaction_keys):
            return 'Some elements of the transaction are missing', HttpResponse(request(status=400))
        index = blockchain.add_transaction(received_json['sender'], received_json['receiver'], received_json['amount'],received_json['time'])
        response = render(request({'message': f'This transaction will be added to Block {index}'}))
    return render(request,JsonResponse(response))


Подключение новых узлов

@csrf_exempt
def connect_node(request): #New
    if request.method == 'POST':
        received_json = json.loads(request.body)
        nodes = received_json.get('nodes')
        if nodes is None:
            return "No node", HttpResponse(request(status=400))
        for node in nodes:
            blockchain.add_node(node)
        response = render(request({'message': 'All the nodes are now connected. The Sudocoin Blockchain now contains the following nodes:',
                    'total_nodes': list(blockchain.nodes)}))
    return render(request,JsonResponse(response))

Замена цепи на самую длинную при необходимости

def replace_chain(request): #New
    if request.method == 'GET':
  is_chain_replaced = blockchain.replace_chain()
        if is_chain_replaced:
            response = render(request({'message': 'The nodes had different chains so the chain was replaced by the longest one.',
                        'new_chain': blockchain.chain}))
        else:
            response = render(request({'message': 'All good. The chain is the largest one.',
                        'actual_chain': blockchain.chain}))
    return render(request,JsonResponse(response))

это мой код

TypeError: 'WSGIRequest' object is not callable

это ошибка

Django version==4
python==3.8

и версии Django и Python Спасибо, что подсказали решение

Вернуться на верх