@atomiqlabs/lp-lib 14.0.0-dev.34 → 14.0.0-dev.36

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.
@@ -44,6 +44,8 @@ class AmountAssertions {
44
44
  * @throws {DefinedRuntimeError} will throw an error if the response is an error
45
45
  */
46
46
  static handlePluginErrorResponses(res) {
47
+ if (res == null)
48
+ return;
47
49
  if ((0, IPlugin_1.isQuoteThrow)(res))
48
50
  throw {
49
51
  code: 29999,
@@ -48,17 +48,25 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
48
48
  * @param vout
49
49
  */
50
50
  async tryClaimSwap(tx, swap, vout) {
51
- const { swapContract, signer } = this.getChain(swap.chainIdentifier);
51
+ const { chainInterface, swapContract, signer } = this.getChain(swap.chainIdentifier);
52
52
  const blockHeader = await this.bitcoinRpc.getBlockHeader(tx.blockhash);
53
53
  //Set flag that we are sending the transaction already, so we don't end up with race condition
54
+ if (swap.isLocked())
55
+ return false;
56
+ let txns;
57
+ try {
58
+ txns = await swapContract.txsClaimWithTxData(signer, swap.data, { ...tx, height: blockHeader.getHeight() }, swap.requiredConfirmations, vout, null, null, false);
59
+ }
60
+ catch (e) {
61
+ this.swapLogger.error(swap, "tryClaimSwap(): error occurred creating swap claim transactions, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout + " address: " + swap.address, e);
62
+ return false;
63
+ }
54
64
  const unlock = swap.lock(swapContract.claimWithTxDataTimeout);
55
65
  if (unlock == null)
56
66
  return false;
57
67
  try {
58
68
  this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout);
59
- const result = await swapContract.claimWithTxData(signer, swap.data, { ...tx, height: blockHeader.getHeight() }, swap.requiredConfirmations, vout, null, null, false, {
60
- waitForConfirmation: true
61
- });
69
+ await chainInterface.sendAndConfirm(signer, txns, true);
62
70
  this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout + " address: " + swap.address);
63
71
  if (swap.metadata != null)
64
72
  swap.metadata.times.txClaimed = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "14.0.0-dev.34",
3
+ "version": "14.0.0-dev.36",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -52,6 +52,7 @@ export abstract class AmountAssertions {
52
52
  * @throws {DefinedRuntimeError} will throw an error if the response is an error
53
53
  */
54
54
  static handlePluginErrorResponses(res: any): void {
55
+ if(res==null) return;
55
56
  if(isQuoteThrow(res)) throw {
56
57
  code: 29999,
57
58
  msg: res.message
@@ -104,17 +104,16 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
104
104
  * @param vout
105
105
  */
106
106
  private async tryClaimSwap(tx: {blockhash: string, confirmations: number, txid: string, hex: string}, swap: ToBtcSwapAbs, vout: number): Promise<boolean> {
107
- const {swapContract, signer} = this.getChain(swap.chainIdentifier);
107
+ const {chainInterface, swapContract, signer} = this.getChain(swap.chainIdentifier);
108
108
 
109
109
  const blockHeader = await this.bitcoinRpc.getBlockHeader(tx.blockhash);
110
110
 
111
111
  //Set flag that we are sending the transaction already, so we don't end up with race condition
112
- const unlock: () => boolean = swap.lock(swapContract.claimWithTxDataTimeout);
113
- if(unlock==null) return false;
112
+ if(swap.isLocked()) return false;
114
113
 
114
+ let txns: any[];
115
115
  try {
116
- this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout);
117
- const result = await swapContract.claimWithTxData(
116
+ txns = await swapContract.txsClaimWithTxData(
118
117
  signer,
119
118
  swap.data,
120
119
  {...tx, height: blockHeader.getHeight()},
@@ -122,11 +121,19 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
122
121
  vout,
123
122
  null,
124
123
  null,
125
- false,
126
- {
127
- waitForConfirmation: true
128
- }
124
+ false
129
125
  );
126
+ } catch (e) {
127
+ this.swapLogger.error(swap, "tryClaimSwap(): error occurred creating swap claim transactions, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout+" address: "+swap.address, e);
128
+ return false
129
+ }
130
+
131
+ const unlock: () => boolean = swap.lock(swapContract.claimWithTxDataTimeout);
132
+ if(unlock==null) return false;
133
+
134
+ try {
135
+ this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout);
136
+ await chainInterface.sendAndConfirm(signer, txns, true);
130
137
  this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout+" address: "+swap.address);
131
138
  if(swap.metadata!=null) swap.metadata.times.txClaimed = Date.now();
132
139
  unlock();