Skip to content

Commit

Permalink
improve: add topic tags
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Feb 13, 2024
1 parent c2264ce commit a9e4f16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ cache
yarn-error.log
yarn-debug.log*
gasReporterOutput.json
logs
12 changes: 10 additions & 2 deletions src/caching/Arweave/ArweaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import Arweave from "arweave";
import { JWKInterface } from "arweave/node/lib/wallet";
import { ethers } from "ethers";
import winston from "winston";
import { jsonReplacerWithBigNumbers, parseWinston } from "../../utils";
import { isDefined, jsonReplacerWithBigNumbers, parseWinston } from "../../utils";
import { Struct, is } from "superstruct";
import { ARWEAVE_TAG_APP_NAME } from "../../constants";

export class ArweaveClient {
private client: Arweave;
Expand All @@ -30,16 +31,23 @@ export class ArweaveClient {
* JSON.stringify to convert the record to a string. The record has all of its big numbers converted
* to strings for convenience.
* @param value The value to store
* @param topicTag An optional topic tag to add to the transaction
* @returns The transaction ID of the stored value
* @
*/
async set(value: Record<string, unknown>): Promise<string | undefined> {
async set(value: Record<string, unknown>, topicTag?: string | undefined): Promise<string | undefined> {
const transaction = await this.client.createTransaction(
{ data: JSON.stringify(value, jsonReplacerWithBigNumbers) },
this.arweaveJWT
);

// Add tags to the transaction
transaction.addTag("Content-Type", "application/json");
transaction.addTag("App-Name", ARWEAVE_TAG_APP_NAME);
if (isDefined(topicTag)) {
transaction.addTag("Topic", topicTag);
}

// Sign the transaction
await this.client.transactions.sign(transaction, this.arweaveJWT);
// Send the transaction
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const HUBPOOL_CHAIN_ID = 1;
// List of versions where certain UMIP features were deprecated
export const TRANSFER_THRESHOLD_MAX_CONFIG_STORE_VERSION = 1;

// A hardcoded identifier used, by default, to tag all Arweave records.
export const ARWEAVE_TAG_APP_NAME = "across-protocol";

/**
* A default list of chain Ids that the protocol supports. This is outlined
* in the UMIP (https://github.com/UMAprotocol/UMIPs/pull/590) and is used
Expand Down

0 comments on commit a9e4f16

Please sign in to comment.