Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat(warp): add sort key for interactions
Browse files Browse the repository at this point in the history
Its a deterministic formula provided by warp.
  • Loading branch information
dtfiedler committed Nov 27, 2023
1 parent ab7dfdb commit c1c06e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +150,7 @@ export async function getWalletInteractionsForContract(
value
}
block {
id
height
timestamp
}
Expand Down Expand Up @@ -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,
});
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type ArNSInteraction = {
input: PstInput | undefined;
height: number;
owner: string;
sortKey: string;
timestamp: number;
errorMessage?: string;
};
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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,
});
Expand Down

0 comments on commit c1c06e7

Please sign in to comment.