Skip to content

Commit

Permalink
fix: replace all the null bytecodes from token fields before saving i… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters committed Oct 18, 2023
1 parent 3aeffe2 commit e8bfbdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
6 changes: 5 additions & 1 deletion packages/worker/src/blockchain/blockchain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ export class BlockchainService implements OnModuleInit {
erc20Contract.decimals(),
erc20Contract.name(),
]);
return { symbol, decimals, name };
return {
symbol: symbol?.replace(/\0/g, ""),
decimals,
name: name?.replace(/\0/g, ""),
};
}

public async getBalance(address: string, blockNumber: number, tokenAddress: string): Promise<BigNumber> {
Expand Down
28 changes: 7 additions & 21 deletions packages/worker/src/token/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,13 @@ export class TokenService {
tokenAddress: contractAddress.address,
});

try {
await this.tokenRepository.upsert({
...erc20Token,
blockNumber: contractAddress.blockNumber,
transactionHash: contractAddress.transactionHash,
l2Address: contractAddress.address,
logIndex: contractAddress.logIndex,
});
} catch (err) {
// tmp fix for invalid byte sequence for encoding "UTF8"
if (err.code === "22021") {
this.logger.error({
message: "Skipping token with fields having invalid byte sequence for encoding UTF8",
blockNumber: contractAddress.blockNumber,
transactionHash: contractAddress.transactionHash,
tokenAddress: contractAddress.address,
});
return;
}
throw err;
}
await this.tokenRepository.upsert({
...erc20Token,
blockNumber: contractAddress.blockNumber,
transactionHash: contractAddress.transactionHash,
l2Address: contractAddress.address,
logIndex: contractAddress.logIndex,
});
}
}
}

0 comments on commit e8bfbdf

Please sign in to comment.