Skip to content

Commit 50028ec

Browse files
feat: Ethereum Registry Writer (#951)
1 parent ba62910 commit 50028ec

30 files changed

+2929
-172
lines changed

package-lock.json

Lines changed: 2011 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"start": "node dist/babel/src",
1010
"start:blockchain-writer": "node dist/babel/src/BlockchainWriter/index.js",
11+
"start:ethereum-registry-writer": "node dist/babel/src/EthereumRegistryWriter/index.js",
1112
"build": "npm run build-clear && npm run build-ts && npm run build-babel",
1213
"lint": "tslint -p ./tsconfig.with-tests.json",
1314
"lint:fix": "tslint -p ./tsconfig.with-tests.json --fix",
@@ -71,7 +72,8 @@
7172
"pino": "4.17.6",
7273
"protobufjs": "6.8.8",
7374
"ramda": "0.26.1",
74-
"string-to-stream": "1.1.1"
75+
"string-to-stream": "1.1.1",
76+
"web3": "1.2.2"
7577
},
7678
"devDependencies": {
7779
"@po.et/tslint-rules": "2.2.0",
@@ -82,7 +84,7 @@
8284
"@types/koa": "2.0.47",
8385
"@types/koa-helmet": "3.1.2",
8486
"@types/koa-router": "7.0.35",
85-
"@types/mongodb": "3.1.17",
87+
"@types/mongodb": "3.3.8",
8688
"@types/node-fetch": "1.6.9",
8789
"@types/pino": "4.16.1",
8890
"@types/ramda": "0.26.0",

src/API/FileController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as FormData from 'form-data'
1+
import FormData from 'form-data'
22
import * as fs from 'fs'
33
import fetch, {Response} from 'node-fetch'
44
import * as Pino from 'pino'
55

6-
import { childWithFileName } from 'Helpers/Logging'
76
import { minutesToMiliseconds } from 'Helpers/Time'
87
import { asyncPipe } from 'Helpers/asyncPipe'
98

src/API/Router.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
import * as fs from 'fs'
1010
import * as http from 'http'
1111
import * as Joi from 'joi'
12-
import * as Koa from 'koa'
13-
import * as KoaBody from 'koa-body'
14-
import * as KoaCors from 'koa-cors'
15-
import * as helmet from 'koa-helmet'
16-
import * as KoaRouter from 'koa-router'
12+
import Koa from 'koa'
13+
import KoaBody from 'koa-body'
14+
import KoaCors from 'koa-cors'
15+
import helmet from 'koa-helmet'
16+
import KoaRouter from 'koa-router'
1717
import * as Pino from 'pino'
1818
import { map, values, prop, pipe } from 'ramda'
1919

src/BatchReader/ClaimController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export class ClaimController {
2626
this.ipfs = ipfs
2727
}
2828

29-
addEntries = (entries: ReadonlyArray<{ ipfsDirectoryHash: string }>): Promise<InsertWriteOpResult> =>
30-
this.directoryDAO.addEntries(entries)
29+
addEntries = async (entries: ReadonlyArray<{ ipfsDirectoryHash: string }>): Promise<void> => {
30+
await this.directoryDAO.addEntries(entries)
31+
}
3132

3233
readNextDirectory = async (): Promise<{ ipfsDirectoryHash: string; ipfsFileHashes: ReadonlyArray<string> }> => {
3334
const collectionItem = await this.directoryDAO.findNextEntry()

src/BatchReader/DirectoryDAO.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Entry {
1414

1515
type start = () => Promise<void>
1616

17-
type addEntries = (xs: ReadonlyArray<Entry>) => Promise<InsertWriteOpResult>
17+
type addEntries = (xs: ReadonlyArray<Entry>) => Promise<void>
1818

1919
type findNextEntry = (
2020
options?: {
@@ -53,8 +53,8 @@ export class DirectoryDAO {
5353
await this.directoryCollection.createIndex({ ipfsDirectoryHash: 1 }, { unique: true })
5454
}
5555

56-
readonly addEntries: addEntries = async (entries = []) =>
57-
this.directoryCollection
56+
readonly addEntries: addEntries = async (entries = []) => {
57+
await this.directoryCollection
5858
.insertMany(
5959
entries.map((entry: Entry) => ({
6060
ipfsDirectoryHash: entry.ipfsDirectoryHash,
@@ -66,6 +66,7 @@ export class DirectoryDAO {
6666
{ ordered: false },
6767
)
6868
.ignoreError(error => error.code === ErrorCodes.DuplicateKey)
69+
}
6970

7071
readonly findNextEntry: findNextEntry = ({
7172
currentTime = new Date().getTime(),

src/BatchWriter/BatchWriter.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import * as Pino from 'pino'
33
import { pick } from 'ramda'
44

55
import { LoggingConfiguration } from 'Configuration'
6+
import { IPFS, IPFSConfiguration } from 'Helpers/IPFS'
67
import { createModuleLogger } from 'Helpers/Logging'
78
import { Messaging } from 'Messaging/Messaging'
89

910
import { ClaimController } from './ClaimController'
1011
import { ExchangeConfiguration } from './ExchangeConfiguration'
1112
import { FileDAO } from './FileDAO'
12-
import { IPFS, IPFSConfiguration } from './IPFS'
1313
import { Router } from './Router'
1414
import { Service, ServiceConfiguration } from './Service'
1515

16-
export interface BatchWriterConfiguration extends LoggingConfiguration, ServiceConfiguration, IPFSConfiguration {
16+
export interface BatchWriterConfiguration extends LoggingConfiguration, ServiceConfiguration {
1717
readonly dbUrl: string
1818
readonly rabbitmqUrl: string
1919
readonly exchanges: ExchangeConfiguration
20+
readonly ipfs: IPFSConfiguration
2021
}
2122

2223
export class BatchWriter {
@@ -42,11 +43,7 @@ export class BatchWriter {
4243
this.messaging = new Messaging(this.configuration.rabbitmqUrl, exchangesMessaging)
4344
await this.messaging.start()
4445

45-
const ipfs = new IPFS({
46-
configuration: {
47-
ipfsUrl: this.configuration.ipfsUrl,
48-
},
49-
})
46+
const ipfs = IPFS(this.configuration.ipfs)
5047

5148
const fileCollection: Collection = this.dbConnection.collection('batchWriter')
5249

src/BatchWriter/ClaimController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NoMoreEntriesException } from 'Exceptions'
2+
import { IPFS } from 'Helpers/IPFS'
23

34
import { FileDAO } from './FileDAO'
4-
import { IPFS } from './IPFS'
55

66
export interface Dependencies {
77
readonly fileDAO: FileDAO

src/BatchWriter/FileDAO.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Entry {
99

1010
type start = () => Promise<void>
1111

12-
type addEntry = (x: Entry) => Promise<InsertOneWriteOpResult>
12+
type addEntry = (x: Entry) => Promise<void>
1313

1414
type findNextEntries = () => Promise<ReadonlyArray<Entry>>
1515

@@ -40,8 +40,9 @@ export class FileDAO {
4040
await this.fileCollection.createIndex({ ipfsFileHash: 1 }, { unique: true })
4141
}
4242

43-
addEntry: addEntry = ({ ipfsFileHash }) =>
44-
this.fileCollection.insertOne({ ipfsFileHash, successTime: null, ipfsDirectoryHash: null })
43+
addEntry: addEntry = async ({ ipfsFileHash }) => {
44+
await this.fileCollection.insertOne({ ipfsFileHash, successTime: null, ipfsDirectoryHash: null })
45+
}
4546

4647
findNextEntries: findNextEntries = () =>
4748
this.fileCollection.find({ successTime: null }, { fields: { _id: false, ipfsFileHash: true } }).toArray()

src/BatchWriter/IPFS.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)