@rosen-bridge/watcher-data-extractor 0.1.0-alpha → 0.1.0-alpha-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ class EventTriggerDB {
16
16
  row.boxId = event.boxId;
17
17
  row.boxSerialized = event.boxSerialized;
18
18
  row.blockId = block.hash;
19
+ row.height = block.height;
19
20
  row.extractor = extractor;
20
21
  row.WIDs = event.WIDs;
21
22
  row.amount = event.amount;
@@ -19,6 +19,8 @@ class CommitmentEntityAction {
19
19
  row.WID = commitment.WID;
20
20
  row.extractor = extractorId;
21
21
  row.blockId = block.hash;
22
+ row.height = block.height;
23
+ row.boxSerialized = commitment.boxSerialized;
22
24
  return row;
23
25
  });
24
26
  let success = true;
@@ -48,7 +50,7 @@ class CommitmentEntityAction {
48
50
  for (const id of spendId) {
49
51
  await this.datasource.createQueryBuilder()
50
52
  .update(CommitmentEntity)
51
- .set({ spendBlock: block.hash })
53
+ .set({ spendBlockHash: block.hash })
52
54
  .where("commitmentBoxId = :id", { id: id })
53
55
  .execute();
54
56
  }
@@ -66,6 +68,13 @@ class CommitmentEntityAction {
66
68
  "block": block,
67
69
  "extractor": extractor
68
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();
69
78
  };
70
79
  }
71
80
  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
@@ -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;
@@ -6,6 +6,9 @@ declare class CommitmentEntity {
6
6
  WID: string;
7
7
  commitmentBoxId: string;
8
8
  blockId: string;
9
- spendBlock?: string;
9
+ height: number;
10
+ boxSerialized: string;
11
+ spendBlockHash: string;
12
+ spendBlockHeight?: number;
10
13
  }
11
14
  export default CommitmentEntity;
@@ -16,7 +16,10 @@ let CommitmentEntity = class CommitmentEntity {
16
16
  WID;
17
17
  commitmentBoxId;
18
18
  blockId;
19
- spendBlock;
19
+ height;
20
+ boxSerialized;
21
+ spendBlockHash;
22
+ spendBlockHeight;
20
23
  };
21
24
  __decorate([
22
25
  PrimaryGeneratedColumn(),
@@ -46,10 +49,22 @@ __decorate([
46
49
  Column(),
47
50
  __metadata("design:type", String)
48
51
  ], CommitmentEntity.prototype, "blockId", void 0);
52
+ __decorate([
53
+ Column(),
54
+ __metadata("design:type", Number)
55
+ ], CommitmentEntity.prototype, "height", void 0);
56
+ __decorate([
57
+ Column(),
58
+ __metadata("design:type", String)
59
+ ], CommitmentEntity.prototype, "boxSerialized", void 0);
49
60
  __decorate([
50
61
  Column({ nullable: true }),
51
62
  __metadata("design:type", String)
52
- ], CommitmentEntity.prototype, "spendBlock", void 0);
63
+ ], CommitmentEntity.prototype, "spendBlockHash", void 0);
64
+ __decorate([
65
+ Column({ nullable: true }),
66
+ __metadata("design:type", Number)
67
+ ], CommitmentEntity.prototype, "spendBlockHeight", void 0);
53
68
  CommitmentEntity = __decorate([
54
69
  Entity()
55
70
  ], CommitmentEntity);
@@ -4,6 +4,7 @@ declare class EventTriggerEntity {
4
4
  boxId: string;
5
5
  boxSerialized: string;
6
6
  blockId: string;
7
+ height: number;
7
8
  fromChain: string;
8
9
  toChain: string;
9
10
  fromAddress: string;
@@ -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)
@@ -5,5 +5,8 @@ declare class PermitEntity {
5
5
  boxSerialized: string;
6
6
  WID: string;
7
7
  blockId: string;
8
+ height: number;
9
+ spendBlockHash: string;
10
+ spendBlockHeight?: number;
8
11
  }
9
12
  export default PermitEntity;
