Skip to content

Commit

Permalink
fix(types): remove ArweaveTransactionID type for now
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 14, 2024
1 parent f6c4f8b commit 3adf53b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 48 deletions.
3 changes: 1 addition & 2 deletions src/common/ArIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ArweaveTransactionID } from '../types.js';
import { ContractStateProvider } from '../types.js';
import { DefaultLogger } from './logger.js';

Expand Down Expand Up @@ -46,7 +45,7 @@ export class ArIO implements ContractStateProvider {
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: ArweaveTransactionID;
contractTxId: string;
}): Promise<ContractState> {
return this.contractStateProvider.getContractState({ contractTxId });
}
Expand Down
8 changes: 2 additions & 6 deletions src/common/ContractStateProviders/ArNSRemoteCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {
ArweaveTransactionID,
ContractStateProvider,
HTTPClient,
} from '../../types.js';
import { ContractStateProvider, HTTPClient } from '../../types.js';
import { AxiosHTTPService } from '../http.js';
import { DefaultLogger } from '../logger.js';

Expand Down Expand Up @@ -46,7 +42,7 @@ export class ArNSRemoteCache implements ContractStateProvider {
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: ArweaveTransactionID;
contractTxId: string;
}): Promise<ContractState> {
this.logger.debug(`Fetching contract state`);

Expand Down
38 changes: 1 addition & 37 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@
import { Readable } from 'stream';
import { ReadableStream } from 'stream/web';

import { ARWEAVE_TX_REGEX } from './constants.js';

export interface ContractStateProvider {
/**
* The ContractStateProvider interface is used to define a contract state provider.
*/
getContractState<T>({
contractTxId,
}: {
contractTxId: ArweaveTransactionID;
}): Promise<T>;
getContractState<T>({ contractTxId }: { contractTxId: string }): Promise<T>;
}
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface Logger {
Expand Down Expand Up @@ -66,33 +60,3 @@ export interface HTTPClient {
data: Readable | ReadableStream | Buffer;
}): Promise<T>;
}

export interface Equatable<T> {
equals(other: T): boolean;
}

export class ArweaveTransactionID implements Equatable<ArweaveTransactionID> {
constructor(private readonly transactionId?: string) {
if (transactionId === undefined || !ARWEAVE_TX_REGEX.test(transactionId)) {
throw new Error(
'Transaction ID should be a 43-character, alphanumeric string potentially including "-" and "_" characters.',
);
}
}

[Symbol.toPrimitive](hint?: string): string {
if (hint === 'number') {
throw new Error('Transaction IDs cannot be interpreted as a number!');
}

return this.toString();
}

toString(): string {
return this.transactionId ?? '';
}

equals(entityId: ArweaveTransactionID): boolean {
return this.transactionId === entityId.transactionId;
}
}
5 changes: 2 additions & 3 deletions tests/ArNSRemoteCache.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ArIO } from '../src/common/ArIO.js';
import { ArNSRemoteCache } from '../src/common/ContractStateProviders/ArNSRemoteCache.js';
import { ArweaveTransactionID } from '../src/types.js';

describe('ArIO Client', () => {
const remoteCacheProvider = new ArNSRemoteCache({});
Expand All @@ -16,15 +15,15 @@ describe('ArIO Client', () => {

const stubGetContractState = jest.fn();
remoteProvider.getContractState = stubGetContractState;
const contractTxId = new ArweaveTransactionID(''.padEnd(43, 'a'));
const contractTxId = ''.padEnd(43, 'a');
await client.getContractState({ contractTxId });
expect(stubGetContractState).toHaveBeenCalledWith({ contractTxId });
});

it('should throw on bad contract id', async () => {
let result;
try {
const contractTxId = new ArweaveTransactionID(''.padEnd(42, 'a'));
const contractTxId = ''.padEnd(42, 'a');
result = await arioClient
.getContractState({ contractTxId })
.catch((e) => e);
Expand Down

0 comments on commit 3adf53b

Please sign in to comment.