@rosen-bridge/abstract-extractor 1.0.2 → 2.0.0-8792333e
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/dist/ergo/AbstractErgoExtractor.d.ts +20 -4
- package/dist/ergo/AbstractErgoExtractor.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractor.js +27 -8
- package/dist/ergo/AbstractErgoExtractorAction.d.ts +1 -1
- package/dist/ergo/AbstractErgoExtractorAction.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractorAction.js +1 -1
- package/dist/ergo/initializable/AbstractInitializable.d.ts +2 -2
- package/dist/ergo/initializable/AbstractInitializable.d.ts.map +1 -1
- package/dist/ergo/initializable/AbstractInitializable.js +2 -2
- package/dist/ergo/interfaces.d.ts +7 -44
- package/dist/ergo/interfaces.d.ts.map +1 -1
- package/dist/ergo/interfaces.js +1 -6
- package/dist/ergo/network/ExplorerNetwork.d.ts +2 -2
- package/dist/ergo/network/ExplorerNetwork.d.ts.map +1 -1
- package/dist/ergo/network/ExplorerNetwork.js +1 -1
- package/dist/ergo/network/NodeNetwork.d.ts +1 -1
- package/dist/ergo/network/NodeNetwork.d.ts.map +1 -1
- package/dist/ergo/network/NodeNetwork.js +1 -1
- package/dist/ergo/utils.d.ts +1 -1
- package/dist/ergo/utils.d.ts.map +1 -1
- package/dist/ergo/utils.js +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/ergo/AbstractErgoExtractor.ts +41 -12
- package/lib/ergo/AbstractErgoExtractorAction.ts +1 -1
- package/lib/ergo/initializable/AbstractInitializable.ts +2 -6
- package/lib/ergo/interfaces.ts +4 -51
- package/lib/ergo/network/ExplorerNetwork.ts +2 -2
- package/lib/ergo/network/NodeNetwork.ts +1 -1
- package/lib/ergo/utils.ts +1 -1
- package/lib/index.ts +0 -2
- package/package.json +2 -1
- package/tests/AbstractErgoExtractor.mock.ts +2 -2
- package/tests/AbstractErgoExtractor.spec.ts +6 -5
- package/tests/AbstractErgoExtractorAction.mock.ts +1 -1
- package/tests/initializable/AbstractInitializable.mock.ts +3 -6
- package/tests/initializable/AbstractInitializable.spec.ts +1 -1
- package/tests/initializable/AbstractInitializableAction.mock.ts +1 -1
- package/tests/testData.ts +2 -1
- package/tsconfig.build.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +2 -1
- package/lib/AbstractExtractor.ts +0 -31
- package/lib/interfaces.ts +0 -12
|
@@ -2,19 +2,22 @@ import { AbstractLogger, DummyLogger } from '@rosen-bridge/abstract-logger';
|
|
|
2
2
|
import JsonBigInt from '@rosen-bridge/json-bigint';
|
|
3
3
|
import { Mutex } from 'await-semaphore';
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
|
|
6
|
-
import { AbstractExtractor } from '../AbstractExtractor';
|
|
7
|
-
import { AbstractErgoExtractorAction } from './AbstractErgoExtractorAction';
|
|
8
|
-
import { BlockInfo } from '../interfaces';
|
|
9
5
|
import {
|
|
10
6
|
Transaction,
|
|
11
7
|
OutputBox,
|
|
8
|
+
InputExtension,
|
|
9
|
+
AbstractExtractor,
|
|
10
|
+
BlockInfo,
|
|
11
|
+
} from '@rosen-bridge/scanner-interfaces';
|
|
12
|
+
|
|
13
|
+
import { AbstractErgoExtractorAction } from './AbstractErgoExtractorAction';
|
|
14
|
+
import {
|
|
12
15
|
AbstractBoxData,
|
|
13
16
|
SpendInfo,
|
|
14
17
|
CallbackType,
|
|
15
18
|
CallbackMap,
|
|
16
19
|
CallbackDataMap,
|
|
17
|
-
|
|
20
|
+
TxExtra,
|
|
18
21
|
} from './interfaces';
|
|
19
22
|
import { AbstractErgoExtractorEntity } from './AbstractErgoExtractorEntity';
|
|
20
23
|
|
|
@@ -105,7 +108,8 @@ export abstract class AbstractErgoExtractor<
|
|
|
105
108
|
*/
|
|
106
109
|
abstract extractBoxData: (
|
|
107
110
|
box: OutputBox,
|
|
108
|
-
inputExtensions: InputExtension[]
|
|
111
|
+
inputExtensions: InputExtension[],
|
|
112
|
+
txExtra?: TxExtra
|
|
109
113
|
) => ExtractedData | undefined;
|
|
110
114
|
|
|
111
115
|
/**
|
|
@@ -115,6 +119,31 @@ export abstract class AbstractErgoExtractor<
|
|
|
115
119
|
*/
|
|
116
120
|
abstract hasData: (box: OutputBox) => boolean;
|
|
117
121
|
|
|
122
|
+
/**
|
|
123
|
+
* create spend info array for the transaction
|
|
124
|
+
* @param tx
|
|
125
|
+
* @returns spend info array of the transaction
|
|
126
|
+
*/
|
|
127
|
+
getTransactionSpendInfo = (tx: Transaction) => {
|
|
128
|
+
let boxIndex = 1;
|
|
129
|
+
const spendInfoArray = [];
|
|
130
|
+
for (const input of tx.inputs) {
|
|
131
|
+
spendInfoArray.push({ txId: tx.id, boxId: input.boxId, index: boxIndex });
|
|
132
|
+
boxIndex += 1;
|
|
133
|
+
}
|
|
134
|
+
return spendInfoArray;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* extract transaction extra information
|
|
139
|
+
* override this function if there is extra needed information
|
|
140
|
+
* @param tx
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
143
|
+
getTransactionExtraData = (tx: Transaction): TxExtra | undefined => {
|
|
144
|
+
return undefined;
|
|
145
|
+
};
|
|
146
|
+
|
|
118
147
|
/**
|
|
119
148
|
* process a list of transactions in a block and store required information
|
|
120
149
|
* @param txs list of transactions in the block
|
|
@@ -135,7 +164,11 @@ export abstract class AbstractErgoExtractor<
|
|
|
135
164
|
continue;
|
|
136
165
|
}
|
|
137
166
|
this.logger.debug(`Trying to extract data from box ${output.boxId}`);
|
|
138
|
-
const extractedData = this.extractBoxData(
|
|
167
|
+
const extractedData = this.extractBoxData(
|
|
168
|
+
output,
|
|
169
|
+
inputExtensions,
|
|
170
|
+
this.getTransactionExtraData(tx)
|
|
171
|
+
);
|
|
139
172
|
if (extractedData) {
|
|
140
173
|
this.logger.debug(
|
|
141
174
|
`Extracted data ${JsonBigInt.stringify(extractedData)} from box ${
|
|
@@ -145,11 +178,7 @@ export abstract class AbstractErgoExtractor<
|
|
|
145
178
|
boxes.push(extractedData);
|
|
146
179
|
}
|
|
147
180
|
}
|
|
148
|
-
|
|
149
|
-
for (const input of tx.inputs) {
|
|
150
|
-
spentInfos.push({ txId: tx.id, boxId: input.boxId, index: boxIndex });
|
|
151
|
-
boxIndex += 1;
|
|
152
|
-
}
|
|
181
|
+
spentInfos.push(...this.getTransactionSpendInfo(tx));
|
|
153
182
|
}
|
|
154
183
|
|
|
155
184
|
if (boxes.length > 0) {
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
import { chunk, difference, pick } from 'lodash-es';
|
|
11
11
|
import { AbstractLogger, DummyLogger } from '@rosen-bridge/abstract-logger';
|
|
12
12
|
import JsonBigInt from '@rosen-bridge/json-bigint';
|
|
13
|
+
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
13
14
|
|
|
14
|
-
import { BlockInfo } from '../interfaces';
|
|
15
15
|
import { AbstractBoxData, BoxInfo, SpendInfo } from './interfaces';
|
|
16
16
|
import { DB_CHUNK_SIZE } from '../constants';
|
|
17
17
|
import { AbstractErgoExtractorEntity } from './AbstractErgoExtractorEntity';
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { AbstractLogger } from '@rosen-bridge/abstract-logger';
|
|
2
2
|
import { groupBy, sortBy } from 'lodash-es';
|
|
3
|
+
import { BlockInfo, ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
AbstractBoxData,
|
|
6
|
-
ErgoNetworkType,
|
|
7
|
-
ExtendedTransaction,
|
|
8
|
-
} from '../interfaces';
|
|
5
|
+
import { AbstractBoxData, ExtendedTransaction } from '../interfaces';
|
|
9
6
|
import { API_LIMIT, RETRIAL_COUNT } from '../../constants';
|
|
10
7
|
import { AbstractErgoExtractor } from '../AbstractErgoExtractor';
|
|
11
8
|
import { AbstractInitializableErgoExtractorAction } from './AbstractInitializableAction';
|
|
12
|
-
import { BlockInfo } from '../../interfaces';
|
|
13
9
|
import { ExplorerNetwork } from '../network/ExplorerNetwork';
|
|
14
10
|
import { NodeNetwork } from '../network/NodeNetwork';
|
|
15
11
|
import { AbstractErgoExtractorEntity } from '../AbstractErgoExtractorEntity';
|
package/lib/ergo/interfaces.ts
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Explorer = 'explorer',
|
|
3
|
-
Node = 'node',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type InputExtension = {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type InputBox = {
|
|
11
|
-
boxId: string;
|
|
12
|
-
extension?: InputExtension;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type DataInput = {
|
|
16
|
-
boxId: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type Asset = {
|
|
20
|
-
tokenId: string;
|
|
21
|
-
amount: bigint;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type AdditionalRegisters = {
|
|
25
|
-
R4?: string;
|
|
26
|
-
R5?: string;
|
|
27
|
-
R6?: string;
|
|
28
|
-
R7?: string;
|
|
29
|
-
R8?: string;
|
|
30
|
-
R9?: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type OutputBox = {
|
|
34
|
-
boxId: string;
|
|
35
|
-
value: bigint;
|
|
36
|
-
ergoTree: string;
|
|
37
|
-
creationHeight: number;
|
|
38
|
-
assets: Array<Asset>;
|
|
39
|
-
additionalRegisters: AdditionalRegisters;
|
|
40
|
-
transactionId: string;
|
|
41
|
-
index: number;
|
|
42
|
-
};
|
|
1
|
+
import { OutputBox, Transaction } from '@rosen-bridge/scanner-interfaces';
|
|
43
2
|
|
|
44
3
|
export interface ErgoBox extends OutputBox {
|
|
45
4
|
blockId: string;
|
|
@@ -50,14 +9,6 @@ export interface ErgoBox extends OutputBox {
|
|
|
50
9
|
spentIndex?: number;
|
|
51
10
|
}
|
|
52
11
|
|
|
53
|
-
export type Transaction = {
|
|
54
|
-
id: string;
|
|
55
|
-
inputs: Array<InputBox>;
|
|
56
|
-
dataInputs: Array<DataInput>;
|
|
57
|
-
outputs: Array<OutputBox>;
|
|
58
|
-
size?: bigint;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
12
|
export interface ExtendedTransaction extends Transaction {
|
|
62
13
|
inclusionHeight: number;
|
|
63
14
|
blockId: string;
|
|
@@ -67,7 +18,7 @@ export interface SpendInfo {
|
|
|
67
18
|
boxId: string;
|
|
68
19
|
txId: string;
|
|
69
20
|
index: number;
|
|
70
|
-
extras?: string
|
|
21
|
+
extras?: { [key: string]: string };
|
|
71
22
|
}
|
|
72
23
|
|
|
73
24
|
export interface AbstractBoxData {
|
|
@@ -96,3 +47,5 @@ export type CallbackDataMap<ExtractedData extends AbstractBoxData> = {
|
|
|
96
47
|
export type CallbackMap<ExtractedData extends AbstractBoxData> = {
|
|
97
48
|
[K in CallbackType]: (data: CallbackDataMap<ExtractedData>[K]) => void;
|
|
98
49
|
};
|
|
50
|
+
|
|
51
|
+
export type TxExtra = { [key: string]: string };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ergoExplorerClientFactory from '@rosen-clients/ergo-explorer';
|
|
2
2
|
import { AbstractNetwork } from './AbstractNetwork';
|
|
3
3
|
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
4
|
+
import { BlockInfo, Transaction } from '@rosen-bridge/scanner-interfaces';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import { ErgoBox, ExtendedTransaction, Transaction } from '../interfaces';
|
|
6
|
+
import { ErgoBox, ExtendedTransaction } from '../interfaces';
|
|
7
7
|
import { mapValues, pick } from 'lodash-es';
|
|
8
8
|
import { API_LIMIT } from '../../constants';
|
|
9
9
|
|
|
@@ -2,8 +2,8 @@ import ergoNodeClientFactory, {
|
|
|
2
2
|
IndexedErgoBox,
|
|
3
3
|
IndexedErgoTransaction,
|
|
4
4
|
} from '@rosen-clients/ergo-node';
|
|
5
|
+
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
5
6
|
|
|
6
|
-
import { BlockInfo } from '../../interfaces';
|
|
7
7
|
import { ErgoBox, ExtendedTransaction } from '../interfaces';
|
|
8
8
|
import { AbstractNetwork } from './AbstractNetwork';
|
|
9
9
|
|
package/lib/ergo/utils.ts
CHANGED
package/lib/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosen-bridge/abstract-extractor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-8792333e",
|
|
4
4
|
"description": "Rosen Bridge extractor interfaces to work with scanner",
|
|
5
5
|
"repository": "",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@rosen-bridge/abstract-logger": "^2.0.1",
|
|
40
40
|
"@rosen-bridge/json-bigint": "^0.1.0",
|
|
41
|
+
"@rosen-bridge/scanner-interfaces": "^0.1.0-8792333e",
|
|
41
42
|
"@rosen-clients/ergo-explorer": "^1.1.2",
|
|
42
43
|
"@rosen-clients/ergo-node": "^1.2.0",
|
|
43
44
|
"lodash-es": "^4.17.21",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
2
|
+
import { BlockInfo, OutputBox } from '@rosen-bridge/scanner-interfaces';
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
AbstractErgoExtractor,
|
|
4
|
-
BlockInfo,
|
|
5
|
-
OutputBox,
|
|
6
6
|
AbstractBoxData,
|
|
7
7
|
AbstractErgoExtractorAction,
|
|
8
8
|
AbstractErgoExtractorEntity,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
2
2
|
import { describe, it, expect, vitest } from 'vitest';
|
|
3
|
+
import { OutputBox } from '@rosen-bridge/scanner-interfaces';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
|
-
OutputBox,
|
|
6
6
|
AbstractBoxData,
|
|
7
7
|
AbstractErgoExtractorAction,
|
|
8
8
|
CallbackType,
|
|
@@ -49,10 +49,11 @@ describe('AbstractErgoExtractor', () => {
|
|
|
49
49
|
const result = await extractor.processTransactions([tx], block);
|
|
50
50
|
|
|
51
51
|
expect(extractSpy).toBeCalledTimes(1);
|
|
52
|
-
expect(extractSpy).toBeCalledWith(
|
|
53
|
-
tx.
|
|
54
|
-
{},
|
|
55
|
-
|
|
52
|
+
expect(extractSpy).toBeCalledWith(
|
|
53
|
+
tx.outputs[0],
|
|
54
|
+
[tx.inputs[0].extension, {}],
|
|
55
|
+
undefined
|
|
56
|
+
);
|
|
56
57
|
expect(storeSpy).toBeCalledWith([extractedData], block, 'Test');
|
|
57
58
|
expect(result).toEqual(true);
|
|
58
59
|
expect(triggerCallbacks).toBeCalledWith(CallbackType.Insert, [
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
|
+
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
AbstractErgoExtractorAction,
|
|
6
7
|
AbstractErgoExtractorEntity,
|
|
7
|
-
BlockInfo,
|
|
8
8
|
AbstractBoxData,
|
|
9
9
|
} from '../lib';
|
|
10
10
|
import { TestEntity } from './testUtils';
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
2
|
+
import { BlockInfo, OutputBox } from '@rosen-bridge/scanner-interfaces';
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
AbstractInitializableErgoExtractor,
|
|
4
6
|
AbstractInitializableErgoExtractorAction,
|
|
5
7
|
} from '../../lib/ergo/initializable';
|
|
6
|
-
import {
|
|
7
|
-
OutputBox,
|
|
8
|
-
AbstractBoxData,
|
|
9
|
-
BlockInfo,
|
|
10
|
-
AbstractErgoExtractorEntity,
|
|
11
|
-
} from '../../lib';
|
|
8
|
+
import { AbstractBoxData, AbstractErgoExtractorEntity } from '../../lib';
|
|
12
9
|
import { ergoBoxes } from './testData';
|
|
13
10
|
|
|
14
11
|
export class MockedInitializableErgoExtractor extends AbstractInitializableErgoExtractor<
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
|
+
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
AbstractErgoExtractorEntity,
|
|
6
|
-
BlockInfo,
|
|
7
7
|
AbstractBoxData,
|
|
8
8
|
AbstractInitializableErgoExtractorAction,
|
|
9
9
|
} from '../../lib';
|
package/tests/testData.ts
CHANGED