From d9d420990c2fabd64a45e72aa41bd3d15470d2cc Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Fri, 28 Jul 2023 17:09:25 +0300 Subject: [PATCH] add loop for crappy rpc --- src/mappings/erc721Factory.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mappings/erc721Factory.ts b/src/mappings/erc721Factory.ts index 2f2e5d93..b5ca8eed 100644 --- a/src/mappings/erc721Factory.ts +++ b/src/mappings/erc721Factory.ts @@ -55,10 +55,16 @@ export function handleNewToken(event: TokenCreated): void { token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18) // get token id const contract = ERC20Template.bind(event.params.newTokenAddress) - const contractTemplate = contract.try_getId() - if (!contractTemplate.reverted) { - token.templateId = contractTemplate.value - } + let tries = 0 + // protect against crappy rpc + do { + const contractTemplate = contract.try_getId() + if (!contractTemplate.reverted) { + token.templateId = contractTemplate.value + break + } + tries++ + } while (tries < 300) token.save() addDatatoken() if (token.templateId == 3) {