dash 3.22.0-dev.9 → 3.22.2

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.
@@ -35,7 +35,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ var waitForCoreChainLockedHeight_1 = __importDefault(require("./waitForCoreChainLockedHeight"));
43
+ var _a = require('@dashevo/wallet-lib/src/errors'), InstantLockTimeoutError = _a.InstantLockTimeoutError, TxMetadataTimeoutError = _a.TxMetadataTimeoutError;
39
44
  /**
40
45
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
41
46
  * @param {Platform} platform
@@ -46,22 +51,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
46
51
  */
47
52
  function createAssetLockProof(platform, assetLockTransaction, outputIndex) {
48
53
  return __awaiter(this, void 0, void 0, function () {
49
- var account, dpp, instantLock;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
54
+ var account, dpp, _a, instantLockPromise, cancelInstantLock, _b, txMetadataPromise, cancelTxMetadata, cancelObtainCoreChainLockedHeight, rejectTimer, rejectionTimeout;
55
+ return __generator(this, function (_c) {
56
+ switch (_c.label) {
52
57
  case 0: return [4 /*yield*/, platform.initialize()];
53
58
  case 1:
54
- _a.sent();
59
+ _c.sent();
55
60
  return [4 /*yield*/, platform.client.getWalletAccount()];
56
61
  case 2:
57
- account = _a.sent();
62
+ account = _c.sent();
58
63
  dpp = platform.dpp;
59
- return [4 /*yield*/, account.waitForInstantLock(assetLockTransaction.hash)];
60
- case 3:
61
- instantLock = _a.sent();
62
- // Create poof that the transaction won't be double spend
63
- // @ts-ignore
64
- return [2 /*return*/, dpp.identity.createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex)];
64
+ _a = account.waitForInstantLock(assetLockTransaction.hash), instantLockPromise = _a.promise, cancelInstantLock = _a.cancel;
65
+ _b = account.waitForTxMetadata(assetLockTransaction.hash), txMetadataPromise = _b.promise, cancelTxMetadata = _b.cancel;
66
+ rejectionTimeout = account.waitForTxMetadataTimeout > account.waitForInstantLockTimeout
67
+ // @ts-ignore
68
+ ? account.waitForTxMetadataTimeout + 360000 // wait for platform to sync core chain locked height
69
+ // @ts-ignore
70
+ : account.waitForInstantLockTimeout;
71
+ return [2 /*return*/, Promise.race([
72
+ // Wait for Instant Lock
73
+ instantLockPromise
74
+ .then(function (instantLock) {
75
+ clearTimeout(rejectTimer);
76
+ cancelTxMetadata();
77
+ if (cancelObtainCoreChainLockedHeight) {
78
+ cancelObtainCoreChainLockedHeight();
79
+ }
80
+ // @ts-ignore
81
+ return dpp.identity.createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex);
82
+ })
83
+ .catch(function (error) {
84
+ if (error instanceof InstantLockTimeoutError) {
85
+ // Instant Lock is timed out.
86
+ // Allow chain proof to win the race
87
+ return new Promise(function () { });
88
+ }
89
+ return Promise.reject(error);
90
+ }),
91
+ // Wait for transaction is mined and platform chain synced core height to the transaction height
92
+ txMetadataPromise
93
+ .then(function (assetLockMetadata) {
94
+ // @ts-ignore
95
+ return waitForCoreChainLockedHeight_1.default(platform, assetLockMetadata.height)
96
+ .then(function (_a) {
97
+ var promise = _a.promise, cancel = _a.cancel;
98
+ cancelObtainCoreChainLockedHeight = cancel;
99
+ return promise;
100
+ })
101
+ .then(function () {
102
+ clearTimeout(rejectTimer);
103
+ cancelInstantLock();
104
+ // @ts-ignore
105
+ return dpp.identity.createChainAssetLockProof(
106
+ // @ts-ignore
107
+ assetLockMetadata.height, assetLockTransaction.getOutPointBuffer(outputIndex));
108
+ });
109
+ })
110
+ .catch(function (error) {
111
+ if (error instanceof TxMetadataTimeoutError) {
112
+ // Instant Lock is timed out.
113
+ // Allow instant proof to win the race
114
+ return new Promise(function () { });
115
+ }
116
+ return Promise.reject(error);
117
+ }),
118
+ // Common timeout for getting proofs
119
+ new Promise(function (_, reject) {
120
+ rejectTimer = setTimeout(function () {
121
+ cancelTxMetadata();
122
+ if (cancelObtainCoreChainLockedHeight) {
123
+ cancelObtainCoreChainLockedHeight();
124
+ }
125
+ cancelInstantLock();
126
+ reject(new Error('Asset Lock Proof creation timeout'));
127
+ }, rejectionTimeout);
128
+ })
129
+ ])];
65
130
  }
66
131
  });
67
132
  });
