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

Commit

Permalink
fix(gql): validate tags for gql interactions
Browse files Browse the repository at this point in the history
This will throw out any poorly formatted tags when fetching interactions from gql.
  • Loading branch information
dtfiedler committed Nov 27, 2023
1 parent 77ee231 commit ab7dfdb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import Arweave from 'arweave';
import { ArNSInteraction } from '../types.js';
import { GQLEdgeInterface, TagsParser } from 'warp-contracts';

Check failure on line 19 in src/api/graphql.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

'GQLEdgeInterface' is defined but never used
import logger from '../logger';

export const MAX_REQUEST_SIZE = 100;

Expand Down Expand Up @@ -170,9 +171,19 @@ export async function getWalletInteractionsForContract(
if (!response.data.data?.transactions?.edges?.length) {
continue;
}
response.data.data.transactions.edges.forEach((e: GQLEdgeInterface) => {
for (const e of response.data.data.transactions.edges) {
// basic validation for smartweave tags
const inputTag = parser.getInputTag(e.node, contractTxId);

const contractTag = parser.getContractTag(e.node);
if (!inputTag || !contractTag) {
logger.debug('Invalid tags for interaction via GQL, ignoring...', {
contractTxId,
interactionId: e.node.id,
inputTag,
contractTag,
});
continue;
}
const parsedInput = inputTag?.value
? JSON.parse(inputTag.value)
: undefined;
Expand All @@ -182,7 +193,7 @@ export async function getWalletInteractionsForContract(
input: parsedInput,
owner: e.node.owner.address,
});
});
}
cursor =
response.data.data.transactions.edges[MAX_REQUEST_SIZE - 1]?.cursor ??
undefined;
Expand Down

0 comments on commit ab7dfdb

Please sign in to comment.