From 0d864a392f137bc5d68088bdf69a2db305a04196 Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Thu, 5 Jun 2025 20:39:23 +0300 Subject: [PATCH] rm subpackage --- .gitignore | 2 - README.md | 1 - package.json | 4 +- packages/brubeck-migration-script/.env | 14 - packages/brubeck-migration-script/.env_prod | 12 - .../contracts/emptyFolderPlaceholder | 0 .../hardhat.config.ts | 74 ----- .../brubeck-migration-script/package.json | 43 --- .../src/GraphQLClient.ts | 62 ----- .../brubeck-migration-script/src/Migrator.ts | 236 ---------------- .../brubeck-migration-script/src/README.md | 6 - .../src/comparator.ts | 100 ------- .../brubeck-migration-script/src/index.ts | 108 -------- .../src/old/cleanupStreams.ts | 94 ------- .../src/old/migrateStreams.ts | 249 ----------------- .../src/old/migrateStreamsHighGas.ts | 253 ------------------ .../brubeck-migration-script/tsconfig.json | 22 -- 17 files changed, 1 insertion(+), 1279 deletions(-) delete mode 100644 packages/brubeck-migration-script/.env delete mode 100644 packages/brubeck-migration-script/.env_prod delete mode 100644 packages/brubeck-migration-script/contracts/emptyFolderPlaceholder delete mode 100644 packages/brubeck-migration-script/hardhat.config.ts delete mode 100644 packages/brubeck-migration-script/package.json delete mode 100644 packages/brubeck-migration-script/src/GraphQLClient.ts delete mode 100644 packages/brubeck-migration-script/src/Migrator.ts delete mode 100644 packages/brubeck-migration-script/src/README.md delete mode 100644 packages/brubeck-migration-script/src/comparator.ts delete mode 100644 packages/brubeck-migration-script/src/index.ts delete mode 100644 packages/brubeck-migration-script/src/old/cleanupStreams.ts delete mode 100644 packages/brubeck-migration-script/src/old/migrateStreams.ts delete mode 100644 packages/brubeck-migration-script/src/old/migrateStreamsHighGas.ts delete mode 100644 packages/brubeck-migration-script/tsconfig.json diff --git a/.gitignore b/.gitignore index 6807b71cd..67954a24a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ **node_modules/ **build **cache -/packages/brubeck-migration-script/artifacts -/packages/brubeck-migration-script/typechain /packages/tatum-thegraph-subgraph/artifacts /packages/tatum-thegraph-subgraph/cache /packages/tatum-thegraph-subgraph/generated diff --git a/README.md b/README.md index 30f41db88..cb1dbae15 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,3 @@ This is a monorepo containing various smart contracts and subgraphs used by the ## Other packages - [chainlink-ens-external-adapter](https://github.com/streamr-dev/network-contracts/tree/master/packages/chainlink-ens-external-adapter) Custom Chainlink job that implements an ENS oracle used to verify ENS ownership on mainnet when creating streams -- [brubeck-migration-script](https://github.com/streamr-dev/network-contracts/tree/master/packages/brubeck-migration-script) Script that migrates opted-in streams from Corea to Brubeck network diff --git a/package.json b/package.json index 4a3dda59f..65dd96906 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,7 @@ "graph2_copyInfo": "./scripts/copyAbis.sh && ./scripts/generateYaml.sh", "graph3_build": "npm run doAll --workspace=network-subgraphs", "graph": "npm run graph1_build && npm run graph2_copyInfo && npm run graph3_build", - "e2etest": "npm run e2etest --workspace=network-contracts", - "migration-build": "npm run build -w=brubeck-migration-script", - "migration-run": "npm run migration -w=brubeck-migration-script" + "e2etest": "npm run e2etest --workspace=network-contracts" }, "devDependencies": { "@chainsafe/ssz": "^0.10.2", diff --git a/packages/brubeck-migration-script/.env b/packages/brubeck-migration-script/.env deleted file mode 100644 index 13817e7c8..000000000 --- a/packages/brubeck-migration-script/.env +++ /dev/null @@ -1,14 +0,0 @@ -DB_HOST="localhost" -DB_USER="root" -DB_PASSWORD="password" -DB_NAME="core_test" - -PAUSE_BETWEEN_MIGRATIONS_MS="5000" -THE_GRAPH_URL="http://10.200.10.1:8000/subgraphs/name/streamr-dev/network-contracts" -CHAIN_NODE_URL="http://localhost:8546" -ADMIN_PRIVATEKEY="0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0" -MIGRATOR_PRIVATEKEY="0x000000000000000000000000000000000000000000000000000000000000000c" -STREAMREGISTRY_ADDRESS="0x6cCdd5d866ea766f6DF5965aA98DeCCD629ff222" - -GASPRICE_INCREASE_PERCENT="10" -GASPRICE_INCREASE_TIMEOUT_MS="40000" \ No newline at end of file diff --git a/packages/brubeck-migration-script/.env_prod b/packages/brubeck-migration-script/.env_prod deleted file mode 100644 index cf2f1b5b3..000000000 --- a/packages/brubeck-migration-script/.env_prod +++ /dev/null @@ -1,12 +0,0 @@ -DB_HOST="localhost" -DB_USER="root" -DB_PASSWORD="" -DB_NAME="streamr_prod" - -PAUSE_BETWEEN_MIGRATIONS_MS="30000" -THE_GRAPH_URL="https://api.thegraph.com/subgraphs/name/streamr-dev/streams" -CHAIN_NODE_URL="https://polygon-rpc.com/" -STREAMREGISTRY_ADDRESS="0x0D483E10612F327FC11965Fc82E90dC19b141641" - -GASPRICE_INCREASE_PERCENT="10" -GASPRICE_INCREASE_TIMEOUT_MS="40000" \ No newline at end of file diff --git a/packages/brubeck-migration-script/contracts/emptyFolderPlaceholder b/packages/brubeck-migration-script/contracts/emptyFolderPlaceholder deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/brubeck-migration-script/hardhat.config.ts b/packages/brubeck-migration-script/hardhat.config.ts deleted file mode 100644 index 38caac5f0..000000000 --- a/packages/brubeck-migration-script/hardhat.config.ts +++ /dev/null @@ -1,74 +0,0 @@ -// import { task } from 'hardhat/config' -// import '@nomiclabs/hardhat-waffle' -import 'hardhat-typechain' -// import { HardhatUserConfig } from 'hardhat/types' -// import 'hardhat-deploy' -import 'hardhat-deploy-ethers' -require('@openzeppelin/hardhat-upgrades') - -// require('solidity-coverage') -require('hardhat-dependency-compiler') - -// This is a sample Hardhat task. To learn how to create your own go to -// https://hardhat.org/guides/create-task.html -// task('accounts', 'Prints the list of accounts', async (args, hre) => { -// const accounts = await hre.ethers.getSigners() -// // eslint-disable-next-line no-restricted-syntax -// for (const account of accounts) { -// // eslint-disable-next-line no-console -// console.log(account.address) -// } -// }) - -// TODO: add this to the hardhat-dependency-compiler repo as a pull request or whatever -// declare module 'hardhat/types/config' { -// interface HardhatUserConfig { -// dependencyCompiler?: any; -// } -// } - -// You need to export an object to set up your config -// Go to https://hardhat.org/config/ to learn more - -module.exports = { - - defaultNetwork: 'hardhat', - networks: { - hardhat: { - gas: 12000000, - blockGasLimit: 0x1fffffffffffff, - allowUnlimitedContractSize: true - }, - localsidechain: { - chainId: 8997, - url: 'http://10.200.10.1:8546', - accounts: ['0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0'] - }, - polygonMainnet: { - chainId: 137, - // url: 'https://polygon-rpc.com', - url: 'https://wild-dark-thunder.matic.quiknode.pro/08b0fa6254499defc975c381ee21777cb197fac5/', - } - }, - dependencyCompiler: { - paths: [ - '@streamr/network-contracts/contracts/StreamRegistry/StreamRegistryV3.sol' - ], - }, - solidity: { - compilers: [ - { - version: '0.8.9', - settings: { - optimizer: { - enabled: true, - runs: 100, - }, - }, - }], - }, - typechain: { - outDir: './typechain', - target: 'ethers-v5', - } -} \ No newline at end of file diff --git a/packages/brubeck-migration-script/package.json b/packages/brubeck-migration-script/package.json deleted file mode 100644 index 481c4895b..000000000 --- a/packages/brubeck-migration-script/package.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "brubeck-migration-script", - "version": "2.4.0", - "description": "Script to migrate stream data from core to brubeck", - "author": "Streamr Network AG ", - "license": "STREAMR NETWORK OPEN SOURCE LICENSE", - "private": true, - "main": "index.js", - "scripts": { - "test": "echo \"No tests in migration script.\"", - "migration": "hardhat run --network polygonMainnet src/index.ts", - "clean": "rm -rf artifacts cache coverage typechain deployments .openzeppelin", - "build": "hardhat compile" - }, - "dependencies": { - "@ethersproject/bignumber": "^5.5.0", - "@ethersproject/constants": "^5.5.0", - "@ethersproject/contracts": "^5.1.1", - "@ethersproject/experimental": "^5.5.0", - "@ethersproject/providers": "^5.1.2", - "@ethersproject/wallet": "^5.5.0", - "@nomiclabs/hardhat-ethers": "^2.0.4", - "@nomiclabs/hardhat-waffle": "^2.0.1", - "@types/debug": "^4.1.7", - "debug": "^4.3.1", - "dotenv": "^16.0.0", - "eslint-config-streamr-nodejs": "^2.0.1", - "hardhat": "^2.2.1", - "hardhat-dependency-compiler": "^1.1.2", - "hardhat-deploy": "^0.7.5", - "hardhat-deploy-ethers": "*", - "hardhat-typechain": "^0.3.5", - "mysql": "^2.18.1", - "node-fetch": "^2.6.6", - "web3": "1.2.4" - }, - "devDependencies": { - "@types/mysql": "^2.15.21", - "@typescript-eslint/eslint-plugin": "^4.22.1", - "@typescript-eslint/parser": "^4.22.1", - "typescript": "^4.4.4" - } -} diff --git a/packages/brubeck-migration-script/src/GraphQLClient.ts b/packages/brubeck-migration-script/src/GraphQLClient.ts deleted file mode 100644 index 750d8aad3..000000000 --- a/packages/brubeck-migration-script/src/GraphQLClient.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable max-len */ -import fetch from 'node-fetch' -import Debug from 'debug' - -export class GraphQLClient { - private debug = Debug('migrator') - - private theGraphUrl = process.env.THE_GRAPH_URL || '' - // eslint-disable-next-line @typescript-eslint/ban-types - async sendQuery(gqlQuery: string): Promise { - // this.debug('GraphQL query: %s', gqlQuery) - const res = await fetch(this.theGraphUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - accept: '*/*', - }, - body: gqlQuery - }) - const resText = await res.text() - let resJson - try { - resJson = JSON.parse(resText) - } catch { - throw new Error(`GraphQL query failed with "${resText}", check that your theGraphUrl="${this.theGraphUrl}" is correct`) - } - // this.debug('GraphQL response: %o', resJson) - if (!resJson.data) { - if (resJson.errors && resJson.errors.length > 0) { - throw new Error('GraphQL query failed: ' + JSON.stringify(resJson.errors.map((e: any) => e.message))) - } else { - throw new Error('GraphQL query failed') - } - } - return resJson.data - } - - async* fetchPaginatedResults( - createQuery: (lastId: string, pageSize: number) => string, - pageSize = 1000 - ): AsyncGenerator { - let lastResultSet: T[] | undefined - do { - const lastId = (lastResultSet !== undefined) ? lastResultSet[lastResultSet.length - 1].id : '' - const query = createQuery(lastId, pageSize) - // eslint-disable-next-line no-await-in-loop - const response = await this.sendQuery(query) - const rootKey = Object.keys(response)[0] // there is a always a one root level property, e.g. "streams" or "permissions" - const items: T[] = (response as any)[rootKey] as T[] - yield* items - lastResultSet = items - } while (lastResultSet.length === pageSize) - } - - static createWhereClause(variables: Record): string { - const parameterList = Object.keys(variables) - .filter((k) => variables[k] !== undefined) - .map((k) => k + ': $' + k) - .join(' ') - return `where: { ${parameterList} }` - } -} diff --git a/packages/brubeck-migration-script/src/Migrator.ts b/packages/brubeck-migration-script/src/Migrator.ts deleted file mode 100644 index e3dc5c12c..000000000 --- a/packages/brubeck-migration-script/src/Migrator.ts +++ /dev/null @@ -1,236 +0,0 @@ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable no-await-in-loop */ -/* eslint-disable max-len */ - -import Debug from 'debug' -import hhat from 'hardhat' -import { BigNumber, BigNumberish } from '@ethersproject/bignumber' -import { MaxInt256 } from '@ethersproject/constants' - -import { StreamRegistryV3 } from '../typechain/StreamRegistryV3' -import { TransactionRequest } from '@ethersproject/providers' -import { Wallet } from '@ethersproject/wallet' - -const { ethers } = hhat - -export type Permission = { - canEdit: boolean; - canDelete: boolean; - publishExpiration: BigNumberish; - subscribeExpiration: BigNumberish; - canGrant: boolean; -} - -export type StreamsWithPermissions = { - [key: string]: { // key is stream id - metadata: string, - permissions: { - [key: string]: Permission // key is the ethereum address of the permission holder - } - } -} - -export type StreamData = { - id: string, - user: string, - permissions: Permission -} - -export class Migrator { - private debug = Debug('migration-script:migrator') - - private registryFromMigrator: StreamRegistryV3 - private migratorWallet: Wallet - private networkProvider: any - private gasPriceIncrease: number - private originalGasPrice: number - - async migrate(streams: StreamsWithPermissions, mysql: {query: (arg0: string, arg1: string[]) => unknown }): Promise { - for (const streamid of Object.keys(streams)) { - if (!(await this.registryFromMigrator.exists(streamid))) { - try { - this.debug('creating stream ' + streamid) - const transaction = await this.registryFromMigrator.populateTransaction.trustedSetStreamMetadata(streamid, streams[streamid].metadata) - await this.sendTransaction(transaction) - } catch (e) { - this.debug('ERROR creating stream: ' + e) - } - } - } - const streamDataChunks = await Migrator.convertToStreamDataArray(streams) - let updatedStreams: { [key: string]: Date} = {} - for (const streamData of streamDataChunks) { - try { - await this.sendStreamsToChain(streamData) - for (const streamDataItem of streamData) { - updatedStreams[streamDataItem.id] = new Date() - } - await this.updateDB(updatedStreams, mysql) - updatedStreams = {} - } catch (err) { - this.debug('error sending permission chunks to chain: ' + err) - } - } - } - async sendTransaction(tx: TransactionRequest): Promise { - try { - this.debug('sending transaction') - - let replacementTimer = setTimeout(() => {}, 0) - const replaceTX = () => { - return new Promise((resolve, reject) => { - replacementTimer = setTimeout(async () => { - try { - const gasPriceIncreaseFactor = Number.parseInt(process.env.GASPRICE_INCREASE_PERCENT!) / 100 - let gasPrice = 0 - if (tx.gasPrice) { - gasPrice = (tx.gasPrice as BigNumber).toNumber() - } else { - gasPrice = await this.networkProvider.getGasPrice() - this.originalGasPrice = gasPrice - this.gasPriceIncrease = gasPrice * gasPriceIncreaseFactor - } - const newGasPrice = Math.ceil(+gasPrice + +this.gasPriceIncrease) - if (newGasPrice > this.originalGasPrice * 3) { - reject(new Error('gas price got too high, aborting')) - } - this.debug(`nothing happened for a while, increasing gas price from ${gasPrice} to ${newGasPrice}`) - // eslint-disable-next-line require-atomic-updates - tx.gasPrice = BigNumber.from(newGasPrice) - await this.sendTransaction(tx) - resolve(void 0) - } catch (e) { - reject(e) - } - }, Number.parseInt(process.env.GASPRICE_INCREASE_TIMEOUT_MS!)) - }) - } - - const sendTx = async() => { - const response = await this.migratorWallet.sendTransaction(tx) - this.debug('sent, waiting for transaction with hash ' + response.hash) - const receipt = await response.wait() - this.debug('mined transaction with hash ' + receipt.transactionHash) - return receipt - } - - await Promise.race([replaceTX(), sendTx()]) - clearTimeout(replacementTimer) - } catch (err: any) { - if (err.code === 'TRANSACTION_REPLACED') { this.debug('a transaction got replaced') } - else { throw err } - } - // throw('transaction failed') - // return (await this.migratorWallet.sendTransaction(tx)).wait() - // { - // gasPrice: this.networkProvider.getGasPrice().then((estimatedGasPrice: BigNumber) => estimatedGasPrice.add('10000000000')) - // } - } - - async updateDB(streams: { [key: string]: Date }, mysql: {query: (arg0: string, arg1: string[]) => unknown }): Promise { - this.debug('updating db with ' + Object.keys(streams).length + ' streams') - for (const streamid of Object.keys(streams)) { - // date format conversion from "2022-03-02T10:16:20.054Z" to "2022-03-02 10:16:25" - const updatedAt = streams[streamid].toISOString().slice(0, 19).replace('T', ' ') - const sql = 'UPDATE stream SET migrate_sync_last_run_at = ? WHERE id = ?' - const params = [updatedAt, streamid] - await mysql.query(sql, params) - } - this.debug('updated streams updatedAt time in DB') - } - - static async convertToStreamDataArray(streams: StreamsWithPermissions): Promise { - const result: StreamData[][] = [] - let streamDatas: StreamData[] = [] - Object.keys(streams).forEach((streamid: string) => { - const stream = streams[streamid] - Object.keys(stream.permissions).forEach((user: string) => { - if (streamDatas.length >= 20) { - result.push(streamDatas) - streamDatas = [] - } - streamDatas.push({ - id: streamid, - user, - permissions: stream.permissions[user] - }) - }) - }) - if (streamDatas.length > 0) { - result.push(streamDatas) - } - return result - } - - async init(): Promise { - this.networkProvider = new ethers.providers.JsonRpcProvider(process.env.CHAIN_NODE_URL) - this.migratorWallet = new ethers.Wallet(process.env.MIGRATOR_PRIVATEKEY || '', this.networkProvider) - const streamregistryFactory = await ethers.getContractFactory('StreamRegistryV3', this.migratorWallet) - const registry = await streamregistryFactory.attach(process.env.STREAMREGISTRY_ADDRESS || '') - const registryContract = await registry.deployed() - this.registryFromMigrator = await registryContract.connect(this.migratorWallet) as StreamRegistryV3 - - // debug, only needed once - // const adminWallet = new ethers.Wallet(process.env.ADMIN_PRIVATEKEY!, this.networkProvider) - // const registryFromAdmin = await registryContract.connect(adminWallet) as StreamRegistryV3 - // const mtx = await registryFromAdmin.grantRole(await registryFromAdmin.TRUSTED_ROLE(), - // this.migratorWallet.address) - // await mtx.wait() - // this.debug('added migrator role to ' + this.migratorWallet.address) - } - - async sendStreamsToChain(streamDatas: StreamData[]): Promise { - if (streamDatas.length === 0) { - this.debug('no streams to migrate') - return - } - this.debug('migrating ' + streamDatas.length + ' streams-user-permissions') - try { - const tx = await this.registryFromMigrator.populateTransaction.trustedSetPermissions( - streamDatas.map((el) => el.id), - streamDatas.map((el) => el.user), - streamDatas.map((el) => el.permissions), - { - gasPrice: this.networkProvider.getGasPrice().then((estimatedGasPrice: BigNumber) => estimatedGasPrice.add('10000000000')) - } - ) - await this.sendTransaction(tx) - // await tx.wait() - // this.debug('mined tx with nonce ' + tx.nonce) - } catch (err: any) { - this.debug(err) - } - } - - static convertPermissions(permissions: string[]): Permission { - const permissionSet = { - canEdit: false, - canDelete: false, - publishExpiration: BigNumber.from(0), - subscribeExpiration: BigNumber.from(0), - canGrant: false, - } - permissions.forEach((el) => { - switch (el) { - case 'stream_edit': - permissionSet.canEdit = true - break - case 'stream_delete': - permissionSet.canDelete = true - break - case 'stream_publish': - permissionSet.publishExpiration = MaxInt256 - break - case 'stream_subscribe': - permissionSet.subscribeExpiration = MaxInt256 - break - case 'stream_share': - permissionSet.canGrant = true - break - default: - break - } - }) - return permissionSet - } -} diff --git a/packages/brubeck-migration-script/src/README.md b/packages/brubeck-migration-script/src/README.md deleted file mode 100644 index ad1ab5c58..000000000 --- a/packages/brubeck-migration-script/src/README.md +++ /dev/null @@ -1,6 +0,0 @@ -import prod db dump into local mysql -mysql -u root -ppassword -h 127.0.0.1 -P 3306 core_test < streamr_prod.2021-11-10__12_05.sql - -export data into tsv file -echo "select id, name from stream;" | mysql -u root -ppassword -h 127.0.0.1 -P 3306 core_test | grep -v "^id" > myformat.tsv - diff --git a/packages/brubeck-migration-script/src/comparator.ts b/packages/brubeck-migration-script/src/comparator.ts deleted file mode 100644 index c496331f6..000000000 --- a/packages/brubeck-migration-script/src/comparator.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* eslint-disable no-continue */ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable max-len */ -import Debug from 'debug' -import { BigNumber } from '@ethersproject/bignumber' - -import { GraphQLClient } from './GraphQLClient' -import { Permission, StreamsWithPermissions } from './Migrator' - -export type PermissionAdditions = { - id: string, - userAddress: string, - stream: { - id: string, - metadata: string - } -} -const graphqlClient = new GraphQLClient() -const debug = Debug('migration-script:compareToMigrated') -const buildQuery = ( - lastId: string, - pageSize: number, - streamIds: string[] = [] -): string => { - // streams (first: ${pageSize} id_gt: "${lastId}" where: {id_in: ${JSON.stringify(streamIds)}}) { - // permissions (first: ${pageSize} id_gt: "${lastId}" where: {stream_in: ${JSON.stringify(streamIds)}}) { - const query = ` - { - permissions (first: ${pageSize} where: {id_gt: "${lastId}", stream_in: ${JSON.stringify(streamIds)}}) { - id - stream{id, metadata} - userAddress - canEdit - canDelete - publishExpiration - subscribeExpiration - canGrant - } - }` - return JSON.stringify({ - query - }) -} - -// description, partitions, inactivit threshhold -const compareToMigrated = async (streamsFromDB: StreamsWithPermissions): Promise => { - debug('comparing streams from DB to migrated streams, total: ' + Object.keys(streamsFromDB).length) - const streamIDs = Object.keys(streamsFromDB) - const userPermissionsGraph = graphqlClient.fetchPaginatedResults((lastId: string, pageSize: number) => buildQuery(lastId, pageSize, streamIDs)) - for await (const userPermissionGraph of userPermissionsGraph) { - if (userPermissionGraph.stream === null) { - continue - } - let migrationRequired = false - if (streamsFromDB[userPermissionGraph.stream.id] === undefined || streamsFromDB[userPermissionGraph.stream.id].permissions[userPermissionGraph.userAddress] === undefined) { - debug('didnt find user permissions in DB for stream ' + userPermissionGraph.stream.id + ' user ' + userPermissionGraph.userAddress) - throw new Error('didnt find user permissions in DB for stream ' + userPermissionGraph.stream.id + ' user ' + userPermissionGraph.userAddress) - } - const userPermissionsDb: Permission = streamsFromDB[userPermissionGraph.stream.id].permissions[userPermissionGraph.userAddress] - if ((userPermissionsDb.canDelete && !userPermissionGraph.canDelete) - || (userPermissionsDb.canEdit && !userPermissionGraph.canEdit) - || (userPermissionsDb.canGrant && !userPermissionGraph.canGrant) - || BigNumber.from(userPermissionsDb.publishExpiration).gt(userPermissionGraph.publishExpiration) - || BigNumber.from(userPermissionsDb.subscribeExpiration).gt(userPermissionGraph.subscribeExpiration)) { - migrationRequired = true - } - if (migrationRequired) { - // eslint-disable-next-line no-param-reassign - streamsFromDB[userPermissionGraph.stream.id] = { - ...streamsFromDB[userPermissionGraph.stream.id], - [userPermissionGraph.userAddress]: { - canEdit: userPermissionsDb.canEdit || userPermissionGraph.canEdit, - canDelete: userPermissionsDb.canDelete || userPermissionGraph.canDelete, - publishExpiration: userPermissionsDb.publishExpiration < userPermissionGraph.publishExpiration - ? userPermissionsDb.publishExpiration : userPermissionGraph.publishExpiration, - subscribeExpiration: userPermissionsDb.subscribeExpiration < userPermissionGraph.subscribeExpiration - ? userPermissionsDb.subscribeExpiration : userPermissionGraph.subscribeExpiration, - canGrant: userPermissionsDb.canGrant || userPermissionGraph.canGrant - } - } - } else { - // eslint-disable-next-line no-param-reassign - delete streamsFromDB[userPermissionGraph.stream.id].permissions[userPermissionGraph.userAddress] - } - } - Object.keys(streamsFromDB).forEach((streamId) => { - if (Object.keys(streamsFromDB[streamId].permissions).length === 0) { - // eslint-disable-next-line no-param-reassign - delete streamsFromDB[streamId] - } - }) - // if (streamsFromDB[streamFromGraph.id].permissions && Object.keys(streamsFromDB[streamFromGraph.id].permissions).length === 0) { - // // eslint-disable-next-line no-param-reassign - // delete streamsFromDB[streamFromGraph.id] - // } - debug('streams left to migrate at least some permissions after comparison: ' + Object.keys(streamsFromDB).length) - return streamsFromDB -} - -export default compareToMigrated diff --git a/packages/brubeck-migration-script/src/index.ts b/packages/brubeck-migration-script/src/index.ts deleted file mode 100644 index 2fc91c12d..000000000 --- a/packages/brubeck-migration-script/src/index.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable no-param-reassign */ -/* eslint-disable max-len */ - -// get all data -// select DISTINCT stream.id, user.username, permission.operation from user, stream, permission where stream.migrate_to_brubeck = 1 -// and user.id = permission.user_id and permission.stream_id = stream.id and permission.operation != 'stream_get' order by stream.id, user.username limit 10; - -// select DISTINCT stream.id, stream.description, stream.partitions, stream.inactivity_threshold_hours, user.username, permission.operation -// from user, stream, permission -// where stream.migrate_to_brubeck = 1 -// and user.id = permission.user_id -// and permission.stream_id = stream.id -// and permission.operation != 'stream_get' -// order by stream.id, user.username; - -// debug update migration flag to 1 -// UPDATE stream SET migrate_to_brubeck = 1 LIMIT 100; - -import { ethers } from 'hardhat' -import Debug from 'debug' -import 'dotenv/config' -import comparator from './comparator' -import { Migrator } from './Migrator' - -import mysql from 'mysql' - -const migrator = new Migrator() -const debug = Debug('migration-script:index') - -const connection = mysql.createConnection({ - host: process.env.DB_HOST, - user: process.env.DB_USER, - password: process.env.DB_PASSWORD, - database: process.env.DB_NAME -}) - -const compareAndMigrate = async () => { - const query = 'select DISTINCT stream.id, stream.description, stream.partitions, stream.inactivity_threshold_hours, user.username, permission.operation from user, stream, permission where stream.migrate_to_brubeck = 1 and user.id = permission.user_id' - + ' and permission.stream_id = stream.id and permission.operation != \'stream_get\' order by stream.id, user.username;' - return new Promise((resolve) => { - connection.query(query, async (error: any, results: any) => { - if (error) { throw error } - debug('number of streamr-user-combinations from DB to migrate: ' + results.length) - const streams: any = {} - results.forEach((queryResultLine: any) => { - const metadata = JSON.stringify({ - description: queryResultLine.description || '', - partitions: queryResultLine.partitions || 1, - inactivityThresholdHours: queryResultLine.inactivity_threshold_hours - }) - if (ethers.utils.isAddress(queryResultLine.username)) { - if (!streams[queryResultLine.id]) { - streams[queryResultLine.id] = { - metadata, - permissions: {} - } - } - const userAddressLowercase = queryResultLine.username.toLowerCase() - if (!streams[queryResultLine.id].permissions[userAddressLowercase]) { - streams[queryResultLine.id].permissions[userAddressLowercase] = [] - } - streams[queryResultLine.id].permissions[userAddressLowercase].push(queryResultLine.operation) - } else { - debug('skipping user ' + queryResultLine.username + ' in stream ' + queryResultLine.id + ' because user is not an address') - } - }) - for (const streamid of Object.keys(streams)) { - const stream = streams[streamid] - for (const user of Object.keys(stream.permissions)) { - if (Object.keys(stream.permissions[user]).length === 0) { - debug('ERR') - } - const convertedPermission = Migrator.convertPermissions(stream.permissions[user]) - stream.permissions[user] = convertedPermission - } - } - const migratedFilteredOut = await comparator(streams) - await migrator.init() - await migrator.migrate(migratedFilteredOut, connection) - resolve(void 0) - }) - }) -} - -const main = async () => { - connection.connect((err: any) => { - if (err) { throw err } - debug('Connected!') - }) - while(true) { - await compareAndMigrate() - await new Promise((resolve) => setTimeout(resolve, Number.parseInt(process.env.PAUSE_BETWEEN_MIGRATIONS_MS || ''))) - } -} - -// eslint-disable-next-line promise/always-return -// connection.connect((err: any) => { -// if (err) { throw err } -// debug('Connected!') -main().then(() => { - debug('done') - return void 0 -}).catch((err: any) => { - connection.end() - debug('err: ' + err) -}) -// }) diff --git a/packages/brubeck-migration-script/src/old/cleanupStreams.ts b/packages/brubeck-migration-script/src/old/cleanupStreams.ts deleted file mode 100644 index 24aa2a908..000000000 --- a/packages/brubeck-migration-script/src/old/cleanupStreams.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable max-len */ -// without metrics Read 3220084 lines, 23955 streams, 1017490 valid ids, 953081 stream+user combos,0 without metrics. -// with metrics Read 3220084 lines, 435427 streams, 3075190 valid ids, 1365005 stream+user combos,0 without metrics. - -// get data out of db: -// echo "select DISTINCT stream.id, user.username, permission.operation from user, stream, permission where user.id = permission.user_id and permission.stream_id = stream.id and permission.operation != 'stream_get' order by stream.id, user.username;" | mysql -u root -ppassword -h 127.0.0.1 -P 3306 core_test > streamData.tsv - -import * as fs from 'fs' - -import es from 'event-stream' -import hhat from 'hardhat' - -const { ethers } = hhat - -const IN_FILE = ('./streamData.tsv') -const OUT_FILE = ('./streamData_cleaned.tsv') - -let currententStream: string -let currentUser: string -let currentPermissions: string[] -let streamUserCombos = 0 -let streams = 0 - -const writeLine = async (stream: string, user: string, permissions: string[]) => { - const line = stream + '\t' + user + '\t' + JSON.stringify(permissions) + '\n' - fs.appendFile(OUT_FILE, line, () => {}) - streamUserCombos++ - if (streamUserCombos % 10000 === 0) { console.log('written ' + streamUserCombos) } -} - -const handleLine = async (streamid: string, user: string, permission: string) => { - if (streamid !== currententStream) { - writeLine(currententStream, currentUser, currentPermissions) - currententStream = streamid - currentUser = user - currentPermissions = [] - streams++ - } else if (user !== currentUser) { - writeLine(currententStream, currentUser, currentPermissions) - currentUser = user - currentPermissions = [] - } - currentPermissions.push(permission) -} - -async function main() { - let lineNr = 0 - let valids = 0 - const withoutMetrics = 0 - - let resolver: any - const promise = new Promise((resolve) => { resolver = resolve }) - - const s = fs.createReadStream(IN_FILE) - .pipe(es.split()) - .pipe(es.mapSync(async (line: string) => { - s.pause() - lineNr += 1 - if (lineNr % 10000 === 0) { console.log('parsed ' + lineNr) } - const words = line.split('\t') - const streamid = words[0] - const user = words[1] - const permission = words[2] - if (streamid && !streamid.includes('metrics')) { // && id.includes('/')) { // && !id.includes('metrics')) { - // const address = id.split('/')[0] - // if (ethers.utils.isAddress(address)) { - if (ethers.utils.isAddress(user)) { - valids += 1 - handleLine(streamid, user, permission) - // if (!id.includes('metrics')) { withoutMetrics += 1 } - // console.log(id) - } - // } - } - s.resume() - }) - .on('error', (err: any) => { - console.log('Error while reading file.', err) - }) - .on('end', () => { - console.log(`Read ${lineNr} lines, ${streams} streams, ${valids} valid ids, ${streamUserCombos} stream+user combos,${withoutMetrics} without metrics.`) - resolver(true) - })) - return promise -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error) - process.exit(1) - }) - diff --git a/packages/brubeck-migration-script/src/old/migrateStreams.ts b/packages/brubeck-migration-script/src/old/migrateStreams.ts deleted file mode 100644 index f7988cdc4..000000000 --- a/packages/brubeck-migration-script/src/old/migrateStreams.ts +++ /dev/null @@ -1,249 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable max-len */ -// first register ens domain on mainnet -// scripts/deploy.js - -import * as fs from 'fs' - -import es from 'event-stream' -import { NonceManager } from '@ethersproject/experimental' -import { Wallet } from '@ethersproject/wallet' -import hhat from 'hardhat' -import { BigNumber, BigNumberish } from '@ethersproject/bignumber' -import { MaxInt256 } from '@ethersproject/constants' - -// import { Signer } from '@ethersproject/abstract-signer' - -// import { mnemonicToSeed } from '@ethersproject/hdnode' -import { StreamRegistry } from '../../typechain/StreamRegistry' - -const { ethers } = hhat - -const CHAIN_NODE_URL = 'http://localhost:8546' -const ADMIN_PRIVATEKEY = '0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0' -const MIGRATOR_PRIVATEKEY = '0x000000000000000000000000000000000000000000000000000000000000000c' -const STREAMREGISTRY_ADDRESS = '0xEAA002f7Dc60178B6103f8617Be45a9D3df659B6' -const PROGRESS_FILENAME = 'progressFile.txt' -const DATA_FILE = './streamData_cleaned.tsv' - -export type Permission = { - edit: boolean; - canDelete: boolean; - publishExpiration: BigNumberish; - subscribeExpiration: BigNumberish; - share: boolean; -} - -export type StreamData = { - id: string, - metadata?: string, - user: string, - permissions: Permission -} - -let adminWallet: Wallet -let migratorWallet: Wallet -let registryFromAdmin: StreamRegistry -let registryFromMigrator: StreamRegistry -let streamsToMigrate: StreamData[] = [] -let nonceManager: NonceManager -let nonce: number -let transactionData: Array<{ - streamdata: StreamData[], - nonce: number -}> = [] -let sucessfulLineNumber = -1 - -// one transaction with 30 streams, one permission each costs about 2mio gas -// polygon has 20 mio blockgaslimit, 5 transactions should fit in one block (depending on how many -// permissions each stream has) -const convertPermissions = (permissions: string[]) => { - const permissionSet = { - edit: false, - canDelete: false, - publishExpiration: BigNumber.from(0), - subscribeExpiration: BigNumber.from(0), - share: false, - } - permissions.forEach((el) => { - switch (el) { - case 'stream_edit': - permissionSet.edit = true - break - case 'stream_delete': - permissionSet.canDelete = true - break - case 'stream_publish': - permissionSet.publishExpiration = MaxInt256 - break - case 'stream_subscribe': - permissionSet.subscribeExpiration = MaxInt256 - break - case 'stream_share': - permissionSet.share = true - break - default: - break - } - }) - return permissionSet -} - -const sendStreamsToChain = async (streams: StreamData[], nonceParam: number) => { - // const permissions = new Array(streams.length) - // permissions.fill([{ - // edit: true, - // canDelete: true, - // publishExpiration: 0, - // subscribeExpiration: 0, - // share: true, - // }]) - // const fakeAddr = Wallet.createRandom().address - // const users = new Array(streams.length) - // users.fill(fakeAddr) - const metadatas = new Array(streams.length) - metadatas.fill('') - - // nonceManager.setTransactionCount(nonce) - // nonce += 1 - - try { - const tx = await registryFromMigrator.populateTransaction.trustedBulkAddStreams( - streams.map((el) => el.id), - streams.map((el) => el.user), - metadatas, - streams.map((el) => el.permissions) - ) - tx.nonce = nonceParam - tx.gasPrice = BigNumber.from(1) - // tx.gasLimit = BigNumber.from(6000000) - // const signedtx = await migratorWallet.signTransaction(tx) - const tx2 = await migratorWallet.sendTransaction(tx) - // eslint-disable-next-line no-underscore-dangle - console.log(`sent out tx: nonce: ${tx2.nonce}, gas: ${parseInt(tx2.gasLimit._hex, 16)}, gasPrice: ${tx2.gasPrice?.toNumber()}`) - const timer = setTimeout(async () => { - console.log(`nothing happening for 20s, resending tx with nonce ${tx2.nonce}`) - const newGasPrice = (tx2.gasPrice as BigNumber).toNumber() + 150 //* 1.2 - // const newGasPrice = 200 - if (tx2.gasPrice) { tx.gasPrice = BigNumber.from(Math.ceil(newGasPrice)) } - const txResend = await migratorWallet.sendTransaction(tx) - // eslint-disable-next-line no-underscore-dangle - console.log(`resent tx with nonce: ${txResend.nonce}, gas: ${parseInt(txResend.gasLimit._hex, 16)}, gasPrice: ${txResend.gasPrice?.toNumber()}`) - await txResend.wait() - console.log('mined resent tx with nonce ' + txResend.nonce) - }, 30000) - // console.log(`tx2: ${JSON.stringify(tx2)}`) - await tx2.wait() - clearTimeout(timer) - console.log('mined tx with nonce ' + tx2.nonce) - } catch (err: any) { - if (err.code === 'TRANSACTION_REPLACED') { console.log('a transaction got replaced') } - else { console.log(err) } - } -} - -const addAndSendStreamPermission = async (streamID: string, user: string, permissionStrings: string[], lineNr: number) => { - if (lineNr <= sucessfulLineNumber) { - return Promise.resolve() - } - sucessfulLineNumber = lineNr - process.stdout.write('.') - const permissions = convertPermissions(permissionStrings) - streamsToMigrate.push({ id: streamID, user, permissions }) - if (streamsToMigrate.length >= 60) { - const clonedArr = streamsToMigrate.map((a) => ({ ...a })) - // const a1 = streamsToMigrate.splice(0, 50) - // const a2 = streamsToMigrate.splice(0, 50) - streamsToMigrate = [] - transactionData.push({ - streamdata: clonedArr, - nonce - }) - nonce += 1 - if (transactionData.length >= 5) { - const promises = transactionData.map( - (data) => sendStreamsToChain(data.streamdata, data.nonce) - ) - await Promise.all(promises) - // eslint-disable-next-line require-atomic-updates - transactionData = [] - // fs.writeFile(PROGRESS_FILENAME, sucessfulLineNumber.toString(), (err) => { - // if (err) { throw err } - // console.log('saved current linenumber ' + sucessfulLineNumber) - // }) - fs.writeFileSync(PROGRESS_FILENAME, sucessfulLineNumber.toString()) - console.log('saved current linenumber ' + sucessfulLineNumber) - } - // nonce += 1 - // nonceManager.setTransactionCount(nonce) - // nonce += 1 - // nonceManager.setTransactionCount(nonce) - // sendStreamsToChain(a2) - // await new Promise((resolve) => setTimeout(resolve, 500000)) - } - return Promise.resolve() -} - -async function main() { - let lineNr = 0 - const valids = 0 - const withoutMetrics = 0 - - const networkProvider = new ethers.providers.JsonRpcProvider(CHAIN_NODE_URL) - adminWallet = new ethers.Wallet(ADMIN_PRIVATEKEY, networkProvider) - migratorWallet = new ethers.Wallet(MIGRATOR_PRIVATEKEY, networkProvider) - nonceManager = new NonceManager(migratorWallet) - const { signer } = nonceManager - const streamregistryFactory = await ethers.getContractFactory('StreamRegistry') - const registry = await streamregistryFactory.attach(STREAMREGISTRY_ADDRESS) - const registryContract = await registry.deployed() - registryFromAdmin = await registryContract.connect(adminWallet) as StreamRegistry - registryFromMigrator = await registryContract.connect(signer) as StreamRegistry - nonce = await nonceManager.getTransactionCount() - console.log('startnonce: ' + nonce) - const mtx = await registryFromAdmin.grantRole(await registryFromAdmin.TRUSTED_ROLE(), migratorWallet.address) - await mtx.wait(2) - console.log('added migrator role to ' + migratorWallet.address) - let resolver: any - const promise = new Promise((resolve) => { resolver = resolve }) - - const data = fs.readFileSync(PROGRESS_FILENAME, 'utf8') - sucessfulLineNumber = parseInt(data, 10) - console.log('read progressFile, starting with that number: ' + sucessfulLineNumber) - const s = fs.createReadStream(DATA_FILE) - .pipe(es.split()) - .pipe(es.mapSync(async (line: string) => { - s.pause() - lineNr += 1 - const words = line.split('\t') - const streamid = words[0] - const user = words[1] - const permissions = JSON.parse(words[2]) as string[] - // const address = id.split('/')[0] - // if (ethers.utils.isAddress(address)) { - if (ethers.utils.isAddress(user)) { - // valids += 1 - // if (!id.includes('metrics')) { withoutMetrics += 1 } - // console.log(id) - await addAndSendStreamPermission(streamid, user, permissions, lineNr) - } - // } - s.resume() - }) - .on('error', (err: any) => { - console.log('Error while reading file.', err) - }) - .on('end', () => { - console.log(`Read ${lineNr} lines, ${valids} valid ids, ${withoutMetrics} without metrics.`) - resolver(true) - })) - return promise -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error) - process.exit(1) - }) - diff --git a/packages/brubeck-migration-script/src/old/migrateStreamsHighGas.ts b/packages/brubeck-migration-script/src/old/migrateStreamsHighGas.ts deleted file mode 100644 index 11c85f840..000000000 --- a/packages/brubeck-migration-script/src/old/migrateStreamsHighGas.ts +++ /dev/null @@ -1,253 +0,0 @@ -/* eslint-disable no-console */ -// first register ens domain on mainnet -// scripts/deploy.js - -import * as fs from 'fs' - -import es from 'event-stream' -import { NonceManager } from '@ethersproject/experimental' -import { Wallet } from '@ethersproject/wallet' -import hhat from 'hardhat' -import { BigNumber, BigNumberish } from '@ethersproject/bignumber' -import { MaxInt256 } from '@ethersproject/constants' - -// import { Signer } from '@ethersproject/abstract-signer' - -// import { mnemonicToSeed } from '@ethersproject/hdnode' -import { StreamRegistry } from '../../typechain/StreamRegistry' -// import { TimerOptions } from 'timers' -// import ts from 'typescript' - -const { ethers } = hhat - -const CHAIN_NODE_URL = 'http://localhost:8546' -const ADMIN_PRIVATEKEY = '0x5e98cce00cff5dea6b454889f359a4ec06b9fa6b88e9d69b86de8e1c81887da0' -const MIGRATOR_PRIVATEKEY = '0x0000000000000000000000000000000000000000000000000000000000000010' -const STREAMREGISTRY_ADDRESS = '0xE4eA76e830a659282368cA2e7E4d18C4AE52D8B3' -const PROGRESS_FILENAME = 'progressFile.txt' -const DATA_FILE = './streamData_cleaned.tsv' - -export type Permission = { - edit: boolean; - canDelete: boolean; - publishExpiration: BigNumberish; - subscribeExpiration: BigNumberish; - share: boolean; -} - -export type StreamData = { - id: string, - metadata?: string, - user: string, - permissions: Permission -} - -let adminWallet: Wallet -let migratorWallet: Wallet -let registryFromAdmin: StreamRegistry -let registryFromMigrator: StreamRegistry -let streamsToMigrate: StreamData[] = [] -let nonceManager: NonceManager -let nonce: number -let transactionData: Array<{ - streamdata: StreamData[], - nonce: number -}> = [] -let sucessfulLineNumber = -1 -// let timer - -// one transaction with 30 streams, one permission each costs about 2mio gas -// polygon has 20 mio blockgaslimit, 5 transactions should fit in one block (depending on how many -// permissions each stream has) -const convertPermissions = (permissions: string[]) => { - const permissionSet = { - edit: false, - canDelete: false, - publishExpiration: BigNumber.from(0), - subscribeExpiration: BigNumber.from(0), - share: false, - } - permissions.forEach((el) => { - switch (el) { - case 'stream_edit': - permissionSet.edit = true - break - case 'stream_delete': - permissionSet.canDelete = true - break - case 'stream_publish': - permissionSet.publishExpiration = MaxInt256 - break - case 'stream_subscribe': - permissionSet.subscribeExpiration = MaxInt256 - break - case 'stream_share': - permissionSet.share = true - break - default: - break - } - }) - return permissionSet -} - -const sendStreamsToChain = async (streams: StreamData[], nonceParam: number) => { - // const permissions = new Array(streams.length) - // permissions.fill([{ - // edit: true, - // canDelete: true, - // publishExpiration: 0, - // subscribeExpiration: 0, - // share: true, - // }]) - // const fakeAddr = Wallet.createRandom().address - // const users = new Array(streams.length) - // users.fill(fakeAddr) - const metadatas = new Array(streams.length) - metadatas.fill('') - - // nonceManager.setTransactionCount(nonce) - // nonce += 1 - - try { - const tx = await registryFromMigrator.populateTransaction.trustedBulkAddStreams( - streams.map((el) => el.id), - streams.map((el) => el.user), - metadatas, - streams.map((el) => el.permissions) - ) - tx.nonce = nonceParam - tx.gasPrice = BigNumber.from(100) - // tx.gasLimit = BigNumber.from(6000000) - // const signedtx = await migratorWallet.signTransaction(tx) - const tx2 = await migratorWallet.sendTransaction(tx) - // eslint-disable-next-line no-underscore-dangle - console.log(`sent out tx: nonce: ${tx2.nonce}, gas: ${parseInt(tx2.gasLimit._hex, 16)}, gasPrice: ${tx2.gasPrice?.toNumber()}`) - // timer = setTimeout(async () => { - // console.log('nothing happening for 20s, resending last batch') - // const newGasPrice = (tx2.gasPrice as BigNumber).toNumber() + 150 //* 1.2 - // // const newGasPrice = 200 - // if (tx2.gasPrice) { tx.gasPrice = BigNumber.from(Math.ceil(newGasPrice)) } - // const txResend = await migratorWallet.sendTransaction(tx) - // console.log(`resent tx with nonce: ${txResend.nonce}, gas: ${parseInt(txResend.gasLimit._hex, 16)}`) - // }, 20000) - // console.log(`tx2: ${JSON.stringify(tx2)}`) - await tx2.wait() - console.log('mined tx with nonce ' + tx2.nonce) - } catch (err) { - console.log(err) - } -} - -const addAndSendStreamPermission = async (streamID: string, user: string, permissionStrings: string[], lineNr: number) => { - if (lineNr <= sucessfulLineNumber) { - return Promise.resolve() - } - sucessfulLineNumber = lineNr - // process.stdout.write('.') - const permissions = convertPermissions(permissionStrings) - streamsToMigrate.push({ id: streamID, user, permissions }) - if (streamsToMigrate.length >= 30) { - const clonedArr = streamsToMigrate.map((a) => ({ ...a })) - // const a1 = streamsToMigrate.splice(0, 50) - // const a2 = streamsToMigrate.splice(0, 50) - streamsToMigrate = [] - transactionData.push({ - streamdata: clonedArr, - nonce - }) - nonce += 1 - if (transactionData.length >= 5) { - // const promises = - transactionData.map( - (data) => sendStreamsToChain(data.streamdata, data.nonce) - ) - // await Promise.all(promises) - - // eslint-disable-next-line require-atomic-updates - transactionData = [] - // fs.writeFile(PROGRESS_FILENAME, sucessfulLineNumber.toString(), (err) => { - // if (err) { throw err } - // console.log('saved current linenumber ' + sucessfulLineNumber) - // }) - fs.writeFileSync(PROGRESS_FILENAME, sucessfulLineNumber.toString()) - console.log('saved current linenumber ' + sucessfulLineNumber) - } - // nonce += 1 - // nonceManager.setTransactionCount(nonce) - // nonce += 1 - // nonceManager.setTransactionCount(nonce) - // sendStreamsToChain(a2) - await new Promise((resolve) => setTimeout(resolve, 1000)) - } - return Promise.resolve() -} - -async function main() { - let lineNr = 0 - const valids = 0 - const withoutMetrics = 0 - - const networkProvider = new ethers.providers.JsonRpcProvider(CHAIN_NODE_URL) - adminWallet = new ethers.Wallet(ADMIN_PRIVATEKEY, networkProvider) - migratorWallet = new ethers.Wallet(MIGRATOR_PRIVATEKEY, networkProvider) - nonceManager = new NonceManager(migratorWallet) - const { signer } = nonceManager - const streamregistryFactory = await ethers.getContractFactory('StreamRegistry') - const registry = await streamregistryFactory.attach(STREAMREGISTRY_ADDRESS) - const registryContract = await registry.deployed() - registryFromAdmin = await registryContract.connect(adminWallet) as StreamRegistry - registryFromMigrator = await registryContract.connect(signer) as StreamRegistry - nonce = await nonceManager.getTransactionCount() - console.log('startnonce: ' + nonce) - const mtx = await registryFromAdmin.grantRole(await registryFromAdmin.TRUSTED_ROLE(), migratorWallet.address) - await mtx.wait(2) - console.log('added migrator role to ' + migratorWallet.address) - let resolver: any - const promise = new Promise((resolve) => { resolver = resolve }) - - fs.readFile(PROGRESS_FILENAME, 'utf8', (err, data) => { - if (err) { - console.log('cant read progress file ', err) - throw err - } - sucessfulLineNumber = parseInt(data, 10) - console.log('read progressFile, starting with that number: ' + sucessfulLineNumber) - }) - const s = fs.createReadStream(DATA_FILE) - .pipe(es.split()) - .pipe(es.mapSync(async (line: string) => { - s.pause() - lineNr += 1 - const words = line.split('\t') - const streamid = words[0] - const user = words[1] - const permissions = JSON.parse(words[2]) as string[] - // const address = id.split('/')[0] - // if (ethers.utils.isAddress(address)) { - if (ethers.utils.isAddress(user)) { - // valids += 1 - // if (!id.includes('metrics')) { withoutMetrics += 1 } - // console.log(id) - await addAndSendStreamPermission(streamid, user, permissions, lineNr) - } - // } - s.resume() - }) - .on('error', (err: any) => { - console.log('Error while reading file.', err) - }) - .on('end', () => { - console.log(`Read ${lineNr} lines, ${valids} valid ids, ${withoutMetrics} without metrics.`) - resolver(true) - })) - return promise -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error) - process.exit(1) - }) - diff --git a/packages/brubeck-migration-script/tsconfig.json b/packages/brubeck-migration-script/tsconfig.json deleted file mode 100644 index 8190f706b..000000000 --- a/packages/brubeck-migration-script/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "display": "Node 12", - "compilerOptions": { - "lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"], - "module": "CommonJS", - "target": "es2019", - "preserveSymlinks": true, - "strict": true, - "esModuleInterop": true, - "noImplicitAny": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "outDir": "dist", - "strictPropertyInitialization": false - }, - "include": ["./scripts", "./test", "./typechain", "test-contracts"], - "files": [ - "./hardhat.config.ts" - ] -} \ No newline at end of file