@atomiqlabs/chain-evm 2.4.0 → 2.4.1
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.
|
@@ -185,6 +185,10 @@ export declare class EVMChainInterface<ChainId extends string = string> implemen
|
|
|
185
185
|
* @inheritDoc
|
|
186
186
|
*/
|
|
187
187
|
getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
|
|
188
|
+
/**
|
|
189
|
+
* @inheritDoc
|
|
190
|
+
*/
|
|
191
|
+
getTxId(signedTX: Transaction): Promise<string>;
|
|
188
192
|
/**
|
|
189
193
|
* @inheritDoc
|
|
190
194
|
*/
|
|
@@ -157,6 +157,15 @@ class EVMChainInterface {
|
|
|
157
157
|
getTxIdStatus(txId) {
|
|
158
158
|
return this.Transactions.getTxIdStatus(txId);
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* @inheritDoc
|
|
162
|
+
*/
|
|
163
|
+
getTxId(signedTX) {
|
|
164
|
+
const txId = signedTX.hash;
|
|
165
|
+
if (txId == null)
|
|
166
|
+
throw new Error("Passed transaction is not signed!");
|
|
167
|
+
return Promise.resolve(txId);
|
|
168
|
+
}
|
|
160
169
|
/**
|
|
161
170
|
* @inheritDoc
|
|
162
171
|
*/
|
|
@@ -247,15 +247,30 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
247
247
|
const escrowHash = data.getEscrowHash();
|
|
248
248
|
const stateData = await this.contract.getHashState("0x" + escrowHash);
|
|
249
249
|
const state = Number(stateData.state);
|
|
250
|
+
const initBlockHeight = Number(stateData.initBlockheight);
|
|
250
251
|
const blockHeight = Number(stateData.finishBlockheight);
|
|
252
|
+
const getInitTxId = async () => {
|
|
253
|
+
const events = await this._Events.getContractBlockEvents(["Initialize"], [null, null, "0x" + escrowHash], initBlockHeight, initBlockHeight);
|
|
254
|
+
if (events.length === 0)
|
|
255
|
+
throw new Error("Initialize event not found!");
|
|
256
|
+
return events[0].transactionHash;
|
|
257
|
+
};
|
|
251
258
|
switch (state) {
|
|
252
259
|
case ESCROW_STATE_COMMITTED:
|
|
253
|
-
if (data.isOfferer(signer) && await this.isExpired(signer, data))
|
|
254
|
-
return {
|
|
255
|
-
|
|
260
|
+
if (data.isOfferer(signer) && await this.isExpired(signer, data)) {
|
|
261
|
+
return {
|
|
262
|
+
type: base_1.SwapCommitStateType.REFUNDABLE,
|
|
263
|
+
getInitTxId
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
type: base_1.SwapCommitStateType.COMMITED,
|
|
268
|
+
getInitTxId
|
|
269
|
+
};
|
|
256
270
|
case ESCROW_STATE_CLAIMED:
|
|
257
271
|
return {
|
|
258
272
|
type: base_1.SwapCommitStateType.PAID,
|
|
273
|
+
getInitTxId,
|
|
259
274
|
getTxBlock: async () => {
|
|
260
275
|
return {
|
|
261
276
|
blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
|
|
@@ -278,6 +293,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
278
293
|
case ESCROW_STATE_REFUNDED:
|
|
279
294
|
return {
|
|
280
295
|
type: await this.isExpired(signer, data) ? base_1.SwapCommitStateType.EXPIRED : base_1.SwapCommitStateType.NOT_COMMITED,
|
|
296
|
+
getInitTxId,
|
|
281
297
|
getTxBlock: async () => {
|
|
282
298
|
return {
|
|
283
299
|
blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
|
|
@@ -358,6 +374,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
358
374
|
init: foundSwapData,
|
|
359
375
|
state: {
|
|
360
376
|
type: base_1.SwapCommitStateType.PAID,
|
|
377
|
+
getInitTxId: foundSwapData?.getInitTxId,
|
|
361
378
|
getClaimTxId: () => Promise.resolve(event.transactionHash),
|
|
362
379
|
getClaimResult: () => Promise.resolve(event.args.witnessResult.substring(2)),
|
|
363
380
|
getTxBlock: async () => {
|
|
@@ -378,6 +395,7 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
378
395
|
init: foundSwapData,
|
|
379
396
|
state: {
|
|
380
397
|
type: isExpired ? base_1.SwapCommitStateType.EXPIRED : base_1.SwapCommitStateType.NOT_COMMITED,
|
|
398
|
+
getInitTxId: foundSwapData?.getInitTxId,
|
|
381
399
|
getRefundTxId: () => Promise.resolve(event.transactionHash),
|
|
382
400
|
getTxBlock: async () => {
|
|
383
401
|
return {
|
|
@@ -399,8 +417,8 @@ class EVMSwapContract extends EVMContractBase_1.EVMContractBase {
|
|
|
399
417
|
resultingSwaps[escrowHash] = {
|
|
400
418
|
init: foundSwapData,
|
|
401
419
|
state: foundSwapData.data.isOfferer(signer) && await this.isExpired(signer, foundSwapData.data)
|
|
402
|
-
? { type: base_1.SwapCommitStateType.REFUNDABLE }
|
|
403
|
-
: { type: base_1.SwapCommitStateType.COMMITED }
|
|
420
|
+
? { type: base_1.SwapCommitStateType.REFUNDABLE, getInitTxId: foundSwapData.getInitTxId }
|
|
421
|
+
: { type: base_1.SwapCommitStateType.COMMITED, getInitTxId: foundSwapData.getInitTxId }
|
|
404
422
|
};
|
|
405
423
|
}
|
|
406
424
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/chain-evm",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "EVM specific base implementation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "adambor",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@atomiqlabs/base": "^13.4.
|
|
30
|
+
"@atomiqlabs/base": "^13.4.2",
|
|
31
31
|
"@noble/hashes": "^1.8.0",
|
|
32
32
|
"@scure/btc-signer": "^1.6.0",
|
|
33
33
|
"buffer": "6.0.3",
|
|
@@ -312,6 +312,15 @@ export class EVMChainInterface<ChainId extends string = string> implements Chain
|
|
|
312
312
|
return this.Transactions.getTxIdStatus(txId);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
/**
|
|
316
|
+
* @inheritDoc
|
|
317
|
+
*/
|
|
318
|
+
getTxId(signedTX: Transaction): Promise<string> {
|
|
319
|
+
const txId = signedTX.hash;
|
|
320
|
+
if(txId==null) throw new Error("Passed transaction is not signed!");
|
|
321
|
+
return Promise.resolve(txId);
|
|
322
|
+
}
|
|
323
|
+
|
|
315
324
|
/**
|
|
316
325
|
* @inheritDoc
|
|
317
326
|
*/
|
|
@@ -333,14 +333,35 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
333
333
|
const escrowHash = data.getEscrowHash();
|
|
334
334
|
const stateData = await this.contract.getHashState("0x"+escrowHash);
|
|
335
335
|
const state = Number(stateData.state);
|
|
336
|
+
const initBlockHeight = Number(stateData.initBlockheight);
|
|
336
337
|
const blockHeight = Number(stateData.finishBlockheight);
|
|
338
|
+
|
|
339
|
+
const getInitTxId = async () => {
|
|
340
|
+
const events = await this._Events.getContractBlockEvents(
|
|
341
|
+
["Initialize"],
|
|
342
|
+
[null, null, "0x"+escrowHash],
|
|
343
|
+
initBlockHeight, initBlockHeight
|
|
344
|
+
);
|
|
345
|
+
if(events.length===0) throw new Error("Initialize event not found!");
|
|
346
|
+
return events[0].transactionHash;
|
|
347
|
+
}
|
|
348
|
+
|
|
337
349
|
switch(state) {
|
|
338
350
|
case ESCROW_STATE_COMMITTED:
|
|
339
|
-
if(data.isOfferer(signer) && await this.isExpired(signer,data))
|
|
340
|
-
|
|
351
|
+
if(data.isOfferer(signer) && await this.isExpired(signer,data)) {
|
|
352
|
+
return {
|
|
353
|
+
type: SwapCommitStateType.REFUNDABLE,
|
|
354
|
+
getInitTxId
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
type: SwapCommitStateType.COMMITED,
|
|
359
|
+
getInitTxId
|
|
360
|
+
};
|
|
341
361
|
case ESCROW_STATE_CLAIMED:
|
|
342
362
|
return {
|
|
343
363
|
type: SwapCommitStateType.PAID,
|
|
364
|
+
getInitTxId,
|
|
344
365
|
getTxBlock: async () => {
|
|
345
366
|
return {
|
|
346
367
|
blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
|
|
@@ -369,6 +390,7 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
369
390
|
case ESCROW_STATE_REFUNDED:
|
|
370
391
|
return {
|
|
371
392
|
type: await this.isExpired(signer, data) ? SwapCommitStateType.EXPIRED : SwapCommitStateType.NOT_COMMITED,
|
|
393
|
+
getInitTxId,
|
|
372
394
|
getTxBlock: async () => {
|
|
373
395
|
return {
|
|
374
396
|
blockTime: await this.Chain.Blocks.getBlockTime(blockHeight),
|
|
@@ -493,6 +515,7 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
493
515
|
init: foundSwapData,
|
|
494
516
|
state: {
|
|
495
517
|
type: SwapCommitStateType.PAID,
|
|
518
|
+
getInitTxId: foundSwapData?.getInitTxId,
|
|
496
519
|
getClaimTxId: () => Promise.resolve(event.transactionHash),
|
|
497
520
|
getClaimResult: () => Promise.resolve(event.args.witnessResult.substring(2)),
|
|
498
521
|
getTxBlock: async () => {
|
|
@@ -513,6 +536,7 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
513
536
|
init: foundSwapData,
|
|
514
537
|
state: {
|
|
515
538
|
type: isExpired ? SwapCommitStateType.EXPIRED : SwapCommitStateType.NOT_COMMITED,
|
|
539
|
+
getInitTxId: foundSwapData?.getInitTxId,
|
|
516
540
|
getRefundTxId: () => Promise.resolve(event.transactionHash),
|
|
517
541
|
getTxBlock: async () => {
|
|
518
542
|
return {
|
|
@@ -547,8 +571,8 @@ export class EVMSwapContract<ChainId extends string = string>
|
|
|
547
571
|
resultingSwaps[escrowHash] = {
|
|
548
572
|
init: foundSwapData,
|
|
549
573
|
state: foundSwapData.data.isOfferer(signer) && await this.isExpired(signer, foundSwapData.data)
|
|
550
|
-
? {type: SwapCommitStateType.REFUNDABLE}
|
|
551
|
-
: {type: SwapCommitStateType.COMMITED}
|
|
574
|
+
? {type: SwapCommitStateType.REFUNDABLE, getInitTxId: foundSwapData.getInitTxId}
|
|
575
|
+
: {type: SwapCommitStateType.COMMITED, getInitTxId: foundSwapData.getInitTxId}
|
|
552
576
|
}
|
|
553
577
|
}
|
|
554
578
|
|