starknet 3.15.5 → 3.16.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.
- package/CHANGELOG.md +18 -0
- package/__tests__/fixtures.ts +1 -1
- package/dist/provider/default.js +12 -3
- package/dist/provider/errors.d.ts +9 -0
- package/dist/provider/errors.js +40 -0
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/index.js +2 -3
- package/dist/provider/utils.d.ts +0 -5
- package/dist/provider/utils.js +1 -27
- package/package.json +1 -1
- package/provider/default.js +11 -3
- package/provider/errors.d.ts +9 -0
- package/provider/errors.js +50 -0
- package/provider/index.d.ts +1 -1
- package/provider/index.js +2 -8
- package/provider/utils.d.ts +0 -6
- package/provider/utils.js +1 -38
- package/src/provider/default.ts +11 -3
- package/src/provider/errors.ts +14 -0
- package/src/provider/index.ts +1 -1
- package/src/provider/utils.ts +0 -8
- package/.github/workflows/pr.yml +0 -28
- package/.github/workflows/release.yml +0 -69
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/tsconfig.json +0 -107
- package/www/tsconfig.json +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [3.16.1](https://github.com/0xs34n/starknet.js/compare/v3.16.0...v3.16.1) (2022-07-02)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **test:** for new devnet version ([63d145f](https://github.com/0xs34n/starknet.js/commit/63d145f1fba90cca9e679f115525801ee140ceec))
|
|
6
|
+
|
|
7
|
+
# [3.16.0](https://github.com/0xs34n/starknet.js/compare/v3.15.6...v3.16.0) (2022-06-29)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- **npm:** add npmignore file ([e6084dd](https://github.com/0xs34n/starknet.js/commit/e6084ddbb9ea305847a312cd3a3247b730cca9b5))
|
|
12
|
+
|
|
13
|
+
## [3.15.6](https://github.com/0xs34n/starknet.js/compare/v3.15.5...v3.15.6) (2022-06-28)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- throw http error when parsing fails ([898574f](https://github.com/0xs34n/starknet.js/commit/898574f0087bf653b5d74bbe3dc52a0cb6efc432))
|
|
18
|
+
|
|
1
19
|
## [3.15.5](https://github.com/0xs34n/starknet.js/compare/v3.15.4...v3.15.5) (2022-06-27)
|
|
2
20
|
|
|
3
21
|
### Bug Fixes
|
package/__tests__/fixtures.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const compiledTestDapp = readContract('TestDapp');
|
|
|
14
14
|
|
|
15
15
|
const DEFAULT_TEST_PROVIDER_BASE_URL = 'http://127.0.0.1:5050/';
|
|
16
16
|
const DEFAULT_TEST_ACCOUNT_ADDRESS = // run `starknet-devnet --seed 0` and this will be the first account
|
|
17
|
-
'
|
|
17
|
+
'0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a';
|
|
18
18
|
const DEFAULT_TEST_ACCOUNT_PRIVATE_KEY = '0xe3e70682c2094cac629f6fbed82c07cd';
|
|
19
19
|
|
|
20
20
|
const BASE_URL = process.env.TEST_PROVIDER_BASE_URL || DEFAULT_TEST_PROVIDER_BASE_URL;
|
package/dist/provider/default.js
CHANGED
|
@@ -73,6 +73,7 @@ var hash_1 = require("../utils/hash");
|
|
|
73
73
|
var json_1 = require("../utils/json");
|
|
74
74
|
var number_1 = require("../utils/number");
|
|
75
75
|
var stark_1 = require("../utils/stark");
|
|
76
|
+
var errors_1 = require("./errors");
|
|
76
77
|
var interface_1 = require("./interface");
|
|
77
78
|
var utils_1 = require("./utils");
|
|
78
79
|
function wait(delay) {
|
|
@@ -206,9 +207,16 @@ var Provider = /** @class */ (function () {
|
|
|
206
207
|
case 3:
|
|
207
208
|
textResponse = _c.sent();
|
|
208
209
|
if (!res.ok) {
|
|
209
|
-
responseBody =
|
|
210
|
+
responseBody = void 0;
|
|
211
|
+
try {
|
|
212
|
+
responseBody = (0, json_1.parse)(textResponse);
|
|
213
|
+
}
|
|
214
|
+
catch (_d) {
|
|
215
|
+
// if error parsing fails, return an http error
|
|
216
|
+
throw new errors_1.HttpError(res.statusText, res.status);
|
|
217
|
+
}
|
|
210
218
|
errorCode = responseBody.code || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.status_code);
|
|
211
|
-
throw new
|
|
219
|
+
throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
|
|
212
220
|
}
|
|
213
221
|
if (endpoint === 'estimate_fee') {
|
|
214
222
|
return [2 /*return*/, (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
|
|
@@ -221,7 +229,8 @@ var Provider = /** @class */ (function () {
|
|
|
221
229
|
return [2 /*return*/, (0, json_1.parse)(textResponse)];
|
|
222
230
|
case 4:
|
|
223
231
|
err_1 = _c.sent();
|
|
224
|
-
|
|
232
|
+
// rethrow custom errors
|
|
233
|
+
if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
|
|
225
234
|
throw err_1;
|
|
226
235
|
}
|
|
227
236
|
if (err_1 instanceof Error) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CustomError } from 'ts-custom-error';
|
|
2
|
+
export declare class GatewayError extends CustomError {
|
|
3
|
+
errorCode: string;
|
|
4
|
+
constructor(message: string, errorCode: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class HttpError extends CustomError {
|
|
7
|
+
errorCode: number;
|
|
8
|
+
constructor(message: string, errorCode: number);
|
|
9
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HttpError = exports.GatewayError = void 0;
|
|
19
|
+
/* eslint-disable max-classes-per-file */
|
|
20
|
+
var ts_custom_error_1 = require("ts-custom-error");
|
|
21
|
+
var GatewayError = /** @class */ (function (_super) {
|
|
22
|
+
__extends(GatewayError, _super);
|
|
23
|
+
function GatewayError(message, errorCode) {
|
|
24
|
+
var _this = _super.call(this, message) || this;
|
|
25
|
+
_this.errorCode = errorCode;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
return GatewayError;
|
|
29
|
+
}(ts_custom_error_1.CustomError));
|
|
30
|
+
exports.GatewayError = GatewayError;
|
|
31
|
+
var HttpError = /** @class */ (function (_super) {
|
|
32
|
+
__extends(HttpError, _super);
|
|
33
|
+
function HttpError(message, errorCode) {
|
|
34
|
+
var _this = _super.call(this, message) || this;
|
|
35
|
+
_this.errorCode = errorCode;
|
|
36
|
+
return _this;
|
|
37
|
+
}
|
|
38
|
+
return HttpError;
|
|
39
|
+
}(ts_custom_error_1.CustomError));
|
|
40
|
+
exports.HttpError = HttpError;
|
package/dist/provider/index.d.ts
CHANGED
package/dist/provider/index.js
CHANGED
|
@@ -14,10 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.defaultProvider =
|
|
17
|
+
exports.defaultProvider = void 0;
|
|
18
18
|
var default_1 = require("./default");
|
|
19
19
|
__exportStar(require("./default"), exports);
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "GatewayError", { enumerable: true, get: function () { return utils_1.GatewayError; } });
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
|
22
21
|
__exportStar(require("./interface"), exports);
|
|
23
22
|
exports.defaultProvider = new default_1.Provider();
|
package/dist/provider/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CustomError } from 'ts-custom-error';
|
|
2
1
|
import type { BlockNumber } from '../types';
|
|
3
2
|
import { BigNumberish } from '../utils/number';
|
|
4
3
|
/**
|
|
@@ -40,8 +39,4 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
40
39
|
* @returns block identifier for API request
|
|
41
40
|
*/
|
|
42
41
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
|
43
|
-
export declare class GatewayError extends CustomError {
|
|
44
|
-
errorCode: string;
|
|
45
|
-
constructor(message: string, errorCode: string);
|
|
46
|
-
}
|
|
47
42
|
export {};
|
package/dist/provider/utils.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
var ts_custom_error_1 = require("ts-custom-error");
|
|
3
|
+
exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
|
|
20
4
|
var number_1 = require("../utils/number");
|
|
21
5
|
/**
|
|
22
6
|
*
|
|
@@ -93,13 +77,3 @@ function getFormattedBlockIdentifier(blockIdentifier) {
|
|
|
93
77
|
return "blockHash=".concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
|
|
94
78
|
}
|
|
95
79
|
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
|
96
|
-
var GatewayError = /** @class */ (function (_super) {
|
|
97
|
-
__extends(GatewayError, _super);
|
|
98
|
-
function GatewayError(message, errorCode) {
|
|
99
|
-
var _this = _super.call(this, message) || this;
|
|
100
|
-
_this.errorCode = errorCode;
|
|
101
|
-
return _this;
|
|
102
|
-
}
|
|
103
|
-
return GatewayError;
|
|
104
|
-
}(ts_custom_error_1.CustomError));
|
|
105
|
-
exports.GatewayError = GatewayError;
|
package/package.json
CHANGED
package/provider/default.js
CHANGED
|
@@ -179,6 +179,7 @@ var hash_1 = require('../utils/hash');
|
|
|
179
179
|
var json_1 = require('../utils/json');
|
|
180
180
|
var number_1 = require('../utils/number');
|
|
181
181
|
var stark_1 = require('../utils/stark');
|
|
182
|
+
var errors_1 = require('./errors');
|
|
182
183
|
var interface_1 = require('./interface');
|
|
183
184
|
var utils_1 = require('./utils');
|
|
184
185
|
function wait(delay) {
|
|
@@ -333,13 +334,19 @@ var Provider = /** @class */ (function () {
|
|
|
333
334
|
case 3:
|
|
334
335
|
textResponse = _c.sent();
|
|
335
336
|
if (!res.ok) {
|
|
336
|
-
responseBody =
|
|
337
|
+
responseBody = void 0;
|
|
338
|
+
try {
|
|
339
|
+
responseBody = (0, json_1.parse)(textResponse);
|
|
340
|
+
} catch (_d) {
|
|
341
|
+
// if error parsing fails, return an http error
|
|
342
|
+
throw new errors_1.HttpError(res.statusText, res.status);
|
|
343
|
+
}
|
|
337
344
|
errorCode =
|
|
338
345
|
responseBody.code ||
|
|
339
346
|
(responseBody === null || responseBody === void 0
|
|
340
347
|
? void 0
|
|
341
348
|
: responseBody.status_code);
|
|
342
|
-
throw new
|
|
349
|
+
throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
|
|
343
350
|
}
|
|
344
351
|
if (endpoint === 'estimate_fee') {
|
|
345
352
|
return [
|
|
@@ -355,7 +362,8 @@ var Provider = /** @class */ (function () {
|
|
|
355
362
|
return [2 /*return*/, (0, json_1.parse)(textResponse)];
|
|
356
363
|
case 4:
|
|
357
364
|
err_1 = _c.sent();
|
|
358
|
-
|
|
365
|
+
// rethrow custom errors
|
|
366
|
+
if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
|
|
359
367
|
throw err_1;
|
|
360
368
|
}
|
|
361
369
|
if (err_1 instanceof Error) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CustomError } from 'ts-custom-error';
|
|
2
|
+
export declare class GatewayError extends CustomError {
|
|
3
|
+
errorCode: string;
|
|
4
|
+
constructor(message: string, errorCode: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class HttpError extends CustomError {
|
|
7
|
+
errorCode: number;
|
|
8
|
+
constructor(message: string, errorCode: number);
|
|
9
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __extends =
|
|
3
|
+
(this && this.__extends) ||
|
|
4
|
+
(function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics =
|
|
7
|
+
Object.setPrototypeOf ||
|
|
8
|
+
({ __proto__: [] } instanceof Array &&
|
|
9
|
+
function (d, b) {
|
|
10
|
+
d.__proto__ = b;
|
|
11
|
+
}) ||
|
|
12
|
+
function (d, b) {
|
|
13
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
14
|
+
};
|
|
15
|
+
return extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
if (typeof b !== 'function' && b !== null)
|
|
19
|
+
throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
|
|
20
|
+
extendStatics(d, b);
|
|
21
|
+
function __() {
|
|
22
|
+
this.constructor = d;
|
|
23
|
+
}
|
|
24
|
+
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
28
|
+
exports.HttpError = exports.GatewayError = void 0;
|
|
29
|
+
/* eslint-disable max-classes-per-file */
|
|
30
|
+
var ts_custom_error_1 = require('ts-custom-error');
|
|
31
|
+
var GatewayError = /** @class */ (function (_super) {
|
|
32
|
+
__extends(GatewayError, _super);
|
|
33
|
+
function GatewayError(message, errorCode) {
|
|
34
|
+
var _this = _super.call(this, message) || this;
|
|
35
|
+
_this.errorCode = errorCode;
|
|
36
|
+
return _this;
|
|
37
|
+
}
|
|
38
|
+
return GatewayError;
|
|
39
|
+
})(ts_custom_error_1.CustomError);
|
|
40
|
+
exports.GatewayError = GatewayError;
|
|
41
|
+
var HttpError = /** @class */ (function (_super) {
|
|
42
|
+
__extends(HttpError, _super);
|
|
43
|
+
function HttpError(message, errorCode) {
|
|
44
|
+
var _this = _super.call(this, message) || this;
|
|
45
|
+
_this.errorCode = errorCode;
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
return HttpError;
|
|
49
|
+
})(ts_custom_error_1.CustomError);
|
|
50
|
+
exports.HttpError = HttpError;
|
package/provider/index.d.ts
CHANGED
package/provider/index.js
CHANGED
|
@@ -27,15 +27,9 @@ var __exportStar =
|
|
|
27
27
|
__createBinding(exports, m, p);
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
30
|
-
exports.defaultProvider =
|
|
30
|
+
exports.defaultProvider = void 0;
|
|
31
31
|
var default_1 = require('./default');
|
|
32
32
|
__exportStar(require('./default'), exports);
|
|
33
|
-
|
|
34
|
-
Object.defineProperty(exports, 'GatewayError', {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () {
|
|
37
|
-
return utils_1.GatewayError;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
33
|
+
__exportStar(require('./errors'), exports);
|
|
40
34
|
__exportStar(require('./interface'), exports);
|
|
41
35
|
exports.defaultProvider = new default_1.Provider();
|
package/provider/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CustomError } from 'ts-custom-error';
|
|
2
|
-
|
|
3
1
|
import type { BlockNumber } from '../types';
|
|
4
2
|
import { BigNumberish } from '../utils/number';
|
|
5
3
|
/**
|
|
@@ -43,8 +41,4 @@ export declare function getBlockIdentifier(blockIdentifier: BlockIdentifier): Bl
|
|
|
43
41
|
* @returns block identifier for API request
|
|
44
42
|
*/
|
|
45
43
|
export declare function getFormattedBlockIdentifier(blockIdentifier?: BlockIdentifier): string;
|
|
46
|
-
export declare class GatewayError extends CustomError {
|
|
47
|
-
errorCode: string;
|
|
48
|
-
constructor(message: string, errorCode: string);
|
|
49
|
-
}
|
|
50
44
|
export {};
|
package/provider/utils.js
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __extends =
|
|
3
|
-
(this && this.__extends) ||
|
|
4
|
-
(function () {
|
|
5
|
-
var extendStatics = function (d, b) {
|
|
6
|
-
extendStatics =
|
|
7
|
-
Object.setPrototypeOf ||
|
|
8
|
-
({ __proto__: [] } instanceof Array &&
|
|
9
|
-
function (d, b) {
|
|
10
|
-
d.__proto__ = b;
|
|
11
|
-
}) ||
|
|
12
|
-
function (d, b) {
|
|
13
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
14
|
-
};
|
|
15
|
-
return extendStatics(d, b);
|
|
16
|
-
};
|
|
17
|
-
return function (d, b) {
|
|
18
|
-
if (typeof b !== 'function' && b !== null)
|
|
19
|
-
throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null');
|
|
20
|
-
extendStatics(d, b);
|
|
21
|
-
function __() {
|
|
22
|
-
this.constructor = d;
|
|
23
|
-
}
|
|
24
|
-
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
27
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
28
|
-
exports.
|
|
29
|
-
exports.getFormattedBlockIdentifier =
|
|
3
|
+
exports.getFormattedBlockIdentifier =
|
|
30
4
|
exports.getBlockIdentifier =
|
|
31
5
|
exports.txIdentifier =
|
|
32
6
|
exports.formatHash =
|
|
33
7
|
void 0;
|
|
34
|
-
var ts_custom_error_1 = require('ts-custom-error');
|
|
35
8
|
var number_1 = require('../utils/number');
|
|
36
9
|
/**
|
|
37
10
|
*
|
|
@@ -109,13 +82,3 @@ function getFormattedBlockIdentifier(blockIdentifier) {
|
|
|
109
82
|
return 'blockHash='.concat((0, number_1.toHex)((0, number_1.toBN)(blockIdentifierObject.data)));
|
|
110
83
|
}
|
|
111
84
|
exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
|
|
112
|
-
var GatewayError = /** @class */ (function (_super) {
|
|
113
|
-
__extends(GatewayError, _super);
|
|
114
|
-
function GatewayError(message, errorCode) {
|
|
115
|
-
var _this = _super.call(this, message) || this;
|
|
116
|
-
_this.errorCode = errorCode;
|
|
117
|
-
return _this;
|
|
118
|
-
}
|
|
119
|
-
return GatewayError;
|
|
120
|
-
})(ts_custom_error_1.CustomError);
|
|
121
|
-
exports.GatewayError = GatewayError;
|
package/src/provider/default.ts
CHANGED
|
@@ -23,8 +23,9 @@ import { getSelectorFromName } from '../utils/hash';
|
|
|
23
23
|
import { parse, parseAlwaysAsBig, stringify } from '../utils/json';
|
|
24
24
|
import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
|
|
25
25
|
import { compressProgram, randomAddress } from '../utils/stark';
|
|
26
|
+
import { GatewayError, HttpError } from './errors';
|
|
26
27
|
import { ProviderInterface } from './interface';
|
|
27
|
-
import { BlockIdentifier,
|
|
28
|
+
import { BlockIdentifier, getFormattedBlockIdentifier } from './utils';
|
|
28
29
|
|
|
29
30
|
type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
|
|
30
31
|
|
|
@@ -162,7 +163,13 @@ export class Provider implements ProviderInterface {
|
|
|
162
163
|
const textResponse = await res.text();
|
|
163
164
|
if (!res.ok) {
|
|
164
165
|
// This will allow user to handle contract errors
|
|
165
|
-
|
|
166
|
+
let responseBody: any;
|
|
167
|
+
try {
|
|
168
|
+
responseBody = parse(textResponse);
|
|
169
|
+
} catch {
|
|
170
|
+
// if error parsing fails, return an http error
|
|
171
|
+
throw new HttpError(res.statusText, res.status);
|
|
172
|
+
}
|
|
166
173
|
|
|
167
174
|
const errorCode = responseBody.code || ((responseBody as any)?.status_code as string); // starknet-devnet uses status_code instead of code; They need to fix that
|
|
168
175
|
throw new GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
|
|
@@ -178,7 +185,8 @@ export class Provider implements ProviderInterface {
|
|
|
178
185
|
}
|
|
179
186
|
return parse(textResponse) as Endpoints[T]['RESPONSE'];
|
|
180
187
|
} catch (err) {
|
|
181
|
-
|
|
188
|
+
// rethrow custom errors
|
|
189
|
+
if (err instanceof GatewayError || err instanceof HttpError) {
|
|
182
190
|
throw err;
|
|
183
191
|
}
|
|
184
192
|
if (err instanceof Error) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { CustomError } from 'ts-custom-error';
|
|
3
|
+
|
|
4
|
+
export class GatewayError extends CustomError {
|
|
5
|
+
constructor(message: string, public errorCode: string) {
|
|
6
|
+
super(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class HttpError extends CustomError {
|
|
11
|
+
constructor(message: string, public errorCode: number) {
|
|
12
|
+
super(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/provider/index.ts
CHANGED
package/src/provider/utils.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CustomError } from 'ts-custom-error';
|
|
2
|
-
|
|
3
1
|
import type { BlockNumber } from '../types';
|
|
4
2
|
import { BigNumberish, toBN, toHex } from '../utils/number';
|
|
5
3
|
|
|
@@ -84,9 +82,3 @@ export function getFormattedBlockIdentifier(blockIdentifier: BlockIdentifier = n
|
|
|
84
82
|
}
|
|
85
83
|
return `blockHash=${toHex(toBN(blockIdentifierObject.data))}`;
|
|
86
84
|
}
|
|
87
|
-
|
|
88
|
-
export class GatewayError extends CustomError {
|
|
89
|
-
constructor(message: string, public errorCode: string) {
|
|
90
|
-
super(message);
|
|
91
|
-
}
|
|
92
|
-
}
|
package/.github/workflows/pr.yml
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: PR check
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
- develop
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build-and-test:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
|
|
12
|
-
env:
|
|
13
|
-
TEST_PROVIDER_BASE_URL: http://127.0.0.1:5050/
|
|
14
|
-
services:
|
|
15
|
-
devnet:
|
|
16
|
-
image: janek2601/starknet-devnet-patched
|
|
17
|
-
ports:
|
|
18
|
-
- 5050:5050
|
|
19
|
-
|
|
20
|
-
steps:
|
|
21
|
-
- uses: actions/checkout@v2
|
|
22
|
-
- name: Use Node.js 14
|
|
23
|
-
uses: actions/setup-node@v2
|
|
24
|
-
with:
|
|
25
|
-
node-version: lts/*
|
|
26
|
-
- run: npm ci
|
|
27
|
-
- run: npm run build --if-present
|
|
28
|
-
- run: npm test
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
- develop
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build-and-test:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
|
|
12
|
-
env:
|
|
13
|
-
TEST_PROVIDER_BASE_URL: http://127.0.0.1:5050/
|
|
14
|
-
services:
|
|
15
|
-
devnet:
|
|
16
|
-
image: janek2601/starknet-devnet-patched
|
|
17
|
-
ports:
|
|
18
|
-
- 5050:5050
|
|
19
|
-
|
|
20
|
-
steps:
|
|
21
|
-
- uses: actions/checkout@v2
|
|
22
|
-
- name: Use Node.js 14
|
|
23
|
-
uses: actions/setup-node@v2
|
|
24
|
-
with:
|
|
25
|
-
node-version: lts/*
|
|
26
|
-
- run: npm ci
|
|
27
|
-
- run: npm run build --if-present
|
|
28
|
-
- run: npm test
|
|
29
|
-
|
|
30
|
-
- uses: actions/upload-artifact@v2
|
|
31
|
-
with:
|
|
32
|
-
name: build
|
|
33
|
-
path: dist
|
|
34
|
-
|
|
35
|
-
integration-test:
|
|
36
|
-
runs-on: ubuntu-latest
|
|
37
|
-
|
|
38
|
-
env:
|
|
39
|
-
TEST_PROVIDER_BASE_URL: https://alpha4.starknet.io
|
|
40
|
-
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}
|
|
41
|
-
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
|
|
42
|
-
TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
|
|
43
|
-
|
|
44
|
-
steps:
|
|
45
|
-
- uses: actions/checkout@v2
|
|
46
|
-
- name: Use Node.js 14
|
|
47
|
-
uses: actions/setup-node@v2
|
|
48
|
-
with:
|
|
49
|
-
node-version: lts/*
|
|
50
|
-
- run: npm ci
|
|
51
|
-
- run: npm test
|
|
52
|
-
|
|
53
|
-
release:
|
|
54
|
-
name: Release
|
|
55
|
-
runs-on: ubuntu-latest
|
|
56
|
-
needs: [build-and-test, integration-test]
|
|
57
|
-
steps:
|
|
58
|
-
- uses: actions/checkout@v2
|
|
59
|
-
- uses: actions/setup-node@v2
|
|
60
|
-
with:
|
|
61
|
-
node-version: lts/*
|
|
62
|
-
- run: npm ci
|
|
63
|
-
- uses: actions/download-artifact@v2
|
|
64
|
-
with:
|
|
65
|
-
name: build
|
|
66
|
-
- env:
|
|
67
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
68
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
69
|
-
run: npx semantic-release
|
package/.husky/commit-msg
DELETED
package/.husky/pre-commit
DELETED
package/tsconfig.json
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
|
-
"lib": [
|
|
16
|
-
"es2017",
|
|
17
|
-
"es7",
|
|
18
|
-
"es6",
|
|
19
|
-
"dom"
|
|
20
|
-
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
|
21
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
22
|
-
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
23
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
24
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
|
25
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
26
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
|
27
|
-
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
|
28
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
29
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
30
|
-
|
|
31
|
-
/* Modules */
|
|
32
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
33
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
34
|
-
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
35
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
36
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
37
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
38
|
-
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
|
39
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
40
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
41
|
-
// "resolveJsonModule": true, /* Enable importing .json files */
|
|
42
|
-
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
|
43
|
-
|
|
44
|
-
/* JavaScript Support */
|
|
45
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
|
46
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
47
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
|
48
|
-
|
|
49
|
-
/* Emit */
|
|
50
|
-
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
|
51
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
52
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
53
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
54
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
|
55
|
-
"outDir": "dist" /* Specify an output folder for all emitted files. */,
|
|
56
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
57
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
58
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
59
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
|
60
|
-
"downlevelIteration": true /* Emit more compliant, but verbose and less performant JavaScript for iteration. */,
|
|
61
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
62
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
63
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
64
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
65
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
66
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
67
|
-
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
|
68
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
|
69
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
70
|
-
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
|
71
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
72
|
-
|
|
73
|
-
/* Interop Constraints */
|
|
74
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
75
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
76
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
|
|
77
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
78
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
79
|
-
|
|
80
|
-
/* Type Checking */
|
|
81
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
82
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
|
83
|
-
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
|
84
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
85
|
-
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
|
86
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
87
|
-
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
|
88
|
-
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
|
89
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
90
|
-
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
|
91
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
|
92
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
93
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
94
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
95
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
96
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
97
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
|
98
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
99
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
100
|
-
|
|
101
|
-
/* Completeness */
|
|
102
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
103
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
104
|
-
},
|
|
105
|
-
"include": ["src/**/*"],
|
|
106
|
-
"exclude": ["node_modules"]
|
|
107
|
-
}
|