We're going to refactor the /transaction endpoint in this section, so that it works perfectly with the new /transaction/broadcast endpoint. Let's apply the following steps to modify the endpoint:
- To get started, go to the dev/networkNode.js file and delete everything that is in the /transaction endpoint. The only time the /transaction endpoint will be hit is when the broadcast takes place. When the /transaction endpoint is being hit, the newTransaction variable will be sent as data. This condition can be defined as follows:
app.post('/transaction', function(req, res) {
const newTransaction = req.body;
};
In the preceding highlighted line, the newTransaction variable is sent to the /transaction endpoint with the help of req.body.
- Next, add the new transaction to the pendingTransactions array of whichever node receives...