@rosen-bridge/tx-pot 0.1.0 → 1.0.1
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/CHANGELOG.md +28 -0
- package/README.md +436 -7
- package/dist/db/entities/TransactionEntity.d.ts +2 -2
- package/dist/db/entities/TransactionEntity.d.ts.map +1 -1
- package/dist/db/entities/TransactionEntity.js +3 -3
- package/dist/db/migrations/index.d.ts +3 -3
- package/dist/db/migrations/index.js +3 -3
- package/dist/db/migrations/postgres/1706350644686-migration.d.ts +4 -4
- package/dist/db/migrations/postgres/1706350644686-migration.js +8 -8
- package/dist/db/migrations/sqlite/1706007154531-migration.d.ts +4 -4
- package/dist/db/migrations/sqlite/1706007154531-migration.js +8 -8
- package/dist/index.d.ts +1 -1
- package/dist/network/AbstractPotChainManager.d.ts +36 -33
- package/dist/transaction/TxPot.d.ts +55 -7
- package/dist/transaction/TxPot.d.ts.map +1 -1
- package/dist/transaction/TxPot.js +173 -26
- package/dist/transaction/types.d.ts +1 -1
- package/dist/transaction/types.d.ts.map +1 -1
- package/dist/transaction/types.js +1 -1
- package/dist/transaction/utils.d.ts +4 -2
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/db/entities/TransactionEntity.ts +2 -2
- package/lib/transaction/TxPot.ts +240 -31
- package/lib/transaction/types.ts +1 -1
- package/package.json +2 -2
- package/tests/transaction/TestTxPot.ts +1 -1
- package/tests/transaction/TxPot.spec.ts +366 -2
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { SigningStatus } from '../transaction/types';
|
|
2
2
|
export declare abstract class AbstractPotChainManager {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
3
|
+
/**
|
|
4
|
+
* gets the blockchain current height
|
|
5
|
+
*/
|
|
6
|
+
abstract getHeight: () => Promise<number>;
|
|
7
|
+
/**
|
|
8
|
+
* returns required number of confirmation
|
|
9
|
+
* @param txType
|
|
10
|
+
*/
|
|
11
|
+
abstract getTxRequiredConfirmation: (txType: string) => number;
|
|
12
|
+
/**
|
|
13
|
+
* gets number of confirmation for a tx
|
|
14
|
+
* returns -1 if tx is not in the blockchain
|
|
15
|
+
* @param txId
|
|
16
|
+
*/
|
|
17
|
+
abstract getTxConfirmation: (txId: string) => Promise<number>;
|
|
18
|
+
/**
|
|
19
|
+
* checks if a tx is still valid and can be sent to the network
|
|
20
|
+
* @param serializedTx
|
|
21
|
+
* @param signingStatus
|
|
22
|
+
*/
|
|
23
|
+
abstract isTxValid: (
|
|
24
|
+
serializedTx: string,
|
|
25
|
+
signingStatus: SigningStatus
|
|
26
|
+
) => Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* submits a tx to the blockchain
|
|
29
|
+
* @param serializedTx
|
|
30
|
+
*/
|
|
31
|
+
abstract submitTransaction: (serializedTx: string) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* checks if a tx is in mempool
|
|
34
|
+
* returns false if the chain has no mempool
|
|
35
|
+
* @param txId
|
|
36
|
+
*/
|
|
37
|
+
abstract isTxInMempool: (txId: string) => Promise<boolean>;
|
|
35
38
|
}
|
|
36
|
-
//# sourceMappingURL=AbstractPotChainManager.d.ts.map
|
|
39
|
+
//# sourceMappingURL=AbstractPotChainManager.d.ts.map
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { DataSource, Repository } from 'typeorm';
|
|
2
2
|
import { TransactionEntity } from '../db/entities/TransactionEntity';
|
|
3
|
-
import { AbstractLogger } from '@rosen-bridge/logger
|
|
3
|
+
import { AbstractLogger } from '@rosen-bridge/abstract-logger';
|
|
4
4
|
import { CallbackFunction, TransactionStatus, TxOptions, ValidatorFunction } from './types';
|
|
5
5
|
import { AbstractPotChainManager } from '../network/AbstractPotChainManager';
|
|
6
6
|
export declare class TxPot {
|
|
7
7
|
protected static instance: TxPot;
|
|
8
8
|
protected readonly txRepository: Repository<TransactionEntity>;
|
|
9
9
|
protected chains: Map<string, AbstractPotChainManager>;
|
|
10
|
-
protected validators: Map<string, Map<string, ValidatorFunction
|
|
11
|
-
protected txTypeCallbacks: Map<string, Map<TransactionStatus, CallbackFunction
|
|
10
|
+
protected validators: Map<string, Map<string, Map<string, ValidatorFunction>>>;
|
|
11
|
+
protected txTypeCallbacks: Map<string, Map<TransactionStatus, Map<string, CallbackFunction>>>;
|
|
12
|
+
protected submissionAllowance: Map<string, Map<string, ValidatorFunction>>;
|
|
12
13
|
protected logger: AbstractLogger;
|
|
13
14
|
protected constructor(dataSource: DataSource, logger?: AbstractLogger);
|
|
14
15
|
/**
|
|
@@ -33,18 +34,47 @@ export declare class TxPot {
|
|
|
33
34
|
* registers a validator function
|
|
34
35
|
* @param chain
|
|
35
36
|
* @param txType
|
|
37
|
+
* @param id
|
|
36
38
|
* @param validator
|
|
37
39
|
*/
|
|
38
|
-
registerValidator: (chain: string, txType: string, validator: ValidatorFunction) => void;
|
|
40
|
+
registerValidator: (chain: string, txType: string, id: string, validator: ValidatorFunction) => void;
|
|
41
|
+
/**
|
|
42
|
+
* removes a validator function
|
|
43
|
+
* @param chain
|
|
44
|
+
* @param txType
|
|
45
|
+
* @param id
|
|
46
|
+
*/
|
|
47
|
+
unregisterValidator: (chain: string, txType: string, id: string) => void;
|
|
48
|
+
/**
|
|
49
|
+
* registers a submit validator function
|
|
50
|
+
* @param chain
|
|
51
|
+
* @param id
|
|
52
|
+
* @param validator
|
|
53
|
+
*/
|
|
54
|
+
registerSubmitValidator: (chain: string, id: string, validator: ValidatorFunction) => void;
|
|
55
|
+
/**
|
|
56
|
+
* removes a submit validator function
|
|
57
|
+
* @param chain
|
|
58
|
+
* @param id
|
|
59
|
+
*/
|
|
60
|
+
unregisterSubmitValidator: (chain: string, id: string) => void;
|
|
39
61
|
/**
|
|
40
62
|
* registers a callback function
|
|
41
63
|
* the callback will be called when status of any transactions
|
|
42
64
|
* of given type changes to given status
|
|
43
65
|
* @param txType
|
|
44
66
|
* @param status
|
|
67
|
+
* @param id
|
|
45
68
|
* @param callback
|
|
46
69
|
*/
|
|
47
|
-
registerCallback: (txType: string, status: TransactionStatus, callback: CallbackFunction) => void;
|
|
70
|
+
registerCallback: (txType: string, status: TransactionStatus, id: string, callback: CallbackFunction) => void;
|
|
71
|
+
/**
|
|
72
|
+
* removes a callback function
|
|
73
|
+
* @param txType
|
|
74
|
+
* @param status
|
|
75
|
+
* @param id
|
|
76
|
+
*/
|
|
77
|
+
unregisterCallback: (txType: string, status: TransactionStatus, id: string) => void;
|
|
48
78
|
/**
|
|
49
79
|
* returns chain manager for given chain
|
|
50
80
|
* throws error if no manager is registered for it
|
|
@@ -63,6 +93,13 @@ export declare class TxPot {
|
|
|
63
93
|
* @param tx
|
|
64
94
|
*/
|
|
65
95
|
protected validateTx: (tx: TransactionEntity) => Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* checks a transaction for submission
|
|
98
|
+
* returns true if no validator functions is set or all validators allow tx to submit
|
|
99
|
+
* otherwise returns false
|
|
100
|
+
* @param tx
|
|
101
|
+
*/
|
|
102
|
+
protected isSubmitAllowed: (tx: TransactionEntity) => Promise<boolean>;
|
|
66
103
|
/**
|
|
67
104
|
* updates the status of a tx
|
|
68
105
|
* @param txKey tx id and chain
|
|
@@ -98,15 +135,18 @@ export declare class TxPot {
|
|
|
98
135
|
getTxsByStatus: (status: TransactionStatus, validate?: boolean) => Promise<Array<TransactionEntity>>;
|
|
99
136
|
/**
|
|
100
137
|
* inserts a new transaction into db
|
|
138
|
+
* Note: make sure to set `lastCheck` field if initialStatus is `signed` or `sent`
|
|
101
139
|
* @param txId
|
|
102
140
|
* @param chain
|
|
103
141
|
* @param txType
|
|
104
142
|
* @param requiredSign
|
|
105
143
|
* @param serializedTx
|
|
106
144
|
* @param initialStatus
|
|
107
|
-
* @param lastCheck
|
|
145
|
+
* @param lastCheck last blockchain height that tx was valid
|
|
146
|
+
* @param extra
|
|
147
|
+
* @param extra2
|
|
108
148
|
*/
|
|
109
|
-
addTx: (txId: string, chain: string, txType: string, requiredSign: number, serializedTx: string, initialStatus?: TransactionStatus, lastCheck?: number) => Promise<void>;
|
|
149
|
+
addTx: (txId: string, chain: string, txType: string, requiredSign: number, serializedTx: string, initialStatus?: TransactionStatus, lastCheck?: number, extra?: string | null, extra2?: string | null) => Promise<void>;
|
|
110
150
|
/**
|
|
111
151
|
* updates the status of a tx
|
|
112
152
|
* @param txId
|
|
@@ -160,5 +200,13 @@ export declare class TxPot {
|
|
|
160
200
|
* @returns the transactions with valid status
|
|
161
201
|
*/
|
|
162
202
|
getTxsQuery: (options?: Array<TxOptions>) => Promise<TransactionEntity[]>;
|
|
203
|
+
/**
|
|
204
|
+
* updates extra fields of a transaction
|
|
205
|
+
* @param txId
|
|
206
|
+
* @param chain
|
|
207
|
+
* @param extra
|
|
208
|
+
* @param extra2
|
|
209
|
+
*/
|
|
210
|
+
updateExtra: (txId: string, chain: string, extra?: string | null, extra2?: string | null) => Promise<void>;
|
|
163
211
|
}
|
|
164
212
|
//# sourceMappingURL=TxPot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TxPot.d.ts","sourceRoot":"","sources":["../../lib/transaction/TxPot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EA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