From c1c06e70d20cb2a8c08788bd59b1ddad63c258d3 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 27 Nov 2023 14:44:46 -0800 Subject: [PATCH] feat(warp): add sort key for interactions Its a deterministic formula provided by warp. --- src/api/graphql.ts | 10 +++++++++- src/types.ts | 1 + tests/integration/routes.test.ts | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/api/graphql.ts b/src/api/graphql.ts index e64e0bf..dc57370 100644 --- a/src/api/graphql.ts +++ b/src/api/graphql.ts @@ -16,7 +16,7 @@ */ import Arweave from 'arweave'; import { ArNSInteraction } from '../types.js'; -import { GQLEdgeInterface, TagsParser } from 'warp-contracts'; +import { LexicographicalInteractionsSorter, TagsParser } from 'warp-contracts'; import logger from '../logger'; export const MAX_REQUEST_SIZE = 100; @@ -109,6 +109,7 @@ export async function getWalletInteractionsForContract( >; }> { const parser = new TagsParser(); + const interactionSorter = new LexicographicalInteractionsSorter(arweave); const { address, contractTxId } = params; let hasNextPage = false; let cursor: string | undefined; @@ -149,6 +150,7 @@ export async function getWalletInteractionsForContract( value } block { + id height timestamp } @@ -187,9 +189,15 @@ export async function getWalletInteractionsForContract( const parsedInput = inputTag?.value ? JSON.parse(inputTag.value) : undefined; + const sortKey = await interactionSorter.createSortKey( + e.block.id, + e.node.id, + e.block.height, + ); interactions.set(e.node.id, { height: e.node.block.height, timestamp: e.node.block.timestamp, + sortKey, input: parsedInput, owner: e.node.owner.address, }); diff --git a/src/types.ts b/src/types.ts index a5baa1e..6528c7f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -54,6 +54,7 @@ export type ArNSInteraction = { input: PstInput | undefined; height: number; owner: string; + sortKey: string; timestamp: number; errorMessage?: string; }; diff --git a/tests/integration/routes.test.ts b/tests/integration/routes.test.ts index 1fdcbb9..f78c469 100644 --- a/tests/integration/routes.test.ts +++ b/tests/integration/routes.test.ts @@ -18,7 +18,10 @@ import { describe } from 'mocha'; import { expect } from 'chai'; import axiosPackage from 'axios'; import { arweave, createLocalWallet, warp } from './setup.test'; -import { JWKInterface } from 'warp-contracts'; +import { + JWKInterface, + LexicographicalInteractionsSorter, +} from 'warp-contracts'; import * as path from 'path'; import * as fs from 'fs'; import { ArNSInteraction } from '../../src/types'; @@ -37,6 +40,7 @@ describe('Integration tests', () => { let transferToAddress: string; let walletJWK: JWKInterface; const contractInteractions: ArNSInteraction[] = []; + const interactionSorter = new LexicographicalInteractionsSorter(arweave); before(async function () { // set a large timeout to 10 secs @@ -84,6 +88,11 @@ describe('Integration tests', () => { input: transferInteraction, owner: walletAddress, timestamp: Math.floor(interactionBlock.timestamp / 1000), + sortKey: await interactionSorter.createSortKey( + interactionBlock.hash, + writeInteraction?.originalTxId, + interactionBlock.height, + ), valid: true, id: writeInteraction!.originalTxId, });