@rosen-bridge/address-extractor 0.1.3-alpha → 0.1.4-alpha

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.
@@ -1,4 +1,5 @@
1
1
  import { BoxEntity } from "../entities/boxEntity";
2
+ import { In } from "typeorm";
2
3
  export class BoxEntityAction {
3
4
  datasource;
4
5
  constructor(dataSource) {
@@ -12,26 +13,42 @@ export class BoxEntityAction {
12
13
  * @param extractor
13
14
  */
14
15
  storeBox = async (boxes, spendBoxes, block, extractor) => {
15
- const boxEntities = boxes.map((box) => {
16
- const row = new BoxEntity();
17
- row.address = box.address;
18
- row.boxId = box.boxId;
19
- row.createBlock = block.hash;
20
- row.creationHeight = block.height;
21
- row.serialized = box.serialized;
22
- row.extractor = extractor;
23
- return row;
16
+ const boxIds = boxes.map(item => item.boxId);
17
+ const dbBoxes = await this.datasource.getRepository(BoxEntity).findBy({
18
+ boxId: In(boxIds),
19
+ extractor: extractor
24
20
  });
25
21
  let success = true;
26
22
  const queryRunner = this.datasource.createQueryRunner();
27
23
  await queryRunner.connect();
28
24
  await queryRunner.startTransaction();
29
25
  try {
30
- await queryRunner.manager.save(boxEntities);
26
+ for (const box of boxes) {
27
+ const entity = {
28
+ address: box.address,
29
+ boxId: box.boxId,
30
+ createBlock: block.hash,
31
+ creationHeight: block.height,
32
+ spendBlock: undefined,
33
+ serialized: box.serialized,
34
+ extractor: extractor
35
+ };
36
+ const dbBox = dbBoxes.filter(item => item.boxId === box.boxId);
37
+ if (dbBox.length > 0) {
38
+ await queryRunner.manager.getRepository(BoxEntity).createQueryBuilder()
39
+ .update()
40
+ .set(entity)
41
+ .where({ id: dbBox[0].id })
42
+ .execute();
43
+ }
44
+ else {
45
+ await queryRunner.manager.getRepository(BoxEntity).insert(entity);
46
+ }
47
+ }
31
48
  await this.datasource.getRepository(BoxEntity).createQueryBuilder()
32
49
  .update()
33
50
  .set({ spendBlock: block.hash })
34
- .where("boxId IN (:boxes) AND extractor = :extractor", {
51
+ .where("boxId IN (:...boxes) AND extractor = :extractor", {
35
52
  boxes: spendBoxes,
36
53
  extractor: extractor
37
54
  }).execute();
@@ -1,6 +1,6 @@
1
1
  import { DataSource } from "typeorm";
2
2
  import * as ergoLib from 'ergo-lib-wasm-nodejs';
3
- import { AbstractExtractor } from "@rosen-bridge/scanner/dist/interfaces";
3
+ import { AbstractExtractor } from "@rosen-bridge/scanner";
4
4
  import { BlockEntity } from "@rosen-bridge/scanner";
5
5
  export declare class ErgoUTXOExtractor implements AbstractExtractor<ergoLib.Transaction> {
6
6
  private readonly dataSource;
@@ -49,8 +49,8 @@ export class ErgoUTXOExtractor {
49
49
  }
50
50
  boxes.push({
51
51
  boxId: output.box_id().to_str(),
52
- address: ergoLib.Address.recreate_from_ergo_tree(output.ergo_tree()).to_base58(this.networkType),
53
- serialized: Buffer.from(output.sigma_serialize_bytes()).toString("hex")
52
+ address: ergoLib.Address.recreate_from_ergo_tree(ergoLib.ErgoTree.from_base16_bytes(output.ergo_tree().to_base16_bytes())).to_base58(this.networkType),
53
+ serialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64")
54
54
  });
55
55
  }
56
56
  for (let index2 = 0; index2 < transaction.inputs().len(); index2++) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rosen-bridge/address-extractor",
3
- "version": "0.1.3-alpha",
4
- "description": "",
3
+ "version": "0.1.4-alpha",
4
+ "description": "Utxo box extractor for any address or token.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -17,7 +17,7 @@
17
17
  "author": "Vorujack",
18
18
  "license": "GPL-3.0",
19
19
  "dependencies": {
20
- "@rosen-bridge/scanner": "^0.1.7-alpha",
20
+ "@rosen-bridge/scanner": "^0.1.7-alpha-2",
21
21
  "blakejs": "^1.2.1",
22
22
  "ergo-lib-wasm-nodejs": "^0.18.0",
23
23
  "reflect-metadata": "^0.1.13",