Skip to content

Commit

Permalink
fix(validate id): make validator a private method
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 26, 2024
1 parent b35e5bd commit dce4a94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const contractTxIds = [

const balance = await arIO.mainnet.getBalance({ address });
const gateway = await arIO.mainnet.getGateway({ address });
const record = await arIO.mainnet.getRecord({ domain: 'ar-io' });;
const record = await arIO.mainnet.getRecord({ domain: 'ar-io' });
const records = await arIO.mainnet.getRecords({});
```

Expand Down
28 changes: 14 additions & 14 deletions src/common/caches/arns-remote-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ import { NotFound } from '../error.js';
import { AxiosHTTPService } from '../http.js';
import { DefaultLogger } from '../logger.js';

const validateContractTxId = (contractTxId: string) => {
if (!contractTxId) {
throw new Error(
'Contract TxId not set, set one before calling this function.',
);
}
};

export class ArNSRemoteCache implements ContractCache, ArIOContract {
private contractTxId: string;
private logger: DefaultLogger;
Expand Down Expand Up @@ -63,8 +55,16 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
return this;
}

private validateContractTxId() {
if (!this.contractTxId) {
throw new Error(
'Contract TxId not set, set one before calling this function.',
);
}
}

async getGateway({ address }: { address: string }) {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching gateway ${address}`);
const gateway = await this.getGateways().then((gateways) => {
Expand All @@ -77,7 +77,7 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
}

async getGateways() {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching gateways`);
const { result } = await this.http.get<
Expand All @@ -89,7 +89,7 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
}

async getBalance({ address }: { address: string }) {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching balance for ${address}`);
const { result } = await this.http
Expand All @@ -106,7 +106,7 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
}

async getBalances() {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching balances`);
const { result } = await this.http.get<
Expand All @@ -118,7 +118,7 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
}

async getRecord({ domain }: { domain: string }): Promise<ArNSNameData> {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching record for ${domain}`);
const { result } = await this.http.get<
Expand All @@ -130,7 +130,7 @@ export class ArNSRemoteCache implements ContractCache, ArIOContract {
}

async getRecords(): Promise<Record<string, ArNSNameData>> {
validateContractTxId(this.contractTxId);
this.validateContractTxId();

this.logger.debug(`Fetching all records`);
const { result } = await this.http.get<
Expand Down

0 comments on commit dce4a94

Please sign in to comment.