1
0
Fork 0

[node] fixed contracting and implemented renegotiation

This commit is contained in:
Julien Dessaux 2024-03-30 14:22:59 +01:00
parent 719a9c1a77
commit 8819cf9c67
Signed by: adyxax
GPG key ID: F92E51B86E07177E
8 changed files with 103 additions and 71 deletions

View file

@ -29,8 +29,11 @@ export async function init(): Promise<void> {
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<void> {
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();
}