@rosen-bridge/watcher-data-extractor 0.1.0-alpha-3 → 0.1.2-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.
package/README.md CHANGED
@@ -1,92 +1,67 @@
1
- # rosen-scanner
1
+ # Watcher Data Extractor
2
2
 
3
3
 
4
+ ### Table of Contents
5
+ - [Description](#description)
6
+ - [Related Projects](#related-projects)
7
+ - [How to Use the Watcher Data Extractor](#how-to-use-the-watcher-data-extractor)
8
+ - [Install](#install)
9
+ - [Usage](#usage)
10
+ - [Contributing](#contributing)
11
+ - [License](#license)
4
12
 
5
- ## Getting started
6
-
7
- To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
-
9
- Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
-
11
- ## Add your files
12
-
13
- - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
- - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
13
+ <a name="headers"/>
15
14
 
15
+ ## Description
16
+ Data extractors are modules that are integrated within a scanner. They drive the required information from the scanned blocks and store them in their own database. The watcher data extractor is responsible for tracking all watcher-related data in the network. These data includes permit, commitment and event trigger boxes; all these boxes are created in the network by the watchers. The watchers use their permits to create new commitments, and need to track created commitments and triggers to continue their procedures. On the other side, guards need to track event trigger boxes to verify the related user payment and start an agreement on the exchange transaction.
17
+
18
+
19
+ ## Related Projects
20
+ This module is used within the [Scanner](https://github.com/rosen-bridge/scanner) project. As stated above, this module is used in the [Watcher](https://github.com/rosen-bridge/watcher) service to drive the related boxes. It also used in the [Guard](https://github.com/rosen-bridge/watcher) to track the created event triggers.
21
+
22
+
23
+ ## How to Use the Watcher Data Extractor
24
+ ### Install
25
+ This project is written in node-js using Esnext module and typeorm database. Extractors are not standalone projects and should be used as scanner modules. You can easily install it using npm with the command:
26
+
27
+ ```shell
28
+ npm install @rosen-bridge/watcher-data-extractor
16
29
  ```
17
- cd existing_repo
18
- git remote add origin https://git.ergopool.io/rosen-bridge/scanner/rosen-scanner.git
19
- git branch -M master
20
- git push -uf origin master
30
+
31
+ Alternatively, you can build and use it manually by cloning the project and running:
32
+ ```shell
33
+ npm install
34
+ npm run build
35
+ ```
36
+
37
+ ### Usage
38
+ In the first step, you need to create a scanner instance; follow the steps [here](https://github.com/rosen-bridge/scanner) to create a running instance of the scanner. Then, you need to instantiate your desired extractors and register them to your ergo scanner:
39
+ ```javascript
40
+ const commitmentExtractor = new CommitmentExtractor(
41
+ <extractor_name>,
42
+ <Array<commitment_address>>,
43
+ <rwt_id>,
44
+ dataSource
45
+ )
46
+ const permitExtractor = new PermitExtractor(
47
+ <extractor_name>,
48
+ dataSource,
49
+ <permit_address>,
50
+ <rwt_id>
51
+ )
52
+ const eventTriggerExtractor = new EventTriggerExtractor(
53
+ <extractor_name>,
54
+ dataSource,
55
+ <event_trigger_address>,
56
+ <rwt_id>
57
+ )
58
+ ergoScanner.registerExtractor(commitmentExtractor)
59
+ ergoScanner.registerExtractor(permitExtractor)
60
+ ergoScanner.registerExtractor(eventTriggerExtractor)
21
61
  ```
22
-
23
- ## Integrate with your tools
24
-
25
- - [ ] [Set up project integrations](https://git.ergopool.io/rosen-bridge/scanner/rosen-scanner/-/settings/integrations)
26
-
27
- ## Collaborate with your team
28
-
29
- - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
- - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
- - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
- - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
- - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
-
35
- ## Test and Deploy
36
-
37
- Use the built-in continuous integration in GitLab.
38
-
39
- - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
- - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
- - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
- - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
- - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
-
45
- ***
46
-
47
- # Editing this README
48
-
49
- When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
-
51
- ## Suggestions for a good README
52
- Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
53
-
54
- ## Name
55
- Choose a self-explaining name for your project.
56
-
57
- ## Description
58
- Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
59
-
60
- ## Badges
61
- On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
62
-
63
- ## Visuals
64
- Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
65
-
66
- ## Installation
67
- Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
68
-
69
- ## Usage
70
- Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
71
-
72
- ## Support
73
- Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
74
-
75
- ## Roadmap
76
- If you have ideas for releases in the future, it is a good idea to list them in the README.
77
62
 
78
63
  ## Contributing
79
- State if you are open to contributions and what your requirements are for accepting them.
80
-
81
- For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
82
-
83
- You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
84
-
85
- ## Authors and acknowledgment
86
- Show your appreciation to those who have contributed to the project.
64
+ TBD
87
65
 
88
66
  ## License
89
- For open source projects, say how it is licensed.
90
-
91
- ## Project status
92
- If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
67
+ TBD
@@ -3,14 +3,15 @@ import { BlockEntity } from "@rosen-bridge/scanner";
3
3
  import { ExtractedEventTrigger } from "../interfaces/extractedEventTrigger";
4
4
  declare class EventTriggerDB {
5
5
  private readonly datasource;
6
+ private readonly triggerEventRepository;
6
7
  constructor(dataSource: DataSource);
7
8
  /**
8
- * It stores list of wids in the dataSource with block id
9
- * @param wids
9
+ * It stores list of eventTriggers in the dataSource with block id
10
+ * @param eventTriggers
10
11
  * @param block
11
12
  * @param extractor
12
13
  */
13
- storeEventTriggers: (wids: Array<ExtractedEventTrigger>, block: BlockEntity, extractor: string) => Promise<boolean>;
14
+ storeEventTriggers: (eventTriggers: Array<ExtractedEventTrigger>, block: BlockEntity, extractor: string) => Promise<boolean>;
14
15
  /**
15
16
  * deleting all permits corresponding to the block(id) and extractor(id)
16
17
  * @param block
@@ -1,46 +1,67 @@
1
+ import { In } from "typeorm";
1
2
  import EventTriggerEntity from "../entities/EventTriggerEntity";
2
3
  class EventTriggerDB {
3
4
  datasource;
5
+ triggerEventRepository;
4
6
  constructor(dataSource) {
5
7
  this.datasource = dataSource;
8
+ this.triggerEventRepository = dataSource.getRepository(EventTriggerEntity);
6
9
  }
7
10
  /**
8
- * It stores list of wids in the dataSource with block id
9
- * @param wids
11
+ * It stores list of eventTriggers in the dataSource with block id
12
+ * @param eventTriggers
10
13
  * @param block
11
14
  * @param extractor
12
15
  */
13
- storeEventTriggers = async (wids, block, extractor) => {
14
- const widEntity = wids.map((event) => {
15
- const row = new EventTriggerEntity();
16
- row.boxId = event.boxId;
17
- row.boxSerialized = event.boxSerialized;
18
- row.blockId = block.hash;
19
- row.height = block.height;
20
- row.extractor = extractor;
21
- row.WIDs = event.WIDs;
22
- row.amount = event.amount;
23
- row.bridgeFee = event.bridgeFee;
24
- row.fromAddress = event.fromAddress;
25
- row.toAddress = event.toAddress;
26
- row.fromChain = event.fromChain;
27
- row.networkFee = event.networkFee;
28
- row.sourceChainTokenId = event.sourceChainTokenId;
29
- row.targetChainTokenId = event.targetChainTokenId;
30
- row.sourceBlockId = event.sourceBlockId;
31
- row.toChain = event.toChain;
32
- row.sourceTxId = event.sourceTxId;
33
- return row;
16
+ storeEventTriggers = async (eventTriggers, block, extractor) => {
17
+ if (eventTriggers.length === 0)
18
+ return true;
19
+ const boxIds = eventTriggers.map(trigger => trigger.boxId);
20
+ const savedTriggers = await this.triggerEventRepository.findBy({
21
+ boxId: In(boxIds),
22
+ extractor: extractor,
34
23
  });
35
24
  let success = true;
36
25
  const queryRunner = this.datasource.createQueryRunner();
37
26
  await queryRunner.connect();
38
27
  await queryRunner.startTransaction();
39
28
  try {
40
- await queryRunner.manager.save(widEntity);
29
+ for (const event of eventTriggers) {
30
+ const saved = savedTriggers.some((entity) => {
31
+ return entity.boxId === event.boxId;
32
+ });
33
+ const entity = {
34
+ boxId: event.boxId,
35
+ boxSerialized: event.boxSerialized,
36
+ block: block.hash,
37
+ height: block.height,
38
+ extractor: extractor,
39
+ WIDs: event.WIDs,
40
+ amount: event.amount,
41
+ bridgeFee: event.bridgeFee,
42
+ fromAddress: event.fromAddress,
43
+ toAddress: event.toAddress,
44
+ fromChain: event.fromChain,
45
+ networkFee: event.networkFee,
46
+ sourceChainTokenId: event.sourceChainTokenId,
47
+ targetChainTokenId: event.targetChainTokenId,
48
+ sourceBlockId: event.sourceBlockId,
49
+ toChain: event.toChain,
50
+ sourceTxId: event.sourceTxId,
51
+ };
52
+ if (!saved) {
53
+ await queryRunner.manager.insert(EventTriggerEntity, entity);
54
+ }
55
+ else {
56
+ await queryRunner.manager.update(EventTriggerEntity, {
57
+ boxId: event.boxId
58
+ }, entity);
59
+ }
60
+ }
41
61
  await queryRunner.commitTransaction();
42
62
  }
43
63
  catch (e) {
64
+ console.log(`An error occurred during store eventTrigger action: ${e}`);
44
65
  await queryRunner.rollbackTransaction();
45
66
  success = false;
46
67
  }
@@ -58,7 +79,7 @@ class EventTriggerDB {
58
79
  await this.datasource.createQueryBuilder()
59
80
  .delete()
60
81
  .from(EventTriggerEntity)
61
- .where("extractor = :extractor AND blockId = :block", {
82
+ .where("extractor = :extractor AND block = :block", {
62
83
  "block": block,
63
84
  "extractor": extractor
64
85
  }).execute();
@@ -3,20 +3,22 @@ import { extractedCommitment } from "../interfaces/extractedCommitment";
3
3
  import { BlockEntity } from "@rosen-bridge/scanner";
4
4
  declare class CommitmentEntityAction {
5
5
  private readonly datasource;
6
+ private readonly commitmentRepository;
6
7
  constructor(dataSource: DataSource);
7
8
  /**
8
9
  * It stores list of observations in the dataSource with block id
9
10
  * @param commitments
10
11
  * @param block
11
- * @param extractorId
12
+ * @param extractor
12
13
  */
13
- storeCommitments: (commitments: Array<extractedCommitment>, block: BlockEntity, extractorId: string) => Promise<boolean>;
14
+ storeCommitments: (commitments: Array<extractedCommitment>, block: BlockEntity, extractor: string) => Promise<boolean>;
14
15
  /**
15
16
  * update spendBlock Column of the commitments in the dataBase
16
17
  * @param spendId
17
18
  * @param block
19
+ * @param extractor
18
20
  */
19
- spendCommitments: (spendId: Array<string>, block: BlockEntity) => Promise<void>;
21
+ spendCommitments: (spendId: Array<string>, block: BlockEntity, extractor: string) => Promise<void>;
20
22
  /**
21
23
  * deleting all permits corresponding to the block(id) and extractor(id)
22
24
  * @param block
@@ -1,38 +1,60 @@
1
+ import { In } from "typeorm";
1
2
  import CommitmentEntity from "../entities/CommitmentEntity";
2
3
  class CommitmentEntityAction {
3
4
  datasource;
5
+ commitmentRepository;
4
6
  constructor(dataSource) {
5
7
  this.datasource = dataSource;
8
+ this.commitmentRepository = dataSource.getRepository(CommitmentEntity);
6
9
  }
7
10
  /**
8
11
  * It stores list of observations in the dataSource with block id
9
12
  * @param commitments
10
13
  * @param block
11
- * @param extractorId
14
+ * @param extractor
12
15
  */
13
- storeCommitments = async (commitments, block, extractorId) => {
14
- const commitmentEntity = commitments.map((commitment) => {
15
- const row = new CommitmentEntity();
16
- row.commitment = commitment.commitment;
17
- row.eventId = commitment.eventId;
18
- row.commitmentBoxId = commitment.commitmentBoxId;
19
- row.WID = commitment.WID;
20
- row.extractor = extractorId;
21
- row.blockId = block.hash;
22
- row.height = block.height;
23
- return row;
16
+ storeCommitments = async (commitments, block, extractor) => {
17
+ if (commitments.length === 0)
18
+ return true;
19
+ const boxIds = commitments.map(commitment => commitment.boxId);
20
+ const savedCommitments = await this.commitmentRepository.findBy({
21
+ boxId: In(boxIds),
22
+ extractor: extractor,
24
23
  });
25
24
  let success = true;
26
25
  const queryRunner = this.datasource.createQueryRunner();
27
26
  await queryRunner.connect();
28
27
  await queryRunner.startTransaction();
29
28
  try {
30
- await queryRunner.manager.save(commitmentEntity);
29
+ for (const commitment of commitments) {
30
+ const saved = savedCommitments.some((entity) => {
31
+ return entity.boxId === commitment.boxId;
32
+ });
33
+ const entity = {
34
+ commitment: commitment.commitment,
35
+ eventId: commitment.eventId,
36
+ boxId: commitment.boxId,
37
+ WID: commitment.WID,
38
+ extractor: extractor,
39
+ block: block.hash,
40
+ height: block.height,
41
+ boxSerialized: commitment.boxSerialized,
42
+ };
43
+ if (!saved) {
44
+ await queryRunner.manager.insert(CommitmentEntity, entity);
45
+ }
46
+ else {
47
+ await queryRunner.manager.update(CommitmentEntity, {
48
+ boxId: commitment.boxId
49
+ }, entity);
50
+ }
51
+ }
31
52
  await queryRunner.commitTransaction();
32
53
  }
33
54
  catch (e) {
34
- success = false;
55
+ console.log(`An error occurred during store commitments action: ${e}`);
35
56
  await queryRunner.rollbackTransaction();
57
+ success = false;
36
58
  }
37
59
  finally {
38
60
  await queryRunner.release();
@@ -43,14 +65,15 @@ class CommitmentEntityAction {
43
65
  * update spendBlock Column of the commitments in the dataBase
44
66
  * @param spendId
45
67
  * @param block
68
+ * @param extractor
46
69
  */
47
- spendCommitments = async (spendId, block) => {
70
+ spendCommitments = async (spendId, block, extractor) => {
48
71
  //todo: should change with single db call
49
72
  for (const id of spendId) {
50
73
  await this.datasource.createQueryBuilder()
51
74
  .update(CommitmentEntity)
52
- .set({ spendBlockHash: block.hash })
53
- .where("commitmentBoxId = :id", { id: id })
75
+ .set({ spendBlock: block.hash, spendHeight: block.height })
76
+ .where("boxId = :id AND extractor = :extractor", { id: id, extractor: extractor })
54
77
  .execute();
55
78
  }
56
79
  };
@@ -63,15 +86,15 @@ class CommitmentEntityAction {
63
86
  await this.datasource.createQueryBuilder()
64
87
  .delete()
65
88
  .from(CommitmentEntity)
66
- .where("extractor = :extractor AND blockId = :block", {
89
+ .where("extractor = :extractor AND block = :block", {
67
90
  "block": block,
68
91
  "extractor": extractor
69
92
  }).execute();
70
93
  //TODO: should handled null value in spendBlockHeight
71
94
  await this.datasource.createQueryBuilder()
72
95
  .update(CommitmentEntity)
73
- .set({ spendBlockHash: undefined, spendBlockHeight: 0 })
74
- .where("spendBlockHash = :block AND blockId = :block", {
96
+ .set({ spendBlock: undefined, spendHeight: 0 })
97
+ .where("spendBlock = :block AND block = :block", {
75
98
  block: block
76
99
  }).execute();
77
100
  };
@@ -3,6 +3,7 @@ import { extractedPermit } from "../interfaces/extractedPermit";
3
3
  import { BlockEntity } from "@rosen-bridge/scanner";
4
4
  declare class PermitEntityAction {
5
5
  private readonly datasource;
6
+ private readonly permitRepository;
6
7
  constructor(dataSource: DataSource);
7
8
  /**
8
9
  * It stores list of permits in the dataSource with block id
@@ -15,8 +16,9 @@ declare class PermitEntityAction {
15
16
  * update spendBlock Column of the permits in the dataBase
16
17
  * @param spendId
17
18
  * @param block
19
+ * @param extractor
18
20
  */
19
- spendPermits: (spendId: Array<string>, block: BlockEntity) => Promise<void>;
21
+ spendPermits: (spendId: Array<string>, block: BlockEntity, extractor: string) => Promise<void>;
20
22
  /**
21
23
  * deleting all permits corresponding to the block(id) and extractor(id)
22
24
  * @param block
@@ -1,9 +1,12 @@
1
+ import { In } from "typeorm";
1
2
  import PermitEntity from "../entities/PermitEntity";
2
3
  import CommitmentEntity from "../entities/CommitmentEntity";
3
4
  class PermitEntityAction {
4
5
  datasource;
6
+ permitRepository;
5
7
  constructor(dataSource) {
6
8
  this.datasource = dataSource;
9
+ this.permitRepository = dataSource.getRepository(PermitEntity);
7
10
  }
8
11
  /**
9
12
  * It stores list of permits in the dataSource with block id
@@ -12,25 +15,43 @@ class PermitEntityAction {
12
15
  * @param extractor
13
16
  */
14
17
  storePermits = async (permits, block, extractor) => {
15
- const permitEntity = permits.map((permit) => {
16
- const row = new PermitEntity();
17
- row.boxId = permit.boxId;
18
- row.boxSerialized = permit.boxSerialized;
19
- row.blockId = block.hash;
20
- row.height = block.height;
21
- row.extractor = extractor;
22
- row.WID = permit.WID;
23
- return row;
18
+ if (permits.length === 0)
19
+ return true;
20
+ const boxIds = permits.map(permit => permit.boxId);
21
+ const savedPermits = await this.permitRepository.findBy({
22
+ boxId: In(boxIds),
23
+ extractor: extractor,
24
24
  });
25
25
  let success = true;
26
26
  const queryRunner = this.datasource.createQueryRunner();
27
27
  await queryRunner.connect();
28
28
  await queryRunner.startTransaction();
29
29
  try {
30
- await queryRunner.manager.save(permitEntity);
30
+ for (const permit of permits) {
31
+ const saved = savedPermits.some((entity) => {
32
+ return entity.boxId === permit.boxId;
33
+ });
34
+ const entity = {
35
+ boxId: permit.boxId,
36
+ boxSerialized: permit.boxSerialized,
37
+ block: block.hash,
38
+ height: block.height,
39
+ extractor: extractor,
40
+ WID: permit.WID,
41
+ };
42
+ if (!saved) {
43
+ await queryRunner.manager.insert(PermitEntity, entity);
44
+ }
45
+ else {
46
+ await queryRunner.manager.update(PermitEntity, {
47
+ boxId: permit.boxId
48
+ }, entity);
49
+ }
50
+ }
31
51
  await queryRunner.commitTransaction();
32
52
  }
33
53
  catch (e) {
54
+ console.log(`An error occurred during store permit action: ${e}`);
34
55
  await queryRunner.rollbackTransaction();
35
56
  success = false;
36
57
  }
@@ -43,14 +64,15 @@ class PermitEntityAction {
43
64
  * update spendBlock Column of the permits in the dataBase
44
65
  * @param spendId
45
66
  * @param block
67
+ * @param extractor
46
68
  */
47
- spendPermits = async (spendId, block) => {
69
+ spendPermits = async (spendId, block, extractor) => {
48
70
  //todo: should change with single db call
49
71
  for (const id of spendId) {
50
72
  await this.datasource.createQueryBuilder()
51
73
  .update(PermitEntity)
52
- .set({ spendBlockHash: block.hash })
53
- .where("boxId = :id", { id: id })
74
+ .set({ spendBlock: block.hash, spendHeight: block.height })
75
+ .where("boxId = :id AND extractor = :extractor", { id: id, extractor: extractor })
54
76
  .execute();
55
77
  }
56
78
  };
@@ -64,15 +86,15 @@ class PermitEntityAction {
64
86
  await this.datasource.createQueryBuilder()
65
87
  .delete()
66
88
  .from(PermitEntity)
67
- .where("extractor = :extractor AND blockId = :block", {
89
+ .where("extractor = :extractor AND block = :block", {
68
90
  "block": block,
69
91
  "extractor": extractor
70
92
  }).execute();
71
93
  //TODO: should handled null value in spendBlockHeight
72
94
  await this.datasource.createQueryBuilder()
73
95
  .update(CommitmentEntity)
74
- .set({ spendBlockHash: undefined, spendBlockHeight: 0 })
75
- .where("spendBlockHash = :block AND blockId = :block", {
96
+ .set({ spendBlock: undefined, spendHeight: 0 })
97
+ .where("spendBlock = :block AND block = :block", {
76
98
  block: block
77
99
  }).execute();
78
100
  };
@@ -4,10 +4,11 @@ declare class CommitmentEntity {
4
4
  eventId: string;
5
5
  commitment: string;
6
6
  WID: string;
7
- commitmentBoxId: string;
8
- blockId: string;
7
+ boxId: string;
8
+ block: string;
9
9
  height: number;
10
- spendBlockHash: string;
11
- spendBlockHeight?: number;
10
+ boxSerialized: string;
11
+ spendBlock: string;
12
+ spendHeight?: number;
12
13
  }
13
14
  export default CommitmentEntity;
@@ -7,18 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
10
+ import { Column, Entity, PrimaryGeneratedColumn, Unique } from "typeorm";
11
11
  let CommitmentEntity = class CommitmentEntity {
12
12
  id;
13
13
  extractor;
14
14
  eventId;
15
15
  commitment;
16
16
  WID;
17
- commitmentBoxId;
18
- blockId;
17
+ boxId;
18
+ block;
19
19
  height;
20
- spendBlockHash;
21
- spendBlockHeight;
20
+ boxSerialized;
21
+ spendBlock;
22
+ spendHeight;
22
23
  };
23
24
  __decorate([
24
25
  PrimaryGeneratedColumn(),
@@ -43,24 +44,29 @@ __decorate([
43
44
  __decorate([
44
45
  Column(),
45
46
  __metadata("design:type", String)
46
- ], CommitmentEntity.prototype, "commitmentBoxId", void 0);
47
+ ], CommitmentEntity.prototype, "boxId", void 0);
47
48
  __decorate([
48
49
  Column(),
49
50
  __metadata("design:type", String)
50
- ], CommitmentEntity.prototype, "blockId", void 0);
51
+ ], CommitmentEntity.prototype, "block", void 0);
51
52
  __decorate([
52
53
  Column(),
53
54
  __metadata("design:type", Number)
54
55
  ], CommitmentEntity.prototype, "height", void 0);
56
+ __decorate([
57
+ Column(),
58
+ __metadata("design:type", String)
59
+ ], CommitmentEntity.prototype, "boxSerialized", void 0);
55
60
  __decorate([
56
61
  Column({ nullable: true }),
57
62
  __metadata("design:type", String)
58
- ], CommitmentEntity.prototype, "spendBlockHash", void 0);
63
+ ], CommitmentEntity.prototype, "spendBlock", void 0);
59
64
  __decorate([
60
65
  Column({ nullable: true }),
61
66
  __metadata("design:type", Number)
62
- ], CommitmentEntity.prototype, "spendBlockHeight", void 0);
67
+ ], CommitmentEntity.prototype, "spendHeight", void 0);
63
68
  CommitmentEntity = __decorate([
64
- Entity()
69
+ Entity(),
70
+ Unique(["boxId", "extractor"])
65
71
  ], CommitmentEntity);
66
72
  export default CommitmentEntity;
@@ -3,7 +3,7 @@ declare class EventTriggerEntity {
3
3
  extractor: string;
4
4
  boxId: string;
5
5
  boxSerialized: string;
6
- blockId: string;
6
+ block: string;
7
7
  height: number;
8
8
  fromChain: string;
9
9
  toChain: string;
@@ -7,13 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
10
+ import { Column, Entity, PrimaryGeneratedColumn, Unique } from "typeorm";
11
11
  let EventTriggerEntity = class EventTriggerEntity {
12
12
  id;
13
13
  extractor;
14
14
  boxId;
15
15
  boxSerialized;
16
- blockId;
16
+ block;
17
17
  height;
18
18
  fromChain;
19
19
  toChain;
@@ -47,7 +47,7 @@ __decorate([
47
47
  __decorate([
48
48
  Column(),
49
49
  __metadata("design:type", String)
50
- ], EventTriggerEntity.prototype, "blockId", void 0);
50
+ ], EventTriggerEntity.prototype, "block", void 0);
51
51
  __decorate([
52
52
  Column(),
53
53
  __metadata("design:type", Number)
@@ -101,6 +101,7 @@ __decorate([
101
101
  __metadata("design:type", String)
102
102
  ], EventTriggerEntity.prototype, "WIDs", void 0);
103
103
  EventTriggerEntity = __decorate([
104
- Entity()
104
+ Entity(),
105
+ Unique(["boxId", "extractor"])
105
106
  ], EventTriggerEntity);
106
107
  export default EventTriggerEntity;
@@ -4,9 +4,9 @@ declare class PermitEntity {
4
4
  boxId: string;
5
5
  boxSerialized: string;
6
6
  WID: string;
7
- blockId: string;
7
+ block: string;
8
8
  height: number;
9
- spendBlockHash: string;
10
- spendBlockHeight?: number;
9
+ spendBlock: string;
10
+ spendHeight?: number;
11
11
  }
12
12
  export default PermitEntity;
@@ -7,17 +7,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
10
+ import { Column, Entity, PrimaryGeneratedColumn, Unique } from "typeorm";
11
11
  let PermitEntity = class PermitEntity {
12
12
  id;
13
13
  extractor;
14
14
  boxId;
15
15
  boxSerialized;
16
16
  WID;
17
- blockId;
17
+ block;
18
18
  height;
19
- spendBlockHash;
20
- spendBlockHeight;
19
+ spendBlock;
20
+ spendHeight;
21
21
  };
22
22
  __decorate([
23
23
  PrimaryGeneratedColumn(),
@@ -42,7 +42,7 @@ __decorate([
42
42
  __decorate([
43
43
  Column(),
44
44
  __metadata("design:type", String)
45
- ], PermitEntity.prototype, "blockId", void 0);
45
+ ], PermitEntity.prototype, "block", void 0);
46
46
  __decorate([
47
47
  Column(),
48
48
  __metadata("design:type", Number)
@@ -50,12 +50,13 @@ __decorate([
50
50
  __decorate([
51
51
  Column({ nullable: true }),
52
52
  __metadata("design:type", String)
53
- ], PermitEntity.prototype, "spendBlockHash", void 0);
53
+ ], PermitEntity.prototype, "spendBlock", void 0);
54
54
  __decorate([
55
55
  Column({ nullable: true }),
56
56
  __metadata("design:type", Number)
57
- ], PermitEntity.prototype, "spendBlockHeight", void 0);
57
+ ], PermitEntity.prototype, "spendHeight", void 0);
58
58
  PermitEntity = __decorate([
59
- Entity()
59
+ Entity(),
60
+ Unique(["boxId", "extractor"])
60
61
  ], PermitEntity);
61
62
  export default PermitEntity;
@@ -40,17 +40,15 @@ class EventTriggerExtractor extends AbstractExtractor {
40
40
  R4Serialized.length >= 1 &&
41
41
  R5Serialized.length >= 11 &&
42
42
  output.ergo_tree().to_base16_bytes() === this.eventTriggerErgoTree) {
43
- const WIDs = R4Serialized.map(byteArray => {
44
- Buffer.from(byteArray).toString();
45
- }).join(',');
43
+ const WIDs = R4Serialized.map(byteArray => Buffer.from(byteArray).toString("hex")).join(',');
46
44
  boxes.push({
47
45
  boxId: output.box_id().to_str(),
48
46
  boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64"),
49
47
  toChain: Buffer.from(R5Serialized[2]).toString(),
50
48
  toAddress: Buffer.from(R5Serialized[4]).toString(),
51
- networkFee: Buffer.from(R5Serialized[7]).toString(),
52
- bridgeFee: Buffer.from(R5Serialized[6]).toString(),
53
- amount: Buffer.from(R5Serialized[5]).toString(),
49
+ networkFee: BigInt("0x" + Buffer.from(R5Serialized[7]).toString("hex")).toString(10),
50
+ bridgeFee: BigInt("0x" + Buffer.from(R5Serialized[6]).toString("hex")).toString(10),
51
+ amount: BigInt("0x" + Buffer.from(R5Serialized[5]).toString("hex")).toString(10),
54
52
  sourceChainTokenId: Buffer.from(R5Serialized[8]).toString(),
55
53
  targetChainTokenId: Buffer.from(R5Serialized[9]).toString(),
56
54
  sourceTxId: Buffer.from(R5Serialized[0]).toString(),
@@ -49,7 +49,8 @@ class CommitmentExtractor extends AbstractExtractor {
49
49
  WID: WID,
50
50
  commitment: eventDigest,
51
51
  eventId: requestId,
52
- commitmentBoxId: output.box_id().to_str(),
52
+ boxId: output.box_id().to_str(),
53
+ boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64")
53
54
  });
54
55
  }
55
56
  }
@@ -66,7 +67,7 @@ class CommitmentExtractor extends AbstractExtractor {
66
67
  });
67
68
  // process save commitments
68
69
  this.actions.storeCommitments(commitments, block, this.id).then(() => {
69
- this.actions.spendCommitments(spendIds, block).then(() => {
70
+ this.actions.spendCommitments(spendIds, block, this.id).then(() => {
70
71
  resolve(true);
71
72
  });
72
73
  }).catch((e) => reject(e));
@@ -41,7 +41,7 @@ class PermitExtractor extends AbstractExtractor {
41
41
  boxes.push({
42
42
  boxId: output.box_id().to_str(),
43
43
  boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64"),
44
- WID: Buffer.from(R4Serialized[0]).toString()
44
+ WID: Buffer.from(R4Serialized[0]).toString('hex')
45
45
  });
46
46
  }
47
47
  }
@@ -57,7 +57,7 @@ class PermitExtractor extends AbstractExtractor {
57
57
  }
58
58
  });
59
59
  this.actions.storePermits(boxes, block, this.getId()).then(() => {
60
- this.actions.spendPermits(spendIds, block).then(() => {
60
+ this.actions.spendPermits(spendIds, block, this.getId()).then(() => {
61
61
  resolve(true);
62
62
  });
63
63
  }).catch((e) => {
@@ -2,6 +2,7 @@ interface extractedCommitment {
2
2
  WID: string;
3
3
  commitment: string;
4
4
  eventId: string;
5
- commitmentBoxId: string;
5
+ boxId: string;
6
+ boxSerialized: string;
6
7
  }
7
8
  export { extractedCommitment };
@@ -4,21 +4,23 @@ export class initMigration1659787165000 {
4
4
  await queryRunner.query(`CREATE TABLE "commitment_entity"
5
5
  ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
6
6
  "extractor" varchar NOT NULL,
7
- "eventId" varchar NOT NULL,
7
+ "eventId" varchar NOT NULL,
8
+ "boxSerialized" varchar NOT NULL,
8
9
  "commitment" varchar NOT NULL,
9
10
  "WID" varchar NOT NULL,
10
- "commitmentBoxId" varchar NOT NULL,
11
- "blockId" varchar NOT NULL,
11
+ "boxId" varchar NOT NULL,
12
+ "block" varchar NOT NULL,
12
13
  "height" INTEGER NOT NULL,
13
- "spendBlockHash" varchar,
14
- "spendBlockHeight" INTEGER
14
+ "spendBlock" varchar,
15
+ "spendHeight" INTEGER,
16
+ CONSTRAINT "UQ_cc294fc304a66f8f194840f1ece" UNIQUE ("boxId", "extractor")
15
17
  )`);
16
18
  await queryRunner.query(`CREATE TABLE "event_trigger_entity"
17
19
  ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
18
20
  "extractor" varchar NOT NULL,
19
21
  "boxId" varchar NOT NULL,
20
22
  "boxSerialized" varchar NOT NULL,
21
- "blockId" varchar NOT NULL,
23
+ "block" varchar NOT NULL,
22
24
  "fromChain" varchar NOT NULL,
23
25
  "toChain" varchar NOT NULL,
24
26
  "fromAddress" varchar NOT NULL,
@@ -31,18 +33,20 @@ export class initMigration1659787165000 {
31
33
  "sourceBlockId" varchar NOT NULL,
32
34
  "sourceTxId" varchar NOT NULL,
33
35
  "height" INTEGER NOT NULL,
34
- "WIDs" varchar NOT NULL
36
+ "WIDs" varchar NOT NULL,
37
+ CONSTRAINT "UQ_c905f221a1b6271ca4405dbbe5f" UNIQUE ("boxId", "extractor")
35
38
  )`);
36
39
  await queryRunner.query(`CREATE TABLE "permit_entity"
37
40
  ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
38
41
  "extractor" varchar NOT NULL,
39
42
  "boxId" varchar NOT NULL,
40
43
  "boxSerialized" varchar NOT NULL,
41
- "blockId" varchar NOT NULL,
44
+ "block" varchar NOT NULL,
42
45
  "height" INTEGER NOT NULL,
43
46
  "WID" varchar NOT NULL,
44
- "spendBlockHash" varchar,
45
- "spendBlockHeight" INTEGER
47
+ "spendBlock" varchar,
48
+ "spendHeight" INTEGER,
49
+ CONSTRAINT "UQ_d3226602b909b64bcaeadc39c3c" UNIQUE ("boxId", "extractor")
46
50
  )`);
47
51
  }
48
52
  async down(queryRunner) {
@@ -1,2 +1,2 @@
1
- import { initMigration1659787165000 } from "./init";
1
+ import { initMigration1659787165000 } from "./1659787165000-initMigration";
2
2
  export declare const migrations: (typeof initMigration1659787165000)[];
@@ -1,2 +1,2 @@
1
- import { initMigration1659787165000 } from "./init";
1
+ import { initMigration1659787165000 } from "./1659787165000-initMigration";
2
2
  export const migrations = [initMigration1659787165000];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosen-bridge/watcher-data-extractor",
3
- "version": "0.1.0-alpha-3",
3
+ "version": "0.1.2-alpha",
4
4
  "description": "Extractor for rosen specific boxes on ergo blockchain",
5
5
  "author": "Sahand Zoufan",
6
6
  "license": "GPL-3.0",
@@ -16,7 +16,7 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@rosen-bridge/scanner": "^0.1.7-alpha-2",
19
+ "@rosen-bridge/scanner": "0.1.9-alpha",
20
20
  "blakejs": "^1.2.1",
21
21
  "ergo-lib-wasm-nodejs": "^0.18.0",
22
22
  "reflect-metadata": "^0.1.13",