Skip to content

Commit

Permalink
fix: remove node-localstorage, add StorageProvider interface (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopavezi authored Dec 5, 2024
1 parent cf4c125 commit e6a80ce
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 49 deletions.
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ services:
restart: on-failure:20
graph-deploy:
build:
context: https://github.com/RequestNetwork/docker-images.git#main
dockerfile: request-subgraph-storage/Dockerfile
context: https://github.com/RequestNetwork/docker-images.git#main:request-subgraph-storage
dockerfile: ./Dockerfile
depends_on:
- ipfs
- postgres
- graph-node
- ganache
environment:
GRAPH_NODE: 'http://graph-node:8020'
IPFS_HOST: 'ipfs:5001'
IPFS_HOST: 'http://ipfs:5001'
KEEP_ALIVE: 0
SUBGRAPH_FILE: 'subgraph-private.yaml'
restart: on-failure:20
4 changes: 1 addition & 3 deletions packages/lit-protocol-cipher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@
"@requestnetwork/request-client.js": "0.51.0",
"@requestnetwork/types": "0.46.0",
"@walletconnect/modal": "2.7.0",
"ethers": "5.7.2",
"node-localstorage": "3.0.5"
"ethers": "5.7.2"
},
"devDependencies": {
"@types/node": "18.11.9",
"@types/node-localstorage": "1.3.3",
"jest-junit": "16.0.0",
"ts-node": "10.9.1",
"typescript": "5.1.3"
Expand Down
33 changes: 10 additions & 23 deletions packages/lit-protocol-cipher/src/lit-protocol-cipher-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AuthSig,
LIT_NETWORKS_KEYS,
AuthCallbackParams,
StorageProvider,
} from '@lit-protocol/types';
import {
LitAccessControlConditionResource,
Expand All @@ -16,7 +17,8 @@ import {
} from '@lit-protocol/auth-helpers';
import { Signer } from 'ethers';
import { LIT_ABILITY } from '@lit-protocol/constants';
import { disconnectWeb3, LitNodeClient, LitNodeClientNodeJs } from '@lit-protocol/lit-node-client';
import { disconnectWeb3, LitNodeClient } from '@lit-protocol/lit-node-client';
import type { LitNodeClientNodeJs } from '@lit-protocol/lit-node-client';

/**
* @class LitProvider
Expand Down Expand Up @@ -53,7 +55,7 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
/**
* @property {any} storageProvider - The storage provider for the Node.js Lit client.
*/
private storageProvider: any | null = null;
private nodeJsStorageProvider: StorageProvider | undefined;

/**
* @property {boolean} debug - A boolean indicating if debug mode is enabled.
Expand All @@ -75,11 +77,13 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
network: LIT_NETWORKS_KEYS,
nodeConnectionConfig: NodeConnectionConfig,
debug?: boolean,
nodeJsStorageProvider?: StorageProvider,
) {
this.chain = chain;
this.network = network;
this.dataAccess = new HttpDataAccess({ nodeConnectionConfig });
this.debug = debug || false;
this.nodeJsStorageProvider = nodeJsStorageProvider;
}

/**
Expand All @@ -98,27 +102,10 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
});
await this.client.connect();
} else {
// Evaluate the code in a way that prevents static analysis
const getNodeStorage = new Function(
`
return import('node-localstorage').then(m => m.LocalStorage);
`,
);

const LocalStorage = await getNodeStorage();
const localStorage = new LocalStorage('./request-network-lit-protocol-cipher');

this.storageProvider = {
getItem: (key: string) => localStorage.getItem(key),
setItem: (key: string, value: string) => localStorage.setItem(key, value),
removeItem: (key: string) => localStorage.removeItem(key),
clear: () => localStorage.clear(),
provider: localStorage,
};

const { LitNodeClientNodeJs } = await import('@lit-protocol/lit-node-client');
this.client = new LitNodeClientNodeJs({
litNetwork: this.network,
storageProvider: this.storageProvider,
storageProvider: this.nodeJsStorageProvider,
debug: this.debug,
});

Expand All @@ -139,8 +126,8 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
disconnectWeb3();
}
this.sessionSigs = null;
if (this.storageProvider) {
this.storageProvider.clear();
if (this.nodeJsStorageProvider) {
this.nodeJsStorageProvider.provider.clear();
}
}

Expand Down
19 changes: 19 additions & 0 deletions packages/request-client.js/src/api/request-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default class RequestNetwork {
private contentData: ContentDataExtension;
private currencyManager: CurrencyTypes.ICurrencyManager;

private cipherProvider?: CipherProviderTypes.ICipherProvider;

/**
* @param dataAccess instance of data-access layer
* @param signatureProvider module in charge of the signatures
Expand Down Expand Up @@ -72,6 +74,23 @@ export default class RequestNetwork {
this.currencyManager,
paymentOptions,
);
this.cipherProvider = cipherProvider;
}

/**
* Get the cipher provider
* @returns the cipher provider
*/
public getCipherProvider(): CipherProviderTypes.ICipherProvider | undefined {
return this.cipherProvider;
}

/**
* Set the cipher provider
* @param cipherProvider the cipher provider
*/
public setCipherProvider(cipherProvider: CipherProviderTypes.ICipherProvider): void {
this.cipherProvider = cipherProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import request from 'supertest';
import { getRequestNode } from '../src/server';
import { RequestNode } from '../src/requestNode';

jest.setTimeout(20000);
jest.setTimeout(30000);
const time = Date.now();
const channelId = `01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${time}`;
const anotherChannelId = `01bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb${time}`;
Expand Down
2 changes: 2 additions & 0 deletions packages/request-node/test/persistTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const badlyFormattedTransactionData = { not: 'a transaction' };
let requestNodeInstance: RequestNode;
let server: any;

jest.setTimeout(30000);

const mockServer = setupServer();

/* eslint-disable no-magic-numbers */
Expand Down
4 changes: 2 additions & 2 deletions packages/thegraph-data-access/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ query GetTransactionsByTopics($topics: [String!]!, $first: Int!, $skip: Int!) {
${metaQueryBody}
channels(
where: { topics_contains: $topics }
first: $first
skip: $skip
){
transactions(
orderBy: blockTimestamp,
orderDirection: asc
first: $first
skip: $skip
) {
...TransactionsBody
}
Expand Down
4 changes: 2 additions & 2 deletions packages/thegraph-data-access/src/subgraph-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class SubgraphClient implements StorageTypes.IIndexer {
private graphql: GraphQLClient;
public readonly endpoint: string;

private readonly DEFAULT_PAGE_SIZE = 10;
private readonly MAX_PAGE_SIZE = 100;
private readonly DEFAULT_PAGE_SIZE = 100;
private readonly MAX_PAGE_SIZE = 1000;

constructor(endpoint: string, options?: RequestConfig) {
this.endpoint = endpoint;
Expand Down
16 changes: 1 addition & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5921,13 +5921,6 @@
"@types/node" "*"
form-data "^4.0.0"

"@types/node-localstorage@1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@types/node-localstorage/-/node-localstorage-1.3.3.tgz#b221f1bd6c61a2cc6b16c9934f2110779568f185"
integrity sha512-Wkn5g4eM5x10UNV9Xvl9K6y6m0zorocuJy4WjB5muUdyMZuPbZpSJG3hlhjGHe1HGxbOQO7RcB+jlHcNwkh+Jw==
dependencies:
"@types/node" "*"

"@types/node@*":
version "14.14.35"
resolved "https://registry.npmjs.org/@types/node/-/node-14.14.35.tgz"
Expand Down Expand Up @@ -18615,13 +18608,6 @@ node-int64@^0.4.0:
resolved "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz"
integrity sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=

node-localstorage@3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/node-localstorage/-/node-localstorage-3.0.5.tgz#4acda05bb7d3fffaa477f13c028d105866bb43ad"
integrity sha512-GCwtK33iwVXboZWYcqQHu3aRvXEBwmPkAMRBLeaX86ufhqslyUkLGsi4aW3INEfdQYpUB5M9qtYf3eHvAk2VBg==
dependencies:
write-file-atomic "^5.0.1"

node-releases@^2.0.18:
version "2.0.18"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.18.tgz#f010e8d35e2fe8d6b2944f03f70213ecedc4ca3f"
Expand Down Expand Up @@ -25866,7 +25852,7 @@ write-file-atomic@^4.0.2:
imurmurhash "^0.1.4"
signal-exit "^3.0.7"

write-file-atomic@^5.0.0, write-file-atomic@^5.0.1:
write-file-atomic@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-5.0.1.tgz#68df4717c55c6fa4281a7860b4c2ba0a6d2b11e7"
integrity sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==
Expand Down

0 comments on commit e6a80ce

Please sign in to comment.