diff --git a/src/common/io.ts b/src/common/io.ts index 78a994bf..3dcc9984 100644 --- a/src/common/io.ts +++ b/src/common/io.ts @@ -13,8 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Arweave from 'arweave'; - import { ARIO_TESTNET_PROCESS_ID } from '../constants.js'; import { AoArNSNameDataWithName, @@ -72,12 +70,7 @@ import { } from '../types/io.js'; import { AoSigner, mARIOToken } from '../types/token.js'; import { createAoSigner } from '../utils/ao.js'; -import { - getCurrentBlockUnixTimestampMs, - paginationParamsToTags, - pruneTags, -} from '../utils/arweave.js'; -import { defaultArweave } from './arweave.js'; +import { paginationParamsToTags, pruneTags } from '../utils/arweave.js'; import { AOProcess } from './contracts/ao-process.js'; import { InvalidContractConfigurationError } from './error.js'; @@ -118,9 +111,8 @@ export class ARIO { export class ARIOReadable implements AoARIORead { protected process: AOProcess; - private arweave: Arweave; - constructor(config?: ProcessConfiguration, arweave = defaultArweave) { + constructor(config?: ProcessConfiguration) { if (!config) { this.process = new AOProcess({ processId: ARIO_TESTNET_PROCESS_ID, @@ -134,7 +126,6 @@ export class ARIOReadable implements AoARIORead { } else { throw new InvalidContractConfigurationError(); } - this.arweave = arweave; } async getInfo(): Promise<{ @@ -170,7 +161,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (params as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -189,7 +180,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -349,15 +340,7 @@ export class ARIOReadable implements AoARIORead { async getCurrentEpoch(): Promise { return this.process.read({ - tags: [ - { name: 'Action', value: 'Epoch' }, - { - name: 'Timestamp', - value: ( - await getCurrentBlockUnixTimestampMs(this.arweave) - ).toString(), - }, - ], + tags: [{ name: 'Action', value: 'Epoch' }], }); } @@ -370,7 +353,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -390,7 +373,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -410,7 +393,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -430,7 +413,7 @@ export class ARIOReadable implements AoARIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), + Date.now().toString(), }, { name: 'Epoch-Index', @@ -497,19 +480,6 @@ export class ARIOReadable implements AoARIORead { name: 'Purchase-Type', value: type, }, - { - name: 'Timestamp', - value: ( - await this.arweave.blocks - .getCurrent() - .then((block) => { - return { timestamp: block.timestamp * 1000 }; - }) - .catch(() => { - return { timestamp: Date.now() }; // fallback to current time - }) - ).timestamp.toString(), - }, ]; return this.process.read({ @@ -554,19 +524,6 @@ export class ARIOReadable implements AoARIORead { name: 'Fund-From', value: fundFrom, }, - { - name: 'Timestamp', - value: ( - await this.arweave.blocks - .getCurrent() - .then((block) => { - return { timestamp: block.timestamp * 1000 }; - }) - .catch(() => { - return { timestamp: Date.now() }; // fallback to current time - }) - ).timestamp.toString(), - }, ]; return this.process.read({ diff --git a/src/utils/arweave.ts b/src/utils/arweave.ts index b9030949..3b6d6569 100644 --- a/src/utils/arweave.ts +++ b/src/utils/arweave.ts @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Arweave from 'arweave'; - import { ARWEAVE_TX_REGEX } from '../constants.js'; -import { BlockHeight, Timestamp } from '../types/common.js'; +import { BlockHeight } from '../types/common.js'; import { PaginationParams } from '../types/io.js'; export const validateArweaveId = (id: string): boolean => { @@ -44,19 +42,6 @@ export const pruneTags = ( ); }; -export const getCurrentBlockUnixTimestampMs = async ( - arweave: Arweave, -): Promise => { - return await arweave.blocks - .getCurrent() - .then((block) => { - return block.timestamp * 1000; - }) - .catch(() => { - return Date.now(); // fallback to current time - }); -}; - export const paginationParamsToTags = ( params?: PaginationParams, ): { name: string; value: string }[] => { diff --git a/tests/unit/utils.test.ts b/tests/unit/utils.test.ts index 022329ab..57f20111 100644 --- a/tests/unit/utils.test.ts +++ b/tests/unit/utils.test.ts @@ -1,11 +1,7 @@ -import Arweave from 'arweave'; import { strict as assert } from 'node:assert'; import { describe, it } from 'node:test'; -import { - getCurrentBlockUnixTimestampMs, - pruneTags, -} from '../../src/utils/arweave.js'; +import { pruneTags } from '../../src/utils/arweave.js'; describe('pruneTags', () => { it('should remove tags with undefined values', () => { @@ -52,15 +48,3 @@ describe('pruneTags', () => { assert.deepEqual(prunedTags, []); }); }); - -describe('getCurrentBlockUnixTimestamp', () => { - it('should return the current block timestamp', async () => { - const arweave = Arweave.init({}); - // cheap way to check the returned timestamp is within the boundaries of the async call - const minTimestamp = Date.now(); - const timestamp = await getCurrentBlockUnixTimestampMs(arweave); - const maxTimestamp = Date.now(); - assert.ok(timestamp >= minTimestamp); - assert.ok(timestamp <= maxTimestamp); - }); -});