@open-captable-protocol/canton 0.2.149 → 0.2.151
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.
- package/dist/OcpClient.d.ts +11 -0
- package/dist/OcpClient.d.ts.map +1 -1
- package/dist/OcpClient.js +3 -0
- package/dist/OcpClient.js.map +1 -1
- package/dist/errors/OcpContractError.d.ts +52 -0
- package/dist/errors/OcpContractError.d.ts.map +1 -0
- package/dist/errors/OcpContractError.js +45 -0
- package/dist/errors/OcpContractError.js.map +1 -0
- package/dist/errors/OcpError.d.ts +27 -0
- package/dist/errors/OcpError.d.ts.map +1 -0
- package/dist/errors/OcpError.js +33 -0
- package/dist/errors/OcpError.js.map +1 -0
- package/dist/errors/OcpNetworkError.d.ts +49 -0
- package/dist/errors/OcpNetworkError.d.ts.map +1 -0
- package/dist/errors/OcpNetworkError.js +45 -0
- package/dist/errors/OcpNetworkError.js.map +1 -0
- package/dist/errors/OcpParseError.d.ts +41 -0
- package/dist/errors/OcpParseError.d.ts.map +1 -0
- package/dist/errors/OcpParseError.js +40 -0
- package/dist/errors/OcpParseError.js.map +1 -0
- package/dist/errors/OcpValidationError.d.ts +49 -0
- package/dist/errors/OcpValidationError.d.ts.map +1 -0
- package/dist/errors/OcpValidationError.js +46 -0
- package/dist/errors/OcpValidationError.js.map +1 -0
- package/dist/errors/codes.d.ts +23 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/codes.js +29 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/errors/index.d.ts +48 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +59 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/functions/CouponMinter/index.d.ts +1 -0
- package/dist/functions/CouponMinter/index.d.ts.map +1 -1
- package/dist/functions/CouponMinter/index.js +7 -1
- package/dist/functions/CouponMinter/index.js.map +1 -1
- package/dist/functions/CouponMinter/waitUntilCanMint.d.ts +176 -0
- package/dist/functions/CouponMinter/waitUntilCanMint.d.ts.map +1 -0
- package/dist/functions/CouponMinter/waitUntilCanMint.js +233 -0
- package/dist/functions/CouponMinter/waitUntilCanMint.js.map +1 -0
- package/dist/functions/OpenCapTable/capTable/CapTableBatch.d.ts +2 -1
- package/dist/functions/OpenCapTable/capTable/CapTableBatch.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/capTable/CapTableBatch.js +14 -4
- package/dist/functions/OpenCapTable/capTable/CapTableBatch.js.map +1 -1
- package/dist/functions/OpenCapTable/capTable/ocfToDaml.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/capTable/ocfToDaml.js +151 -50
- package/dist/functions/OpenCapTable/capTable/ocfToDaml.js.map +1 -1
- package/dist/functions/OpenCapTable/issuer/createIssuer.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/issuer/createIssuer.js +15 -4
- package/dist/functions/OpenCapTable/issuer/createIssuer.js.map +1 -1
- package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.js +21 -5
- package/dist/functions/OpenCapTable/stakeholder/getStakeholderAsOcf.js.map +1 -1
- package/dist/functions/OpenCapTable/stakeholder/stakeholderDataToDaml.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/stakeholder/stakeholderDataToDaml.js +19 -5
- package/dist/functions/OpenCapTable/stakeholder/stakeholderDataToDaml.js.map +1 -1
- package/dist/functions/OpenCapTable/stockClass/stockClassDataToDaml.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/stockClass/stockClassDataToDaml.js +11 -3
- package/dist/functions/OpenCapTable/stockClass/stockClassDataToDaml.js.map +1 -1
- package/dist/functions/OpenCapTable/stockIssuance/createStockIssuance.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/stockIssuance/createStockIssuance.js +35 -11
- package/dist/functions/OpenCapTable/stockIssuance/createStockIssuance.js.map +1 -1
- package/dist/functions/OpenCapTable/stockRepurchase/stockRepurchaseDataToDaml.d.ts.map +1 -1
- package/dist/functions/OpenCapTable/stockRepurchase/stockRepurchaseDataToDaml.js +19 -6
- package/dist/functions/OpenCapTable/stockRepurchase/stockRepurchaseDataToDaml.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/typeConversions.d.ts +1 -1
- package/dist/utils/typeConversions.d.ts.map +1 -1
- package/dist/utils/typeConversions.js +23 -6
- package/dist/utils/typeConversions.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/errors/codes.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,aAAa,GAAG;IAC3B,oBAAoB;IACpB,sBAAsB,EAAE,wBAAwB;IAChD,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAE5B,kBAAkB;IAClB,kBAAkB,EAAE,oBAAoB;IACxC,aAAa,EAAE,eAAe;IAC9B,oBAAoB,EAAE,sBAAsB;IAC5C,gBAAgB,EAAE,kBAAkB;IAEpC,iBAAiB;IACjB,iBAAiB,EAAE,mBAAmB;IACtC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAE5B,eAAe;IACf,gBAAgB,EAAE,kBAAkB;IACpC,eAAe,EAAE,iBAAiB;IAClC,kBAAkB,EAAE,oBAAoB;CAChC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error types for the OCP SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a hierarchy of error types for different failure modes,
|
|
5
|
+
* enabling better error handling, debugging, and developer experience.
|
|
6
|
+
*
|
|
7
|
+
* @example Error handling
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* OcpError,
|
|
11
|
+
* OcpValidationError,
|
|
12
|
+
* OcpContractError,
|
|
13
|
+
* OcpNetworkError,
|
|
14
|
+
* OcpParseError,
|
|
15
|
+
* OcpErrorCodes,
|
|
16
|
+
* } from '@open-captable-protocol/canton';
|
|
17
|
+
*
|
|
18
|
+
* try {
|
|
19
|
+
* await ocp.OpenCapTable.capTable.update(params).create('stakeholder', data).execute();
|
|
20
|
+
* } catch (error) {
|
|
21
|
+
* if (error instanceof OcpValidationError) {
|
|
22
|
+
* // Handle validation errors (invalid input)
|
|
23
|
+
* console.error(`Invalid input at ${error.fieldPath}: ${error.message}`);
|
|
24
|
+
* } else if (error instanceof OcpContractError) {
|
|
25
|
+
* // Handle contract errors (DAML/Canton issues)
|
|
26
|
+
* console.error(`Contract error on ${error.choice}: ${error.message}`);
|
|
27
|
+
* } else if (error instanceof OcpNetworkError) {
|
|
28
|
+
* // Handle network errors (connectivity issues)
|
|
29
|
+
* console.error(`Network error: ${error.message}`);
|
|
30
|
+
* } else if (error instanceof OcpParseError) {
|
|
31
|
+
* // Handle parse errors (data transformation issues)
|
|
32
|
+
* console.error(`Parse error: ${error.message}`);
|
|
33
|
+
* } else if (error instanceof OcpError) {
|
|
34
|
+
* // Handle any other OCP errors
|
|
35
|
+
* console.error(`OCP Error [${error.code}]: ${error.message}`);
|
|
36
|
+
* } else {
|
|
37
|
+
* throw error; // Re-throw unknown errors
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export { OcpErrorCodes, type OcpErrorCode } from './codes';
|
|
43
|
+
export { OcpContractError, type OcpContractErrorOptions } from './OcpContractError';
|
|
44
|
+
export { OcpError } from './OcpError';
|
|
45
|
+
export { OcpNetworkError, type OcpNetworkErrorOptions } from './OcpNetworkError';
|
|
46
|
+
export { OcpParseError, type OcpParseErrorOptions } from './OcpParseError';
|
|
47
|
+
export { OcpValidationError, type OcpValidationErrorOptions } from './OcpValidationError';
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGH,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Structured error types for the OCP SDK.
|
|
4
|
+
*
|
|
5
|
+
* This module provides a hierarchy of error types for different failure modes,
|
|
6
|
+
* enabling better error handling, debugging, and developer experience.
|
|
7
|
+
*
|
|
8
|
+
* @example Error handling
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {
|
|
11
|
+
* OcpError,
|
|
12
|
+
* OcpValidationError,
|
|
13
|
+
* OcpContractError,
|
|
14
|
+
* OcpNetworkError,
|
|
15
|
+
* OcpParseError,
|
|
16
|
+
* OcpErrorCodes,
|
|
17
|
+
* } from '@open-captable-protocol/canton';
|
|
18
|
+
*
|
|
19
|
+
* try {
|
|
20
|
+
* await ocp.OpenCapTable.capTable.update(params).create('stakeholder', data).execute();
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof OcpValidationError) {
|
|
23
|
+
* // Handle validation errors (invalid input)
|
|
24
|
+
* console.error(`Invalid input at ${error.fieldPath}: ${error.message}`);
|
|
25
|
+
* } else if (error instanceof OcpContractError) {
|
|
26
|
+
* // Handle contract errors (DAML/Canton issues)
|
|
27
|
+
* console.error(`Contract error on ${error.choice}: ${error.message}`);
|
|
28
|
+
* } else if (error instanceof OcpNetworkError) {
|
|
29
|
+
* // Handle network errors (connectivity issues)
|
|
30
|
+
* console.error(`Network error: ${error.message}`);
|
|
31
|
+
* } else if (error instanceof OcpParseError) {
|
|
32
|
+
* // Handle parse errors (data transformation issues)
|
|
33
|
+
* console.error(`Parse error: ${error.message}`);
|
|
34
|
+
* } else if (error instanceof OcpError) {
|
|
35
|
+
* // Handle any other OCP errors
|
|
36
|
+
* console.error(`OCP Error [${error.code}]: ${error.message}`);
|
|
37
|
+
* } else {
|
|
38
|
+
* throw error; // Re-throw unknown errors
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.OcpValidationError = exports.OcpParseError = exports.OcpNetworkError = exports.OcpError = exports.OcpContractError = exports.OcpErrorCodes = void 0;
|
|
45
|
+
// Error codes
|
|
46
|
+
var codes_1 = require("./codes");
|
|
47
|
+
Object.defineProperty(exports, "OcpErrorCodes", { enumerable: true, get: function () { return codes_1.OcpErrorCodes; } });
|
|
48
|
+
// Error classes
|
|
49
|
+
var OcpContractError_1 = require("./OcpContractError");
|
|
50
|
+
Object.defineProperty(exports, "OcpContractError", { enumerable: true, get: function () { return OcpContractError_1.OcpContractError; } });
|
|
51
|
+
var OcpError_1 = require("./OcpError");
|
|
52
|
+
Object.defineProperty(exports, "OcpError", { enumerable: true, get: function () { return OcpError_1.OcpError; } });
|
|
53
|
+
var OcpNetworkError_1 = require("./OcpNetworkError");
|
|
54
|
+
Object.defineProperty(exports, "OcpNetworkError", { enumerable: true, get: function () { return OcpNetworkError_1.OcpNetworkError; } });
|
|
55
|
+
var OcpParseError_1 = require("./OcpParseError");
|
|
56
|
+
Object.defineProperty(exports, "OcpParseError", { enumerable: true, get: function () { return OcpParseError_1.OcpParseError; } });
|
|
57
|
+
var OcpValidationError_1 = require("./OcpValidationError");
|
|
58
|
+
Object.defineProperty(exports, "OcpValidationError", { enumerable: true, get: function () { return OcpValidationError_1.OcpValidationError; } });
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;;;AAEH,cAAc;AACd,iCAA2D;AAAlD,sGAAA,aAAa,OAAA;AAEtB,gBAAgB;AAChB,uDAAoF;AAA3E,oHAAA,gBAAgB,OAAA;AACzB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qDAAiF;AAAxE,kHAAA,eAAe,OAAA;AACxB,iDAA2E;AAAlE,8GAAA,aAAa,OAAA;AACtB,2DAA0F;AAAjF,wHAAA,kBAAkB,OAAA"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { canMintCouponsNow, type CanMintResult, type CouponMinterPayload, type LastMint } from './canMintCouponsNow';
|
|
2
|
+
export { WaitAbortedError, WaitTimeoutError, getRateLimitStatus, mintWithRateLimit, waitUntilCanMint, type MintWithRateLimitOptions, type MintWithRateLimitResult, type WaitUntilCanMintOptions, } from './waitUntilCanMint';
|
|
2
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/CouponMinter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/functions/CouponMinter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,GAC7B,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canMintCouponsNow = void 0;
|
|
3
|
+
exports.waitUntilCanMint = exports.mintWithRateLimit = exports.getRateLimitStatus = exports.WaitTimeoutError = exports.WaitAbortedError = exports.canMintCouponsNow = void 0;
|
|
4
4
|
var canMintCouponsNow_1 = require("./canMintCouponsNow");
|
|
5
5
|
Object.defineProperty(exports, "canMintCouponsNow", { enumerable: true, get: function () { return canMintCouponsNow_1.canMintCouponsNow; } });
|
|
6
|
+
var waitUntilCanMint_1 = require("./waitUntilCanMint");
|
|
7
|
+
Object.defineProperty(exports, "WaitAbortedError", { enumerable: true, get: function () { return waitUntilCanMint_1.WaitAbortedError; } });
|
|
8
|
+
Object.defineProperty(exports, "WaitTimeoutError", { enumerable: true, get: function () { return waitUntilCanMint_1.WaitTimeoutError; } });
|
|
9
|
+
Object.defineProperty(exports, "getRateLimitStatus", { enumerable: true, get: function () { return waitUntilCanMint_1.getRateLimitStatus; } });
|
|
10
|
+
Object.defineProperty(exports, "mintWithRateLimit", { enumerable: true, get: function () { return waitUntilCanMint_1.mintWithRateLimit; } });
|
|
11
|
+
Object.defineProperty(exports, "waitUntilCanMint", { enumerable: true, get: function () { return waitUntilCanMint_1.waitUntilCanMint; } });
|
|
6
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/CouponMinter/index.ts"],"names":[],"mappings":";;;AAAA,yDAAqH;AAA5G,sHAAA,iBAAiB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/CouponMinter/index.ts"],"names":[],"mappings":";;;AAAA,yDAAqH;AAA5G,sHAAA,iBAAiB,OAAA;AAC1B,uDAS4B;AAR1B,oHAAA,gBAAgB,OAAA;AAChB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,qHAAA,iBAAiB,OAAA;AACjB,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for waiting until coupon minting is allowed based on TPS rate limits.
|
|
3
|
+
*
|
|
4
|
+
* These utilities provide "fire and forget" style minting with automatic rate limit handling.
|
|
5
|
+
*/
|
|
6
|
+
import { type CanMintResult, type CouponMinterPayload } from './canMintCouponsNow';
|
|
7
|
+
/**
|
|
8
|
+
* Options for waiting until minting is allowed.
|
|
9
|
+
*/
|
|
10
|
+
export interface WaitUntilCanMintOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Maximum time to wait in milliseconds before giving up.
|
|
13
|
+
* @default 300000 (5 minutes)
|
|
14
|
+
*/
|
|
15
|
+
maxWaitMs?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Minimum polling interval in milliseconds when rate limited.
|
|
18
|
+
* The actual wait will use the calculated waitMs from canMintCouponsNow,
|
|
19
|
+
* but this sets a minimum interval between checks.
|
|
20
|
+
* @default 100
|
|
21
|
+
*/
|
|
22
|
+
minPollIntervalMs?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Signal to abort the wait operation.
|
|
25
|
+
* If the signal is aborted, the promise will reject with an AbortError.
|
|
26
|
+
*/
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
/**
|
|
29
|
+
* Optional callback invoked when waiting starts, providing the estimated wait time.
|
|
30
|
+
* Useful for logging or updating UI.
|
|
31
|
+
*/
|
|
32
|
+
onWaitStart?: (waitMs: number) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error thrown when the wait operation is aborted.
|
|
36
|
+
*/
|
|
37
|
+
export declare class WaitAbortedError extends Error {
|
|
38
|
+
constructor(message?: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Error thrown when the maximum wait time is exceeded.
|
|
42
|
+
*/
|
|
43
|
+
export declare class WaitTimeoutError extends Error {
|
|
44
|
+
constructor(maxWaitMs: number);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Waits until coupon minting is allowed based on the current rate limit state.
|
|
48
|
+
*
|
|
49
|
+
* This function will sleep until the rate limit allows minting, checking periodically
|
|
50
|
+
* until either minting is allowed or the maximum wait time is exceeded.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Wait until we can mint, then proceed
|
|
55
|
+
* await waitUntilCanMint(couponMinterPayload);
|
|
56
|
+
* await mintCoupons(...);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Wait with a timeout and abort support
|
|
62
|
+
* const controller = new AbortController();
|
|
63
|
+
* setTimeout(() => controller.abort(), 10000); // 10 second timeout
|
|
64
|
+
*
|
|
65
|
+
* try {
|
|
66
|
+
* await waitUntilCanMint(couponMinterPayload, {
|
|
67
|
+
* maxWaitMs: 30000,
|
|
68
|
+
* signal: controller.signal,
|
|
69
|
+
* onWaitStart: (ms) => console.log(`Waiting ${ms}ms for rate limit...`),
|
|
70
|
+
* });
|
|
71
|
+
* await mintCoupons(...);
|
|
72
|
+
* } catch (error) {
|
|
73
|
+
* if (error instanceof WaitAbortedError) {
|
|
74
|
+
* console.log('Wait was cancelled');
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param payload - The CouponMinter contract payload with rate limit state
|
|
80
|
+
* @param options - Optional configuration for the wait operation
|
|
81
|
+
* @returns Promise that resolves when minting is allowed
|
|
82
|
+
* @throws WaitAbortedError if the operation is aborted via the signal
|
|
83
|
+
* @throws WaitTimeoutError if the maximum wait time is exceeded
|
|
84
|
+
*/
|
|
85
|
+
export declare function waitUntilCanMint(payload: CouponMinterPayload, options?: WaitUntilCanMintOptions): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Result of a mintWithRateLimit operation.
|
|
88
|
+
*/
|
|
89
|
+
export interface MintWithRateLimitResult<T> {
|
|
90
|
+
/** Whether we had to wait due to rate limiting */
|
|
91
|
+
wasRateLimited: boolean;
|
|
92
|
+
/** How long we waited in milliseconds (0 if not rate limited) */
|
|
93
|
+
waitedMs: number;
|
|
94
|
+
/** The result from the mint function */
|
|
95
|
+
result: T;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Options for mintWithRateLimit operation.
|
|
99
|
+
*/
|
|
100
|
+
export interface MintWithRateLimitOptions extends WaitUntilCanMintOptions {
|
|
101
|
+
/**
|
|
102
|
+
* Callback invoked just before the mint function is called.
|
|
103
|
+
* Useful for logging or updating UI.
|
|
104
|
+
*/
|
|
105
|
+
onBeforeMint?: () => void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Waits until minting is allowed, then executes the provided mint function.
|
|
109
|
+
*
|
|
110
|
+
* This is a "fire and forget" style wrapper that handles rate limiting automatically.
|
|
111
|
+
* It waits for the rate limit to allow minting, then executes your mint function.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Simple usage with async mint function
|
|
116
|
+
* const { result, wasRateLimited, waitedMs } = await mintWithRateLimit(
|
|
117
|
+
* couponMinterPayload,
|
|
118
|
+
* async () => {
|
|
119
|
+
* return await ledgerClient.exerciseChoice(
|
|
120
|
+
* couponMinterCid,
|
|
121
|
+
* 'MintCoupons',
|
|
122
|
+
* mintParams
|
|
123
|
+
* );
|
|
124
|
+
* }
|
|
125
|
+
* );
|
|
126
|
+
* console.log(`Minting complete. Rate limited: ${wasRateLimited}, waited: ${waitedMs}ms`);
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // With callbacks for progress tracking
|
|
132
|
+
* const { result } = await mintWithRateLimit(
|
|
133
|
+
* couponMinterPayload,
|
|
134
|
+
* async () => mintCoupons(params),
|
|
135
|
+
* {
|
|
136
|
+
* onWaitStart: (ms) => console.log(`Rate limited, waiting ${ms}ms...`),
|
|
137
|
+
* onBeforeMint: () => console.log('Submitting mint transaction...'),
|
|
138
|
+
* maxWaitMs: 60000,
|
|
139
|
+
* }
|
|
140
|
+
* );
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param payload - The CouponMinter contract payload with rate limit state
|
|
144
|
+
* @param mintFn - The async function to execute once minting is allowed
|
|
145
|
+
* @param options - Optional configuration for the wait and mint operation
|
|
146
|
+
* @returns Promise resolving to the mint result along with rate limit metadata
|
|
147
|
+
* @throws WaitAbortedError if the operation is aborted via the signal
|
|
148
|
+
* @throws WaitTimeoutError if the maximum wait time is exceeded
|
|
149
|
+
* @throws Any error thrown by the mintFn
|
|
150
|
+
*/
|
|
151
|
+
export declare function mintWithRateLimit<T>(payload: CouponMinterPayload, mintFn: () => Promise<T>, options?: MintWithRateLimitOptions): Promise<MintWithRateLimitResult<T>>;
|
|
152
|
+
/**
|
|
153
|
+
* Checks the current rate limit status and returns detailed information.
|
|
154
|
+
*
|
|
155
|
+
* This is a convenience wrapper around canMintCouponsNow that provides
|
|
156
|
+
* additional context useful for UI display or logging.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const status = getRateLimitStatus(couponMinterPayload);
|
|
161
|
+
* if (status.canMint) {
|
|
162
|
+
* console.log('Ready to mint!');
|
|
163
|
+
* } else {
|
|
164
|
+
* console.log(`Rate limited. Can mint in ${status.waitMs}ms (${status.waitSeconds.toFixed(1)}s)`);
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @param payload - The CouponMinter contract payload
|
|
169
|
+
* @param now - Optional current time for testing
|
|
170
|
+
* @returns Detailed rate limit status information
|
|
171
|
+
*/
|
|
172
|
+
export declare function getRateLimitStatus(payload: CouponMinterPayload, now?: Date): CanMintResult & {
|
|
173
|
+
waitSeconds?: number;
|
|
174
|
+
isRateLimitEnabled: boolean;
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=waitUntilCanMint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitUntilCanMint.d.ts","sourceRoot":"","sources":["../../../src/functions/CouponMinter/waitUntilCanMint.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAQtG;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,SAA+B;CAInD;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,SAAS,EAAE,MAAM;CAI9B;AAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyCrH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,kDAAkD;IAClD,cAAc,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,MAAM,EAAE,CAAC,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,uBAAuB;IACvE;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAyBrC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,mBAAmB,EAC5B,GAAG,CAAC,EAAE,IAAI,GACT,aAAa,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,CAgBvE"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for waiting until coupon minting is allowed based on TPS rate limits.
|
|
4
|
+
*
|
|
5
|
+
* These utilities provide "fire and forget" style minting with automatic rate limit handling.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.WaitTimeoutError = exports.WaitAbortedError = void 0;
|
|
9
|
+
exports.waitUntilCanMint = waitUntilCanMint;
|
|
10
|
+
exports.mintWithRateLimit = mintWithRateLimit;
|
|
11
|
+
exports.getRateLimitStatus = getRateLimitStatus;
|
|
12
|
+
const canMintCouponsNow_1 = require("./canMintCouponsNow");
|
|
13
|
+
/** Default polling interval when waiting for mint readiness (in milliseconds) */
|
|
14
|
+
const DEFAULT_POLL_INTERVAL_MS = 100;
|
|
15
|
+
/** Maximum wait time to prevent infinite waiting (5 minutes) */
|
|
16
|
+
const DEFAULT_MAX_WAIT_MS = 5 * 60 * 1000;
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when the wait operation is aborted.
|
|
19
|
+
*/
|
|
20
|
+
class WaitAbortedError extends Error {
|
|
21
|
+
constructor(message = 'Wait operation was aborted') {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'WaitAbortedError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.WaitAbortedError = WaitAbortedError;
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when the maximum wait time is exceeded.
|
|
29
|
+
*/
|
|
30
|
+
class WaitTimeoutError extends Error {
|
|
31
|
+
constructor(maxWaitMs) {
|
|
32
|
+
super(`Maximum wait time of ${maxWaitMs}ms exceeded while waiting for rate limit`);
|
|
33
|
+
this.name = 'WaitTimeoutError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.WaitTimeoutError = WaitTimeoutError;
|
|
37
|
+
/**
|
|
38
|
+
* Sleeps for the specified duration, respecting abort signals.
|
|
39
|
+
*
|
|
40
|
+
* @param ms - Duration to sleep in milliseconds
|
|
41
|
+
* @param signal - Optional abort signal
|
|
42
|
+
* @returns Promise that resolves after the sleep duration
|
|
43
|
+
* @throws WaitAbortedError if the signal is aborted during sleep
|
|
44
|
+
*/
|
|
45
|
+
async function sleep(ms, signal) {
|
|
46
|
+
if (signal?.aborted) {
|
|
47
|
+
throw new WaitAbortedError();
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const timeout = setTimeout(resolve, ms);
|
|
51
|
+
if (signal) {
|
|
52
|
+
const abortHandler = () => {
|
|
53
|
+
clearTimeout(timeout);
|
|
54
|
+
reject(new WaitAbortedError());
|
|
55
|
+
};
|
|
56
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
57
|
+
// Clean up the abort handler when the sleep completes
|
|
58
|
+
const originalResolve = resolve;
|
|
59
|
+
const wrappedResolve = () => {
|
|
60
|
+
signal.removeEventListener('abort', abortHandler);
|
|
61
|
+
originalResolve();
|
|
62
|
+
};
|
|
63
|
+
clearTimeout(timeout);
|
|
64
|
+
setTimeout(wrappedResolve, ms);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Waits until coupon minting is allowed based on the current rate limit state.
|
|
70
|
+
*
|
|
71
|
+
* This function will sleep until the rate limit allows minting, checking periodically
|
|
72
|
+
* until either minting is allowed or the maximum wait time is exceeded.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Wait until we can mint, then proceed
|
|
77
|
+
* await waitUntilCanMint(couponMinterPayload);
|
|
78
|
+
* await mintCoupons(...);
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Wait with a timeout and abort support
|
|
84
|
+
* const controller = new AbortController();
|
|
85
|
+
* setTimeout(() => controller.abort(), 10000); // 10 second timeout
|
|
86
|
+
*
|
|
87
|
+
* try {
|
|
88
|
+
* await waitUntilCanMint(couponMinterPayload, {
|
|
89
|
+
* maxWaitMs: 30000,
|
|
90
|
+
* signal: controller.signal,
|
|
91
|
+
* onWaitStart: (ms) => console.log(`Waiting ${ms}ms for rate limit...`),
|
|
92
|
+
* });
|
|
93
|
+
* await mintCoupons(...);
|
|
94
|
+
* } catch (error) {
|
|
95
|
+
* if (error instanceof WaitAbortedError) {
|
|
96
|
+
* console.log('Wait was cancelled');
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param payload - The CouponMinter contract payload with rate limit state
|
|
102
|
+
* @param options - Optional configuration for the wait operation
|
|
103
|
+
* @returns Promise that resolves when minting is allowed
|
|
104
|
+
* @throws WaitAbortedError if the operation is aborted via the signal
|
|
105
|
+
* @throws WaitTimeoutError if the maximum wait time is exceeded
|
|
106
|
+
*/
|
|
107
|
+
async function waitUntilCanMint(payload, options) {
|
|
108
|
+
const { maxWaitMs = DEFAULT_MAX_WAIT_MS, minPollIntervalMs = DEFAULT_POLL_INTERVAL_MS, signal, onWaitStart, } = options ?? {};
|
|
109
|
+
if (signal?.aborted) {
|
|
110
|
+
throw new WaitAbortedError();
|
|
111
|
+
}
|
|
112
|
+
const startTime = Date.now();
|
|
113
|
+
// Initial check
|
|
114
|
+
let result = (0, canMintCouponsNow_1.canMintCouponsNow)(payload);
|
|
115
|
+
while (!result.canMint) {
|
|
116
|
+
const elapsed = Date.now() - startTime;
|
|
117
|
+
// Check if we've exceeded max wait time
|
|
118
|
+
if (elapsed >= maxWaitMs) {
|
|
119
|
+
throw new WaitTimeoutError(maxWaitMs);
|
|
120
|
+
}
|
|
121
|
+
// Calculate wait time (use the larger of waitMs and minPollIntervalMs)
|
|
122
|
+
const waitMs = Math.max(result.waitMs, minPollIntervalMs);
|
|
123
|
+
// Don't wait longer than remaining max wait time
|
|
124
|
+
const remainingTime = maxWaitMs - elapsed;
|
|
125
|
+
const actualWaitMs = Math.min(waitMs, remainingTime);
|
|
126
|
+
// Notify callback if provided
|
|
127
|
+
onWaitStart?.(actualWaitMs);
|
|
128
|
+
// Sleep for the calculated duration
|
|
129
|
+
await sleep(actualWaitMs, signal);
|
|
130
|
+
// Re-check with current time
|
|
131
|
+
result = (0, canMintCouponsNow_1.canMintCouponsNow)(payload);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Waits until minting is allowed, then executes the provided mint function.
|
|
136
|
+
*
|
|
137
|
+
* This is a "fire and forget" style wrapper that handles rate limiting automatically.
|
|
138
|
+
* It waits for the rate limit to allow minting, then executes your mint function.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Simple usage with async mint function
|
|
143
|
+
* const { result, wasRateLimited, waitedMs } = await mintWithRateLimit(
|
|
144
|
+
* couponMinterPayload,
|
|
145
|
+
* async () => {
|
|
146
|
+
* return await ledgerClient.exerciseChoice(
|
|
147
|
+
* couponMinterCid,
|
|
148
|
+
* 'MintCoupons',
|
|
149
|
+
* mintParams
|
|
150
|
+
* );
|
|
151
|
+
* }
|
|
152
|
+
* );
|
|
153
|
+
* console.log(`Minting complete. Rate limited: ${wasRateLimited}, waited: ${waitedMs}ms`);
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* // With callbacks for progress tracking
|
|
159
|
+
* const { result } = await mintWithRateLimit(
|
|
160
|
+
* couponMinterPayload,
|
|
161
|
+
* async () => mintCoupons(params),
|
|
162
|
+
* {
|
|
163
|
+
* onWaitStart: (ms) => console.log(`Rate limited, waiting ${ms}ms...`),
|
|
164
|
+
* onBeforeMint: () => console.log('Submitting mint transaction...'),
|
|
165
|
+
* maxWaitMs: 60000,
|
|
166
|
+
* }
|
|
167
|
+
* );
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @param payload - The CouponMinter contract payload with rate limit state
|
|
171
|
+
* @param mintFn - The async function to execute once minting is allowed
|
|
172
|
+
* @param options - Optional configuration for the wait and mint operation
|
|
173
|
+
* @returns Promise resolving to the mint result along with rate limit metadata
|
|
174
|
+
* @throws WaitAbortedError if the operation is aborted via the signal
|
|
175
|
+
* @throws WaitTimeoutError if the maximum wait time is exceeded
|
|
176
|
+
* @throws Any error thrown by the mintFn
|
|
177
|
+
*/
|
|
178
|
+
async function mintWithRateLimit(payload, mintFn, options) {
|
|
179
|
+
const startTime = Date.now();
|
|
180
|
+
// Check initial rate limit status
|
|
181
|
+
const initialCheck = (0, canMintCouponsNow_1.canMintCouponsNow)(payload);
|
|
182
|
+
const wasRateLimited = !initialCheck.canMint;
|
|
183
|
+
// Wait if necessary
|
|
184
|
+
if (wasRateLimited) {
|
|
185
|
+
await waitUntilCanMint(payload, options);
|
|
186
|
+
}
|
|
187
|
+
const waitedMs = Date.now() - startTime;
|
|
188
|
+
// Notify before mint callback
|
|
189
|
+
options?.onBeforeMint?.();
|
|
190
|
+
// Execute the mint function
|
|
191
|
+
const result = await mintFn();
|
|
192
|
+
return {
|
|
193
|
+
wasRateLimited,
|
|
194
|
+
waitedMs,
|
|
195
|
+
result,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Checks the current rate limit status and returns detailed information.
|
|
200
|
+
*
|
|
201
|
+
* This is a convenience wrapper around canMintCouponsNow that provides
|
|
202
|
+
* additional context useful for UI display or logging.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const status = getRateLimitStatus(couponMinterPayload);
|
|
207
|
+
* if (status.canMint) {
|
|
208
|
+
* console.log('Ready to mint!');
|
|
209
|
+
* } else {
|
|
210
|
+
* console.log(`Rate limited. Can mint in ${status.waitMs}ms (${status.waitSeconds.toFixed(1)}s)`);
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @param payload - The CouponMinter contract payload
|
|
215
|
+
* @param now - Optional current time for testing
|
|
216
|
+
* @returns Detailed rate limit status information
|
|
217
|
+
*/
|
|
218
|
+
function getRateLimitStatus(payload, now) {
|
|
219
|
+
const result = (0, canMintCouponsNow_1.canMintCouponsNow)(payload, now);
|
|
220
|
+
const isRateLimitEnabled = payload.maxTps !== null;
|
|
221
|
+
if (result.canMint) {
|
|
222
|
+
return {
|
|
223
|
+
...result,
|
|
224
|
+
isRateLimitEnabled,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
...result,
|
|
229
|
+
waitSeconds: result.waitMs / 1000,
|
|
230
|
+
isRateLimitEnabled,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=waitUntilCanMint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitUntilCanMint.js","sourceRoot":"","sources":["../../../src/functions/CouponMinter/waitUntilCanMint.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAuIH,4CAyCC;AAqED,8CA6BC;AAsBD,gDAmBC;AAzTD,2DAAsG;AAEtG,iFAAiF;AACjF,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,gEAAgE;AAChE,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAiC1C;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAO,GAAG,4BAA4B;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC;AAED;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,SAAiB;QAC3B,KAAK,CAAC,wBAAwB,SAAS,0CAA0C,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,KAAK,CAAC,EAAU,EAAE,MAAoB;IACnD,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,gBAAgB,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAExC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,YAAY,GAAG,GAAS,EAAE;gBAC9B,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,MAAM,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,E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AAC,OAAO,EAAE,CAAC;QACnB,OAAO;YACL,GAAG,MAAM;YACT,kBAAkB;SACnB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,WAAW,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI;QACjC,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -71,7 +71,8 @@ export declare class CapTableBatch {
|
|
|
71
71
|
* Build and execute the batch update.
|
|
72
72
|
*
|
|
73
73
|
* @returns The result containing the updated cap table contract ID and affected entity IDs
|
|
74
|
-
* @throws
|
|
74
|
+
* @throws OcpValidationError if no client was provided or if the batch is empty
|
|
75
|
+
* @throws OcpContractError if the UpdateCapTable result is not found in the transaction tree
|
|
75
76
|
*/
|
|
76
77
|
execute(): Promise<UpdateCapTableResult>;
|
|
77
78
|
/** Clear all operations from the batch. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CapTableBatch.d.ts","sourceRoot":"","sources":["../../../../src/functions/OpenCapTable/capTable/CapTableBatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,kFAAkF,CAAC;
|
|
1
|
+
{"version":3,"file":"CapTableBatch.d.ts","sourceRoot":"","sources":["../../../../src/functions/OpenCapTable/capTable/CapTableBatch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,kFAAkF,CAAC;AAG1F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAGL,KAAK,cAAc,EAGnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAGtB,kDAAkD;AAClD,MAAM,WAAW,mBAAmB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,mBAAmB,EAAE,OAAO,GAAG,QAAQ,CAAC,EACrD,UAAU,EAAE;IACV,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;KAAE,CAAC,CAAC;IAC9E,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;KAAE,CAAC,CAAC;IAC5E,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtD,GACA,6BAA6B,CAc/B"}
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.CapTableBatch = void 0;
|
|
10
10
|
exports.buildUpdateCapTableCommand = buildUpdateCapTableCommand;
|
|
11
11
|
const open_captable_protocol_daml_js_1 = require("@fairmint/open-captable-protocol-daml-js");
|
|
12
|
+
const errors_1 = require("../../../errors");
|
|
12
13
|
const batchTypes_1 = require("./batchTypes");
|
|
13
14
|
const ocfToDaml_1 = require("./ocfToDaml");
|
|
14
15
|
/**
|
|
@@ -77,7 +78,9 @@ class CapTableBatch {
|
|
|
77
78
|
*/
|
|
78
79
|
build() {
|
|
79
80
|
if (this.isEmpty) {
|
|
80
|
-
throw new
|
|
81
|
+
throw new errors_1.OcpValidationError('batch', 'Cannot build empty batch - add at least one create, edit, or delete operation', {
|
|
82
|
+
code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
|
|
83
|
+
});
|
|
81
84
|
}
|
|
82
85
|
// Use the templateId from capTableContractDetails when provided (from actual ledger),
|
|
83
86
|
// otherwise fall back to the DAML-JS package's hardcoded templateId.
|
|
@@ -108,11 +111,14 @@ class CapTableBatch {
|
|
|
108
111
|
* Build and execute the batch update.
|
|
109
112
|
*
|
|
110
113
|
* @returns The result containing the updated cap table contract ID and affected entity IDs
|
|
111
|
-
* @throws
|
|
114
|
+
* @throws OcpValidationError if no client was provided or if the batch is empty
|
|
115
|
+
* @throws OcpContractError if the UpdateCapTable result is not found in the transaction tree
|
|
112
116
|
*/
|
|
113
117
|
async execute() {
|
|
114
118
|
if (!this.client) {
|
|
115
|
-
throw new
|
|
119
|
+
throw new errors_1.OcpValidationError('client', 'Cannot execute batch without a client - use build() instead and submit manually', {
|
|
120
|
+
code: errors_1.OcpErrorCodes.REQUIRED_FIELD_MISSING,
|
|
121
|
+
});
|
|
116
122
|
}
|
|
117
123
|
const { command, disclosedContracts } = this.build();
|
|
118
124
|
const response = await this.client.submitAndWaitForTransactionTree({
|
|
@@ -138,7 +144,11 @@ class CapTableBatch {
|
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
|
-
throw new
|
|
147
|
+
throw new errors_1.OcpContractError('UpdateCapTable result not found in transaction tree', {
|
|
148
|
+
contractId: this.params.capTableContractId,
|
|
149
|
+
choice: 'UpdateCapTable',
|
|
150
|
+
code: errors_1.OcpErrorCodes.RESULT_NOT_FOUND,
|
|
151
|
+
});
|
|
142
152
|
}
|
|
143
153
|
/** Clear all operations from the batch. */
|
|
144
154
|
clear() {
|