From 8819cf9c67e33c76cbac65a9ca2b6ff86786d251 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 30 Mar 2024 14:22:59 +0100 Subject: [node] fixed contracting and implemented renegotiation --- nodejs/automation/init.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'nodejs/automation/init.ts') diff --git a/nodejs/automation/init.ts b/nodejs/automation/init.ts index 2850fac..74f42fb 100644 --- a/nodejs/automation/init.ts +++ b/nodejs/automation/init.ts @@ -29,8 +29,11 @@ export async function init(): Promise { if (json.error !== undefined) { switch(json.error?.code) { case 4111: // 4111 means the agent symbol has already been claimed so no server reset happened - await libContracts.contracts(); - await libShips.ships(); + // TODO await agents.agents(); + const contracts = await libContracts.getContracts(); + const ongoing = contracts.filter(c => !c.fulfilled); + const ships = await libShips.getShips(); + if (ongoing.length === 0) libShips.negotiate(ships[0]); return; default: throw json; @@ -42,5 +45,5 @@ export async function init(): Promise { dbContracts.setContract(json.data.contract); dbShips.setShip(json.data.ship); // Temporary fix to fetch the data on the startup probe - await libShips.ships(); + await libShips.getShips(); } -- cgit v1.2.3