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

feat(gql): add sortKey and validate interactions from GQL #74

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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.node.block.id,
e.node.id,
e.node.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.indep_hash,
writeInteraction!.originalTxId,
interactionBlock.height,
),
valid: true,
id: writeInteraction!.originalTxId,
});
Expand Down