@rosen-bridge/evm-observation-extractor 2.0.0 → 2.0.1-08d1d81f

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.
@@ -0,0 +1,560 @@
1
+ import { DataSource } from 'typeorm';
2
+ import {
3
+ ObservationEntity,
4
+ migrations,
5
+ } from '@rosen-bridge/observation-extractor';
6
+ import * as wasm from 'ergo-lib-wasm-nodejs';
7
+ import { BlockEntity, Transaction } from '@rosen-bridge/scanner';
8
+ import { migrations as scannerMigrations } from '@rosen-bridge/scanner';
9
+ import { JsonBI } from '@rosen-bridge/scanner/dist/scanner/ergo/network/parser';
10
+ import { Buffer } from 'buffer';
11
+
12
+ export const last10BlockHeader = [
13
+ {
14
+ extensionId:
15
+ '27143b3ad6607ca59fc6b882a96d999c1147dbedb4caa3c945208318feb6ef76',
16
+ difficulty: '5635571712',
17
+ votes: '000000',
18
+ timestamp: 1653932558503,
19
+ size: 221,
20
+ stateRoot:
21
+ 'b3e7d62d8c8d7d6ae38a69b2c369d307c2b41d01f21a313bd4b98345a1551e9516',
22
+ height: 215806,
23
+ nBits: 83972072,
24
+ version: 2,
25
+ id: '9dbe11053b952358e555451169ec9df7f0583bd80e822c0e8a71907edc3fe9af',
26
+ adProofsRoot:
27
+ '4087e5f27842be6105e553d8f7a29a75ad59a04884014d5634bab29b68f6985c',
28
+ transactionsRoot:
29
+ '87a0d482a763d1933edff775e469f8e0f618d1bbc0a3dbaf14e98a9538908c8f',
30
+ extensionHash:
31
+ '29a8cd654991d2cfac09c9e78b1f58730ff3577ad0afd42f13b58e47a62f7277',
32
+ powSolutions: {
33
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
34
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
35
+ n: '00000000b7f19562',
36
+ d: 0,
37
+ },
38
+ adProofsId:
39
+ 'cb91890c525e1f13b84bf5af7178c6dfc55125f3b6a7b16f3891064a8434d717',
40
+ transactionsId:
41
+ '7986444f8f181172e32272df7e7d1bd1fab520f024230802f6bde38c77262b5e',
42
+ parentId:
43
+ '8718e93fa6ea4ec8b3f955b654acf0d6f594e1420df2da4907b8c2eebdecc686',
44
+ },
45
+ {
46
+ extensionId:
47
+ 'e04c61992a27ce4ebe82809f94b8290c078397830a24779908ddd52cd092c6f5',
48
+ difficulty: '5635571712',
49
+ votes: '000000',
50
+ timestamp: 1653932631795,
51
+ size: 221,
52
+ stateRoot:
53
+ '7e56555ce442061f504f92047579f9afef9b2acb259edd56e419dfcecc5df4e716',
54
+ height: 215807,
55
+ nBits: 83972072,
56
+ version: 2,
57
+ id: '4fdbd7ec22ec03477b5b4cb04239c8b30f6f95ac7a3add388cb5a1eae993d2b1',
58
+ adProofsRoot:
59
+ '73cf773ab227ce9b74960397616c9fd89d57bb857c8eac912c0c3d2773e9412b',
60
+ transactionsRoot:
61
+ 'b0e5ca1a2ebeda25087cd601f51485103b12a3dd4492c47419b52c1684738b78',
62
+ extensionHash:
63
+ '29a8cd654991d2cfac09c9e78b1f58730ff3577ad0afd42f13b58e47a62f7277',
64
+ powSolutions: {
65
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
66
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
67
+ n: '0000000381e364f9',
68
+ d: 0,
69
+ },
70
+ adProofsId:
71
+ '2ca8e8de7ca57ca155476cd83314f2e11d61d058baec7951fad80d98523f560d',
72
+ transactionsId:
73
+ 'e2e6ecb25b549ab3ebff505c3cf4a356a4df3b3f869fbc9082018cead4fa141f',
74
+ parentId:
75
+ '9dbe11053b952358e555451169ec9df7f0583bd80e822c0e8a71907edc3fe9af',
76
+ },
77
+ {
78
+ extensionId:
79
+ 'ef8ac46dbcfdcb0fe04fda74f6d206f92a0235be1c4643f7e5bc901d7ddae079',
80
+ difficulty: '5635571712',
81
+ votes: '000000',
82
+ timestamp: 1653932970497,
83
+ size: 221,
84
+ stateRoot:
85
+ 'e3256897e8d264de11a7a2dbde246602d6d89c63c9c3d17dab67b6d5de5b32c816',
86
+ height: 215808,
87
+ nBits: 83972072,
88
+ version: 2,
89
+ id: '7acaca47daadf829438baa14b32f2fcd026937636b6fcd3d05e40d3c43215e46',
90
+ adProofsRoot:
91
+ '32e49ee8e06bac632a71b20649d6a226f9a916103991d5664d5fa76ea73e1da8',
92
+ transactionsRoot:
93
+ '7d758d1ceec75791f11171483c3d2703b047d38ce52e7470662613031e9fb313',
94
+ extensionHash:
95
+ '9c77092d2e63fdf246cd894527c185947bfea37e6511665dba16a1f9790673fa',
96
+ powSolutions: {
97
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
98
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
99
+ n: '000000026912218c',
100
+ d: 0,
101
+ },
102
+ adProofsId:
103
+ 'bcd7a97e0e5b51be17204c16168d37310d17e43bb3242753f92e2a463619f9e4',
104
+ transactionsId:
105
+ '54319ad6b9f7ca7b3d9f8d467fe31e56d65841cc24e983a300a4fcf89b2c5888',
106
+ parentId:
107
+ '4fdbd7ec22ec03477b5b4cb04239c8b30f6f95ac7a3add388cb5a1eae993d2b1',
108
+ },
109
+ {
110
+ extensionId:
111
+ 'b08fef096a9cf24bad3a7e7e049b6b812ca43b51795e4a643591e05ec2f0196f',
112
+ difficulty: '5090705408',
113
+ votes: '000000',
114
+ timestamp: 1653933205053,
115
+ size: 220,
116
+ stateRoot:
117
+ 'e318a25a13dfd14ae41e3820097c33b7d49e8b9bc479d13c93a8d98601588fd316',
118
+ height: 215809,
119
+ nBits: 83963758,
120
+ version: 2,
121
+ id: 'f91cdc031f9ab8451b39a3b292781325cd3941393e1967319df4c5e593daa593',
122
+ adProofsRoot:
123
+ '37d2632b0092dae168e0bccc5192173f12c7d43e631b0f9c4d4bb76d34b0502f',
124
+ transactionsRoot:
125
+ '226640250d9c7e4f317da15ab2b05c96f70dfc387ac3be2b79917592c24dea29',
126
+ extensionHash:
127
+ 'e8d3674f5f14dd2f1eced0aa1f74e23a3294dc62bbd018c349666dcf5de38bad',
128
+ powSolutions: {
129
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
130
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
131
+ n: '000000017bd52182',
132
+ d: 0,
133
+ },
134
+ adProofsId:
135
+ '714677588ae780b6b432e8f53e5d6b0399506a7eda24e300199df9c62de32198',
136
+ transactionsId:
137
+ '3a13afd7c9c6d54f5c888213bc88311d75feef789664902155770d605c01eca2',
138
+ parentId:
139
+ '7acaca47daadf829438baa14b32f2fcd026937636b6fcd3d05e40d3c43215e46',
140
+ },
141
+ {
142
+ extensionId:
143
+ 'a91cbd4ff37c5c29e01c36524a24d6f54b3f97396080b8c5d782650104b952d8',
144
+ difficulty: '5090705408',
145
+ votes: '000000',
146
+ timestamp: 1653933351656,
147
+ size: 220,
148
+ stateRoot:
149
+ '022494222deea6d3fa1145a27b5782f383e01cc96555e28a2bd7a11187d87a5816',
150
+ height: 215810,
151
+ nBits: 83963758,
152
+ version: 2,
153
+ id: 'c3abfe4d6bad9f19a84c11a7dda4e7b0cca1e4aa42f50f34f395f8a6f898d622',
154
+ adProofsRoot:
155
+ 'ae47944cf48005cc54caa538bbcee25480f0c82a8bb0dd23ca92a9a481cb6ce7',
156
+ transactionsRoot:
157
+ 'b34ec763e862304f470373d6556f0c0e4fd9e14e5ba8f542d350ea9c29e850f3',
158
+ extensionHash:
159
+ 'e8d3674f5f14dd2f1eced0aa1f74e23a3294dc62bbd018c349666dcf5de38bad',
160
+ powSolutions: {
161
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
162
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
163
+ n: '00000000d2fbb6d3',
164
+ d: 0,
165
+ },
166
+ adProofsId:
167
+ '58ff7896d75c302420c2b52ced0d8a3750a4b747824ba181765cb6f8861863f1',
168
+ transactionsId:
169
+ '1766ccdd64d8601403c1262bd187db9ebb26dc5adb9ae7100ef92c24472763fa',
170
+ parentId:
171
+ 'f91cdc031f9ab8451b39a3b292781325cd3941393e1967319df4c5e593daa593',
172
+ },
173
+ {
174
+ extensionId:
175
+ '9bdebff276f7cf8051ee9f217bcd319f30b1befb9098f2343652a90a7c635039',
176
+ difficulty: '5090705408',
177
+ votes: '000000',
178
+ timestamp: 1653933434918,
179
+ size: 220,
180
+ stateRoot:
181
+ '4277cabc6bff122c93b7f4f84924733c38278c5a739c0e538452e670dd1e838816',
182
+ height: 215811,
183
+ nBits: 83963758,
184
+ version: 2,
185
+ id: '75a8f5b78624bb5eb4f8e3ac702f80eb10d3a05feeb50d1c8e1e7e17f8fb61b3',
186
+ adProofsRoot:
187
+ '0f193db5aacec6ef6d85177100244b12415b80f196964f523338b6c6a0140247',
188
+ transactionsRoot:
189
+ 'ece2b525d82bd7620ccd8e6c79bf6a56ca22bdafe830e22022dd8bbbc9f946fa',
190
+ extensionHash:
191
+ '66c134df905d7d1d263ebe638d97d384af93ba592954d55fc865b9e54eef70f2',
192
+ powSolutions: {
193
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
194
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
195
+ n: '00000000202e9454',
196
+ d: 0,
197
+ },
198
+ adProofsId:
199
+ '139cf63bd95bf0068c6dedc1f22b3925b37256b3401d4db0dbbb58e8fe391626',
200
+ transactionsId:
201
+ 'ae6e3aca91077dbb894e0e0f2b136049d8ba2791958a5df932dbb654d2f6f034',
202
+ parentId:
203
+ 'c3abfe4d6bad9f19a84c11a7dda4e7b0cca1e4aa42f50f34f395f8a6f898d622',
204
+ },
205
+ {
206
+ extensionId:
207
+ '3396ffe01e400d4eda6f51745e901f1b22b5b75c7a4da209426de9450d7c2f32',
208
+ difficulty: '5090705408',
209
+ votes: '000000',
210
+ timestamp: 1653933451736,
211
+ size: 220,
212
+ stateRoot:
213
+ 'c216821348f1fe154902da75a97c6861e061fa4cb0d84de1ebd27b994bba71ef16',
214
+ height: 215812,
215
+ nBits: 83963758,
216
+ version: 2,
217
+ id: 'b40264ee73987b5919b40f679d4a23cb52aad5d3e9b9f052e76ab2f4c2e03c08',
218
+ adProofsRoot:
219
+ '4a8acc9bf0ccc863c0a4c973ccd60dfab47e4548b139069cf0963b2216e7300f',
220
+ transactionsRoot:
221
+ 'a84c2e3e3b8191783f887d8ab61e3982e011da21a69f658f78e1e561ca589bb7',
222
+ extensionHash:
223
+ '92f4f29731ee9bd01d8d39d1256dc7b55a03cef7f8e445f12afe74705517985c',
224
+ powSolutions: {
225
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
226
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
227
+ n: '0000000094978b6a',
228
+ d: 0,
229
+ },
230
+ adProofsId:
231
+ '5b2d299f412b8066b16e9b3cf9f6e1de2c62302db25bda1346f7ccefaf0d6d9e',
232
+ transactionsId:
233
+ 'b7035ad8507fac49f46e14fc2e414239474ad045f29b6f198b565dec77639602',
234
+ parentId:
235
+ '75a8f5b78624bb5eb4f8e3ac702f80eb10d3a05feeb50d1c8e1e7e17f8fb61b3',
236
+ },
237
+ {
238
+ extensionId:
239
+ '1ad0f5ea4d0249da84cef643b07ebb499a09d6a08e115ec35d521bcceb668f7e',
240
+ difficulty: '5090705408',
241
+ votes: '000000',
242
+ timestamp: 1653933511999,
243
+ size: 220,
244
+ stateRoot:
245
+ '85ee11729ac50ad30eb4cd5937f10e1453eec800fbea6276c76e9b0b10da551f16',
246
+ height: 215813,
247
+ nBits: 83963758,
248
+ version: 2,
249
+ id: '07c4231ad059271f87926baba27ffc59cc9df23b3bb74bbfc958e1e267e55657',
250
+ adProofsRoot:
251
+ '3d26bf3d3a77f7c3cd79c70bdad0233b26f20ffc7799c1797397995917d4c941',
252
+ transactionsRoot:
253
+ '1b0fdd82251cdd998868c44ff247b1f3309aee4f7685bef57d4815883f0974cf',
254
+ extensionHash:
255
+ '92f4f29731ee9bd01d8d39d1256dc7b55a03cef7f8e445f12afe74705517985c',
256
+ powSolutions: {
257
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
258
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
259
+ n: '000000008c46fe39',
260
+ d: 0,
261
+ },
262
+ adProofsId:
263
+ '6979d03b995a191e2aff734e1b12c44b4852ab782260b1da21f1ec0473cbb09e',
264
+ transactionsId:
265
+ '2b64466b904e59552d5796e99b0428b24e85a79da180d5b4ca4d9f05289dc562',
266
+ parentId:
267
+ 'b40264ee73987b5919b40f679d4a23cb52aad5d3e9b9f052e76ab2f4c2e03c08',
268
+ },
269
+ {
270
+ extensionId:
271
+ 'ae51baeb1dd8f68fc9bc5c5d7ddfe227fc1a453045ce5704d2f57b5f7d5c0f9d',
272
+ difficulty: '5090705408',
273
+ votes: '000000',
274
+ timestamp: 1653933569225,
275
+ size: 220,
276
+ stateRoot:
277
+ '870b8cc02f42360bef9766dc42c58a7eac71a12ef186e8b6498b859b304c835516',
278
+ height: 215814,
279
+ nBits: 83963758,
280
+ version: 2,
281
+ id: '2aeed311b23c92427c16f2262bde3396484e109fcddb4f1a56aa1dd5a7b2113b',
282
+ adProofsRoot:
283
+ 'c4cd0df1ee4cad41a010732e21ffd0d073bde060145c640b31aac508a4668594',
284
+ transactionsRoot:
285
+ '935b773457cb4065b7947bc1600b8849707cd70f9f8ca4520adc288f2d4a3d80',
286
+ extensionHash:
287
+ 'c5556727874b10550de7a90240f1bbe9d1e1dcef5741e34d93b73d592a2b4c93',
288
+ powSolutions: {
289
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
290
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
291
+ n: '0000000085faadb5',
292
+ d: 0,
293
+ },
294
+ adProofsId:
295
+ 'de0e6fa550cbf280f0fdf01aca7ae06acc4ee6944073080d822ff2346a2d7098',
296
+ transactionsId:
297
+ 'fa989159c28706c7700cc9f09dc215e4c7da17343fd5b12bd2473921ff2bbc3f',
298
+ parentId:
299
+ '07c4231ad059271f87926baba27ffc59cc9df23b3bb74bbfc958e1e267e55657',
300
+ },
301
+ {
302
+ extensionId:
303
+ 'a5d21ffb6ba8a35c3b5450d6ccb9eb2073cd588a57bdcaa4a767199e74d83576',
304
+ difficulty: '5090705408',
305
+ votes: '000000',
306
+ timestamp: 1653933624717,
307
+ size: 220,
308
+ stateRoot:
309
+ '364c459ee947d41d618411a398b0fb4ed77e2d5188727ff3abc8476f45defc4116',
310
+ height: 215815,
311
+ nBits: 83963758,
312
+ version: 2,
313
+ id: '98ed9df1f0f54d18180fb8957ee364e1e94b68ded4fc55eb52d15a56dbb7e53d',
314
+ adProofsRoot:
315
+ '82a0c03bab1d69677ffa5ce2b180b37bd461e34239e036f0f21cbc9eb515afa9',
316
+ transactionsRoot:
317
+ '5d0d691a780bd078d21b6484d4f72b91a8f70d553b25546938bd16831f27f3d9',
318
+ extensionHash:
319
+ 'c5556727874b10550de7a90240f1bbe9d1e1dcef5741e34d93b73d592a2b4c93',
320
+ powSolutions: {
321
+ pk: '03702266cae8daf75b7f09d4c23ad9cdc954849ee280eefae0d67bd97db4a68f6a',
322
+ w: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
323
+ n: '00000000aa7f2207',
324
+ d: 0,
325
+ },
326
+ adProofsId:
327
+ '58679314a2d9d6432c34577787701555a4ed778574b877d1e4c23c12f09600a9',
328
+ transactionsId:
329
+ '2ac59a2e809aa9f92ea8106aea9de46822a80758d5899f337dac1baf19215ee3',
330
+ parentId:
331
+ '2aeed311b23c92427c16f2262bde3396484e109fcddb4f1a56aa1dd5a7b2113b',
332
+ },
333
+ ];
334
+
335
+ const fromAddress =
336
+ 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0';
337
+
338
+ export const cardanoTxValid = {
339
+ block_hash: '',
340
+ metadata: {
341
+ '0': JSON.parse(
342
+ '{' +
343
+ '"to": "ergo",' +
344
+ '"bridgeFee": "10000",' +
345
+ '"networkFee": "10000",' +
346
+ '"toAddress": "ergoAddress",' +
347
+ ' "fromAddress": ["' +
348
+ fromAddress +
349
+ '"] }'
350
+ ),
351
+ },
352
+ tx_hash: '9f00d372e930d685c3b410a10f2bd035cd9a927c4fd8ef8e419c79b210af7ba6',
353
+ inputs: [
354
+ {
355
+ payment_addr: {
356
+ bech32:
357
+ 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0',
358
+ cred: '90ff35400c4d2cbddef24a750ad7064947a2461c1a0b9ca431c7e9f6',
359
+ },
360
+ stake_addr: null,
361
+ tx_hash:
362
+ '9f00d372e930d685c3b410a10f2bd035cd9a927c4fd8ef8e419c79b210af7ba6',
363
+ tx_index: 1,
364
+ value: '979445417',
365
+ asset_list: [
366
+ {
367
+ policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
368
+ asset_name: '646f6765',
369
+ quantity: '10000000',
370
+ },
371
+ {
372
+ policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
373
+ asset_name: '7369676d61',
374
+ quantity: '9999978',
375
+ },
376
+ ],
377
+ },
378
+ ],
379
+ outputs: [
380
+ {
381
+ payment_addr: {
382
+ bech32:
383
+ 'addr_test1vze7yqqlg8cjlyhz7jzvsg0f3fhxpuu6m3llxrajfzqecggw704re',
384
+ cred: 'b3e2001f41f12f92e2f484c821e98a6e60f39adc7ff30fb248819c21',
385
+ },
386
+ tx_hash:
387
+ 'cf32ad374daefdce563e3391effc4fc42eb0e74bbec8afe16a46eeea69e3b2aa',
388
+ stake_addr: null,
389
+ tx_index: 0,
390
+ value: '10000000',
391
+ asset_list: [
392
+ {
393
+ policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
394
+ asset_name: '7369676d61',
395
+ quantity: '10',
396
+ },
397
+ ],
398
+ },
399
+ {
400
+ payment_addr: {
401
+ bech32:
402
+ 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0',
403
+ cred: '90ff35400c4d2cbddef24a750ad7064947a2461c1a0b9ca431c7e9f6',
404
+ },
405
+ tx_hash:
406
+ 'cf32ad374daefdce563e3391effc4fc42eb0e74bbec8afe16a46eeea69e3b2aa',
407
+ stake_addr: null,
408
+ tx_index: 1,
409
+ value: '969261084',
410
+ asset_list: [
411
+ {
412
+ policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
413
+ asset_name: '646f6765',
414
+ quantity: '10000000',
415
+ },
416
+ {
417
+ policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
418
+ asset_name: '7369676d61',
419
+ quantity: '9999968',
420
+ },
421
+ ],
422
+ },
423
+ ],
424
+ };
425
+
426
+ export const createDatabase = async (): Promise<DataSource> => {
427
+ return new DataSource({
428
+ type: 'sqlite',
429
+ database: `:memory:`,
430
+ entities: [BlockEntity, ObservationEntity],
431
+ migrations: [...migrations.sqlite, ...scannerMigrations.sqlite],
432
+ synchronize: false,
433
+ logging: false,
434
+ })
435
+ .initialize()
436
+ .then(async (dataSource) => {
437
+ await dataSource.runMigrations();
438
+ return dataSource;
439
+ });
440
+ };
441
+
442
+ export const observationTxGenerator = (
443
+ hasToken = true,
444
+ data: Array<string> = [
445
+ 'cardano',
446
+ 'address',
447
+ '10000',
448
+ '1000',
449
+ '9i1EZHaRPTLajwJivCFpdoi65r7A8ZgJxVbMtxZ23W5Z2gDkKdM',
450
+ ],
451
+ bankSecret: string,
452
+ watcherSecret: string,
453
+ boxValue = '1100000000'
454
+ ) => {
455
+ const bankSK = wasm.SecretKey.dlog_from_bytes(
456
+ Uint8Array.from(Buffer.from(bankSecret, 'hex'))
457
+ );
458
+ const bankAddress = wasm.Contract.pay_to_address(bankSK.get_address());
459
+ const watcherSK = wasm.SecretKey.dlog_from_bytes(
460
+ Uint8Array.from(Buffer.from(watcherSecret, 'hex'))
461
+ );
462
+ const watcherAddress = wasm.Contract.pay_to_address(watcherSK.get_address());
463
+ const outBoxValue = wasm.BoxValue.from_i64(wasm.I64.from_str(boxValue));
464
+ const outBoxBuilder = new wasm.ErgoBoxCandidateBuilder(
465
+ outBoxValue,
466
+ bankAddress,
467
+ 0
468
+ );
469
+ if (hasToken) {
470
+ outBoxBuilder.add_token(
471
+ wasm.TokenId.from_str(
472
+ 'f6a69529b12a7e2326acffee8383e0c44408f87a872886fadf410fe8498006d3'
473
+ ),
474
+ wasm.TokenAmount.from_i64(wasm.I64.from_str('10'))
475
+ );
476
+ }
477
+ const registerValue = data.map((val) => {
478
+ return new Uint8Array(Buffer.from(val));
479
+ });
480
+ outBoxBuilder.set_register_value(
481
+ 4,
482
+ wasm.Constant.from_coll_coll_byte(registerValue)
483
+ );
484
+
485
+ const outBox = outBoxBuilder.build();
486
+ const tokens = new wasm.Tokens();
487
+ if (hasToken) {
488
+ tokens.add(
489
+ new wasm.Token(
490
+ wasm.TokenId.from_str(
491
+ 'f6a69529b12a7e2326acffee8383e0c44408f87a872886fadf410fe8498006d3'
492
+ ),
493
+ wasm.TokenAmount.from_i64(wasm.I64.from_str('10'))
494
+ )
495
+ );
496
+ }
497
+
498
+ const inputBoxBank = new wasm.ErgoBox(
499
+ wasm.BoxValue.from_i64(wasm.I64.from_str(boxValue)),
500
+ 0,
501
+ bankAddress,
502
+ wasm.TxId.zero(),
503
+ 0,
504
+ new wasm.Tokens()
505
+ );
506
+
507
+ const inputBoxWatcher = new wasm.ErgoBox(
508
+ wasm.BoxValue.from_i64(wasm.I64.from_str(boxValue)),
509
+ 0,
510
+ watcherAddress,
511
+ wasm.TxId.zero(),
512
+ 0,
513
+ tokens
514
+ );
515
+
516
+ const unspentBoxes = new wasm.ErgoBoxes(inputBoxBank);
517
+ unspentBoxes.add(inputBoxWatcher);
518
+ const txOutputs = new wasm.ErgoBoxCandidates(outBox);
519
+ const fee = wasm.TxBuilder.SUGGESTED_TX_FEE();
520
+ const boxSelector = new wasm.SimpleBoxSelector();
521
+ const targetBalance = wasm.BoxValue.from_i64(
522
+ outBoxValue.as_i64().checked_add(fee.as_i64())
523
+ );
524
+ const boxSelection = boxSelector.select(unspentBoxes, targetBalance, tokens);
525
+ const tx = wasm.TxBuilder.new(
526
+ boxSelection,
527
+ txOutputs,
528
+ 0,
529
+ fee,
530
+ watcherSK.get_address()
531
+ ).build();
532
+ const blockHeaders = wasm.BlockHeaders.from_json(last10BlockHeader);
533
+ const preHeader = wasm.PreHeader.from_block_header(blockHeaders.get(0));
534
+ const ctx = new wasm.ErgoStateContext(preHeader, blockHeaders);
535
+ const sks = new wasm.SecretKeys();
536
+ sks.add(watcherSK);
537
+ sks.add(bankSK);
538
+ const wallet = wasm.Wallet.from_secrets(sks);
539
+ const signed = wallet.sign_transaction(
540
+ ctx,
541
+ tx,
542
+ unspentBoxes,
543
+ wasm.ErgoBoxes.from_boxes_json([])
544
+ );
545
+ return JsonBI.parse(signed.to_json()) as Transaction;
546
+ };
547
+
548
+ export const generateBlockEntity = (
549
+ dataSource: DataSource,
550
+ hash: string,
551
+ parent?: string,
552
+ height?: number
553
+ ) => {
554
+ const repository = dataSource.getRepository(BlockEntity);
555
+ return repository.create({
556
+ height: height ? height : 1,
557
+ parentHash: parent ? parent : '1',
558
+ hash: hash,
559
+ });
560
+ };