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

Commit

Permalink
Merge pull request #64 from ar-io/add-multi-write-support
Browse files Browse the repository at this point in the history
Fix(interactions route): Add multi contract write support
  • Loading branch information
atticusofsparta authored Nov 27, 2023
2 parents 5893994 + 26d8b69 commit 841843a
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions src/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import Arweave from 'arweave';
import { ArNSInteraction } from '../types.js';
import { GQLEdgeInterface, TagsParser } from 'warp-contracts';

export const MAX_REQUEST_SIZE = 100;

Expand Down Expand Up @@ -106,6 +107,7 @@ export async function getWalletInteractionsForContract(
Omit<ArNSInteraction, 'valid' | 'errorMessage' | 'id'>
>;
}> {
const parser = new TagsParser();
const { address, contractTxId } = params;
let hasNextPage = false;
let cursor: string | undefined;
Expand Down Expand Up @@ -167,30 +169,18 @@ export async function getWalletInteractionsForContract(
if (!response.data.data?.transactions?.edges?.length) {
continue;
}
response.data.data.transactions.edges.forEach(
(e: {
cursor: string;
node: {
block: { height: number };
owner: { address: string };
id: string;
tags: { name: string; value: string }[];
};
pageInfo?: { hasNextPage: boolean };
}) => {
const interactionInput = e.node.tags.find(
(t: { name: string; value: string }) => t.name === 'Input',
);
const parsedInput = interactionInput
? JSON.parse(interactionInput.value)
: undefined;
interactions.set(e.node.id, {
height: e.node.block.height,
input: parsedInput,
owner: e.node.owner.address,
});
},
);
response.data.data.transactions.edges.forEach((e: GQLEdgeInterface) => {
const inputTag = parser.getInputTag(e.node, contractTxId);

const parsedInput = inputTag?.value
? JSON.parse(inputTag.value)
: undefined;
interactions.set(e.node.id, {
height: e.node.block.height,
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 841843a

Please sign in to comment.