@rosen-bridge/watcher-data-extractor 0.1.0-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 +92 -0
- package/dist/actions/EventTriggerDB.d.ts +21 -0
- package/dist/actions/EventTriggerDB.js +66 -0
- package/dist/actions/commitmentDB.d.ts +27 -0
- package/dist/actions/commitmentDB.js +71 -0
- package/dist/actions/permitDB.d.ts +21 -0
- package/dist/actions/permitDB.js +56 -0
- package/dist/entities/CommitmentEntity.d.ts +11 -0
- package/dist/entities/CommitmentEntity.js +56 -0
- package/dist/entities/EventTriggerEntity.d.ts +20 -0
- package/dist/entities/EventTriggerEntity.js +101 -0
- package/dist/entities/PermitEntity.d.ts +9 -0
- package/dist/entities/PermitEntity.js +46 -0
- package/dist/extractor/EventTriggerExtractor.d.ts +21 -0
- package/dist/extractor/EventTriggerExtractor.js +88 -0
- package/dist/extractor/commitmentExtractor.d.ts +28 -0
- package/dist/extractor/commitmentExtractor.js +89 -0
- package/dist/extractor/permitExtractor.d.ts +21 -0
- package/dist/extractor/permitExtractor.js +71 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/interfaces/extractedCommitment.d.ts +7 -0
- package/dist/interfaces/extractedCommitment.js +1 -0
- package/dist/interfaces/extractedEventTrigger.d.ts +17 -0
- package/dist/interfaces/extractedEventTrigger.js +1 -0
- package/dist/interfaces/extractedPermit.d.ts +6 -0
- package/dist/interfaces/extractedPermit.js +1 -0
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.js +2 -0
- package/dist/migrations/init.d.ts +6 -0
- package/dist/migrations/init.js +47 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# rosen-scanner
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
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:
|
|
15
|
+
|
|
16
|
+
```
|
|
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
|
|
21
|
+
```
|
|
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
|
+
|
|
78
|
+
## 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.
|
|
87
|
+
|
|
88
|
+
## 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.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { BlockEntity } from "@rosen-bridge/scanner";
|
|
3
|
+
import { ExtractedEventTrigger } from "../interfaces/extractedEventTrigger";
|
|
4
|
+
declare class EventTriggerDB {
|
|
5
|
+
private readonly datasource;
|
|
6
|
+
constructor(dataSource: DataSource);
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of wids in the dataSource with block id
|
|
9
|
+
* @param wids
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractor
|
|
12
|
+
*/
|
|
13
|
+
storeEventTriggers: (wids: Array<ExtractedEventTrigger>, block: BlockEntity, extractor: string) => Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
16
|
+
* @param block
|
|
17
|
+
* @param extractor
|
|
18
|
+
*/
|
|
19
|
+
deleteBlock: (block: string, extractor: string) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export default EventTriggerDB;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import EventTriggerEntity from "../entities/EventTriggerEntity";
|
|
2
|
+
class EventTriggerDB {
|
|
3
|
+
datasource;
|
|
4
|
+
constructor(dataSource) {
|
|
5
|
+
this.datasource = dataSource;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of wids in the dataSource with block id
|
|
9
|
+
* @param wids
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractor
|
|
12
|
+
*/
|
|
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.extractor = extractor;
|
|
20
|
+
row.WIDs = event.WIDs;
|
|
21
|
+
row.amount = event.amount;
|
|
22
|
+
row.bridgeFee = event.bridgeFee;
|
|
23
|
+
row.fromAddress = event.fromAddress;
|
|
24
|
+
row.toAddress = event.toAddress;
|
|
25
|
+
row.fromChain = event.fromChain;
|
|
26
|
+
row.networkFee = event.networkFee;
|
|
27
|
+
row.sourceChainTokenId = event.sourceChainTokenId;
|
|
28
|
+
row.targetChainTokenId = event.targetChainTokenId;
|
|
29
|
+
row.sourceBlockId = event.sourceBlockId;
|
|
30
|
+
row.toChain = event.toChain;
|
|
31
|
+
row.sourceTxId = event.sourceTxId;
|
|
32
|
+
return row;
|
|
33
|
+
});
|
|
34
|
+
let success = true;
|
|
35
|
+
const queryRunner = this.datasource.createQueryRunner();
|
|
36
|
+
await queryRunner.connect();
|
|
37
|
+
await queryRunner.startTransaction();
|
|
38
|
+
try {
|
|
39
|
+
await queryRunner.manager.save(widEntity);
|
|
40
|
+
await queryRunner.commitTransaction();
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
await queryRunner.rollbackTransaction();
|
|
44
|
+
success = false;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await queryRunner.release();
|
|
48
|
+
}
|
|
49
|
+
return success;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
53
|
+
* @param block
|
|
54
|
+
* @param extractor
|
|
55
|
+
*/
|
|
56
|
+
deleteBlock = async (block, extractor) => {
|
|
57
|
+
await this.datasource.createQueryBuilder()
|
|
58
|
+
.delete()
|
|
59
|
+
.from(EventTriggerEntity)
|
|
60
|
+
.where("extractor = :extractor AND blockId = :block", {
|
|
61
|
+
"block": block,
|
|
62
|
+
"extractor": extractor
|
|
63
|
+
}).execute();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export default EventTriggerDB;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { extractedCommitment } from "../interfaces/extractedCommitment";
|
|
3
|
+
import { BlockEntity } from "@rosen-bridge/scanner";
|
|
4
|
+
declare class CommitmentEntityAction {
|
|
5
|
+
private readonly datasource;
|
|
6
|
+
constructor(dataSource: DataSource);
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of observations in the dataSource with block id
|
|
9
|
+
* @param commitments
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractorId
|
|
12
|
+
*/
|
|
13
|
+
storeCommitments: (commitments: Array<extractedCommitment>, block: BlockEntity, extractorId: string) => Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* update spendBlock Column of the commitments in the dataBase
|
|
16
|
+
* @param spendId
|
|
17
|
+
* @param block
|
|
18
|
+
*/
|
|
19
|
+
spendCommitments: (spendId: Array<string>, block: BlockEntity) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
22
|
+
* @param block
|
|
23
|
+
* @param extractor
|
|
24
|
+
*/
|
|
25
|
+
deleteBlockCommitment: (block: string, extractor: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export default CommitmentEntityAction;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import CommitmentEntity from "../entities/CommitmentEntity";
|
|
2
|
+
class CommitmentEntityAction {
|
|
3
|
+
datasource;
|
|
4
|
+
constructor(dataSource) {
|
|
5
|
+
this.datasource = dataSource;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of observations in the dataSource with block id
|
|
9
|
+
* @param commitments
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractorId
|
|
12
|
+
*/
|
|
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
|
+
return row;
|
|
23
|
+
});
|
|
24
|
+
let success = true;
|
|
25
|
+
const queryRunner = this.datasource.createQueryRunner();
|
|
26
|
+
await queryRunner.connect();
|
|
27
|
+
await queryRunner.startTransaction();
|
|
28
|
+
try {
|
|
29
|
+
await queryRunner.manager.save(commitmentEntity);
|
|
30
|
+
await queryRunner.commitTransaction();
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
success = false;
|
|
34
|
+
await queryRunner.rollbackTransaction();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await queryRunner.release();
|
|
38
|
+
}
|
|
39
|
+
return success;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* update spendBlock Column of the commitments in the dataBase
|
|
43
|
+
* @param spendId
|
|
44
|
+
* @param block
|
|
45
|
+
*/
|
|
46
|
+
spendCommitments = async (spendId, block) => {
|
|
47
|
+
//todo: should change with single db call
|
|
48
|
+
for (const id of spendId) {
|
|
49
|
+
await this.datasource.createQueryBuilder()
|
|
50
|
+
.update(CommitmentEntity)
|
|
51
|
+
.set({ spendBlock: block.hash })
|
|
52
|
+
.where("commitmentBoxId = :id", { id: id })
|
|
53
|
+
.execute();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
58
|
+
* @param block
|
|
59
|
+
* @param extractor
|
|
60
|
+
*/
|
|
61
|
+
deleteBlockCommitment = async (block, extractor) => {
|
|
62
|
+
await this.datasource.createQueryBuilder()
|
|
63
|
+
.delete()
|
|
64
|
+
.from(CommitmentEntity)
|
|
65
|
+
.where("extractor = :extractor AND blockId = :block", {
|
|
66
|
+
"block": block,
|
|
67
|
+
"extractor": extractor
|
|
68
|
+
}).execute();
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export default CommitmentEntityAction;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import { extractedPermit } from "../interfaces/extractedPermit";
|
|
3
|
+
import { BlockEntity } from "@rosen-bridge/scanner";
|
|
4
|
+
declare class PermitEntityAction {
|
|
5
|
+
private readonly datasource;
|
|
6
|
+
constructor(dataSource: DataSource);
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of permits in the dataSource with block id
|
|
9
|
+
* @param permits
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractor
|
|
12
|
+
*/
|
|
13
|
+
storePermits: (permits: Array<extractedPermit>, block: BlockEntity, extractor: string) => Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
16
|
+
* @param block
|
|
17
|
+
* @param extractor
|
|
18
|
+
*/
|
|
19
|
+
deleteBlock: (block: string, extractor: string) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export default PermitEntityAction;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import PermitEntity from "../entities/PermitEntity";
|
|
2
|
+
class PermitEntityAction {
|
|
3
|
+
datasource;
|
|
4
|
+
constructor(dataSource) {
|
|
5
|
+
this.datasource = dataSource;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* It stores list of permits in the dataSource with block id
|
|
9
|
+
* @param permits
|
|
10
|
+
* @param block
|
|
11
|
+
* @param extractor
|
|
12
|
+
*/
|
|
13
|
+
storePermits = async (permits, block, extractor) => {
|
|
14
|
+
const permitEntity = permits.map((permit) => {
|
|
15
|
+
const row = new PermitEntity();
|
|
16
|
+
row.boxId = permit.boxId;
|
|
17
|
+
row.boxSerialized = permit.boxSerialized;
|
|
18
|
+
row.blockId = block.hash;
|
|
19
|
+
row.extractor = extractor;
|
|
20
|
+
row.WID = permit.WID;
|
|
21
|
+
return row;
|
|
22
|
+
});
|
|
23
|
+
let success = true;
|
|
24
|
+
const queryRunner = this.datasource.createQueryRunner();
|
|
25
|
+
await queryRunner.connect();
|
|
26
|
+
await queryRunner.startTransaction();
|
|
27
|
+
try {
|
|
28
|
+
await queryRunner.manager.save(permitEntity);
|
|
29
|
+
await queryRunner.commitTransaction();
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
await queryRunner.rollbackTransaction();
|
|
33
|
+
success = false;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await queryRunner.release();
|
|
37
|
+
}
|
|
38
|
+
return success;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
42
|
+
* @param block
|
|
43
|
+
* @param extractor
|
|
44
|
+
*/
|
|
45
|
+
//TODO: should check if deleted or not Promise<Boolean>
|
|
46
|
+
deleteBlock = async (block, extractor) => {
|
|
47
|
+
await this.datasource.createQueryBuilder()
|
|
48
|
+
.delete()
|
|
49
|
+
.from(PermitEntity)
|
|
50
|
+
.where("extractor = :extractor AND blockId = :block", {
|
|
51
|
+
"block": block,
|
|
52
|
+
"extractor": extractor
|
|
53
|
+
}).execute();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export default PermitEntityAction;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
11
|
+
let CommitmentEntity = class CommitmentEntity {
|
|
12
|
+
id;
|
|
13
|
+
extractor;
|
|
14
|
+
eventId;
|
|
15
|
+
commitment;
|
|
16
|
+
WID;
|
|
17
|
+
commitmentBoxId;
|
|
18
|
+
blockId;
|
|
19
|
+
spendBlock;
|
|
20
|
+
};
|
|
21
|
+
__decorate([
|
|
22
|
+
PrimaryGeneratedColumn(),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], CommitmentEntity.prototype, "id", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
Column(),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], CommitmentEntity.prototype, "extractor", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
Column(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], CommitmentEntity.prototype, "eventId", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
Column(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], CommitmentEntity.prototype, "commitment", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
Column(),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], CommitmentEntity.prototype, "WID", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
Column(),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], CommitmentEntity.prototype, "commitmentBoxId", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
Column(),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], CommitmentEntity.prototype, "blockId", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Column({ nullable: true }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], CommitmentEntity.prototype, "spendBlock", void 0);
|
|
53
|
+
CommitmentEntity = __decorate([
|
|
54
|
+
Entity()
|
|
55
|
+
], CommitmentEntity);
|
|
56
|
+
export default CommitmentEntity;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare class EventTriggerEntity {
|
|
2
|
+
id: number;
|
|
3
|
+
extractor: string;
|
|
4
|
+
boxId: string;
|
|
5
|
+
boxSerialized: string;
|
|
6
|
+
blockId: string;
|
|
7
|
+
fromChain: string;
|
|
8
|
+
toChain: string;
|
|
9
|
+
fromAddress: string;
|
|
10
|
+
toAddress: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
bridgeFee: string;
|
|
13
|
+
networkFee: string;
|
|
14
|
+
sourceChainTokenId: string;
|
|
15
|
+
targetChainTokenId: string;
|
|
16
|
+
sourceTxId: string;
|
|
17
|
+
sourceBlockId: string;
|
|
18
|
+
WIDs: string;
|
|
19
|
+
}
|
|
20
|
+
export default EventTriggerEntity;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
11
|
+
let EventTriggerEntity = class EventTriggerEntity {
|
|
12
|
+
id;
|
|
13
|
+
extractor;
|
|
14
|
+
boxId;
|
|
15
|
+
boxSerialized;
|
|
16
|
+
blockId;
|
|
17
|
+
fromChain;
|
|
18
|
+
toChain;
|
|
19
|
+
fromAddress;
|
|
20
|
+
toAddress;
|
|
21
|
+
amount;
|
|
22
|
+
bridgeFee;
|
|
23
|
+
networkFee;
|
|
24
|
+
sourceChainTokenId;
|
|
25
|
+
targetChainTokenId;
|
|
26
|
+
sourceTxId;
|
|
27
|
+
sourceBlockId;
|
|
28
|
+
WIDs;
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
PrimaryGeneratedColumn(),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], EventTriggerEntity.prototype, "id", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
Column(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], EventTriggerEntity.prototype, "extractor", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
Column(),
|
|
40
|
+
__metadata("design:type", String)
|
|
41
|
+
], EventTriggerEntity.prototype, "boxId", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
Column(),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], EventTriggerEntity.prototype, "boxSerialized", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
Column(),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], EventTriggerEntity.prototype, "blockId", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
Column(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], EventTriggerEntity.prototype, "fromChain", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
Column(),
|
|
56
|
+
__metadata("design:type", String)
|
|
57
|
+
], EventTriggerEntity.prototype, "toChain", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
Column(),
|
|
60
|
+
__metadata("design:type", String)
|
|
61
|
+
], EventTriggerEntity.prototype, "fromAddress", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
Column(),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], EventTriggerEntity.prototype, "toAddress", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
Column(),
|
|
68
|
+
__metadata("design:type", String)
|
|
69
|
+
], EventTriggerEntity.prototype, "amount", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
Column(),
|
|
72
|
+
__metadata("design:type", String)
|
|
73
|
+
], EventTriggerEntity.prototype, "bridgeFee", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
Column(),
|
|
76
|
+
__metadata("design:type", String)
|
|
77
|
+
], EventTriggerEntity.prototype, "networkFee", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Column(),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], EventTriggerEntity.prototype, "sourceChainTokenId", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
Column(),
|
|
84
|
+
__metadata("design:type", String)
|
|
85
|
+
], EventTriggerEntity.prototype, "targetChainTokenId", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
Column(),
|
|
88
|
+
__metadata("design:type", String)
|
|
89
|
+
], EventTriggerEntity.prototype, "sourceTxId", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
Column(),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], EventTriggerEntity.prototype, "sourceBlockId", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
Column(),
|
|
96
|
+
__metadata("design:type", String)
|
|
97
|
+
], EventTriggerEntity.prototype, "WIDs", void 0);
|
|
98
|
+
EventTriggerEntity = __decorate([
|
|
99
|
+
Entity()
|
|
100
|
+
], EventTriggerEntity);
|
|
101
|
+
export default EventTriggerEntity;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
11
|
+
let PermitEntity = class PermitEntity {
|
|
12
|
+
id;
|
|
13
|
+
extractor;
|
|
14
|
+
boxId;
|
|
15
|
+
boxSerialized;
|
|
16
|
+
WID;
|
|
17
|
+
blockId;
|
|
18
|
+
};
|
|
19
|
+
__decorate([
|
|
20
|
+
PrimaryGeneratedColumn(),
|
|
21
|
+
__metadata("design:type", Number)
|
|
22
|
+
], PermitEntity.prototype, "id", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
Column(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], PermitEntity.prototype, "extractor", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
Column(),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], PermitEntity.prototype, "boxId", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
Column(),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], PermitEntity.prototype, "boxSerialized", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
Column(),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], PermitEntity.prototype, "WID", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
Column(),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], PermitEntity.prototype, "blockId", void 0);
|
|
43
|
+
PermitEntity = __decorate([
|
|
44
|
+
Entity()
|
|
45
|
+
], PermitEntity);
|
|
46
|
+
export default PermitEntity;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
3
|
+
import { AbstractExtractor, BlockEntity } from "@rosen-bridge/scanner";
|
|
4
|
+
declare class EventTriggerExtractor extends AbstractExtractor<wasm.Transaction> {
|
|
5
|
+
id: string;
|
|
6
|
+
private readonly dataSource;
|
|
7
|
+
private readonly actions;
|
|
8
|
+
private readonly eventTriggerErgoTree;
|
|
9
|
+
private readonly RWT;
|
|
10
|
+
constructor(id: string, dataSource: DataSource, address: string, RWT: string);
|
|
11
|
+
getId: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
14
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
15
|
+
* @param block
|
|
16
|
+
* @param txs
|
|
17
|
+
*/
|
|
18
|
+
processTransactions: (txs: Array<wasm.Transaction>, block: BlockEntity) => Promise<boolean>;
|
|
19
|
+
forkBlock: (hash: string) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export default EventTriggerExtractor;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
2
|
+
import EventTriggerDB from "../actions/EventTriggerDB";
|
|
3
|
+
import { AbstractExtractor } from "@rosen-bridge/scanner";
|
|
4
|
+
class EventTriggerExtractor extends AbstractExtractor {
|
|
5
|
+
id;
|
|
6
|
+
dataSource;
|
|
7
|
+
actions;
|
|
8
|
+
eventTriggerErgoTree;
|
|
9
|
+
RWT;
|
|
10
|
+
constructor(id, dataSource, address, RWT) {
|
|
11
|
+
super();
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.dataSource = dataSource;
|
|
14
|
+
this.actions = new EventTriggerDB(dataSource);
|
|
15
|
+
this.eventTriggerErgoTree = wasm.Address.from_base58(address).to_ergo_tree().to_base16_bytes();
|
|
16
|
+
this.RWT = RWT;
|
|
17
|
+
}
|
|
18
|
+
getId = () => this.id;
|
|
19
|
+
/**
|
|
20
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
21
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
22
|
+
* @param block
|
|
23
|
+
* @param txs
|
|
24
|
+
*/
|
|
25
|
+
processTransactions = (txs, block) => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
try {
|
|
28
|
+
const boxes = [];
|
|
29
|
+
txs.forEach(transaction => {
|
|
30
|
+
for (let index = 0; index < transaction.outputs().len(); index++) {
|
|
31
|
+
const output = transaction.outputs().get(index);
|
|
32
|
+
try {
|
|
33
|
+
const r4 = output.register_value(4);
|
|
34
|
+
const r5 = output.register_value(5);
|
|
35
|
+
if (r4 && r5) {
|
|
36
|
+
const R5Serialized = r5.to_coll_coll_byte();
|
|
37
|
+
const R4Serialized = r4.to_coll_coll_byte();
|
|
38
|
+
if (output.tokens().len() > 0 &&
|
|
39
|
+
output.tokens().get(0).id().to_str() === this.RWT &&
|
|
40
|
+
R4Serialized.length >= 1 &&
|
|
41
|
+
R5Serialized.length >= 11 &&
|
|
42
|
+
output.ergo_tree().to_base16_bytes() === this.eventTriggerErgoTree) {
|
|
43
|
+
const WIDs = R4Serialized.map(byteArray => {
|
|
44
|
+
Buffer.from(byteArray).toString();
|
|
45
|
+
}).join(',');
|
|
46
|
+
boxes.push({
|
|
47
|
+
boxId: output.box_id().to_str(),
|
|
48
|
+
boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64"),
|
|
49
|
+
toChain: Buffer.from(R5Serialized[2]).toString(),
|
|
50
|
+
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(),
|
|
54
|
+
sourceChainTokenId: Buffer.from(R5Serialized[8]).toString(),
|
|
55
|
+
targetChainTokenId: Buffer.from(R5Serialized[9]).toString(),
|
|
56
|
+
sourceTxId: Buffer.from(R5Serialized[0]).toString(),
|
|
57
|
+
fromChain: Buffer.from(R5Serialized[1]).toString(),
|
|
58
|
+
fromAddress: Buffer.from(R5Serialized[3]).toString(),
|
|
59
|
+
sourceBlockId: Buffer.from(R5Serialized[10]).toString(),
|
|
60
|
+
WIDs: WIDs,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.actions.storeEventTriggers(boxes, block, this.getId()).then(() => {
|
|
71
|
+
resolve(true);
|
|
72
|
+
}).catch((e) => {
|
|
73
|
+
console.log(`Error in soring permits of the block ${block}`);
|
|
74
|
+
console.log(e);
|
|
75
|
+
reject(e);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.log(`block ${block} doesn't save in the database with error`, e);
|
|
80
|
+
reject(e);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
forkBlock = async (hash) => {
|
|
85
|
+
await this.actions.deleteBlock(hash, this.getId());
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export default EventTriggerExtractor;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
2
|
+
import { DataSource } from "typeorm";
|
|
3
|
+
import { AbstractExtractor, BlockEntity } from "@rosen-bridge/scanner";
|
|
4
|
+
declare class CommitmentExtractor extends AbstractExtractor<wasm.Transaction> {
|
|
5
|
+
id: string;
|
|
6
|
+
private readonly dataSource;
|
|
7
|
+
private readonly commitmentsErgoTrees;
|
|
8
|
+
private readonly RWTId;
|
|
9
|
+
private readonly actions;
|
|
10
|
+
constructor(id: string, addresses: Array<string>, RWTId: string, dataSource: DataSource);
|
|
11
|
+
/**
|
|
12
|
+
* get Id for current extractor
|
|
13
|
+
*/
|
|
14
|
+
getId: () => string;
|
|
15
|
+
/**
|
|
16
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
17
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
18
|
+
* @param txs
|
|
19
|
+
* @param block
|
|
20
|
+
*/
|
|
21
|
+
processTransactions: (txs: Array<wasm.Transaction>, block: BlockEntity) => Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* fork one block and remove all stored information for this block
|
|
24
|
+
* @param hash: block hash
|
|
25
|
+
*/
|
|
26
|
+
forkBlock: (hash: string) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export default CommitmentExtractor;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
2
|
+
import CommitmentEntityAction from "../actions/commitmentDB";
|
|
3
|
+
import { AbstractExtractor } from "@rosen-bridge/scanner";
|
|
4
|
+
class CommitmentExtractor extends AbstractExtractor {
|
|
5
|
+
id;
|
|
6
|
+
dataSource;
|
|
7
|
+
commitmentsErgoTrees;
|
|
8
|
+
RWTId;
|
|
9
|
+
actions;
|
|
10
|
+
constructor(id, addresses, RWTId, dataSource) {
|
|
11
|
+
super();
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.dataSource = dataSource;
|
|
14
|
+
this.commitmentsErgoTrees = addresses.map(address => wasm.Address.from_base58(address).to_ergo_tree().to_base16_bytes());
|
|
15
|
+
this.actions = new CommitmentEntityAction(dataSource);
|
|
16
|
+
this.RWTId = RWTId;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* get Id for current extractor
|
|
20
|
+
*/
|
|
21
|
+
getId = () => this.id;
|
|
22
|
+
/**
|
|
23
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
24
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
25
|
+
* @param txs
|
|
26
|
+
* @param block
|
|
27
|
+
*/
|
|
28
|
+
processTransactions = (txs, block) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
try {
|
|
31
|
+
const commitments = [];
|
|
32
|
+
const spendIds = [];
|
|
33
|
+
txs.forEach(transaction => {
|
|
34
|
+
// process outputs
|
|
35
|
+
for (let index = 0; index < transaction.outputs().len(); index++) {
|
|
36
|
+
const output = transaction.outputs().get(index);
|
|
37
|
+
if (output.tokens().len() > 0 &&
|
|
38
|
+
output.tokens().get(0).id().to_str() === this.RWTId &&
|
|
39
|
+
this.commitmentsErgoTrees.indexOf(output.ergo_tree().to_base16_bytes()) !== -1) {
|
|
40
|
+
try {
|
|
41
|
+
const R4 = output.register_value(4);
|
|
42
|
+
const R5 = output.register_value(5);
|
|
43
|
+
const R6 = output.register_value(6);
|
|
44
|
+
if (R4 && R5 && R6) {
|
|
45
|
+
const WID = Buffer.from(R4.to_coll_coll_byte()[0]).toString("hex");
|
|
46
|
+
const requestId = Buffer.from(R5.to_coll_coll_byte()[0]).toString("hex");
|
|
47
|
+
const eventDigest = Buffer.from(R6.to_byte_array()).toString("hex");
|
|
48
|
+
commitments.push({
|
|
49
|
+
WID: WID,
|
|
50
|
+
commitment: eventDigest,
|
|
51
|
+
eventId: requestId,
|
|
52
|
+
commitmentBoxId: output.box_id().to_str(),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// process inputs
|
|
62
|
+
for (let index = 0; index < transaction.inputs().len(); index++) {
|
|
63
|
+
const input = transaction.inputs().get(index);
|
|
64
|
+
spendIds.push(input.box_id().to_str());
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// process save commitments
|
|
68
|
+
this.actions.storeCommitments(commitments, block, this.id).then(() => {
|
|
69
|
+
this.actions.spendCommitments(spendIds, block).then(() => {
|
|
70
|
+
resolve(true);
|
|
71
|
+
});
|
|
72
|
+
}).catch((e) => reject(e));
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.log(`Error in soring permits of the block ${block}`);
|
|
76
|
+
console.log(e);
|
|
77
|
+
reject(e);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* fork one block and remove all stored information for this block
|
|
83
|
+
* @param hash: block hash
|
|
84
|
+
*/
|
|
85
|
+
forkBlock = async (hash) => {
|
|
86
|
+
await this.actions.deleteBlockCommitment(hash, this.getId());
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export default CommitmentExtractor;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DataSource } from "typeorm";
|
|
2
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
3
|
+
import { AbstractExtractor, BlockEntity } from "@rosen-bridge/scanner";
|
|
4
|
+
declare class PermitExtractor extends AbstractExtractor<wasm.Transaction> {
|
|
5
|
+
id: string;
|
|
6
|
+
private readonly dataSource;
|
|
7
|
+
private readonly actions;
|
|
8
|
+
private readonly permitErgoTree;
|
|
9
|
+
private readonly RWT;
|
|
10
|
+
constructor(id: string, dataSource: DataSource, address: string, RWT: string);
|
|
11
|
+
getId: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
14
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
15
|
+
* @param block
|
|
16
|
+
* @param txs
|
|
17
|
+
*/
|
|
18
|
+
processTransactions: (txs: Array<wasm.Transaction>, block: BlockEntity) => Promise<boolean>;
|
|
19
|
+
forkBlock: (hash: string) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export default PermitExtractor;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as wasm from 'ergo-lib-wasm-nodejs';
|
|
2
|
+
import PermitEntityAction from "../actions/permitDB";
|
|
3
|
+
import { AbstractExtractor } from "@rosen-bridge/scanner";
|
|
4
|
+
class PermitExtractor extends AbstractExtractor {
|
|
5
|
+
id;
|
|
6
|
+
dataSource;
|
|
7
|
+
actions;
|
|
8
|
+
permitErgoTree;
|
|
9
|
+
RWT;
|
|
10
|
+
constructor(id, dataSource, address, RWT) {
|
|
11
|
+
super();
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.dataSource = dataSource;
|
|
14
|
+
this.actions = new PermitEntityAction(dataSource);
|
|
15
|
+
this.permitErgoTree = wasm.Address.from_base58(address).to_ergo_tree().to_base16_bytes();
|
|
16
|
+
this.RWT = RWT;
|
|
17
|
+
}
|
|
18
|
+
getId = () => this.id;
|
|
19
|
+
/**
|
|
20
|
+
* gets block id and transactions corresponding to the block and saves if they are valid rosen
|
|
21
|
+
* transactions and in case of success return true and in case of failure returns false
|
|
22
|
+
* @param block
|
|
23
|
+
* @param txs
|
|
24
|
+
*/
|
|
25
|
+
processTransactions = (txs, block) => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
try {
|
|
28
|
+
const boxes = [];
|
|
29
|
+
txs.forEach(transaction => {
|
|
30
|
+
for (let index = 0; index < transaction.outputs().len(); index++) {
|
|
31
|
+
const output = transaction.outputs().get(index);
|
|
32
|
+
try {
|
|
33
|
+
const r4 = output.register_value(4);
|
|
34
|
+
if (r4) {
|
|
35
|
+
const R4Serialized = r4.to_coll_coll_byte();
|
|
36
|
+
if (output.tokens().len() > 0 &&
|
|
37
|
+
output.tokens().get(0).id().to_str() == this.RWT &&
|
|
38
|
+
output.ergo_tree().to_base16_bytes() === this.permitErgoTree &&
|
|
39
|
+
R4Serialized.length >= 1) {
|
|
40
|
+
boxes.push({
|
|
41
|
+
boxId: output.box_id().to_str(),
|
|
42
|
+
boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64"),
|
|
43
|
+
WID: Buffer.from(R4Serialized[0]).toString()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.actions.storePermits(boxes, block, this.getId()).then(() => {
|
|
54
|
+
resolve(true);
|
|
55
|
+
}).catch((e) => {
|
|
56
|
+
console.log(`Error in storing permits of the block ${block}`);
|
|
57
|
+
console.log(e);
|
|
58
|
+
reject(e);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.log(`block ${block} doesn't save in the database with error`, e);
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
forkBlock = async (hash) => {
|
|
68
|
+
await this.actions.deleteBlock(hash, this.getId());
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export default PermitExtractor;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import EventTriggerEntity from "./entities/EventTriggerEntity";
|
|
3
|
+
import CommitmentEntity from "./entities/CommitmentEntity";
|
|
4
|
+
import CommitmentExtractor from "./extractor/commitmentExtractor";
|
|
5
|
+
import PermitEntity from "./entities/PermitEntity";
|
|
6
|
+
import PermitExtractor from "./extractor/permitExtractor";
|
|
7
|
+
import EventTriggerExtractor from "./extractor/EventTriggerExtractor";
|
|
8
|
+
export { migrations } from './migrations/index';
|
|
9
|
+
export { PermitExtractor, EventTriggerExtractor, CommitmentExtractor, CommitmentEntity, EventTriggerEntity, PermitEntity };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import EventTriggerEntity from "./entities/EventTriggerEntity";
|
|
3
|
+
import CommitmentEntity from "./entities/CommitmentEntity";
|
|
4
|
+
import CommitmentExtractor from "./extractor/commitmentExtractor";
|
|
5
|
+
import PermitEntity from "./entities/PermitEntity";
|
|
6
|
+
import PermitExtractor from "./extractor/permitExtractor";
|
|
7
|
+
import EventTriggerExtractor from "./extractor/EventTriggerExtractor";
|
|
8
|
+
export { migrations } from './migrations/index';
|
|
9
|
+
export { PermitExtractor, EventTriggerExtractor, CommitmentExtractor, CommitmentEntity, EventTriggerEntity, PermitEntity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface ExtractedEventTrigger {
|
|
2
|
+
boxId: string;
|
|
3
|
+
boxSerialized: string;
|
|
4
|
+
fromChain: string;
|
|
5
|
+
toChain: string;
|
|
6
|
+
fromAddress: string;
|
|
7
|
+
toAddress: string;
|
|
8
|
+
amount: string;
|
|
9
|
+
bridgeFee: string;
|
|
10
|
+
networkFee: string;
|
|
11
|
+
sourceChainTokenId: string;
|
|
12
|
+
targetChainTokenId: string;
|
|
13
|
+
sourceBlockId: string;
|
|
14
|
+
sourceTxId: string;
|
|
15
|
+
WIDs: string;
|
|
16
|
+
}
|
|
17
|
+
export { ExtractedEventTrigger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export class initMigration1659787165000 {
|
|
2
|
+
name = 'initMigration1659787165000';
|
|
3
|
+
async up(queryRunner) {
|
|
4
|
+
await queryRunner.query(`CREATE TABLE "commitment_entity"
|
|
5
|
+
("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
6
|
+
"extractor" varchar NOT NULL,
|
|
7
|
+
"eventId" varchar NOT NULL,
|
|
8
|
+
"commitment" varchar NOT NULL,
|
|
9
|
+
"WID" varchar NOT NULL,
|
|
10
|
+
"commitmentBoxId" varchar NOT NULL,
|
|
11
|
+
"blockId" varchar NOT NULL,
|
|
12
|
+
"spendBlock" varchar
|
|
13
|
+
)`);
|
|
14
|
+
await queryRunner.query(`CREATE TABLE "event_trigger_entity"
|
|
15
|
+
("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
16
|
+
"extractor" varchar NOT NULL,
|
|
17
|
+
"boxId" varchar NOT NULL,
|
|
18
|
+
"boxSerialized" varchar NOT NULL,
|
|
19
|
+
"blockId" varchar NOT NULL,
|
|
20
|
+
"fromChain" varchar NOT NULL,
|
|
21
|
+
"toChain" varchar NOT NULL,
|
|
22
|
+
"fromAddress" varchar NOT NULL,
|
|
23
|
+
"toAddress" varchar NOT NULL,
|
|
24
|
+
"amount" varchar NOT NULL,
|
|
25
|
+
"bridgeFee" varchar NOT NULL,
|
|
26
|
+
"networkFee" varchar NOT NULL,
|
|
27
|
+
"sourceChainTokenId" varchar NOT NULL,
|
|
28
|
+
"targetChainTokenId" varchar NOT NULL,
|
|
29
|
+
"sourceBlockId" varchar NOT NULL,
|
|
30
|
+
"sourceTxId" varchar NOT NULL,
|
|
31
|
+
"WIDs" varchar NOT NULL
|
|
32
|
+
)`);
|
|
33
|
+
await queryRunner.query(`CREATE TABLE "permit_entity"
|
|
34
|
+
("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
35
|
+
"extractor" varchar NOT NULL,
|
|
36
|
+
"boxId" varchar NOT NULL,
|
|
37
|
+
"boxSerialized" varchar NOT NULL,
|
|
38
|
+
"blockId" varchar NOT NULL,
|
|
39
|
+
"WID" varchar NOT NULL
|
|
40
|
+
)`);
|
|
41
|
+
}
|
|
42
|
+
async down(queryRunner) {
|
|
43
|
+
await queryRunner.query(`DROP TABLE "commitment_entity"`);
|
|
44
|
+
await queryRunner.query(`DROP TABLE "event_trigger_entity"`);
|
|
45
|
+
await queryRunner.query(`DROP TABLE "permit_entity"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rosen-bridge/watcher-data-extractor",
|
|
3
|
+
"version": "0.1.0-alpha",
|
|
4
|
+
"description": "Extractor for rosen specific boxes on ergo blockchain",
|
|
5
|
+
"author": "Sahand Zoufan",
|
|
6
|
+
"license": "GPL-3.0",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "eslint --fix .",
|
|
11
|
+
"test": "rimraf sqlite; tsc --noEmit; npm run lint; jest --detectOpenHandles; rimraf sqlite",
|
|
12
|
+
"coverage": "c8 npm run test",
|
|
13
|
+
"build": "rimraf dist && tsc"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@rosen-bridge/scanner": "^0.1.7-alpha",
|
|
20
|
+
"blakejs": "^1.2.1",
|
|
21
|
+
"ergo-lib-wasm-nodejs": "^0.18.0",
|
|
22
|
+
"reflect-metadata": "^0.1.13",
|
|
23
|
+
"sqlite3": "^5.0.9",
|
|
24
|
+
"typeorm": "^0.3.7"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/jest": "^28.1.6",
|
|
29
|
+
"@types/node": "^18.0.6",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
|
31
|
+
"@typescript-eslint/parser": "^5.26.0",
|
|
32
|
+
"c8": "^7.11.3",
|
|
33
|
+
"eslint": "^8.16.0",
|
|
34
|
+
"jest": "^28.1.3",
|
|
35
|
+
"rimraf": "^3.0.2",
|
|
36
|
+
"ts-jest": "^28.0.7",
|
|
37
|
+
"ts-node": "^10.9.1",
|
|
38
|
+
"typescript": "^4.7.4"
|
|
39
|
+
}
|
|
40
|
+
}
|