Skip to content

Commit cd4f55d

Browse files
authored
refactor(data-access): thegraph-data-access package (#931)
1 parent 400b0d5 commit cd4f55d

25 files changed

+214
-83
lines changed

.circleci/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ jobs:
9595
name: Generate Payment Detection queries
9696
command: yarn workspace @requestnetwork/payment-detection run codegen
9797

98+
- run:
99+
name: Build all packages (tsc)
100+
command: yarn build:tsc
101+
98102
- persist_to_workspace:
99103
root: *working_directory
100104
paths: .

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ Join the [Request Hub][requesthub-slack-url] to get in touch with us.
1818

1919
### Published Packages
2020

21-
| Package | Version | Description |
22-
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
23-
| [`@requestnetwork/advanced-logic`](/packages/advanced-logic) | [![npm](https://img.shields.io/npm/v/@requestnetwork/advanced-logic.svg)](https://www.npmjs.com/package/@requestnetwork/advanced-logic) | Extensions to the protocol |
24-
| [`@requestnetwork/request-client.js`](/packages/request-client.js) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-client.js.svg)](https://www.npmjs.com/package/@requestnetwork/request-client.js) | Library to use Request nodes as servers |
25-
| [`@requestnetwork/data-access`](/packages/data-access) | [![npm](https://img.shields.io/npm/v/@requestnetwork/data-access.svg)](https://www.npmjs.com/package/@requestnetwork/data-access) | Indexing an batching of transactions |
26-
| [`@requestnetwork/data-format`](/packages/data-format) | [![npm](https://img.shields.io/npm/v/@requestnetwork/data-format.svg)](https://www.npmjs.com/package/@requestnetwork/data-format) | Standards for data stored on Request, like invoices format |
27-
| [`@requestnetwork/epk-signature`](/packages/epk-signature) | [![npm](https://img.shields.io/npm/v/@requestnetwork/epk-signature.svg)](https://www.npmjs.com/package/@requestnetwork/epk-signature) | Sign requests using Ethereum private keys |
28-
| [`@requestnetwork/ethereum-storage`](/packages/ethereum-storage) | [![npm](https://img.shields.io/npm/v/@requestnetwork/ethereum-storage.svg)](https://www.npmjs.com/package/@requestnetwork/ethereum-storage) | Storage of Request data on Ethereum and IPFS |
29-
| [`@requestnetwork/epk-decryption`](/packages/epk-decryption) | [![npm](https://img.shields.io/npm/v/@requestnetwork/epk-decryption.svg)](https://www.npmjs.com/package/@requestnetwork/epk-decryption) | Decrypt encrypted requests using Ethereum private keys |
30-
| [`@requestnetwork/payment-detection`](/packages/payment-detection) | [![npm](https://img.shields.io/npm/v/@requestnetwork/payment-detection.svg)](https://www.npmjs.com/package/@requestnetwork/payment-detection) | Client-side payment detection, to compute the balance. |
31-
| [`@requestnetwork/payment-processor`](/packages/payment-processor) | [![npm](https://img.shields.io/npm/v/@requestnetwork/payment-processor.svg)](https://www.npmjs.com/package/@requestnetwork/payment-processor) | Pay a request using a web3 wallet |
32-
| [`@requestnetwork/request-logic`](/packages/request-logic) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-logic.svg)](https://www.npmjs.com/package/@requestnetwork/request-logic) | The Request business logic: properties and actions of requests |
33-
| [`@requestnetwork/request-node`](/packages/request-node) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-node.svg)](https://www.npmjs.com/package/@requestnetwork/request-node) | Web server that allows easy access to Request system |
34-
| [`@requestnetwork/transaction-manager`](/packages/transaction-manager) | [![npm](https://img.shields.io/npm/v/@requestnetwork/transaction-manager.svg)](https://www.npmjs.com/package/@requestnetwork/transaction-manager) | Creates transactions to be sent to Data Access, managing encryption |
35-
| [`@requestnetwork/types`](/packages/types) | [![npm](https://img.shields.io/npm/v/@requestnetwork/types.svg)](https://www.npmjs.com/package/@requestnetwork/types) | Typescript types shared across @requestnetwork packages |
36-
| [`@requestnetwork/utils`](/packages/utils) | [![npm](https://img.shields.io/npm/v/@requestnetwork/utils.svg)](https://www.npmjs.com/package/@requestnetwork/utils) | Collection of tools shared between the @requestnetwork packages |
37-
| [`@requestnetwork/web3-signature`](/packages/web3-signature) | [![npm](https://img.shields.io/npm/v/@requestnetwork/web3-signature.svg)](https://www.npmjs.com/package/@requestnetwork/web3-signature) | Sign requests using web3 tools (like Metamask) |
38-
| [`@requestnetwork/multi-format`](/packages/multi-format) | [![npm](https://img.shields.io/npm/v/@requestnetwork/multi-format.svg)](https://www.npmjs.com/package/@requestnetwork/multi-format) | Serialize and deserialize object in the Request Network protocol |
39-
| [`@requestnetwork/smart-contracts`](/packages/smart-contracts) | [![npm](https://img.shields.io/npm/v/@requestnetwork/smart-contracts.svg)](https://www.npmjs.com/package/@requestnetwork/smart-contracts) | Sources and artifacts of the smart contracts |
21+
| Package | Version | Description |
22+
| ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
23+
| [`@requestnetwork/advanced-logic`](/packages/advanced-logic) | [![npm](https://img.shields.io/npm/v/@requestnetwork/advanced-logic.svg)](https://www.npmjs.com/package/@requestnetwork/advanced-logic) | Extensions to the protocol |
24+
| [`@requestnetwork/request-client.js`](/packages/request-client.js) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-client.js.svg)](https://www.npmjs.com/package/@requestnetwork/request-client.js) | Library to use Request nodes as servers |
25+
| [`@requestnetwork/data-access`](/packages/data-access) | [![npm](https://img.shields.io/npm/v/@requestnetwork/data-access.svg)](https://www.npmjs.com/package/@requestnetwork/data-access) | Indexing an batching of transactions |
26+
| [`@requestnetwork/data-format`](/packages/data-format) | [![npm](https://img.shields.io/npm/v/@requestnetwork/data-format.svg)](https://www.npmjs.com/package/@requestnetwork/data-format) | Standards for data stored on Request, like invoices format |
27+
| [`@requestnetwork/epk-signature`](/packages/epk-signature) | [![npm](https://img.shields.io/npm/v/@requestnetwork/epk-signature.svg)](https://www.npmjs.com/package/@requestnetwork/epk-signature) | Sign requests using Ethereum private keys |
28+
| [`@requestnetwork/ethereum-storage`](/packages/ethereum-storage) | [![npm](https://img.shields.io/npm/v/@requestnetwork/ethereum-storage.svg)](https://www.npmjs.com/package/@requestnetwork/ethereum-storage) | Storage of Request data on Ethereum and IPFS, with custom indexing |
29+
| [`@requestnetwork/epk-decryption`](/packages/epk-decryption) | [![npm](https://img.shields.io/npm/v/@requestnetwork/epk-decryption.svg)](https://www.npmjs.com/package/@requestnetwork/epk-decryption) | Decrypt encrypted requests using Ethereum private keys |
30+
| [`@requestnetwork/payment-detection`](/packages/payment-detection) | [![npm](https://img.shields.io/npm/v/@requestnetwork/payment-detection.svg)](https://www.npmjs.com/package/@requestnetwork/payment-detection) | Client-side payment detection, to compute the balance. |
31+
| [`@requestnetwork/payment-processor`](/packages/payment-processor) | [![npm](https://img.shields.io/npm/v/@requestnetwork/payment-processor.svg)](https://www.npmjs.com/package/@requestnetwork/payment-processor) | Pay a request using a web3 wallet |
32+
| [`@requestnetwork/request-logic`](/packages/request-logic) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-logic.svg)](https://www.npmjs.com/package/@requestnetwork/request-logic) | The Request business logic: properties and actions of requests |
33+
| [`@requestnetwork/request-node`](/packages/request-node) | [![npm](https://img.shields.io/npm/v/@requestnetwork/request-node.svg)](https://www.npmjs.com/package/@requestnetwork/request-node) | Web server that allows easy access to Request system |
34+
| [`@requestnetwork/transaction-manager`](/packages/transaction-manager) | [![npm](https://img.shields.io/npm/v/@requestnetwork/transaction-manager.svg)](https://www.npmjs.com/package/@requestnetwork/transaction-manager) | Creates transactions to be sent to Data Access, managing encryption |
35+
| [`@requestnetwork/types`](/packages/types) | [![npm](https://img.shields.io/npm/v/@requestnetwork/types.svg)](https://www.npmjs.com/package/@requestnetwork/types) | Typescript types shared across @requestnetwork packages |
36+
| [`@requestnetwork/utils`](/packages/utils) | [![npm](https://img.shields.io/npm/v/@requestnetwork/utils.svg)](https://www.npmjs.com/package/@requestnetwork/utils) | Collection of tools shared between the @requestnetwork packages |
37+
| [`@requestnetwork/web3-signature`](/packages/web3-signature) | [![npm](https://img.shields.io/npm/v/@requestnetwork/web3-signature.svg)](https://www.npmjs.com/package/@requestnetwork/web3-signature) | Sign requests using web3 tools (like Metamask) |
38+
| [`@requestnetwork/multi-format`](/packages/multi-format) | [![npm](https://img.shields.io/npm/v/@requestnetwork/multi-format.svg)](https://www.npmjs.com/package/@requestnetwork/multi-format) | Serialize and deserialize object in the Request Network protocol |
39+
| [`@requestnetwork/thegraph-data-access`](/packages/thegraph-data-access) | [![npm](https://img.shields.io/npm/v/@requestnetwork/thegraph-data-access.svg)](https://www.npmjs.com/package/@requestnetwork/thegraph-data-access) | Storage of Request data on Ethereum and IPFS, indexed by TheGraph |
40+
| [`@requestnetwork/smart-contracts`](/packages/smart-contracts) | [![npm](https://img.shields.io/npm/v/@requestnetwork/smart-contracts.svg)](https://www.npmjs.com/package/@requestnetwork/smart-contracts) | Sources and artifacts of the smart contracts |
4041

4142
### Private Packages
4243

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"build": "lerna run build",
1818
"clean": "lerna run clean",
19-
"build:tsc": "tsc -b packages/advanced-logic/tsconfig.build.json packages/currency/tsconfig.build.json packages/data-access/tsconfig.build.json packages/data-format/tsconfig.build.json packages/epk-decryption/tsconfig.build.json packages/epk-signature/tsconfig.build.json packages/ethereum-storage/tsconfig.build.json packages/integration-test/tsconfig.build.json packages/multi-format/tsconfig.build.json packages/payment-detection/tsconfig.build.json packages/prototype-estimator/tsconfig.build.json packages/request-client.js/tsconfig.build.json packages/request-logic/tsconfig.build.json packages/request-node/tsconfig.build.json packages/smart-contracts/tsconfig.build.json packages/toolbox/tsconfig.build.json packages/transaction-manager/tsconfig.build.json packages/types/tsconfig.build.json packages/usage-examples/tsconfig.build.json packages/utils/tsconfig.build.json packages/web3-signature/tsconfig.build.json",
19+
"build:tsc": "tsc -b packages/**/tsconfig.build.json",
2020
"lint": "eslint . --fix --quiet",
2121
"lint:check": "eslint . --quiet",
2222
"lint-staged": "lint-staged",
File renamed without changes.

packages/data-access/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as DataAccess } from './data-access';
22
export { default as TransactionIndex } from './transaction-index';
33
export { default as Block } from './block';
4+
export { CombinedDataAccess } from './combined-data-access';

packages/ethereum-storage/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
"@requestnetwork/utils": "0.35.0",
4646
"axios": "0.27.2",
4747
"bluebird": "3.7.2",
48+
"eip1559-fee-suggestions-ethers": "1.3.3",
4849
"ethers": "5.5.1",
4950
"form-data": "3.0.0",
5051
"ipfs-unixfs": "6.0.7",
5152
"keyv": "4.0.3",
5253
"qs": "6.10.3",
5354
"shelljs": "0.8.5",
5455
"tslib": "2.3.1",
56+
"typed-emitter": "1.4.0",
5557
"web3-eth": "1.3.6",
5658
"web3-utils": "1.3.6",
5759
"yargs": "16.2.0"

packages/request-node/src/thegraph/TheGraphStorage.ts renamed to packages/ethereum-storage/src/ethereum-storage-ethers.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@ import { LogTypes, StorageTypes } from '@requestnetwork/types';
66
import { requestHashSubmitterArtifact } from '@requestnetwork/smart-contracts';
77
import { RequestOpenHashSubmitter } from '@requestnetwork/smart-contracts/types';
88
import { suggestFees } from 'eip1559-fee-suggestions-ethers';
9-
import { GasPriceDefiner } from '@requestnetwork/ethereum-storage';
109

11-
type TheGraphStorageProps = {
10+
type StorageProps = {
1211
network: string;
1312
signer: Signer;
1413
ipfsStorage: StorageTypes.IIpfsStorage;
1514
logger?: LogTypes.ILogger;
1615
};
1716

18-
export type TheGraphStorageEventEmitter = TypedEmitter<{
17+
export type StorageEventEmitter = TypedEmitter<{
1918
confirmed: (receipt: ContractReceipt) => void;
2019
error: (error: unknown) => void;
2120
}>;
2221

23-
export class TheGraphStorage {
22+
export class EthereumStorageEthers implements StorageTypes.IStorageWrite {
2423
private readonly logger: LogTypes.ILogger;
2524
private readonly ipfsStorage: StorageTypes.IIpfsStorage;
2625
private readonly hashSubmitter: RequestOpenHashSubmitter;
2726
private readonly network: string;
2827
private readonly provider: providers.JsonRpcProvider;
2928
private enableEip1559 = true;
3029

31-
constructor({ network, signer, ipfsStorage, logger }: TheGraphStorageProps) {
30+
constructor({ network, signer, ipfsStorage, logger }: StorageProps) {
3231
this.logger = logger || new Utils.SimpleLogger();
3332
this.ipfsStorage = ipfsStorage;
3433
this.network = network;
@@ -49,7 +48,7 @@ export class TheGraphStorage {
4948
);
5049
this.enableEip1559 = false;
5150
}
52-
this.logger.debug('TheGraph storage initialized');
51+
this.logger.debug(`${EthereumStorageEthers.name} storage initialized`);
5352
}
5453

5554
async append(content: string): Promise<StorageTypes.IAppendResult> {
@@ -65,21 +64,14 @@ export class TheGraphStorage {
6564
const maxFeePerGas = maxPriorityFeePerGas.add(suggestedFee.baseFeeSuggestion);
6665
overrides.maxPriorityFeePerGas = maxPriorityFeePerGas;
6766
overrides.maxFeePerGas = maxFeePerGas;
68-
} else {
69-
// retro-compatibility for networks where the eth_feeHistory RPC method is not available (pre EIP-1559)
70-
const gasPriceDefiner = new GasPriceDefiner();
71-
overrides.gasPrice = await gasPriceDefiner.getGasPrice(
72-
StorageTypes.GasPriceType.FAST,
73-
this.network,
74-
);
7567
}
7668
const tx = await this.hashSubmitter.submitHash(
7769
ipfsHash,
7870
utils.hexZeroPad(utils.hexlify(ipfsSize), 32),
7971
overrides,
8072
);
8173

82-
const eventEmitter = new EventEmitter() as TheGraphStorageEventEmitter;
74+
const eventEmitter = new EventEmitter() as StorageEventEmitter;
8375
const result: StorageTypes.IEntry = {
8476
id: ipfsHash,
8577
content,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { EthereumStorage } from './ethereum-storage';
2+
export { EthereumStorageEthers } from './ethereum-storage-ethers';
23
export { GasPriceDefiner } from './gas-price-definer';
34
export { IpfsStorage } from './ipfs-storage';

packages/request-node/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
"@requestnetwork/data-access": "0.26.0",
4646
"@requestnetwork/ethereum-storage": "0.26.0",
4747
"@requestnetwork/smart-contracts": "0.28.0",
48+
"@requestnetwork/thegraph-data-access": "0.35.0",
4849
"@requestnetwork/types": "0.35.0",
4950
"@requestnetwork/utils": "0.35.0",
5051
"@truffle/hdwallet-provider": "1.2.3",
5152
"chalk": "4.1.0",
5253
"cors": "2.8.5",
5354
"dotenv": "8.2.0",
54-
"eip1559-fee-suggestions-ethers": "1.3.3",
5555
"ethers": "5.5.1",
5656
"express": "4.17.1",
5757
"graphql": "15.5.0",
@@ -81,7 +81,6 @@
8181
"ts-jest": "26.3.0",
8282
"ts-node": "9.0.0",
8383
"ts-node-dev": "1.0.0-pre.62",
84-
"typed-emitter": "1.4.0",
8584
"typescript": "4.4.4"
8685
},
8786
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"

packages/request-node/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as config from './config';
55
import { Logger } from './logger';
66
import { RequestNode } from './requestNode';
77
import withShutdown from 'http-shutdown';
8-
import { TheGraphRequestNode } from './thegraph';
8+
import { TheGraphRequestNode } from './thegraph-node';
99

1010
// Initialize the node logger
1111
const { logLevel, logMode } = config.getLogConfig();

0 commit comments

Comments
 (0)