@@ -1 +1 @@
1
- {"version":3,"file":"createAssetLockProof.js","sourceRoot":"","sources":["../../../../../../../../src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;GAOG;AACH,SAA8B,oBAAoB,CAAC,QAAmB,EAAE,oBAAiC,EAAE,WAAmB;;;;;wBAC1H,qBAAM,QAAQ,CAAC,UAAU,EAAE,EAAA;;oBAA3B,SAA2B,CAAC;oBAEZ,qBAAM,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAA;;oBAAlD,OAAO,GAAG,SAAwC;oBAChD,GAAG,GAAK,QAAQ,IAAb,CAAc;oBAEP,qBAAM,OAAO,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAA;;oBAAzE,WAAW,GAAG,SAA2D;oBAC7E,yDAAyD;oBAEzD,aAAa;oBACb,sBAAO,GAAG,CAAC,QAAQ,CAAC,2BAA2B,CAAC,WAAW,EAAE,oBAAoB,EAAE,WAAW,CAAC,EAAC;;;;CACnG;AAXD,uCAWC"}
1
+ {"version":3,"file":"createAssetLockProof.js","sourceRoot":"","sources":["../../../../../../../../src/SDK/Client/Platform/methods/identities/internal/createAssetLockProof.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,gGAA0E;AAEpE,IAAA,KAAsD,O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,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;gCACzD,CAAC,EAAE,gBAAgB,CAAC,CAAA;4BACtB,CAAC,CAAC;yBACH,CAAC,EAAC;;;;CACN;AAzGD,uCAyGC"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var systemIds_1 = require("@dashevo/dpns-contract/lib/systemIds");
40
+ function waitForCoreChainLockedHeight(platform, expectedCoreHeight) {
41
+ return __awaiter(this, void 0, void 0, function () {
42
+ function cancel() {
43
+ if (timeout) {
44
+ clearTimeout(timeout);
45
+ }
46
+ isCanceled = true;
47
+ }
48
+ var interval, isCanceled, timeout, coreChainLockedHeight, promise;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0: return [4 /*yield*/, platform.initialize()];
52
+ case 1:
53
+ _a.sent();
54
+ interval = 5000;
55
+ isCanceled = false;
56
+ coreChainLockedHeight = 0;
57
+ promise = new Promise(function (resolve, reject) {
58
+ function obtainCoreChainLockedHeight() {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var identityResponse, metadata, e_1;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ _a.trys.push([0, 2, , 3]);
65
+ return [4 /*yield*/, platform.identities.get(systemIds_1.ownerId)];
66
+ case 1:
67
+ identityResponse = _a.sent();
68
+ if (!identityResponse) {
69
+ reject(new Error('Identity using to obtain core chain locked height is not present'));
70
+ return [2 /*return*/];
71
+ }
72
+ metadata = identityResponse.getMetadata();
73
+ coreChainLockedHeight = metadata.getCoreChainLockedHeight();
74
+ return [3 /*break*/, 3];
75
+ case 2:
76
+ e_1 = _a.sent();
77
+ reject(e_1);
78
+ return [2 /*return*/];
79
+ case 3:
80
+ if (coreChainLockedHeight >= expectedCoreHeight) {
81
+ resolve();
82
+ return [2 /*return*/];
83
+ }
84
+ if (!isCanceled) {
85
+ timeout = setTimeout(obtainCoreChainLockedHeight, interval);
86
+ }
87
+ return [2 /*return*/];
88
+ }
89
+ });
90
+ });
91
+ }
92
+ obtainCoreChainLockedHeight();
93
+ });
94
+ return [2 /*return*/, {
95
+ promise: promise,
96
+ cancel: cancel,
97
+ }];
98
+ }
99
+ });
100
+ });
101
+ }
102
+ exports.default = waitForCoreChainLockedHeight;
103
+ //# sourceMappingURL=waitForCoreChainLockedHeight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waitForCoreChainLockedHeight.js","sourceRoot":"","sources":["../../../../../../../../src/SDK/Client/Platform/methods/identities/internal/waitForCoreChainLockedHeight.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kEAA8E;AAE9E,SAA8B,4BAA4B,CACxD,QAAmB,EACnB,kBAA2B;;QA8C3B,SAAS,MAAM;YACb,IAAI,OAAO,EAAE;gBACX,YAAY,CAAC,OAAO,CAAC,CAAC;aACvB;YAED,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;;;;wBAlDD,qBAAM,QAAQ,CAAC,UAAU,EAAE,EAAA;;oBAA3B,SAA2B,CAAC;oBAEtB,QAAQ,GAAG,IAAI,CAAC;oBAElB,UAAU,GAAG,KAAK,CAAC;oBAInB,qBAAqB,GAAG,CAAC,CAAC;oBAExB,OAAO,GAAG,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBAC1C,SAAe,2BAA2B;;;;;;;4CAEb,qBAAM,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,mBAAW,CAAC,EAAA;;4CAA7D,gBAAgB,GAAG,SAA0C;4CAEnE,IAAI,CAAC,gBAAgB,EAAE;gDACpB,MAAM,CAAC,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC,CAAC;gDAEtF,sBAAO;6CACT;4CAEK,QAAQ,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;4CAEhD,qBAAqB,GAAG,QAAQ,CAAC,wBAAwB,EAAE,CAAC;;;;4CAE5D,MAAM,CAAC,GAAC,CAAC,CAAC;4CAEV,sBAAO;;4CAGT,IAAI,qBAAqB,IAAI,kBAAkB,EAAE;gDAC/C,OAAO,EAAE,CAAC;gDAEV,sBAAO;6CACR;4CAED,IAAI,CAAC,UAAU,EAAE;gDACf,OAAO,GAAG,UAAU,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC;6CAC7D;;;;;yBACF;wBAED,2BAA2B,EAAE,CAAC;oBAChC,CAAC,CAAC,CAAC;oBAUH,sBAAO;4BACL,OAAO,SAAA;4BACP,MAAM,QAAA;yBACP,EAAA;;;;CACF;AA5DD,+CA4DC"}
@@ -0,0 +1,5 @@
1
+ import { Platform } from "../../../Platform";
2
+ export default function waitForCoreChainLockedHeight(platform: Platform, expectedCoreHeight: number): Promise<{
3
+ promise: Promise<any>;
4
+ cancel: Function;
5
+ }>;
@@ -97,6 +97,7 @@ export declare namespace SDK {
97
97
  REHYDRATE_STATE_FAILED: string;
98
98
  REHYDRATE_STATE_SUCCESS: string;
99
99
  INSTANT_LOCK: string;
100
+ TX_METADATA: string;
100
101
  };
