diff --git a/src/api/scoreStore/addTx.js b/src/api/scoreStore/addTx.js index 413086b..e9682fa 100644 --- a/src/api/scoreStore/addTx.js +++ b/src/api/scoreStore/addTx.js @@ -9,12 +9,11 @@ import { callAddScore, callLastId } from "../../utils/scoreStore_contract.js"; */ export async function addTx(request, reply, fastify) { try { - const id = await callLastId(); - const tx = callAddScore(request.body.p1, request.body.p2, request.body.p1Score, request.body.p2Score); + const {tx, id} = await callAddScore(request.body.p1, request.body.p2, request.body.p1Score, request.body.p2Score); - tx.then(tx => { - scoreDB.addTx(id, tx.hash); - }); + scoreDB.addTx(id, tx.hash); + // tx.then(tx => { + // }); return reply.code(200).send({ id: Number(id) diff --git a/src/utils/scoreStore_contract.js b/src/utils/scoreStore_contract.js index b8ada16..f3e6ef2 100644 --- a/src/utils/scoreStore_contract.js +++ b/src/utils/scoreStore_contract.js @@ -54,8 +54,9 @@ async function callAddScore(p1, p2, p1Score, p2Score) { const tx = await contract.addScore(p1, p2, p1Score, p2Score); console.log('Transaction sent:', tx.hash); await tx.wait(); // Wait for the transaction to be mined + const id = await callLastId(); console.log('Transaction confirmed'); - return tx; + return { tx, id }; } catch (error) { console.error('Error calling addScore function:', error); throw error;