-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement components - contains bugs
- Loading branch information
Showing
123 changed files
with
9,894 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.eslintrc.js | ||
jest.config.unit.js | ||
build/ | ||
coverage/ | ||
node_modules/ | ||
src/**/__tests__/ | ||
src/**/__mocks__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = { | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: [`./tsconfig.json`], | ||
ecmaVersion: 12, | ||
sourceType: "module" | ||
}, | ||
root: true, | ||
extends: [ | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking" | ||
], | ||
plugins: ["@typescript-eslint"], | ||
env: { | ||
es2021: true, | ||
node: true | ||
}, | ||
ignorePatterns: ["build", "node_modules", "scripts", "__tests__"], | ||
rules: { | ||
"no-case-declarations": "warn", | ||
"no-unused-vars": "off", | ||
"no-constant-condition": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,9 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
build | ||
|
||
.jest | ||
|
||
coverage |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@alien-worlds:registry=https://npm.pkg.github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
node_modules/ | ||
scripts/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"printWidth": 90 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Alien Worlds | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
# api-history-tools | ||
# api-history-tools | ||
|
||
### Processor | ||
|
||
Lorem | ||
|
||
### Block Range | ||
|
||
Lorem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
collectCoverage: true, | ||
coverageDirectory: 'coverage', | ||
verbose: true, | ||
preset: 'ts-jest', | ||
testEnvironment: 'jest-environment-node', | ||
testMatch: ['**/__tests__/**/*.unit.test.ts'], | ||
collectCoverageFrom: [ | ||
'src/**/*.ts', | ||
'!src/**/index.ts', | ||
'!src/**/*.config.ts', | ||
'!src/**/config.ts', | ||
'!**/query-model.ts', | ||
'!**/mapper.ts', | ||
'!**/use-case.ts', | ||
'!**/*.repository.ts', | ||
'!**/*.fixture.ts', | ||
'!**/*.mock.ts', | ||
'!**/*.error.ts', | ||
'!**/__tests__/**', | ||
'!**/__mocks__/**', | ||
'!src/**/*.enums.ts', | ||
'!src/**/*.dtos.ts', | ||
'!src/**/*.types.ts', | ||
'!src/**/worker.ts', | ||
'!src/**/repository.ts', | ||
'!src/api/*', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"verbose": true, | ||
"watch": ["src/**/*.ts"], | ||
"execMap": { | ||
"ts": "node -r ts-node/register" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@alien-worlds/api-history-tools", | ||
"version": "0.0.1", | ||
"description": "", | ||
"engines": { | ||
"node": ">=17.3.0 <18.0.0", | ||
"npm": ">=8.3.0 <9.0.0" | ||
}, | ||
"packageManager": "[email protected]", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"files": [ | ||
"build" | ||
], | ||
"scripts": { | ||
"test:unit": "jest --config=jest.config.unit.js", | ||
"clean": "rm -rf ./build", | ||
"build": "yarn clean && tsc -b", | ||
"prepublish": "yarn clean && tsc --project tsconfig.build.json", | ||
"lint": "eslint . --ext .ts", | ||
"lint-fix": "eslint . --ext .ts --fix", | ||
"format-check": "prettier --check \"src/\"", | ||
"format": "prettier --write \"src/\"" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^18.7.14", | ||
"@typescript-eslint/eslint-plugin": "^5.37.0", | ||
"@typescript-eslint/parser": "^5.37.0", | ||
"eslint": "^8.23.1", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^27.4.5", | ||
"prettier": "^2.7.1", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.8.2" | ||
}, | ||
"dependencies": { | ||
"@alien-worlds/api-core": "^0.0.27", | ||
"amqplib": "^0.10.3", | ||
"eosjs": "^22.1.0", | ||
"node-fetch": "^3.2.10", | ||
"reflect-metadata": "^0.1.13", | ||
"text-encoding": "^0.7.0", | ||
"ts-node": "^10.9.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
error_exit() | ||
{ | ||
echo "Error: $1" | ||
exit 1 | ||
} | ||
|
||
# major | minor | patch | ||
TYPE=patch | ||
|
||
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] | ||
then | ||
TYPE=$1 | ||
elif [[ $1 == "major" ]] || [[ $1 == "minor" ]] || [[ $1 == "patch" ]] | ||
then | ||
TYPE=$1 | ||
elif [[ $1 == "" ]] | ||
then | ||
TYPE=patch | ||
else | ||
printf "Unknown update type \"%s\".\n- Please use \"major\" | \"minor\" | \"patch\"\n" "$1" | ||
exit 1; | ||
fi | ||
|
||
# Build package | ||
yarn prepublish || error_exit "Prepublish failed" | ||
|
||
# Pull latest changes | ||
git pull || error_exit "Pulling failed" | ||
|
||
# Update version and commit | ||
npm version $TYPE || error_exit "Failed to set a new version of the package" | ||
|
||
# Push changed package.json | ||
git push origin || error_exit "Failed to submit changes to the repository" | ||
|
||
# publish package | ||
npm publish || error_exit "Failed to publish a new version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
BroadcastAmqClient, | ||
BroadcastMessage, | ||
BroadcastMessageContentMapper, | ||
} from '../common/broadcast'; | ||
import { BlockRangeBroadcastMapper } from './block-range.mapper'; | ||
import { BlockRangeTaskInput } from './block-range.task-input'; | ||
|
||
export abstract class BlockRangeBroadcastEmmiter { | ||
public abstract sendMessage(data: BlockRangeTaskInput): Promise<void>; | ||
} | ||
|
||
export class BlockRangeBroadcast implements BlockRangeBroadcastEmmiter { | ||
constructor(private client: BroadcastAmqClient, private channel: string) {} | ||
|
||
public sendMessage(data: BlockRangeTaskInput): Promise<void> { | ||
return this.client.sendMessage(this.channel, data); | ||
} | ||
|
||
public onMessage( | ||
handler: (message: BroadcastMessage<BlockRangeTaskInput>) => void | ||
): void { | ||
return this.client.onMessage(this.channel, handler); | ||
} | ||
} | ||
|
||
export const createBlockRangeBroadcastOptions = ( | ||
mapper?: BroadcastMessageContentMapper | ||
) => { | ||
return { | ||
prefetch: 1, | ||
queues: [ | ||
{ | ||
name: 'block_range', | ||
options: { durable: false }, | ||
mapper: mapper || new BlockRangeBroadcastMapper(), | ||
noAck: true, | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BlockRangeScanConfig } from '../common/block-range-scanner'; | ||
import { BlockReaderConfig } from '../common/blockchain/block-reader'; | ||
|
||
export type BlockRangeConfig = { | ||
broadcast: { | ||
url: string; | ||
}; | ||
reader: BlockReaderConfig; | ||
mongo: { url: string; dbName: string }; | ||
scanner: BlockRangeScanConfig; | ||
threads: number; | ||
}; | ||
|
||
export const blockRangeConfig: BlockRangeConfig = { | ||
broadcast: { | ||
url: '', | ||
}, | ||
reader: { shipEndpoints: [] }, | ||
mongo: { url: '', dbName: '' }, | ||
scanner: { numberOfChildren: 10, minChunkSize: 5000, scanKey: '' }, | ||
threads: 10, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import { Serialize } from 'eosjs'; | ||
import { BroadcastMessageContentMapper } from '../common/broadcast'; | ||
import { BlockRangeTaskInput } from './block-range.task-input'; | ||
|
||
export class BlockRangeBroadcastMapper | ||
implements BroadcastMessageContentMapper<BlockRangeTaskInput, Buffer> | ||
{ | ||
public toContent(buffer: Buffer): BlockRangeTaskInput { | ||
const sb = new Serialize.SerialBuffer({ | ||
textEncoder: new TextEncoder(), | ||
textDecoder: new TextDecoder(), | ||
array: new Uint8Array(buffer), | ||
}); | ||
|
||
const mode = sb.getName(); | ||
const scanKey = sb.getName(); | ||
const traces = sb.getName(); | ||
const deltas = sb.getName(); | ||
|
||
const startBlock: bigint = Buffer.from(sb.getUint8Array(8)).readBigInt64BE(); | ||
const endBlock: bigint = Buffer.from(sb.getUint8Array(8)).readBigInt64BE(); | ||
|
||
return BlockRangeTaskInput.create( | ||
startBlock, | ||
endBlock, | ||
mode, | ||
scanKey, | ||
traces, | ||
deltas | ||
); | ||
} | ||
public toSource(content: BlockRangeTaskInput): Buffer { | ||
const { | ||
startBlock, | ||
endBlock, | ||
mode, | ||
scanKey, | ||
featuredTraces: traces, | ||
featuredDeltas: deltas, | ||
} = content; | ||
|
||
const sb = new Serialize.SerialBuffer({ | ||
textEncoder: new TextEncoder(), | ||
textDecoder: new TextDecoder(), | ||
}); | ||
|
||
sb.pushName(mode); | ||
sb.pushName(scanKey); | ||
sb.pushName(JSON.stringify(traces)); | ||
sb.pushName(JSON.stringify(deltas)); | ||
|
||
const startBlockBuffer = Buffer.alloc(8); | ||
startBlockBuffer.writeBigInt64BE(startBlock); | ||
const endBlockBuffer = Buffer.alloc(8); | ||
endBlockBuffer.writeBigInt64BE(endBlock); | ||
|
||
return Buffer.concat([startBlockBuffer, endBlockBuffer]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { FeaturedTrace, FeaturedDelta } from './block-range.types'; | ||
import { parseToFeaturedDeltas, parseToFeaturedTraces } from './block-range.utils'; | ||
|
||
export class BlockRangeTaskInput { | ||
public static create( | ||
startBlock: bigint, | ||
endBlock: bigint, | ||
mode: string, | ||
scanKey: string, | ||
featuredTraces: string | FeaturedTrace[], | ||
featuredDeltas: string | FeaturedDelta[] | ||
) { | ||
return new BlockRangeTaskInput( | ||
mode, | ||
scanKey, | ||
Array.isArray(featuredTraces) | ||
? featuredTraces | ||
: parseToFeaturedTraces(featuredTraces), | ||
Array.isArray(featuredDeltas) | ||
? featuredDeltas | ||
: parseToFeaturedDeltas(featuredDeltas), | ||
startBlock, | ||
endBlock | ||
); | ||
} | ||
|
||
private constructor( | ||
public readonly mode: string, | ||
public readonly scanKey: string, | ||
public readonly featuredTraces: FeaturedTrace[], | ||
public readonly featuredDeltas: FeaturedDelta[], | ||
public readonly startBlock: bigint, | ||
public readonly endBlock: bigint | ||
) {} | ||
} |
Oops, something went wrong.