101
102
  plugins: {
102
103
  StandardPlugin: typeof import("@dashevo/wallet-libsrc/plugins/StandardPlugin");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dash",
3
- "version": "3.22.0-dev.9",
3
+ "version": "3.22.2",
4
4
  "description": "Dash library for JavaScript/TypeScript ecosystem (Wallet, DAPI, Primitives, BLS, ...)",
5
5
  "main": "build/src/index.js",
6
6
  "unpkg": "dist/dash.min.js",
@@ -34,14 +34,14 @@
34
34
  },
35
35
  "homepage": "https://github.com/dashevo/DashJS#readme",
36
36
  "dependencies": {
37
- "@dashevo/dapi-client": "~0.22.0-dev.9",
38
- "@dashevo/dashcore-lib": "~0.19.30",
39
- "@dashevo/dashpay-contract": "~0.22.0-dev.9",
40
- "@dashevo/dpns-contract": "~0.22.0-dev.9",
41
- "@dashevo/dpp": "~0.22.0-dev.9",
42
- "@dashevo/grpc-common": "~0.22.0-dev.9",
43
- "@dashevo/masternode-reward-shares-contract": "~0.22.0-dev.9",
44
- "@dashevo/wallet-lib": "~7.22.0-dev.9",
37
+ "@dashevo/dapi-client": "~0.22.2",
38
+ "@dashevo/dashcore-lib": "~0.19.31",
39
+ "@dashevo/dashpay-contract": "~0.22.2",
40
+ "@dashevo/dpns-contract": "~0.22.2",
41
+ "@dashevo/dpp": "~0.22.2",
42
+ "@dashevo/grpc-common": "~0.22.2",
43
+ "@dashevo/masternode-reward-shares-contract": "~0.22.2",
44
+ "@dashevo/wallet-lib": "~7.22.2",
45
45
  "bs58": "^4.0.1",
46
46
  "node-inspect-extracted": "^1.0.8"
47
47
  },
