Skip to content

Commit

Permalink
Merge pull request #18 from availproject/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
moraesjeremias authored Aug 2, 2024
2 parents 7befed3 + e59f6a7 commit 9947aed
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 10 deletions.
11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ model availsends {
amount String?
message String?
dataType String
@@index([depositorAddress], map: "idx_depositorAddress_avl")
@@index([receiverAddress], map: "idx_receiverAddress_avl")
@@index([depositorAddress, status], map: "idx_status_depositorAddress_avl")
@@index([receiverAddress, status], map: "idx_status_receiverAddress_avl")
}

model ethereumsends {
Expand All @@ -55,4 +61,9 @@ model ethereumsends {
amount String?
message String?
dataType String
@@index([depositorAddress], map: "idx_depositorAddress_eth")
@@index([receiverAddress], map: "idx_receiverAddress_eth")
@@index([depositorAddress, status], map: "idx_status_depositorAddress_eth")
@@index([receiverAddress, status], map: "idx_status_receiverAddress_eth")
}
80 changes: 70 additions & 10 deletions src/services/transaction-cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class TransactionCron {
});
let startBlockNumber = 0;
if (latestTransaction) {
startBlockNumber = Number(latestTransaction.destinationBlockNumber);
startBlockNumber = Number(latestTransaction.destinationBlockNumber) + 1;
}

let findMore = true;
Expand Down Expand Up @@ -129,7 +129,7 @@ export default class TransactionCron {
});
let startBlockNumber = 0;
if (latestTransaction) {
startBlockNumber = Number(latestTransaction.sourceBlockNumber);
startBlockNumber = Number(latestTransaction.sourceBlockNumber) + 1;
}

let findMore = true;
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class TransactionCron {
});
let startBlockNumber = 0;
if (latestTransaction) {
startBlockNumber = Number(latestTransaction.destinationBlockNumber);
startBlockNumber = Number(latestTransaction.destinationBlockNumber) + 1;
}

let findMore = true;
Expand Down Expand Up @@ -253,7 +253,10 @@ export default class TransactionCron {
},
});
} catch (error) {
logger.error("something went wrong while axios call", error);
logger.error(
"UpdateAvlToETH something went wrong while axios call",
error
);
}
}

Expand All @@ -278,7 +281,10 @@ export default class TransactionCron {
}
}
} catch (error) {
logger.error("something went wrong while axios call", error);
logger.error(
"updateEthToAvl something went wrong while axios call",
error
);
}
}
private async getLatestProcessedBlockNumber(): Promise<number> {
Expand All @@ -291,7 +297,9 @@ export default class TransactionCron {
},
take: 1,
});
return latestTransaction ? Number(latestTransaction.sourceBlockNumber) : 0;
return latestTransaction
? Number(latestTransaction.sourceBlockNumber) + 1
: 0;
}

private groupTransactionsByBlock<
Expand Down Expand Up @@ -410,6 +418,8 @@ export default class TransactionCron {
transaction.id,
"MessageExecuted"
);

logger.debug("AvailReceivePassed");
operation = this.createOperationForAvailReceive(
transaction,
event,
Expand Down Expand Up @@ -480,7 +490,20 @@ export default class TransactionCron {
: decodedData.result!.params[1].value,
dataType: "ERC20",
};
logger.info(schemaObj, "sendAVAIL");

logger.info(
{
...schemaObj,
amount_prettified: parseAmount(
transferLog
? (
decodeParameter("uint256", transferLog.logData) as BigInt
).toString()
: decodedData.result!.params[1].value
),
},
"sendAVAIL"
);

return prisma.ethereumsends.upsert({
where: { messageId: BigInt(messageId) },
Expand Down Expand Up @@ -533,7 +556,13 @@ export default class TransactionCron {
status: "CLAIMED",
};
};
logger.info(updateObj(), "receiveAVAIL");
logger.info(
{
...updateObj(),
amount_prettified: parseAmount((params[1] as string).toString()),
},
"receiveAVAIL"
);

return prisma.availsends.upsert({
where: { messageId: BigInt(messageId) },
Expand Down Expand Up @@ -570,7 +599,16 @@ export default class TransactionCron {
};

const data = event[0];
logger.info(sourceObj(), "MessageSent");

logger.info(
{
...sourceObj(),
amount_prettified: parseAmount(
BigInt(value.fungibleToken.amount).toString()
),
},
"MessageSent"
);
const operation = prisma.availsends.upsert({
where: { messageId: BigInt(data.argsValue[4]) },
update: { ...sourceObj() },
Expand Down Expand Up @@ -610,7 +648,16 @@ export default class TransactionCron {
destinationBlockHash: data.block.hash,
};
};
logger.info(sourceObj(), "MessageExecuted");

logger.info(
{
...sourceObj(),
amount_prettified: parseAmount(
new BigNumber(value.message.fungibleToken.amount, 16).toString()
),
},
"MessageExecuted"
);

return prisma.ethereumsends.upsert({
where: { messageId: BigInt(data.argsValue[2]) },
Expand All @@ -633,3 +680,16 @@ export default class TransactionCron {
}
}
}

function parseAmount(numberString: string): string {
try {
const divisor = BigInt(10 ** 18);

const number = BigInt(numberString);
const result = number / divisor;

return result.toString();
} catch (e) {
return "";
}
}

0 comments on commit 9947aed

Please sign in to comment.