@rosen-bridge/abstract-extractor 0.1.2 → 0.1.4

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.
@@ -93,6 +93,7 @@ export abstract class AbstractInitializableErgoExtractor<
93
93
  * @param initialBlock
94
94
  */
95
95
  initializeBoxes = async (initialBlock: BlockInfo) => {
96
+ const fetched = new Set<string>();
96
97
  let trial = 1;
97
98
  if (this.initialize) {
98
99
  this.logger.debug(
@@ -109,13 +110,18 @@ export abstract class AbstractInitializableErgoExtractor<
109
110
  offset,
110
111
  API_LIMIT
111
112
  );
113
+ const boxes = data.extractedBoxes.filter((item) => {
114
+ if (fetched.has(item.boxId)) return false;
115
+ fetched.add(item.boxId);
116
+ return true;
117
+ });
112
118
  this.logger.info(
113
119
  `Inserting ${
114
- data.extractedBoxes.length
120
+ boxes.length
115
121
  } new extracted data in ${this.getId()} initialization`
116
122
  );
117
123
  const insertSuccess = await this.actions.insertBoxes(
118
- data.extractedBoxes,
124
+ boxes,
119
125
  this.getId()
120
126
  );
121
127
  if (!insertSuccess) throw new Error('Could not store extracted data');
@@ -62,9 +62,10 @@ export class ExplorerNetwork extends AbstractNetwork {
62
62
  offset: number,
63
63
  limit: number
64
64
  ): Promise<{ boxes: ErgoBox[]; hasNextBatch: boolean }> => {
65
- const boxes = await this.api.v1.getApiV1BoxesByaddressP1(address, {
65
+ const boxes = await this.api.v1.getApiV1BoxesUnspentByaddressP1(address, {
66
66
  offset: offset,
67
67
  limit: limit,
68
+ sortDirection: 'desc',
68
69
  });
69
70
  if (!boxes.items)
70
71
  throw new Error('Explorer BoxesByAddress api expected to have items');
@@ -64,16 +64,17 @@ export class NodeNetwork extends AbstractNetwork {
64
64
  offset: number,
65
65
  limit: number
66
66
  ): Promise<{ boxes: ErgoBox[]; hasNextBatch: boolean }> => {
67
- const boxes = await this.api.getBoxesByAddress(address, {
67
+ const boxes = await this.api.getBoxesByAddressUnspent(address, {
68
68
  offset: offset,
69
69
  limit: limit,
70
+ sortDirection: 'desc',
70
71
  });
71
- if (!boxes.items)
72
+ if (!boxes)
72
73
  throw new Error('Ergo node BoxesByAddress api expected to have items');
73
74
  const ergoBoxes = await Promise.all(
74
- boxes.items.map(async (box) => await this.convertToErgoBox(box))
75
+ boxes.map(async (box) => await this.convertToErgoBox(box))
75
76
  );
76
- return { boxes: ergoBoxes, hasNextBatch: boxes.items.length > 0 };
77
+ return { boxes: ergoBoxes, hasNextBatch: boxes.length > 0 };
77
78
  };
78
79
 
79
80
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosen-bridge/abstract-extractor",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Rosen Bridge extractor interfaces to work with scanner",
5
5
  "repository": "",
6
6
  "license": "GPL-3.0",