@@ -1,6 +1,10 @@
1
1
  import { Transaction } from "@dashevo/dashcore-lib";
2
2
  import { Platform } from "../../../Platform";
3
3
 
4
+ import waitForCoreChainLockedHeight from "./waitForCoreChainLockedHeight";
5
+
6
+ const { InstantLockTimeoutError, TxMetadataTimeoutError } = require('@dashevo/wallet-lib/src/errors');
7
+
4
8
  /**
5
9
  * Creates a funding transaction for the platform identity and returns one-time key to sign the state transition
6
10
  * @param {Platform} platform
@@ -15,9 +19,103 @@ export default async function createAssetLockProof(platform : Platform, assetLoc
15
19
  const account = await platform.client.getWalletAccount();
16
20
  const { dpp } = platform;
17
21
 
18
- let instantLock = await account.waitForInstantLock(assetLockTransaction.hash);
19
22
  // Create poof that the transaction won't be double spend
20
23
 
24
+ const {
25
+ promise: instantLockPromise,
26
+ cancel: cancelInstantLock
27
+ } = account.waitForInstantLock(assetLockTransaction.hash);
28
+
29
+ const {
30
+ promise: txMetadataPromise,
31
+ cancel: cancelTxMetadata,
32
+ } = account.waitForTxMetadata(assetLockTransaction.hash);
33
+
34
+ let cancelObtainCoreChainLockedHeight;
35
+
36
+ let rejectTimer;
37
+
21
38
  // @ts-ignore
22
- return dpp.identity.createInstantAssetLockProof(instantLock, assetLockTransaction, outputIndex);
39
+ const rejectionTimeout = account.waitForTxMetadataTimeout > account.waitForInstantLockTimeout
40
+ // @ts-ignore
41
+ ? account.waitForTxMetadataTimeout + 360000 // wait for platform to sync core chain locked height
42
+ // @ts-ignore
43
+ : account.waitForInstantLockTimeout;
44
+
45
+ return Promise.race([
46
+ // Wait for Instant Lock
47
+ instantLockPromise
48
+ .then((instantLock) => {
49
+ clearTimeout(rejectTimer);
50
+
51
+ cancelTxMetadata();
52
+
53
+ if (cancelObtainCoreChainLockedHeight) {
54
+ cancelObtainCoreChainLockedHeight();
55
+ }
56
+
57
+ // @ts-ignore
58
+ return dpp.identity.createInstantAssetLockProof(
59
+ instantLock,
60
+ assetLockTransaction,
61
+ outputIndex,
62
+ );
63
+ })
64
+ .catch((error) => {
65
+ if (error instanceof InstantLockTimeoutError) {
66
+ // Instant Lock is timed out.
67
+ // Allow chain proof to win the race
68
+ return new Promise(() => {});
69
+ }
70
+
71
+ return Promise.reject(error);
72
+ }),
73
+
74
+ // Wait for transaction is mined and platform chain synced core height to the transaction height
75
+ txMetadataPromise
76
+ .then((assetLockMetadata) => {
77
+ // @ts-ignore
78
+ return waitForCoreChainLockedHeight(platform, assetLockMetadata.height)
79
+ .then(({ promise, cancel }) => {
80
+ cancelObtainCoreChainLockedHeight = cancel;
81
+
82
+ return promise;
83
+ })
84
+ .then(() => {
85
+ clearTimeout(rejectTimer);
86
+ cancelInstantLock();
87
+
88
+ // @ts-ignore
89
+ return dpp.identity.createChainAssetLockProof(
90
+ // @ts-ignore
91
+ assetLockMetadata.height,
92
+ assetLockTransaction.getOutPointBuffer(outputIndex),
93
+ );
94
+ })
95
+ })
96
+ .catch((error) => {
97
+ if (error instanceof TxMetadataTimeoutError) {
98
+ // Instant Lock is timed out.
99
+ // Allow instant proof to win the race
100
+ return new Promise(() => {});
101
+ }
102
+
103
+ return Promise.reject(error);
104
+ }),
105
+
106
+ // Common timeout for getting proofs
107
+ new Promise((_, reject) => {
108
+ rejectTimer = setTimeout(() => {
109
+ cancelTxMetadata();
110
+
111
+ if (cancelObtainCoreChainLockedHeight) {
112
+ cancelObtainCoreChainLockedHeight();
113
+ }
114
+
115
+ cancelInstantLock();
116
+
117
+ reject(new Error('Asset Lock Proof creation timeout'));
118
+ }, rejectionTimeout)
119
+ })
120
+ ]);
23
121
  }
@@ -0,0 +1,69 @@
1
+ import { Platform } from "../../../Platform";
2
+
3
+ import { ownerId as dpnsOwnerId } from "@dashevo/dpns-contract/lib/systemIds";
4
+
5
+ export default async function waitForCoreChainLockedHeight(
6
+ platform : Platform,
7
+ expectedCoreHeight : number,
8
+ ): Promise<{ promise: Promise<any>, cancel: Function }> {
9
+ await platform.initialize();
10
+
11
+ const interval = 5000;
12
+
13
+ let isCanceled = false;
14
+
15
+ let timeout: ReturnType<typeof setTimeout>;
16
+
17
+ let coreChainLockedHeight = 0;
18
+
19
+ const promise = new Promise((resolve, reject) => {
20
+ async function obtainCoreChainLockedHeight() {
21
+ try {
22
+ const identityResponse = await platform.identities.get(dpnsOwnerId);
23
+
24
+ if (!identityResponse) {
25
+ reject(new Error('Identity using to obtain core chain locked height is not present'));
26
+
27
+ return;
28
+ }
29
+
30
+ const metadata = identityResponse.getMetadata();
31
+
32
+ coreChainLockedHeight = metadata.getCoreChainLockedHeight();
33
+ } catch (e) {
34
+ reject(e);
35
+
36
+ return;
37
+ }
38
+
39
+ if (coreChainLockedHeight >= expectedCoreHeight) {
40
+ resolve();
41
+
42
+ return;
43
+ }
44
+
45
+ if (!isCanceled) {
46
+ timeout = setTimeout(obtainCoreChainLockedHeight, interval);
47
+ }
48
+ }
49
+
50
+ obtainCoreChainLockedHeight();
51
+ });
52
+
53
+ function cancel() {
54
+ if (timeout) {
55
+ clearTimeout(timeout);
56
+ }
57
+
58
+ isCanceled = true;
59
+ }
60
+
61
+ return {
62
+ promise,
63
+ cancel,
64
+ }
65
+ }
66
+
67
+
68
+
69
+