@rosen-bridge/watcher-data-extractor 0.1.0-alpha-2 → 0.1.0-alpha-3
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/actions/EventTriggerDB.js +1 -0
- package/dist/actions/commitmentDB.js +9 -1
- package/dist/actions/permitDB.d.ts +6 -0
- package/dist/actions/permitDB.js +24 -0
- package/dist/entities/CommitmentEntity.d.ts +3 -1
- package/dist/entities/CommitmentEntity.js +12 -2
- package/dist/entities/EventTriggerEntity.d.ts +1 -0
- package/dist/entities/EventTriggerEntity.js +5 -0
- package/dist/entities/PermitEntity.d.ts +3 -0
- package/dist/entities/PermitEntity.js +15 -0
- package/dist/extractor/permitExtractor.js +9 -1
- package/dist/migrations/init.js +8 -2
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ class CommitmentEntityAction {
|
|
|
19
19
|
row.WID = commitment.WID;
|
|
20
20
|
row.extractor = extractorId;
|
|
21
21
|
row.blockId = block.hash;
|
|
22
|
+
row.height = block.height;
|
|
22
23
|
return row;
|
|
23
24
|
});
|
|
24
25
|
let success = true;
|
|
@@ -48,7 +49,7 @@ class CommitmentEntityAction {
|
|
|
48
49
|
for (const id of spendId) {
|
|
49
50
|
await this.datasource.createQueryBuilder()
|
|
50
51
|
.update(CommitmentEntity)
|
|
51
|
-
.set({
|
|
52
|
+
.set({ spendBlockHash: block.hash })
|
|
52
53
|
.where("commitmentBoxId = :id", { id: id })
|
|
53
54
|
.execute();
|
|
54
55
|
}
|
|
@@ -66,6 +67,13 @@ class CommitmentEntityAction {
|
|
|
66
67
|
"block": block,
|
|
67
68
|
"extractor": extractor
|
|
68
69
|
}).execute();
|
|
70
|
+
//TODO: should handled null value in spendBlockHeight
|
|
71
|
+
await this.datasource.createQueryBuilder()
|
|
72
|
+
.update(CommitmentEntity)
|
|
73
|
+
.set({ spendBlockHash: undefined, spendBlockHeight: 0 })
|
|
74
|
+
.where("spendBlockHash = :block AND blockId = :block", {
|
|
75
|
+
block: block
|
|
76
|
+
}).execute();
|
|
69
77
|
};
|
|
70
78
|
}
|
|
71
79
|
export default CommitmentEntityAction;
|
|
@@ -11,6 +11,12 @@ declare class PermitEntityAction {
|
|
|
11
11
|
* @param extractor
|
|
12
12
|
*/
|
|
13
13
|
storePermits: (permits: Array<extractedPermit>, block: BlockEntity, extractor: string) => Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* update spendBlock Column of the permits in the dataBase
|
|
16
|
+
* @param spendId
|
|
17
|
+
* @param block
|
|
18
|
+
*/
|
|
19
|
+
spendPermits: (spendId: Array<string>, block: BlockEntity) => Promise<void>;
|
|
14
20
|
/**
|
|
15
21
|
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
16
22
|
* @param block
|
package/dist/actions/permitDB.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import PermitEntity from "../entities/PermitEntity";
|
|
2
|
+
import CommitmentEntity from "../entities/CommitmentEntity";
|
|
2
3
|
class PermitEntityAction {
|
|
3
4
|
datasource;
|
|
4
5
|
constructor(dataSource) {
|
|
@@ -16,6 +17,7 @@ class PermitEntityAction {
|
|
|
16
17
|
row.boxId = permit.boxId;
|
|
17
18
|
row.boxSerialized = permit.boxSerialized;
|
|
18
19
|
row.blockId = block.hash;
|
|
20
|
+
row.height = block.height;
|
|
19
21
|
row.extractor = extractor;
|
|
20
22
|
row.WID = permit.WID;
|
|
21
23
|
return row;
|
|
@@ -37,6 +39,21 @@ class PermitEntityAction {
|
|
|
37
39
|
}
|
|
38
40
|
return success;
|
|
39
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* update spendBlock Column of the permits in the dataBase
|
|
44
|
+
* @param spendId
|
|
45
|
+
* @param block
|
|
46
|
+
*/
|
|
47
|
+
spendPermits = async (spendId, block) => {
|
|
48
|
+
//todo: should change with single db call
|
|
49
|
+
for (const id of spendId) {
|
|
50
|
+
await this.datasource.createQueryBuilder()
|
|
51
|
+
.update(PermitEntity)
|
|
52
|
+
.set({ spendBlockHash: block.hash })
|
|
53
|
+
.where("boxId = :id", { id: id })
|
|
54
|
+
.execute();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
40
57
|
/**
|
|
41
58
|
* deleting all permits corresponding to the block(id) and extractor(id)
|
|
42
59
|
* @param block
|
|
@@ -51,6 +68,13 @@ class PermitEntityAction {
|
|
|
51
68
|
"block": block,
|
|
52
69
|
"extractor": extractor
|
|
53
70
|
}).execute();
|
|
71
|
+
//TODO: should handled null value in spendBlockHeight
|
|
72
|
+
await this.datasource.createQueryBuilder()
|
|
73
|
+
.update(CommitmentEntity)
|
|
74
|
+
.set({ spendBlockHash: undefined, spendBlockHeight: 0 })
|
|
75
|
+
.where("spendBlockHash = :block AND blockId = :block", {
|
|
76
|
+
block: block
|
|
77
|
+
}).execute();
|
|
54
78
|
};
|
|
55
79
|
}
|
|
56
80
|
export default PermitEntityAction;
|
|
@@ -16,7 +16,9 @@ let CommitmentEntity = class CommitmentEntity {
|
|
|
16
16
|
WID;
|
|
17
17
|
commitmentBoxId;
|
|
18
18
|
blockId;
|
|
19
|
-
|
|
19
|
+
height;
|
|
20
|
+
spendBlockHash;
|
|
21
|
+
spendBlockHeight;
|
|
20
22
|
};
|
|
21
23
|
__decorate([
|
|
22
24
|
PrimaryGeneratedColumn(),
|
|
@@ -46,10 +48,18 @@ __decorate([
|
|
|
46
48
|
Column(),
|
|
47
49
|
__metadata("design:type", String)
|
|
48
50
|
], CommitmentEntity.prototype, "blockId", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
Column(),
|
|
53
|
+
__metadata("design:type", Number)
|
|
54
|
+
], CommitmentEntity.prototype, "height", void 0);
|
|
49
55
|
__decorate([
|
|
50
56
|
Column({ nullable: true }),
|
|
51
57
|
__metadata("design:type", String)
|
|
52
|
-
], CommitmentEntity.prototype, "
|
|
58
|
+
], CommitmentEntity.prototype, "spendBlockHash", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
Column({ nullable: true }),
|
|
61
|
+
__metadata("design:type", Number)
|
|
62
|
+
], CommitmentEntity.prototype, "spendBlockHeight", void 0);
|
|
53
63
|
CommitmentEntity = __decorate([
|
|
54
64
|
Entity()
|
|
55
65
|
], CommitmentEntity);
|
|
@@ -14,6 +14,7 @@ let EventTriggerEntity = class EventTriggerEntity {
|
|
|
14
14
|
boxId;
|
|
15
15
|
boxSerialized;
|
|
16
16
|
blockId;
|
|
17
|
+
height;
|
|
17
18
|
fromChain;
|
|
18
19
|
toChain;
|
|
19
20
|
fromAddress;
|
|
@@ -47,6 +48,10 @@ __decorate([
|
|
|
47
48
|
Column(),
|
|
48
49
|
__metadata("design:type", String)
|
|
49
50
|
], EventTriggerEntity.prototype, "blockId", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
Column(),
|
|
53
|
+
__metadata("design:type", Number)
|
|
54
|
+
], EventTriggerEntity.prototype, "height", void 0);
|
|
50
55
|
__decorate([
|
|
51
56
|
Column(),
|
|
52
57
|
__metadata("design:type", String)
|
|
@@ -15,6 +15,9 @@ let PermitEntity = class PermitEntity {
|
|
|
15
15
|
boxSerialized;
|
|
16
16
|
WID;
|
|
17
17
|
blockId;
|
|
18
|
+
height;
|
|
19
|
+
spendBlockHash;
|
|
20
|
+
spendBlockHeight;
|
|
18
21
|
};
|
|
19
22
|
__decorate([
|
|
20
23
|
PrimaryGeneratedColumn(),
|
|
@@ -40,6 +43,18 @@ __decorate([
|
|
|
40
43
|
Column(),
|
|
41
44
|
__metadata("design:type", String)
|
|
42
45
|
], PermitEntity.prototype, "blockId", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
Column(),
|
|
48
|
+
__metadata("design:type", Number)
|
|
49
|
+
], PermitEntity.prototype, "height", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
Column({ nullable: true }),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], PermitEntity.prototype, "spendBlockHash", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
Column({ nullable: true }),
|
|
56
|
+
__metadata("design:type", Number)
|
|
57
|
+
], PermitEntity.prototype, "spendBlockHeight", void 0);
|
|
43
58
|
PermitEntity = __decorate([
|
|
44
59
|
Entity()
|
|
45
60
|
], PermitEntity);
|
|
@@ -26,6 +26,7 @@ class PermitExtractor extends AbstractExtractor {
|
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
try {
|
|
28
28
|
const boxes = [];
|
|
29
|
+
const spendIds = [];
|
|
29
30
|
txs.forEach(transaction => {
|
|
30
31
|
for (let index = 0; index < transaction.outputs().len(); index++) {
|
|
31
32
|
const output = transaction.outputs().get(index);
|
|
@@ -49,9 +50,16 @@ class PermitExtractor extends AbstractExtractor {
|
|
|
49
50
|
continue;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
// process inputs
|
|
54
|
+
for (let index = 0; index < transaction.inputs().len(); index++) {
|
|
55
|
+
const input = transaction.inputs().get(index);
|
|
56
|
+
spendIds.push(input.box_id().to_str());
|
|
57
|
+
}
|
|
52
58
|
});
|
|
53
59
|
this.actions.storePermits(boxes, block, this.getId()).then(() => {
|
|
54
|
-
|
|
60
|
+
this.actions.spendPermits(spendIds, block).then(() => {
|
|
61
|
+
resolve(true);
|
|
62
|
+
});
|
|
55
63
|
}).catch((e) => {
|
|
56
64
|
console.log(`Error in storing permits of the block ${block}`);
|
|
57
65
|
console.log(e);
|
package/dist/migrations/init.js
CHANGED
|
@@ -9,7 +9,9 @@ export class initMigration1659787165000 {
|
|
|
9
9
|
"WID" varchar NOT NULL,
|
|
10
10
|
"commitmentBoxId" varchar NOT NULL,
|
|
11
11
|
"blockId" varchar NOT NULL,
|
|
12
|
-
"
|
|
12
|
+
"height" INTEGER NOT NULL,
|
|
13
|
+
"spendBlockHash" varchar,
|
|
14
|
+
"spendBlockHeight" INTEGER
|
|
13
15
|
)`);
|
|
14
16
|
await queryRunner.query(`CREATE TABLE "event_trigger_entity"
|
|
15
17
|
("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
@@ -28,6 +30,7 @@ export class initMigration1659787165000 {
|
|
|
28
30
|
"targetChainTokenId" varchar NOT NULL,
|
|
29
31
|
"sourceBlockId" varchar NOT NULL,
|
|
30
32
|
"sourceTxId" varchar NOT NULL,
|
|
33
|
+
"height" INTEGER NOT NULL,
|
|
31
34
|
"WIDs" varchar NOT NULL
|
|
32
35
|
)`);
|
|
33
36
|
await queryRunner.query(`CREATE TABLE "permit_entity"
|
|
@@ -36,7 +39,10 @@ export class initMigration1659787165000 {
|
|
|
36
39
|
"boxId" varchar NOT NULL,
|
|
37
40
|
"boxSerialized" varchar NOT NULL,
|
|
38
41
|
"blockId" varchar NOT NULL,
|
|
39
|
-
"
|
|
42
|
+
"height" INTEGER NOT NULL,
|
|
43
|
+
"WID" varchar NOT NULL,
|
|
44
|
+
"spendBlockHash" varchar,
|
|
45
|
+
"spendBlockHeight" INTEGER
|
|
40
46
|
)`);
|
|
41
47
|
}
|
|
42
48
|
async down(queryRunner) {
|