@cityofzion/blockchain-service 1.18.1 → 1.18.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.
- package/dist/functions.d.ts +0 -2
- package/dist/functions.js +6 -32
- package/dist/helpers/BSNumberHelper.d.ts +16 -0
- package/dist/helpers/BSNumberHelper.js +75 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces.d.ts +4 -4
- package/package.json +8 -3
package/dist/functions.d.ts
CHANGED
|
@@ -24,6 +24,4 @@ type NormalizedHashOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
export declare function normalizeHash(hash: string, options?: NormalizedHashOptions): string;
|
|
26
26
|
export declare function denormalizeHash(hash: string): string;
|
|
27
|
-
export declare function countDecimals(value: string | number): number;
|
|
28
|
-
export declare function formatNumber(value?: string | number, decimals?: number): string;
|
|
29
27
|
export {};
|
package/dist/functions.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.denormalizeHash = exports.normalizeHash = exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.wait = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
13
|
function hasNameService(service) {
|
|
14
14
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
15
|
}
|
|
@@ -51,7 +51,7 @@ function waitForTransaction(service, txId) {
|
|
|
51
51
|
yield service.blockchainDataService.getTransaction(txId);
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
|
-
catch (
|
|
54
|
+
catch (_a) {
|
|
55
55
|
// Empty block
|
|
56
56
|
}
|
|
57
57
|
attempts++;
|
|
@@ -73,7 +73,7 @@ function waitForAccountTransaction(params) {
|
|
|
73
73
|
if (isTransactionConfirmed)
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
|
-
catch (
|
|
76
|
+
catch (_a) {
|
|
77
77
|
// Empty block
|
|
78
78
|
}
|
|
79
79
|
attempts++;
|
|
@@ -96,7 +96,7 @@ function fetchAccounts(blockchainServices, initialIndex, getAccountCallback) {
|
|
|
96
96
|
if (!transactions || transactions.length <= 0)
|
|
97
97
|
shouldBreak = true;
|
|
98
98
|
}
|
|
99
|
-
catch (
|
|
99
|
+
catch (_a) {
|
|
100
100
|
shouldBreak = true;
|
|
101
101
|
}
|
|
102
102
|
accounts.push(generatedAccount);
|
|
@@ -123,9 +123,9 @@ function generateAccountForBlockchainService(blockchainServices, getAccountCallb
|
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
const accountsByBlockchainService = new Map();
|
|
125
125
|
const promises = blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
var
|
|
126
|
+
var _a;
|
|
127
127
|
const firstAccount = yield getAccountCallback(service, 0);
|
|
128
|
-
const untilIndex = (
|
|
128
|
+
const untilIndex = (_a = untilIndexByBlockchainService === null || untilIndexByBlockchainService === void 0 ? void 0 : untilIndexByBlockchainService[service.name]) === null || _a === void 0 ? void 0 : _a[firstAccount.address];
|
|
129
129
|
if (untilIndex === undefined) {
|
|
130
130
|
const accounts = yield fetchAccounts(service, 1, getAccountCallback);
|
|
131
131
|
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
@@ -152,29 +152,3 @@ function denormalizeHash(hash) {
|
|
|
152
152
|
return hash.startsWith('0x') ? hash : `0x${hash}`;
|
|
153
153
|
}
|
|
154
154
|
exports.denormalizeHash = denormalizeHash;
|
|
155
|
-
function countDecimals(value) {
|
|
156
|
-
var _b;
|
|
157
|
-
const [, decimals] = value.toString().split('.');
|
|
158
|
-
return (_b = decimals === null || decimals === void 0 ? void 0 : decimals.length) !== null && _b !== void 0 ? _b : 0;
|
|
159
|
-
}
|
|
160
|
-
exports.countDecimals = countDecimals;
|
|
161
|
-
function formatNumber(value, decimals = 0) {
|
|
162
|
-
if (!value)
|
|
163
|
-
return '0';
|
|
164
|
-
let newValue = typeof value === 'number' ? value.toFixed(decimals) : value;
|
|
165
|
-
newValue = newValue.replace(/,|\.\.|\.,/g, '.');
|
|
166
|
-
if (decimals === 0) {
|
|
167
|
-
newValue = newValue.split('.')[0];
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
newValue = newValue.replace(/[^\d.]/g, '');
|
|
171
|
-
const countedDecimals = countDecimals(newValue);
|
|
172
|
-
if (countedDecimals > decimals) {
|
|
173
|
-
newValue = newValue.slice(0, newValue.length - countedDecimals + decimals);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return newValue.replace(/\s|-/g, '').replace(/^([^.]*\.)(.*)$/, function (_a, b, c) {
|
|
177
|
-
return b + c.replace(/\./g, '');
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
exports.formatNumber = formatNumber;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type FormatNumberOptions = {
|
|
2
|
+
decimals?: number;
|
|
3
|
+
shouldRemoveLeadingZero?: boolean;
|
|
4
|
+
shouldRemoveTrailingZero?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class BSNumberHelper {
|
|
7
|
+
static readonly sciNotationRegex: RegExp;
|
|
8
|
+
static countDecimals(value: string | number): number;
|
|
9
|
+
static sanitizeCommasAndDotsInNumber(value: string): string;
|
|
10
|
+
static isSciNotationValue(value: string): boolean;
|
|
11
|
+
static convertSciNotationValueToString(value: number): string;
|
|
12
|
+
static removeLeadingZero(value: string): string;
|
|
13
|
+
static removeTrailingZero(value: string): string;
|
|
14
|
+
static formatNumber(value?: string | number, options?: FormatNumberOptions): string;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSNumberHelper = void 0;
|
|
4
|
+
class BSNumberHelper {
|
|
5
|
+
static countDecimals(value) {
|
|
6
|
+
var _b;
|
|
7
|
+
const [, decimals] = value.toString().split('.');
|
|
8
|
+
return (_b = decimals === null || decimals === void 0 ? void 0 : decimals.length) !== null && _b !== void 0 ? _b : 0;
|
|
9
|
+
}
|
|
10
|
+
static sanitizeCommasAndDotsInNumber(value) {
|
|
11
|
+
let newValue = value.replace(/,|\.\.|\.,|,,/g, '.');
|
|
12
|
+
const parts = newValue.split('.');
|
|
13
|
+
if (parts.length > 2)
|
|
14
|
+
newValue = `${parts[0]}.${parts.slice(1).join('')}`;
|
|
15
|
+
return newValue;
|
|
16
|
+
}
|
|
17
|
+
static isSciNotationValue(value) {
|
|
18
|
+
return BSNumberHelper.sciNotationRegex.test(value);
|
|
19
|
+
}
|
|
20
|
+
static convertSciNotationValueToString(value) {
|
|
21
|
+
if (Math.abs(value) < 1.0) {
|
|
22
|
+
const parts = value.toString().split('e-');
|
|
23
|
+
const hasNegativeExponent = parts.length === 2;
|
|
24
|
+
if (hasNegativeExponent) {
|
|
25
|
+
const negativeExponent = parseInt(parts[1], 10);
|
|
26
|
+
value *= Math.pow(10, negativeExponent - 1);
|
|
27
|
+
return `0.${'0'.repeat(negativeExponent - 1)}${value.toString().substring(2)}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return value.toString();
|
|
31
|
+
}
|
|
32
|
+
static removeLeadingZero(value) {
|
|
33
|
+
return value.replace(/^0+(?!\.)/, '') || '0';
|
|
34
|
+
}
|
|
35
|
+
static removeTrailingZero(value) {
|
|
36
|
+
return value.replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0+$/, '');
|
|
37
|
+
}
|
|
38
|
+
static formatNumber(value, options) {
|
|
39
|
+
if (!value)
|
|
40
|
+
return '0';
|
|
41
|
+
const { decimals = 0, shouldRemoveLeadingZero = true, shouldRemoveTrailingZero = true } = options !== null && options !== void 0 ? options : {};
|
|
42
|
+
let newValue = typeof value === 'number' ? value.toString() : value.trim();
|
|
43
|
+
newValue = BSNumberHelper.sanitizeCommasAndDotsInNumber(newValue);
|
|
44
|
+
const newValueAsNumber = Number(newValue);
|
|
45
|
+
if (isNaN(newValueAsNumber))
|
|
46
|
+
return '0';
|
|
47
|
+
const isNegativeValue = newValue.startsWith('-');
|
|
48
|
+
if (BSNumberHelper.isSciNotationValue(newValue))
|
|
49
|
+
newValue = BSNumberHelper.convertSciNotationValueToString(newValueAsNumber);
|
|
50
|
+
if (decimals === 0)
|
|
51
|
+
newValue = newValue.split('.')[0];
|
|
52
|
+
else {
|
|
53
|
+
newValue = newValue.replace(/[^\d.]/g, '');
|
|
54
|
+
const countedDecimals = BSNumberHelper.countDecimals(newValue);
|
|
55
|
+
if (countedDecimals > decimals)
|
|
56
|
+
newValue = newValue.slice(0, newValue.length - countedDecimals + decimals);
|
|
57
|
+
}
|
|
58
|
+
newValue = newValue.replace(/\s|-/g, '').replace(/^([^.]*\.)(.*)$/, (_a, b, c) => b + c.replace(/\./g, ''));
|
|
59
|
+
if (shouldRemoveLeadingZero)
|
|
60
|
+
newValue = BSNumberHelper.removeLeadingZero(newValue);
|
|
61
|
+
if (shouldRemoveTrailingZero)
|
|
62
|
+
newValue = BSNumberHelper.removeTrailingZero(newValue);
|
|
63
|
+
if (newValue.startsWith('.'))
|
|
64
|
+
newValue = `0${newValue}`;
|
|
65
|
+
if (newValue.endsWith('.'))
|
|
66
|
+
newValue = newValue.slice(0, newValue.length - 1);
|
|
67
|
+
if (!newValue)
|
|
68
|
+
newValue = '0';
|
|
69
|
+
if (newValue !== '0' && isNegativeValue)
|
|
70
|
+
newValue = `-${newValue}`;
|
|
71
|
+
return newValue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.BSNumberHelper = BSNumberHelper;
|
|
75
|
+
BSNumberHelper.sciNotationRegex = /^[+-]?\d+(\.\d+)?e[+-]?\d+$/i;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './constants/BSCommonConstants';
|
|
2
2
|
export * from './helpers/BSFullTransactionsByAddressHelper';
|
|
3
3
|
export * from './helpers/BSPromisesHelper';
|
|
4
|
+
export * from './helpers/BSNumberHelper';
|
|
4
5
|
export * from './services/exchange-data/CryptoCompareEDS';
|
|
5
6
|
export * from './services/exchange-data/FlamingoForthewinEDS';
|
|
6
7
|
export * from './BSAggregator';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./constants/BSCommonConstants"), exports);
|
|
18
18
|
__exportStar(require("./helpers/BSFullTransactionsByAddressHelper"), exports);
|
|
19
19
|
__exportStar(require("./helpers/BSPromisesHelper"), exports);
|
|
20
|
+
__exportStar(require("./helpers/BSNumberHelper"), exports);
|
|
20
21
|
__exportStar(require("./services/exchange-data/CryptoCompareEDS"), exports);
|
|
21
22
|
__exportStar(require("./services/exchange-data/FlamingoForthewinEDS"), exports);
|
|
22
23
|
__exportStar(require("./BSAggregator"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export type ExportTransactionsByAddressParams = {
|
|
|
137
137
|
};
|
|
138
138
|
export type FullTransactionNftEvent = {
|
|
139
139
|
eventType: 'nft';
|
|
140
|
-
amount
|
|
140
|
+
amount?: string;
|
|
141
141
|
methodName: string;
|
|
142
142
|
hash: string;
|
|
143
143
|
hashUrl?: string;
|
|
@@ -154,7 +154,7 @@ export type FullTransactionNftEvent = {
|
|
|
154
154
|
};
|
|
155
155
|
export type FullTransactionAssetEvent = {
|
|
156
156
|
eventType: 'token';
|
|
157
|
-
amount
|
|
157
|
+
amount?: string;
|
|
158
158
|
methodName: string;
|
|
159
159
|
hash: string;
|
|
160
160
|
hashUrl?: string;
|
|
@@ -172,8 +172,8 @@ export type FullTransactionsItem = {
|
|
|
172
172
|
date: string;
|
|
173
173
|
invocationCount: number;
|
|
174
174
|
notificationCount: number;
|
|
175
|
-
networkFeeAmount
|
|
176
|
-
systemFeeAmount
|
|
175
|
+
networkFeeAmount?: string;
|
|
176
|
+
systemFeeAmount?: string;
|
|
177
177
|
events: (FullTransactionAssetEvent | FullTransactionNftEvent)[];
|
|
178
178
|
};
|
|
179
179
|
export type FullTransactionsByAddressResponse = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "~20.2.5",
|
|
14
|
+
"@types/jest": "29.5.3",
|
|
14
15
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
15
16
|
"@typescript-eslint/parser": "^6.5.0",
|
|
17
|
+
"dotenv": "16.3.1",
|
|
16
18
|
"eslint": "^8.48.0",
|
|
17
19
|
"ts-node": "10.9.1",
|
|
18
20
|
"typescript": "4.9.5",
|
|
19
|
-
"typed-emitter": "~2.1.0"
|
|
21
|
+
"typed-emitter": "~2.1.0",
|
|
22
|
+
"jest": "29.6.2",
|
|
23
|
+
"ts-jest": "29.1.1"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
26
|
"@ledgerhq/hw-transport": "~6.30.5",
|
|
@@ -24,7 +28,8 @@
|
|
|
24
28
|
"date-fns": "~4.1.0"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
|
-
"build": "tsc",
|
|
31
|
+
"build": "tsc --project tsconfig.build.json",
|
|
32
|
+
"test": "jest --config jest.config.ts",
|
|
28
33
|
"lint": "eslint .",
|
|
29
34
|
"format": "eslint --fix"
|
|
30
35
|
}
|