From 042560e8b70c4baee6e69d67150dab2b0fb64eaf Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Thu, 9 Jan 2025 16:16:30 +0000 Subject: [PATCH] Refactor address validation: update isAddress method to return ContractAddress type for improved type safety --- typescript/ethers-v5/src/ethers5Adapter.ts | 5 ++++- typescript/ethers-v6/src/ethers6Adapter.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/typescript/ethers-v5/src/ethers5Adapter.ts b/typescript/ethers-v5/src/ethers5Adapter.ts index f897e95..08fd690 100644 --- a/typescript/ethers-v5/src/ethers5Adapter.ts +++ b/typescript/ethers-v5/src/ethers5Adapter.ts @@ -5,6 +5,9 @@ import { FunctionCall } from "@skalenetwork/skale-contracts"; import { BaseContract, ethers } from "ethers"; +import { + ContractAddress +} from "@skalenetwork/skale-contracts/lib/domain/types"; import { Provider } from "@ethersproject/providers"; @@ -47,7 +50,7 @@ export class Ethers5Adapter implements Adapter { } // eslint-disable-next-line class-methods-use-this - isAddress (value: string): boolean { + isAddress (value: string): value is ContractAddress { return ethers.utils.isAddress(value); } } diff --git a/typescript/ethers-v6/src/ethers6Adapter.ts b/typescript/ethers-v6/src/ethers6Adapter.ts index e7d0c9b..c420c16 100644 --- a/typescript/ethers-v6/src/ethers6Adapter.ts +++ b/typescript/ethers-v6/src/ethers6Adapter.ts @@ -5,6 +5,9 @@ import { FunctionCall } from "@skalenetwork/skale-contracts"; import { BaseContract, Provider, ethers } from "ethers"; +import { + ContractAddress +} from "@skalenetwork/skale-contracts/lib/domain/types"; export class Ethers6Adapter implements Adapter { @@ -46,7 +49,7 @@ export class Ethers6Adapter implements Adapter { } // eslint-disable-next-line class-methods-use-this - isAddress (value: string): boolean { + isAddress (value: string): value is ContractAddress { return ethers.isAddress(value); } }