@rosen-bridge/tx-pot 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/README.md +36 -0
- package/dist/db/entities/TransactionEntity.d.ts +15 -0
- package/dist/db/entities/TransactionEntity.d.ts.map +1 -0
- package/dist/db/entities/TransactionEntity.js +81 -0
- package/dist/db/migrations/index.d.ts +7 -0
- package/dist/db/migrations/index.d.ts.map +1 -0
- package/dist/db/migrations/index.js +7 -0
- package/dist/db/migrations/postgres/1706350644686-migration.d.ts +7 -0
- package/dist/db/migrations/postgres/1706350644686-migration.d.ts.map +1 -0
- package/dist/db/migrations/postgres/1706350644686-migration.js +28 -0
- package/dist/db/migrations/sqlite/1706007154531-migration.d.ts +7 -0
- package/dist/db/migrations/sqlite/1706007154531-migration.d.ts.map +1 -0
- package/dist/db/migrations/sqlite/1706007154531-migration.js +28 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/network/AbstractPotChainManager.d.ts +36 -0
- package/dist/network/AbstractPotChainManager.d.ts.map +1 -0
- package/dist/network/AbstractPotChainManager.js +3 -0
- package/dist/transaction/TxPot.d.ts +164 -0
- package/dist/transaction/TxPot.d.ts.map +1 -0
- package/dist/transaction/TxPot.js +386 -0
- package/dist/transaction/types.d.ts +35 -0
- package/dist/transaction/types.d.ts.map +1 -0
- package/dist/transaction/types.js +21 -0
- package/dist/transaction/utils.d.ts +8 -0
- package/dist/transaction/utils.d.ts.map +1 -0
- package/dist/transaction/utils.js +56 -0
- package/lib/db/entities/TransactionEntity.ts +44 -0
- package/lib/db/migrations/index.ts +7 -0
- package/lib/db/migrations/postgres/1706350644686-migration.ts +31 -0
- package/lib/db/migrations/sqlite/1706007154531-migration.ts +31 -0
- package/lib/index.ts +5 -0
- package/lib/network/AbstractPotChainManager.ts +44 -0
- package/lib/transaction/TxPot.ts +519 -0
- package/lib/transaction/types.ts +46 -0
- package/lib/transaction/utils.ts +59 -0
- package/package.json +39 -0
- package/tests/.gitkeep +0 -0
- package/tests/db/dataSource.mock.ts +18 -0
- package/tests/network/TestPotChainManager.ts +23 -0
- package/tests/transaction/TestTxPot.ts +32 -0
- package/tests/transaction/TxPot.spec.ts +1517 -0
- package/tests/transaction/testData.ts +84 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { In, Not } from 'typeorm';
|
|
2
|
+
import { TxOptions } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* converts options for fetching txs to typeorm clause
|
|
6
|
+
* @param options
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const txOptionToClause = (options: TxOptions) => {
|
|
10
|
+
const clause: Record<string, any> = {};
|
|
11
|
+
|
|
12
|
+
// add txId clause
|
|
13
|
+
if (typeof options.txId === 'string') {
|
|
14
|
+
clause.txId = options.txId;
|
|
15
|
+
} else if (Array.isArray(options.txId)) {
|
|
16
|
+
clause.txId = In(options.txId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// add chain clause
|
|
20
|
+
if (typeof options.chain === 'string') {
|
|
21
|
+
clause.chain = options.chain;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// add txType clause
|
|
25
|
+
if (typeof options.txType === 'string') {
|
|
26
|
+
clause.txType = options.txType;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// add status clause
|
|
30
|
+
if (options.status) {
|
|
31
|
+
if (typeof options.status.value === 'string') {
|
|
32
|
+
if (options.status.not) {
|
|
33
|
+
clause.status = Not(options.status.value);
|
|
34
|
+
} else {
|
|
35
|
+
clause.status = options.status.value;
|
|
36
|
+
}
|
|
37
|
+
} else if (Array.isArray(options.status.value)) {
|
|
38
|
+
if (options.status.not) {
|
|
39
|
+
clause.status = Not(In(options.status.value));
|
|
40
|
+
} else {
|
|
41
|
+
clause.status = In(options.status.value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// add failedInSign clause
|
|
47
|
+
if (typeof options.failedInSign === 'boolean') {
|
|
48
|
+
clause.failedInSign = options.failedInSign;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// add extra clause
|
|
52
|
+
if (typeof options.extra === 'string') {
|
|
53
|
+
clause.extra = options.extra;
|
|
54
|
+
} else if (Array.isArray(options.extra)) {
|
|
55
|
+
clause.extra = In(options.extra);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return clause;
|
|
59
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rosen-bridge/tx-pot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "a Typescript package to manage transactions storage, sign, submit and related processes",
|
|
5
|
+
"repository": "@rosen-bridge/tx-pot",
|
|
6
|
+
"license": "GPL-3.0",
|
|
7
|
+
"author": "Rosen Team",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc --build tsconfig.build.json",
|
|
13
|
+
"coverage": "npm run test -- --coverage",
|
|
14
|
+
"lint": "eslint --fix . && npm run prettify",
|
|
15
|
+
"prettify": "prettier --write . --ignore-path ./.gitignore",
|
|
16
|
+
"release": "npm run test -- --run && npm run build && npm publish --access public",
|
|
17
|
+
"test": "NODE_OPTIONS=--experimental-specifier-resolution=node vitest",
|
|
18
|
+
"type-check": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^18.11.18",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
23
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
24
|
+
"@vitest/coverage-v8": "^1.2.2",
|
|
25
|
+
"eslint": "^8.16.0",
|
|
26
|
+
"eslint-config-prettier": "^8.5.0",
|
|
27
|
+
"prettier": "2.7.1",
|
|
28
|
+
"typescript": "^5.0.0",
|
|
29
|
+
"vite-plugin-wasm": "^3.3.0",
|
|
30
|
+
"vitest": "^1.2.1"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.12.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@rosen-bridge/abstract-logger": "^1.0.0",
|
|
37
|
+
"typeorm": "^0.3.17"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/tests/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { TransactionEntity, migrations } from '../../lib';
|
|
3
|
+
|
|
4
|
+
export const mockDataSource = async () => {
|
|
5
|
+
const testDataSource = new DataSource({
|
|
6
|
+
type: 'sqlite',
|
|
7
|
+
database: ':memory:',
|
|
8
|
+
entities: [TransactionEntity],
|
|
9
|
+
migrations: [...migrations.sqlite],
|
|
10
|
+
synchronize: false,
|
|
11
|
+
logging: false,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
await testDataSource.initialize();
|
|
15
|
+
await testDataSource.runMigrations();
|
|
16
|
+
|
|
17
|
+
return testDataSource;
|
|
18
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractPotChainManager, SigningStatus } from '../../lib';
|
|
2
|
+
|
|
3
|
+
export class TestPotChainManager implements AbstractPotChainManager {
|
|
4
|
+
notImplemented = () => {
|
|
5
|
+
throw Error('Not implemented');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
getHeight: () => Promise<number> = this.notImplemented;
|
|
9
|
+
|
|
10
|
+
getTxRequiredConfirmation: (txType: string) => number = this.notImplemented;
|
|
11
|
+
|
|
12
|
+
getTxConfirmation: (txId: string) => Promise<number> = this.notImplemented;
|
|
13
|
+
|
|
14
|
+
isTxValid: (
|
|
15
|
+
serializedTx: string,
|
|
16
|
+
signingStatus: SigningStatus
|
|
17
|
+
) => Promise<boolean> = this.notImplemented;
|
|
18
|
+
|
|
19
|
+
submitTransaction: (serializedTx: string) => Promise<void> =
|
|
20
|
+
this.notImplemented;
|
|
21
|
+
|
|
22
|
+
isTxInMempool: (txId: string) => Promise<boolean> = this.notImplemented;
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { AbstractLogger } from '@rosen-bridge/logger-interface';
|
|
3
|
+
import { TransactionEntity, TransactionStatus, TxPot } from '../../lib';
|
|
4
|
+
|
|
5
|
+
export class TestTxPot extends TxPot {
|
|
6
|
+
protected static instance: TestTxPot;
|
|
7
|
+
|
|
8
|
+
public static setup = (
|
|
9
|
+
dataSource: DataSource,
|
|
10
|
+
logger?: AbstractLogger
|
|
11
|
+
): TestTxPot => {
|
|
12
|
+
TestTxPot.instance = new TestTxPot(dataSource, logger);
|
|
13
|
+
return TestTxPot.instance;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
callSetTransactionAsInvalid = async (tx: TransactionEntity): Promise<void> =>
|
|
17
|
+
this.setTransactionAsInvalid(tx);
|
|
18
|
+
|
|
19
|
+
callValidateTx = async (tx: TransactionEntity): Promise<boolean> =>
|
|
20
|
+
this.validateTx(tx);
|
|
21
|
+
|
|
22
|
+
callSetTxStatus = async (
|
|
23
|
+
tx: TransactionEntity,
|
|
24
|
+
status: TransactionStatus
|
|
25
|
+
): Promise<void> => this.setTxStatus(tx, status);
|
|
26
|
+
|
|
27
|
+
callProcessSignedTx = async (tx: TransactionEntity): Promise<void> =>
|
|
28
|
+
this.processSignedTx(tx);
|
|
29
|
+
|
|
30
|
+
callProcessesSentTx = async (tx: TransactionEntity): Promise<void> =>
|
|
31
|
+
this.processesSentTx(tx);
|
|
32
|
+
}
|