@@ -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);
@@ -40,23 +40,21 @@ 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(),
54
- sourceChainTokenId: Buffer.from(R5Serialized[8]).toString(),
55
- targetChainTokenId: Buffer.from(R5Serialized[9]).toString(),
56
- sourceTxId: Buffer.from(R5Serialized[0]).toString(),
49
+ networkFee: Buffer.from(R5Serialized[7]).toString("hex"),
50
+ bridgeFee: Buffer.from(R5Serialized[6]).toString("hex"),
51
+ amount: Buffer.from(R5Serialized[5]).toString("hex"),
52
+ sourceChainTokenId: Buffer.from(R5Serialized[8]).toString("hex"),
53
+ targetChainTokenId: Buffer.from(R5Serialized[9]).toString("hex"),
54
+ sourceTxId: Buffer.from(R5Serialized[0]).toString("hex"),
57
55
  fromChain: Buffer.from(R5Serialized[1]).toString(),
58
56
  fromAddress: Buffer.from(R5Serialized[3]).toString(),
59
- sourceBlockId: Buffer.from(R5Serialized[10]).toString(),
57
+ sourceBlockId: Buffer.from(R5Serialized[10]).toString("hex"),
60
58
  WIDs: WIDs,
61
59
  });
62
60
  }
@@ -50,6 +50,7 @@ class CommitmentExtractor extends AbstractExtractor {
50
50
  commitment: eventDigest,
51
51
  eventId: requestId,
52
52
  commitmentBoxId: output.box_id().to_str(),
53
+ boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64")
53
54
  });
54
55
  }
55
56
  }
@@ -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);
@@ -40,7 +41,7 @@ class PermitExtractor extends AbstractExtractor {
40
41
  boxes.push({
41
42
  boxId: output.box_id().to_str(),
42
43
  boxSerialized: Buffer.from(output.sigma_serialize_bytes()).toString("base64"),
43
- WID: Buffer.from(R4Serialized[0]).toString()
44
+ WID: Buffer.from(R4Serialized[0]).toString('hex')
44
45
  });
45
46
  }
46
47
  }
@@ -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
- resolve(true);
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);
@@ -3,5 +3,6 @@ interface extractedCommitment {
3
3
  commitment: string;
4
4
  eventId: string;
5
5
  commitmentBoxId: string;
6
+ boxSerialized: string;
6
7
  }
7
8
  export { extractedCommitment };
@@ -4,12 +4,15 @@ 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
11
  "commitmentBoxId" varchar NOT NULL,
11
12
  "blockId" varchar NOT NULL,
12
- "spendBlock" varchar
13
+ "height" INTEGER NOT NULL,
14
+ "spendBlockHash" varchar,
15
+ "spendBlockHeight" INTEGER
13
16
  )`);
14
17
  await queryRunner.query(`CREATE TABLE "event_trigger_entity"
15
18
  ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
@@ -28,6 +31,7 @@ export class initMigration1659787165000 {
28
31
  "targetChainTokenId" varchar NOT NULL,
29
32
  "sourceBlockId" varchar NOT NULL,
30
33
  "sourceTxId" varchar NOT NULL,
34
+ "height" INTEGER NOT NULL,
31
35
  "WIDs" varchar NOT NULL
32
36
  )`);
33
37
  await queryRunner.query(`CREATE TABLE "permit_entity"
@@ -36,7 +40,10 @@ export class initMigration1659787165000 {
36
40
  "boxId" varchar NOT NULL,
37
41
  "boxSerialized" varchar NOT NULL,
38
42
  "blockId" varchar NOT NULL,
39
- "WID" varchar NOT NULL
43
+ "height" INTEGER NOT NULL,
44
+ "WID" varchar NOT NULL,
45
+ "spendBlockHash" varchar,
46
+ "spendBlockHeight" INTEGER
40
47
  )`);
41
48
  }
42
49
  async down(queryRunner) {
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
+ "version": "0.1.0-alpha-4",
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",
19
+ "@rosen-bridge/scanner": "^0.1.7-alpha-2",
20
20
  "blakejs": "^1.2.1",
21
21
  "ergo-lib-wasm-nodejs": "^0.18.0",
22
22
  "reflect-metadata": "^0.1.13",