@teleportdao/bitcoin 1.3.0 → 1.4.0

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.
@@ -143,7 +143,8 @@ declare class BitcoinInterface extends BitcoinInterfaceUtils {
143
143
  lockerLockingScript: any;
144
144
  }[];
145
145
  }>;
146
- getTeleportRequestByTx(transaction: any, lockerAddress: any): Promise<{
146
+ getTeleportRequestByTx(inputTransaction: any, lockerAddress: any): Promise<{
147
+ transaction: any;
147
148
  request: {
148
149
  status: boolean;
149
150
  data: {
@@ -1 +1 @@
1
- {"version":3,"file":"bitcoin-interface.d.ts","sourceRoot":"","sources":["../src/bitcoin-interface.js"],"names":[],"mappings":";AAYA;IACE;;OAeC;IAZG,2EAAqD;IAMrD,qBAAkD;IAClD,iBAAkE;IAGpE,+BAA2D;IAC3D,cAAoD;IAMtD,qCAGC;IAED,6CAGC;IAED,kDAGC;IAED,wCAEC;IAGD,4CAMC;IAKD;;;;;SAkCC;IAED;;;;;;;;;;;;OAoBC;IAED;;;OAMC;IAKD,oDA0BC;IAED,gEAsCC;IAED,uCAMC;IAID,2FAUC;IAGD,8HAiBC;IAGD,gGAcC;IAGD,2DAMC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqBC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAcC;IAED;;;;;;;;;;SAqBC;IAED;;;;;;;;;cAYC;CACF"}
1
+ {"version":3,"file":"bitcoin-interface.d.ts","sourceRoot":"","sources":["../src/bitcoin-interface.js"],"names":[],"mappings":";AAYA;IACE;;OAeC;IAZG,2EAAqD;IAMrD,qBAAkD;IAClD,iBAAkE;IAGpE,+BAA2D;IAC3D,cAAoD;IAMtD,qCAGC;IAED,6CAGC;IAED,kDAGC;IAED,wCAEC;IAGD,4CAMC;IAKD;;;;;SAkCC;IAED;;;;;;;;;;;;OAoBC;IAED;;;OAMC;IAKD,oDA0BC;IAED,gEAsCC;IAED,uCAMC;IAID,2FAUC;IAGD,8HAiBC;IAGD,gGAcC;IAGD,2DAMC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmBC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmBC;IAED;;;;;;;;;;SAqBC;IAED;;;;;;;;;cAYC;CACF"}
@@ -243,9 +243,8 @@ class BitcoinInterface extends BitcoinInterfaceUtils {
243
243
  : yield this.getTransactionHistory(addresses, startblockNumber, endBlockNumber);
244
244
  let requests = [];
245
245
  let invalidRequests = [];
246
- for (let transaction of transactions) {
247
- let address = transaction.address;
248
- let { request, lockerAddress, lockerLockingScript } = yield this.getTeleportRequestByTx(transaction, address);
246
+ for (let inputTx of transactions) {
247
+ let { transaction, request, lockerAddress, lockerLockingScript } = yield this.getTeleportRequestByTx(inputTx, inputTx.address);
249
248
  if (request.status) {
250
249
  requests.push({ transaction, request, lockerAddress, lockerLockingScript });
251
250
  }
@@ -256,16 +255,21 @@ class BitcoinInterface extends BitcoinInterfaceUtils {
256
255
  return { requests, invalidRequests };
257
256
  });
258
257
  }
259
- getTeleportRequestByTx(transaction, lockerAddress) {
258
+ getTeleportRequestByTx(inputTransaction, lockerAddress) {
260
259
  return __awaiter(this, void 0, void 0, function* () {
260
+ let transaction = inputTransaction;
261
261
  if (!transaction.txId)
262
262
  throw new Error("txId not exist");
263
- let vout = transaction.vout || (yield this.getTransaction(transaction.txId)).vout;
263
+ if (!transaction.vout) {
264
+ transaction = yield this.getTransaction(transaction.txId);
265
+ }
266
+ let vout = transaction.vout;
264
267
  let request = checkAndParseProtocolRequest(vout, lockerAddress, {
265
268
  minTeleporterFeeAmount: this.minTeleporterFeeAmount,
266
269
  });
267
270
  let lockerLockingScript = transaction.addressScript || this.convertAddressToScript(lockerAddress).script.toString("hex");
268
271
  return {
272
+ transaction,
269
273
  request,
270
274
  lockerAddress,
271
275
  lockerLockingScript,
@@ -1 +1 @@
1
- {"version":3,"file":"bitcoin-interface.js","sourceRoot":"","sources":["../src/bitcoin-interface.js"],"names":[],"mappings":";;;;;;;;;;AAAA,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAA;AACpF,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAC1D,MAAM,EACJ,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,2CAA2C,GAC5C,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAC9B,MAAM,EAAE,4BAA4B,EAAE,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAA;AACpF,MAAM,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAA;AAC1E,MAAM,qBAAqB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;AAElE,MAAM,gBAAiB,SAAQ,qBAAqB;IAClD,YAAY,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,EAAE,sBAAsB,EAAE,CAAC,EAAE;;QAC7E,KAAK,CAAC,WAAW,CAAC,CAAA;QAClB,IAAI,MAAA,cAAc,CAAC,GAAG,0CAAE,OAAO,EAAE;YAC/B,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;SACtD;aAAM,IAAI,cAAc,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;YACxD,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;SACnF;QAED,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE;YAC9B,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,GA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AgB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teleportdao/bitcoin",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "teleswap bitcoin package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "author": "",
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
- "@teleportdao/configs": "^1.3.0",
15
+ "@teleportdao/configs": "^1.4.0",
16
16
  "@teleportdao/providers": "^1.2.4",
17
17
  "axios": "^0.27.2",
18
18
  "bignumber.js": "^9.1.1",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "9d6fde43ae29335b3dc7c7c3f7d1e8406c81e1ed"
34
+ "gitHead": "c0c0001c9b78a18aff4545892adb60db8e4747f0"
35
35
  }
@@ -1,347 +1,350 @@
1
- const { getRpcProvider, getApiProvider } = require("@teleportdao/providers").bitcoin
2
- const { runWithRetries, sleep } = require("./utils/tools")
3
- const {
4
- parseRawTransaction,
5
- calculateMerkleProof,
6
- parseBlockHeader,
7
- extractTransactionsAndBlockInfoFromRawBlock,
8
- } = require("./bitcoin-utils")
9
- const { checkAndParseProtocolRequest } = require("./helper/teleport-request-helper")
10
- const { getBurnTransactionInfo } = require("./helper/burn-request-helper")
11
- const BitcoinInterfaceUtils = require("./bitcoin-interface-utils")
12
-
13
- class BitcoinInterface extends BitcoinInterfaceUtils {
14
- constructor(connectionInfo, networkName, config = { minTeleporterFeeAmount: 0 }) {
15
- super(networkName)
16
- if (connectionInfo.rpc?.enabled) {
17
- this.rpcProvider = getRpcProvider(connectionInfo.rpc)
18
- } else if (connectionInfo.api.provider !== "BlockStream") {
19
- throw new Error("if rpc is disabled, we just support BlockStream as api provider")
20
- }
21
-
22
- if (connectionInfo.api.enabled) {
23
- this.apiProviderName = connectionInfo.api.provider
24
- this.apiProvider = getApiProvider(connectionInfo.api, networkName)
25
- }
26
-
27
- this.minTeleporterFeeAmount = config.minTeleporterFeeAmount
28
- this.provider = this.rpcProvider || this.apiProvider
29
- }
30
-
31
- // rpc + api
32
-
33
- // general
34
- async getLatestBlockNumber() {
35
- let latestHeight = await this.provider.getLatestBlockNumber()
36
- return latestHeight
37
- }
38
-
39
- async getBlockHash(blockNumber) {
40
- let headerHash = await runWithRetries(() => this.provider.getBlockHash(blockNumber))
41
- return headerHash
42
- }
43
-
44
- async getBlockHeaderHex(blockNumber) {
45
- let headerHex = await runWithRetries(() => this.provider.getBlockHeaderHex(blockNumber))
46
- return headerHex
47
- }
48
-
49
- async getTransaction(txId) {
50
- return this.provider.getTransaction(txId)
51
- }
52
-
53
- // speed : low normal fast
54
- async getFeeRate(speed = "normal") {
55
- if (!(speed === "normal" || speed === "slow" || speed === "fast")) {
56
- throw new Error("incorrect speed")
57
- }
58
- let fee = await this.provider.getFeeRate(speed)
59
- return +fee
60
- }
61
-
62
- // ----------- specific
63
-
64
- // relayer
65
- async getHexBlockHeaders(startBlockNumber, endBlockNumber) {
66
- const blockHeaders = []
67
- let difficulty = null
68
- let hexBlockHeaders = ""
69
-
70
- let fromBlockNumber = startBlockNumber
71
- for (let blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber += 1) {
72
- let blockHeader = await this.getBlockHeaderHex(blockNumber)
73
- console.log("block", blockNumber)
74
- let parsedBlockHeader = parseBlockHeader(blockHeader)
75
- if (difficulty && parsedBlockHeader.difficulty !== difficulty) {
76
- blockHeaders.push({
77
- hexBlockHeaders,
78
- fromBlockNumber,
79
- toBlockNumber: blockNumber - 1,
80
- difficulty,
81
- })
82
- hexBlockHeaders = blockHeader
83
- fromBlockNumber = blockNumber
84
- } else {
85
- hexBlockHeaders += blockHeader
86
- }
87
- difficulty = parsedBlockHeader.difficulty
88
- }
89
- if (hexBlockHeaders) {
90
- blockHeaders.push({
91
- hexBlockHeaders,
92
- fromBlockNumber,
93
- toBlockNumber: endBlockNumber,
94
- difficulty,
95
- })
96
- }
97
-
98
- return blockHeaders
99
- }
100
-
101
- async getRequestProof(transaction) {
102
- let transactionHex =
103
- transaction.hex || (await this.provider.getRawTransaction(transaction.txId))
104
-
105
- let txInfo
106
- if (!(transaction.blockHash && transaction.blockNumber)) {
107
- txInfo = await this.provider.getTransaction(transaction.txId)
108
- }
109
- let blockHash = transaction.blockHash || txInfo.blockHash
110
- let blockNumber = transaction.blockNumber || txInfo.blockNumber
111
- let parsedTx = parseRawTransaction(transactionHex)
112
- let merkleProof =
113
- transaction.merkleProof || (await this.getMerkleProof(transaction.txId, blockHash))
114
-
115
- return {
116
- parsedTx,
117
- merkleProof,
118
- blockNumber,
119
- blockHash,
120
- }
121
- }
122
-
123
- async getMerkleProof(txId, blockHash) {
124
- let txIds = await this.provider.getBlockTransactionIds(blockHash)
125
- // let a = await this.provider.getMerkleProof(txId)
126
- let proof = calculateMerkleProof(txIds, txId)
127
- // console.log(a.intermediateNodes === proof.intermediateNodes)
128
- return proof
129
- }
130
-
131
- // ------------------ utxo providers --------------------------------
132
-
133
- // teleporter + locker
134
- async getAddressesUtxo(allAddresses) {
135
- if (!this.apiProvider) {
136
- throw new Error("this function need an api provider")
137
- }
138
- const chunkOfAddresses = []
139
- const chunkLength = 20
140
- for (let i = 0; i < allAddresses.length; i += chunkLength) {
141
- const tmp = allAddresses.slice(i, i + chunkLength)
142
- chunkOfAddresses.push(tmp)
143
- }
144
-
145
- let results = []
146
-
147
- for (let addresses of chunkOfAddresses) {
148
- const allPromises = []
149
- for (let address of addresses) {
150
- let promise = await this.apiProvider.getUtxos(address)
151
- allPromises.push(promise)
152
- }
153
- let result = await Promise.all(allPromises)
154
- if (result.flat(1).length === 0) {
155
- break
156
- }
157
- results.push(result.flat(1))
158
- }
159
- return results.flat(1)
160
- }
161
-
162
- async getAddressesExtendedUtxo(allAddressesInfo) {
163
- if (!this.apiProvider) {
164
- throw new Error("this function need an api provider")
165
- }
166
- const chunkOfAddressesInfo = []
167
- const chunkLength = 20
168
- for (let i = 0; i < allAddressesInfo.length; i += chunkLength) {
169
- const tmp = allAddressesInfo.slice(i, i + chunkLength)
170
- chunkOfAddressesInfo.push(tmp)
171
- }
172
-
173
- let results = []
174
-
175
- for (let addressesInfo of chunkOfAddressesInfo) {
176
- const allPromises = []
177
- for (let info of addressesInfo) {
178
- let promise = this.apiProvider.getUtxos(info.address)
179
- allPromises.push(promise)
180
- }
181
- let result = await Promise.all(allPromises)
182
- if (result.flat(1).length === 0) {
183
- break
184
- }
185
- results.push(
186
- result
187
- .map((utxos, i) =>
188
- utxos.map((tx) => ({
189
- hash: tx.txId,
190
- value: tx.value,
191
- index: tx.index,
192
- ...addressesInfo[i],
193
- signerInfo: addressesInfo[i],
194
- })),
195
- )
196
- .flat(1),
197
- )
198
- }
199
- return results.flat(1)
200
- }
201
-
202
- async getBalance(address) {
203
- if (!this.apiProvider) {
204
- throw new Error("this function need an api provider")
205
- }
206
- let utxos = (await this.apiProvider.getUtxos(address)) ?? []
207
- return utxos.reduce((a, tx) => a + Number(tx.value), 0)
208
- }
209
-
210
- // ------------------ utxo provider + rpc or blockstream----------------
211
- // teleporter
212
- async getBlockTransactions(addresses, blockNumber, inputTxIds = []) {
213
- let rawBlockHex = await this.rpcProvider.getBlockByBlockNumber(blockNumber, 0)
214
- let { withdrawTxs, depositTxs } = extractTransactionsAndBlockInfoFromRawBlock(
215
- rawBlockHex,
216
- blockNumber,
217
- addresses,
218
- inputTxIds,
219
- this.network,
220
- )
221
- return depositTxs.concat(withdrawTxs)
222
- }
223
-
224
- // teleporter
225
- async getMultipleBlocksTransactions(
226
- addresses,
227
- startBlockNumber,
228
- endBlockNumber,
229
- inputTxIds = [],
230
- ) {
231
- if (endBlockNumber - startBlockNumber > 20) {
232
- throw new Error("cant get more than 20 block per function call")
233
- }
234
- let blockTxs = []
235
- for (let blockNumber = +startBlockNumber + 1; blockNumber <= endBlockNumber; blockNumber += 1) {
236
- const response = this.getBlockTransactions(addresses, blockNumber, inputTxIds)
237
- blockTxs.push(response)
238
- await sleep(200)
239
- }
240
- blockTxs = await Promise.all(blockTxs)
241
- return blockTxs.flat(1)
242
- }
243
-
244
- // teleporter
245
- async getTransactionHistory(addresses, startBlockNumber, endBlockNumber) {
246
- if (this.rpcProvider) {
247
- let endBlock = endBlockNumber || (await this.getLatestBlockNumber())
248
- let startBlock = Math.max(+startBlockNumber, +endBlock - 20)
249
- return this.getMultipleBlocksTransactions(addresses, startBlock, endBlock)
250
- }
251
- if (this.apiProviderName !== "BlockStream") {
252
- throw new Error("just support BlockStream as api provider for this function")
253
- }
254
- let txs = await this.apiProvider.getTransactionHistoryForMultipleAddresses(
255
- addresses,
256
- startBlockNumber,
257
- )
258
- return txs.flat(1)
259
- }
260
-
261
- // ------------------just blockstream----------------------
262
- async getMempoolTransactionHistory(addresses) {
263
- if (this.apiProviderName !== "BlockStream") {
264
- throw new Error("teleporter just support BlockStream as api provider")
265
- }
266
- let txs = await this.apiProvider.getMempoolTransactionHistoryForMultipleAddresses(addresses)
267
- return txs.flat(1)
268
- }
269
-
270
- async getTeleporterRequests(addresses, startblockNumber, endBlockNumber, mempool = false) {
271
- // transaction in StartBlock is not returned --> (startblockNumber,endBlockNumber]
272
- let transactions = mempool
273
- ? await this.getMempoolTransactionHistory(addresses)
274
- : await this.getTransactionHistory(addresses, startblockNumber, endBlockNumber)
275
-
276
- let requests = []
277
- let invalidRequests = []
278
- for (let transaction of transactions) {
279
- let address = transaction.address
280
- let { request, lockerAddress, lockerLockingScript } = await this.getTeleportRequestByTx(
281
- transaction,
282
- address,
283
- )
284
- if (request.status) {
285
- requests.push({ transaction, request, lockerAddress, lockerLockingScript })
286
- } else if (request.code !== "NO_OP_RETURN") {
287
- invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript })
288
- }
289
- }
290
- return { requests, invalidRequests }
291
- }
292
-
293
- async getTeleportRequestByTx(transaction, lockerAddress) {
294
- if (!transaction.txId) throw new Error("txId not exist")
295
- let vout = transaction.vout || (await this.getTransaction(transaction.txId)).vout
296
- let request = checkAndParseProtocolRequest(vout, lockerAddress, {
297
- minTeleporterFeeAmount: this.minTeleporterFeeAmount,
298
- })
299
- let lockerLockingScript =
300
- transaction.addressScript || this.convertAddressToScript(lockerAddress).script.toString("hex")
301
-
302
- return {
303
- request,
304
- lockerAddress,
305
- lockerLockingScript,
306
- }
307
- }
308
-
309
- async getLockersBurnTransactions(addresses, startBlockNumber, endBlockNumber, mempool = false) {
310
- let transactions = mempool
311
- ? await this.getMempoolTransactionHistory(addresses)
312
- : await this.getTransactionHistory(addresses, startBlockNumber, endBlockNumber)
313
-
314
- let validTxs = []
315
- for (let transaction of transactions) {
316
- let address = transaction.address
317
- // check if its a transaction to spend btc
318
- let txBurnInfo = await this.getTransactionBurnInfoByTx(transaction, address)
319
- if (txBurnInfo) {
320
- const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo
321
- validTxs.push({
322
- transaction,
323
- burnInfo,
324
- lockerAddress,
325
- lockerLockingScript,
326
- })
327
- }
328
- }
329
- return validTxs
330
- }
331
-
332
- async getTransactionBurnInfoByTx(transaction, lockerAddress) {
333
- if (!transaction.txId) throw new Error("txId not exist")
334
- let vin = transaction.vin || (await this.getTransaction(transaction.txId)).vin
335
- let burnInfo = getBurnTransactionInfo(lockerAddress, vin, transaction.vout)
336
- if (!burnInfo) return null
337
- let lockerLockingScript =
338
- transaction.addressScript || this.convertAddressToScript(lockerAddress).script.toString("hex")
339
- return {
340
- burnInfo,
341
- lockerAddress,
342
- lockerLockingScript,
343
- }
344
- }
345
- }
346
-
347
- module.exports = BitcoinInterface
1
+ const { getRpcProvider, getApiProvider } = require("@teleportdao/providers").bitcoin
2
+ const { runWithRetries, sleep } = require("./utils/tools")
3
+ const {
4
+ parseRawTransaction,
5
+ calculateMerkleProof,
6
+ parseBlockHeader,
7
+ extractTransactionsAndBlockInfoFromRawBlock,
8
+ } = require("./bitcoin-utils")
9
+ const { checkAndParseProtocolRequest } = require("./helper/teleport-request-helper")
10
+ const { getBurnTransactionInfo } = require("./helper/burn-request-helper")
11
+ const BitcoinInterfaceUtils = require("./bitcoin-interface-utils")
12
+
13
+ class BitcoinInterface extends BitcoinInterfaceUtils {
14
+ constructor(connectionInfo, networkName, config = { minTeleporterFeeAmount: 0 }) {
15
+ super(networkName)
16
+ if (connectionInfo.rpc?.enabled) {
17
+ this.rpcProvider = getRpcProvider(connectionInfo.rpc)
18
+ } else if (connectionInfo.api.provider !== "BlockStream") {
19
+ throw new Error("if rpc is disabled, we just support BlockStream as api provider")
20
+ }
21
+
22
+ if (connectionInfo.api.enabled) {
23
+ this.apiProviderName = connectionInfo.api.provider
24
+ this.apiProvider = getApiProvider(connectionInfo.api, networkName)
25
+ }
26
+
27
+ this.minTeleporterFeeAmount = config.minTeleporterFeeAmount
28
+ this.provider = this.rpcProvider || this.apiProvider
29
+ }
30
+
31
+ // rpc + api
32
+
33
+ // general
34
+ async getLatestBlockNumber() {
35
+ let latestHeight = await this.provider.getLatestBlockNumber()
36
+ return latestHeight
37
+ }
38
+
39
+ async getBlockHash(blockNumber) {
40
+ let headerHash = await runWithRetries(() => this.provider.getBlockHash(blockNumber))
41
+ return headerHash
42
+ }
43
+
44
+ async getBlockHeaderHex(blockNumber) {
45
+ let headerHex = await runWithRetries(() => this.provider.getBlockHeaderHex(blockNumber))
46
+ return headerHex
47
+ }
48
+
49
+ async getTransaction(txId) {
50
+ return this.provider.getTransaction(txId)
51
+ }
52
+
53
+ // speed : low normal fast
54
+ async getFeeRate(speed = "normal") {
55
+ if (!(speed === "normal" || speed === "slow" || speed === "fast")) {
56
+ throw new Error("incorrect speed")
57
+ }
58
+ let fee = await this.provider.getFeeRate(speed)
59
+ return +fee
60
+ }
61
+
62
+ // ----------- specific
63
+
64
+ // relayer
65
+ async getHexBlockHeaders(startBlockNumber, endBlockNumber) {
66
+ const blockHeaders = []
67
+ let difficulty = null
68
+ let hexBlockHeaders = ""
69
+
70
+ let fromBlockNumber = startBlockNumber
71
+ for (let blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber += 1) {
72
+ let blockHeader = await this.getBlockHeaderHex(blockNumber)
73
+ console.log("block", blockNumber)
74
+ let parsedBlockHeader = parseBlockHeader(blockHeader)
75
+ if (difficulty && parsedBlockHeader.difficulty !== difficulty) {
76
+ blockHeaders.push({
77
+ hexBlockHeaders,
78
+ fromBlockNumber,
79
+ toBlockNumber: blockNumber - 1,
80
+ difficulty,
81
+ })
82
+ hexBlockHeaders = blockHeader
83
+ fromBlockNumber = blockNumber
84
+ } else {
85
+ hexBlockHeaders += blockHeader
86
+ }
87
+ difficulty = parsedBlockHeader.difficulty
88
+ }
89
+ if (hexBlockHeaders) {
90
+ blockHeaders.push({
91
+ hexBlockHeaders,
92
+ fromBlockNumber,
93
+ toBlockNumber: endBlockNumber,
94
+ difficulty,
95
+ })
96
+ }
97
+
98
+ return blockHeaders
99
+ }
100
+
101
+ async getRequestProof(transaction) {
102
+ let transactionHex =
103
+ transaction.hex || (await this.provider.getRawTransaction(transaction.txId))
104
+
105
+ let txInfo
106
+ if (!(transaction.blockHash && transaction.blockNumber)) {
107
+ txInfo = await this.provider.getTransaction(transaction.txId)
108
+ }
109
+ let blockHash = transaction.blockHash || txInfo.blockHash
110
+ let blockNumber = transaction.blockNumber || txInfo.blockNumber
111
+ let parsedTx = parseRawTransaction(transactionHex)
112
+ let merkleProof =
113
+ transaction.merkleProof || (await this.getMerkleProof(transaction.txId, blockHash))
114
+
115
+ return {
116
+ parsedTx,
117
+ merkleProof,
118
+ blockNumber,
119
+ blockHash,
120
+ }
121
+ }
122
+
123
+ async getMerkleProof(txId, blockHash) {
124
+ let txIds = await this.provider.getBlockTransactionIds(blockHash)
125
+ // let a = await this.provider.getMerkleProof(txId)
126
+ let proof = calculateMerkleProof(txIds, txId)
127
+ // console.log(a.intermediateNodes === proof.intermediateNodes)
128
+ return proof
129
+ }
130
+
131
+ // ------------------ utxo providers --------------------------------
132
+
133
+ // teleporter + locker
134
+ async getAddressesUtxo(allAddresses) {
135
+ if (!this.apiProvider) {
136
+ throw new Error("this function need an api provider")
137
+ }
138
+ const chunkOfAddresses = []
139
+ const chunkLength = 20
140
+ for (let i = 0; i < allAddresses.length; i += chunkLength) {
141
+ const tmp = allAddresses.slice(i, i + chunkLength)
142
+ chunkOfAddresses.push(tmp)
143
+ }
144
+
145
+ let results = []
146
+
147
+ for (let addresses of chunkOfAddresses) {
148
+ const allPromises = []
149
+ for (let address of addresses) {
150
+ let promise = await this.apiProvider.getUtxos(address)
151
+ allPromises.push(promise)
152
+ }
153
+ let result = await Promise.all(allPromises)
154
+ if (result.flat(1).length === 0) {
155
+ break
156
+ }
157
+ results.push(result.flat(1))
158
+ }
159
+ return results.flat(1)
160
+ }
161
+
162
+ async getAddressesExtendedUtxo(allAddressesInfo) {
163
+ if (!this.apiProvider) {
164
+ throw new Error("this function need an api provider")
165
+ }
166
+ const chunkOfAddressesInfo = []
167
+ const chunkLength = 20
168
+ for (let i = 0; i < allAddressesInfo.length; i += chunkLength) {
169
+ const tmp = allAddressesInfo.slice(i, i + chunkLength)
170
+ chunkOfAddressesInfo.push(tmp)
171
+ }
172
+
173
+ let results = []
174
+
175
+ for (let addressesInfo of chunkOfAddressesInfo) {
176
+ const allPromises = []
177
+ for (let info of addressesInfo) {
178
+ let promise = this.apiProvider.getUtxos(info.address)
179
+ allPromises.push(promise)
180
+ }
181
+ let result = await Promise.all(allPromises)
182
+ if (result.flat(1).length === 0) {
183
+ break
184
+ }
185
+ results.push(
186
+ result
187
+ .map((utxos, i) =>
188
+ utxos.map((tx) => ({
189
+ hash: tx.txId,
190
+ value: tx.value,
191
+ index: tx.index,
192
+ ...addressesInfo[i],
193
+ signerInfo: addressesInfo[i],
194
+ })),
195
+ )
196
+ .flat(1),
197
+ )
198
+ }
199
+ return results.flat(1)
200
+ }
201
+
202
+ async getBalance(address) {
203
+ if (!this.apiProvider) {
204
+ throw new Error("this function need an api provider")
205
+ }
206
+ let utxos = (await this.apiProvider.getUtxos(address)) ?? []
207
+ return utxos.reduce((a, tx) => a + Number(tx.value), 0)
208
+ }
209
+
210
+ // ------------------ utxo provider + rpc or blockstream----------------
211
+ // teleporter
212
+ async getBlockTransactions(addresses, blockNumber, inputTxIds = []) {
213
+ let rawBlockHex = await this.rpcProvider.getBlockByBlockNumber(blockNumber, 0)
214
+ let { withdrawTxs, depositTxs } = extractTransactionsAndBlockInfoFromRawBlock(
215
+ rawBlockHex,
216
+ blockNumber,
217
+ addresses,
218
+ inputTxIds,
219
+ this.network,
220
+ )
221
+ return depositTxs.concat(withdrawTxs)
222
+ }
223
+
224
+ // teleporter
225
+ async getMultipleBlocksTransactions(
226
+ addresses,
227
+ startBlockNumber,
228
+ endBlockNumber,
229
+ inputTxIds = [],
230
+ ) {
231
+ if (endBlockNumber - startBlockNumber > 20) {
232
+ throw new Error("cant get more than 20 block per function call")
233
+ }
234
+ let blockTxs = []
235
+ for (let blockNumber = +startBlockNumber + 1; blockNumber <= endBlockNumber; blockNumber += 1) {
236
+ const response = this.getBlockTransactions(addresses, blockNumber, inputTxIds)
237
+ blockTxs.push(response)
238
+ await sleep(200)
239
+ }
240
+ blockTxs = await Promise.all(blockTxs)
241
+ return blockTxs.flat(1)
242
+ }
243
+
244
+ // teleporter
245
+ async getTransactionHistory(addresses, startBlockNumber, endBlockNumber) {
246
+ if (this.rpcProvider) {
247
+ let endBlock = endBlockNumber || (await this.getLatestBlockNumber())
248
+ let startBlock = Math.max(+startBlockNumber, +endBlock - 20)
249
+ return this.getMultipleBlocksTransactions(addresses, startBlock, endBlock)
250
+ }
251
+ if (this.apiProviderName !== "BlockStream") {
252
+ throw new Error("just support BlockStream as api provider for this function")
253
+ }
254
+ let txs = await this.apiProvider.getTransactionHistoryForMultipleAddresses(
255
+ addresses,
256
+ startBlockNumber,
257
+ )
258
+ return txs.flat(1)
259
+ }
260
+
261
+ // ------------------just blockstream----------------------
262
+ async getMempoolTransactionHistory(addresses) {
263
+ if (this.apiProviderName !== "BlockStream") {
264
+ throw new Error("teleporter just support BlockStream as api provider")
265
+ }
266
+ let txs = await this.apiProvider.getMempoolTransactionHistoryForMultipleAddresses(addresses)
267
+ return txs.flat(1)
268
+ }
269
+
270
+ async getTeleporterRequests(addresses, startblockNumber, endBlockNumber, mempool = false) {
271
+ // transaction in StartBlock is not returned --> (startblockNumber,endBlockNumber]
272
+ let transactions = mempool
273
+ ? await this.getMempoolTransactionHistory(addresses)
274
+ : await this.getTransactionHistory(addresses, startblockNumber, endBlockNumber)
275
+
276
+ let requests = []
277
+ let invalidRequests = []
278
+
279
+ for (let inputTx of transactions) {
280
+ let { transaction, request, lockerAddress, lockerLockingScript } =
281
+ await this.getTeleportRequestByTx(inputTx, inputTx.address)
282
+ if (request.status) {
283
+ requests.push({ transaction, request, lockerAddress, lockerLockingScript })
284
+ } else if (request.code !== "NO_OP_RETURN") {
285
+ invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript })
286
+ }
287
+ }
288
+ return { requests, invalidRequests }
289
+ }
290
+
291
+ async getTeleportRequestByTx(inputTransaction, lockerAddress) {
292
+ let transaction = inputTransaction
293
+ if (!transaction.txId) throw new Error("txId not exist")
294
+ if (!transaction.vout) {
295
+ transaction = await this.getTransaction(transaction.txId)
296
+ }
297
+ let vout = transaction.vout
298
+ let request = checkAndParseProtocolRequest(vout, lockerAddress, {
299
+ minTeleporterFeeAmount: this.minTeleporterFeeAmount,
300
+ })
301
+ let lockerLockingScript =
302
+ transaction.addressScript || this.convertAddressToScript(lockerAddress).script.toString("hex")
303
+
304
+ return {
305
+ transaction,
306
+ request,
307
+ lockerAddress,
308
+ lockerLockingScript,
309
+ }
310
+ }
311
+
312
+ async getLockersBurnTransactions(addresses, startBlockNumber, endBlockNumber, mempool = false) {
313
+ let transactions = mempool
314
+ ? await this.getMempoolTransactionHistory(addresses)
315
+ : await this.getTransactionHistory(addresses, startBlockNumber, endBlockNumber)
316
+
317
+ let validTxs = []
318
+ for (let transaction of transactions) {
319
+ let address = transaction.address
320
+ // check if its a transaction to spend btc
321
+ let txBurnInfo = await this.getTransactionBurnInfoByTx(transaction, address)
322
+ if (txBurnInfo) {
323
+ const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo
324
+ validTxs.push({
325
+ transaction,
326
+ burnInfo,
327
+ lockerAddress,
328
+ lockerLockingScript,
329
+ })
330
+ }
331
+ }
332
+ return validTxs
333
+ }
334
+
335
+ async getTransactionBurnInfoByTx(transaction, lockerAddress) {
336
+ if (!transaction.txId) throw new Error("txId not exist")
337
+ let vin = transaction.vin || (await this.getTransaction(transaction.txId)).vin
338
+ let burnInfo = getBurnTransactionInfo(lockerAddress, vin, transaction.vout)
339
+ if (!burnInfo) return null
340
+ let lockerLockingScript =
341
+ transaction.addressScript || this.convertAddressToScript(lockerAddress).script.toString("hex")
342
+ return {
343
+ burnInfo,
344
+ lockerAddress,
345
+ lockerLockingScript,
346
+ }
347
+ }
348
+ }
349
+
350
+ module.exports = BitcoinInterface