0
@app.route('/nodes/resolve', methods=['GET'])
def consensus():
    replaced = blockchain.resolve_conflicts()

    if replaced:
        response = {
            'message': 'Our chain was replaced',
            'new_chain': blockchain.chain
        }
    else:
        response = {
            'message': 'Our chain is authoritative',
            'chain': blockchain.chain
        }

    return jsonify(response), 200

resolve_conflicts function :

def resolve_conflicts(self):
        neighbours = self.nodes
        new_chain = None
        max_length = len(self.chain)
        for node in neighbours:
            response = requests.get(f'http://{node}/chain')
            if response.status_code == 200:
                length = response.json()['length']
                chain = response.json()['chain']
                if length > max_length and self.valid_chain(chain):
                    max_length = length
                    new_chain = chain
        if new_chain:
            self.chain = new_chain
            return True
        return False

when i run "curl http://localhost:5000/nodes/resolve" in cmd, but it is throwing below error:

TypeError: Object of type ndarray is not JSON serializable

3
  • it seems chain = response.json()['chain'] returns numpy array which can not be serialized using json. post sample data returned in above line Commented Apr 21, 2021 at 4:54
  • source code herer : github.com/iQuHACK/2021_QryptoQuHackers , thanks for your support Commented Apr 21, 2021 at 15:03
  • I tried to improve your formatting, but it tells me It looks like your post is mostly code; please add some more details. - so this is a recommendation for you. Commented Sep 8, 2021 at 14:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.