@pioneer-platform/helpers 4.0.8 → 4.0.10
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.
@@ -146,13 +146,11 @@ var createAssetValue = function (assetString, value) {
|
|
146
146
|
case 1:
|
147
147
|
_a.trys.push([1, 3, , 4]);
|
148
148
|
(0, validators_1.validateIdentifier)(assetString);
|
149
|
-
console.log(tag + 'assetString', assetString);
|
150
149
|
return [4 /*yield*/, (0, asset_1.getDecimal)(getAssetInfo(assetString))];
|
151
150
|
case 2:
|
152
151
|
decimal = _a.sent();
|
153
|
-
console.log(tag + 'decimal', decimal);
|
154
152
|
parsedValue = safeValue(value, decimal);
|
155
|
-
console.log(tag + 'parsedValue', parsedValue);
|
153
|
+
//console.log(tag + 'parsedValue', parsedValue);
|
156
154
|
// @ts-ignore
|
157
155
|
return [2 /*return*/, new AssetValue({ decimal: decimal, value: parsedValue, identifier: assetString })];
|
158
156
|
case 3:
|
@@ -322,9 +320,9 @@ var AssetValue = /** @class */ (function (_super) {
|
|
322
320
|
if (!decimal || !identifier)
|
323
321
|
throw Error('unknown coin! ' + assetString);
|
324
322
|
var parsedValue = safeValue(value, decimal);
|
325
|
-
console.log(tag + "parsedValue: ", parsedValue);
|
326
|
-
console.log(tag + "decimal: ", decimal);
|
327
|
-
console.log(tag + "identifier: ", identifier);
|
323
|
+
//console.log(tag + "parsedValue: ", parsedValue);
|
324
|
+
//console.log(tag + "decimal: ", decimal);
|
325
|
+
//console.log(tag + "identifier: ", identifier);
|
328
326
|
// @ts-ignore
|
329
327
|
return new AssetValue({ value: parsedValue, decimal: decimal, identifier: identifier });
|
330
328
|
}
|
@@ -33,7 +33,7 @@ var bigintPow = function (base, exponent) {
|
|
33
33
|
};
|
34
34
|
var toMultiplier = function (decimal) {
|
35
35
|
var tag = TAG + " | toMultiplier | ";
|
36
|
-
console.log(tag + 'input decimal:', decimal);
|
36
|
+
//console.log(tag + 'input decimal:', decimal);
|
37
37
|
try {
|
38
38
|
if (decimal < 0) {
|
39
39
|
throw new Error("Decimal must be non-negative");
|
@@ -42,7 +42,7 @@ var toMultiplier = function (decimal) {
|
|
42
42
|
for (var i = 0; i < decimal; i++) {
|
43
43
|
result *= BigInt(10);
|
44
44
|
}
|
45
|
-
console.log(tag + 'result:', result);
|
45
|
+
//console.log(tag + 'result:', result);
|
46
46
|
return result;
|
47
47
|
}
|
48
48
|
catch (error) {
|
@@ -65,7 +65,7 @@ function formatBigIntToSafeValue(_a) {
|
|
65
65
|
var value = _a.value, bigIntDecimal = _a.bigIntDecimal, decimal = _a.decimal;
|
66
66
|
var tag = TAG + " | BigIntArithmetics | ";
|
67
67
|
try {
|
68
|
-
console.log(tag,
|
68
|
+
//console.log(tag,'value:',value,'bigIntDecimal:',bigIntDecimal,'decimal:',decimal);
|
69
69
|
if (!decimal)
|
70
70
|
decimal = DEFAULT_DECIMAL;
|
71
71
|
if (!bigIntDecimal)
|
@@ -76,9 +76,9 @@ function formatBigIntToSafeValue(_a) {
|
|
76
76
|
}
|
77
77
|
// Convert bigint to string and then to number
|
78
78
|
var valueString = value.toString();
|
79
|
-
console.log(tag,
|
80
|
-
console.log(tag,
|
81
|
-
console.log(tag,
|
79
|
+
//console.log(tag,'valueString:',valueString);
|
80
|
+
//console.log(tag,'valueString:',valueString.length);
|
81
|
+
//console.log(tag,'decimal:',decimal);
|
82
82
|
// Ensure the valueString has enough length for the decimal places
|
83
83
|
if (valueString.length <= decimal) {
|
84
84
|
valueString = '0'.repeat(decimal - valueString.length + 1) + valueString;
|
@@ -88,7 +88,7 @@ function formatBigIntToSafeValue(_a) {
|
|
88
88
|
var decimalPart = valueString.slice(valueString.length - decimal).padEnd(decimal, '0');
|
89
89
|
// Construct the final formatted value
|
90
90
|
var formattedValue = "".concat(integerPart, ".").concat(decimalPart);
|
91
|
-
console.log(tag,
|
91
|
+
//console.log(tag,"formattedValue:", formattedValue);
|
92
92
|
return formattedValue;
|
93
93
|
}
|
94
94
|
catch (error) {
|
@@ -138,13 +138,13 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
138
138
|
function BigIntArithmetics(params) {
|
139
139
|
var tag = TAG + " | constructor | ";
|
140
140
|
try {
|
141
|
-
console.log(tag + 'Constructor Params:', params);
|
141
|
+
////console.log(tag + 'Constructor Params:', params);
|
142
142
|
var value = getStringValue(params);
|
143
|
-
console.log(tag + 'String Value:', value);
|
143
|
+
////console.log(tag + 'String Value:', value);
|
144
144
|
var isComplex = typeof params === 'object' && params !== null;
|
145
145
|
this.decimal = isComplex ? params.decimal : undefined;
|
146
|
-
console.log(tag, 'Decimal:', this.decimal);
|
147
|
-
console.log(tag, 'isComplex:', isComplex);
|
146
|
+
////console.log(tag , 'Decimal:', this.decimal);
|
147
|
+
////console.log(tag , 'isComplex:', isComplex);
|
148
148
|
if (isComplex) {
|
149
149
|
this.decimalMultiplier = (0, exports.toMultiplier)(this.decimal || DEFAULT_DECIMAL);
|
150
150
|
}
|
@@ -152,10 +152,10 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
152
152
|
var maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
|
153
153
|
this.decimalMultiplier = (0, exports.toMultiplier)(maxDecimals);
|
154
154
|
}
|
155
|
-
console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
155
|
+
////console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
156
156
|
this.setValue(value);
|
157
157
|
//@ts-ignore
|
158
|
-
console.log(tag + 'BigInt Value:', this.bigIntValue);
|
158
|
+
////console.log(tag + 'BigInt Value:', this.bigIntValue);
|
159
159
|
}
|
160
160
|
catch (error) {
|
161
161
|
console.error(tag + 'Error in constructor:', error);
|
@@ -166,7 +166,7 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
166
166
|
BigIntArithmetics.fromBigInt = function (value, decimal) {
|
167
167
|
var tag = TAG + " | fromBigInt | ";
|
168
168
|
try {
|
169
|
-
console.log(tag,
|
169
|
+
//console.log(tag,"Decimal: ", decimal);
|
170
170
|
return new BigIntArithmetics({
|
171
171
|
decimal: decimal,
|
172
172
|
value: formatBigIntToSafeValue({ value: value, bigIntDecimal: (0, exports.toMultiplier)(decimal || DEFAULT_DECIMAL), decimal: decimal }),
|
@@ -180,24 +180,24 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
180
180
|
// constructor(params: SKBigIntParams) {
|
181
181
|
// let tag = TAG + " | constructor | ";
|
182
182
|
// try {
|
183
|
-
// console.log(tag + 'Constructor Params:', params);
|
183
|
+
// //console.log(tag + 'Constructor Params:', params);
|
184
184
|
// const value = getStringValue(params);
|
185
|
-
// console.log(tag + 'String Value:', value);
|
185
|
+
// //console.log(tag + 'String Value:', value);
|
186
186
|
// const isComplex = typeof params === 'object' && params !== null;
|
187
187
|
// this.decimal = isComplex ? (params as { decimal?: number }).decimal : undefined;
|
188
|
-
// console.log(tag , 'Decimal:', this.decimal);
|
189
|
-
// console.log(tag , 'isComplex:', isComplex);
|
188
|
+
// //console.log(tag , 'Decimal:', this.decimal);
|
189
|
+
// //console.log(tag , 'isComplex:', isComplex);
|
190
190
|
// if (isComplex) {
|
191
191
|
// this.decimalMultiplier = this.decimal;
|
192
192
|
// } else {
|
193
193
|
// const maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
|
194
194
|
// this.decimalMultiplier = toMultiplier(maxDecimals);
|
195
195
|
// }
|
196
|
-
// console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
196
|
+
// //console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
197
197
|
//
|
198
198
|
// this.setValue(value);
|
199
199
|
// //@ts-ignore
|
200
|
-
// console.log(tag + 'BigInt Value:', this.bigIntValue);
|
200
|
+
// //console.log(tag + 'BigInt Value:', this.bigIntValue);
|
201
201
|
// } catch (error) {
|
202
202
|
// console.error(tag + 'Error in constructor:', error);
|
203
203
|
// this.decimalMultiplier = BigInt(1);
|
@@ -325,14 +325,14 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
325
325
|
BigIntArithmetics.prototype.getValue = function (type) {
|
326
326
|
var tag = TAG + " | getValue | ";
|
327
327
|
try {
|
328
|
-
console.log(tag,
|
329
|
-
console.log(tag,
|
328
|
+
//console.log(tag,'getValue type:', type);
|
329
|
+
//console.log(tag,'decimalMultiplier: ', this.decimalMultiplier);
|
330
330
|
var value = formatBigIntToSafeValue({
|
331
331
|
value: this.bigIntValue,
|
332
332
|
bigIntDecimal: (0, exports.toMultiplier)(this.decimal || DEFAULT_DECIMAL),
|
333
333
|
decimal: this.decimal || DEFAULT_DECIMAL,
|
334
334
|
});
|
335
|
-
console.log(tag,
|
335
|
+
//console.log(tag,'value:', value);
|
336
336
|
switch (type) {
|
337
337
|
case 'number':
|
338
338
|
return Number(value);
|
@@ -545,10 +545,10 @@ var BigIntArithmetics = /** @class */ (function () {
|
|
545
545
|
BigIntArithmetics.prototype.setValue = function (value) {
|
546
546
|
var tag = TAG + " | setValue | ";
|
547
547
|
try {
|
548
|
-
console.log(tag, 'value:', value);
|
549
|
-
console.log(tag, ' this.decimal:',
|
548
|
+
//console.log(tag, 'value:', value);
|
549
|
+
//console.log(tag, ' this.decimal:', this.decimal);
|
550
550
|
var safeValue = formatBigIntToSafeValue({ value: value, decimal: this.decimal });
|
551
|
-
console.log(tag, 'safeValue:', safeValue);
|
551
|
+
//console.log(tag, 'safeValue:', safeValue);
|
552
552
|
this.bigIntValue = this.toBigInt(safeValue);
|
553
553
|
}
|
554
554
|
catch (error) {
|
package/package.json
CHANGED
@@ -86,14 +86,14 @@ const createAssetValue = async (assetString: string, value: NumberPrimitives = 0
|
|
86
86
|
let tag = TAG + " | createAssetValue | ";
|
87
87
|
try {
|
88
88
|
validateIdentifier(assetString);
|
89
|
-
console.log(tag + 'assetString', assetString);
|
89
|
+
//console.log(tag + 'assetString', assetString);
|
90
90
|
|
91
91
|
//@ts-ignore
|
92
92
|
const decimal = await getDecimal(getAssetInfo(assetString));
|
93
|
-
console.log(tag + 'decimal', decimal);
|
93
|
+
//console.log(tag + 'decimal', decimal);
|
94
94
|
|
95
95
|
const parsedValue = safeValue(value, decimal);
|
96
|
-
console.log(tag + 'parsedValue', parsedValue);
|
96
|
+
//console.log(tag + 'parsedValue', parsedValue);
|
97
97
|
|
98
98
|
// @ts-ignore
|
99
99
|
return new AssetValue({ decimal, value: parsedValue, identifier: assetString });
|
@@ -261,9 +261,9 @@ export class AssetValue extends BigIntArithmetics {
|
|
261
261
|
const { decimal, identifier } = getCommonAssetInfo(assetString);
|
262
262
|
if (!decimal || !identifier) throw Error('unknown coin! ' + assetString);
|
263
263
|
const parsedValue = safeValue(value, decimal);
|
264
|
-
console.log(tag + "parsedValue: ", parsedValue);
|
265
|
-
console.log(tag + "decimal: ", decimal);
|
266
|
-
console.log(tag + "identifier: ", identifier);
|
264
|
+
//console.log(tag + "parsedValue: ", parsedValue);
|
265
|
+
//console.log(tag + "decimal: ", decimal);
|
266
|
+
//console.log(tag + "identifier: ", identifier);
|
267
267
|
|
268
268
|
// @ts-ignore
|
269
269
|
return new AssetValue({ value: parsedValue, decimal, identifier });
|
@@ -36,7 +36,7 @@ const bigintPow = (base: bigint, exponent: number): bigint => {
|
|
36
36
|
|
37
37
|
export const toMultiplier = (decimal: number): bigint => {
|
38
38
|
let tag = TAG + " | toMultiplier | ";
|
39
|
-
console.log(tag + 'input decimal:', decimal);
|
39
|
+
//console.log(tag + 'input decimal:', decimal);
|
40
40
|
try {
|
41
41
|
if (decimal < 0) {
|
42
42
|
throw new Error("Decimal must be non-negative");
|
@@ -45,7 +45,7 @@ export const toMultiplier = (decimal: number): bigint => {
|
|
45
45
|
for (let i = 0; i < decimal; i++) {
|
46
46
|
result *= BigInt(10);
|
47
47
|
}
|
48
|
-
console.log(tag + 'result:', result);
|
48
|
+
//console.log(tag + 'result:', result);
|
49
49
|
return result;
|
50
50
|
} catch (error) {
|
51
51
|
console.error(tag + 'Error in toMultiplier:', error);
|
@@ -74,7 +74,7 @@ export function formatBigIntToSafeValue({
|
|
74
74
|
}): string {
|
75
75
|
const tag = TAG+" | BigIntArithmetics | ";
|
76
76
|
try {
|
77
|
-
console.log(tag,'value:',value,'bigIntDecimal:',bigIntDecimal,'decimal:',decimal);
|
77
|
+
//console.log(tag,'value:',value,'bigIntDecimal:',bigIntDecimal,'decimal:',decimal);
|
78
78
|
if(!decimal) decimal = DEFAULT_DECIMAL;
|
79
79
|
if(!bigIntDecimal) bigIntDecimal = toMultiplier(decimal);
|
80
80
|
|
@@ -85,10 +85,10 @@ export function formatBigIntToSafeValue({
|
|
85
85
|
|
86
86
|
// Convert bigint to string and then to number
|
87
87
|
let valueString = value.toString();
|
88
|
-
console.log(tag,'valueString:',valueString);
|
89
|
-
console.log(tag,'valueString:',valueString.length);
|
88
|
+
//console.log(tag,'valueString:',valueString);
|
89
|
+
//console.log(tag,'valueString:',valueString.length);
|
90
90
|
|
91
|
-
console.log(tag,'decimal:',decimal);
|
91
|
+
//console.log(tag,'decimal:',decimal);
|
92
92
|
// Ensure the valueString has enough length for the decimal places
|
93
93
|
if (valueString.length <= decimal) {
|
94
94
|
valueString = '0'.repeat(decimal - valueString.length + 1) + valueString;
|
@@ -101,7 +101,7 @@ export function formatBigIntToSafeValue({
|
|
101
101
|
// Construct the final formatted value
|
102
102
|
const formattedValue = `${integerPart}.${decimalPart}`;
|
103
103
|
|
104
|
-
console.log(tag,"formattedValue:", formattedValue);
|
104
|
+
//console.log(tag,"formattedValue:", formattedValue);
|
105
105
|
return formattedValue;
|
106
106
|
} catch (error) {
|
107
107
|
console.error(TAG + 'Error in formatBigIntToSafeValue:', error);
|
@@ -118,7 +118,7 @@ export class BigIntArithmetics {
|
|
118
118
|
static fromBigInt(value: bigint, decimal?: number): BigIntArithmetics {
|
119
119
|
let tag = TAG + " | fromBigInt | ";
|
120
120
|
try {
|
121
|
-
console.log(tag,"Decimal: ", decimal);
|
121
|
+
//console.log(tag,"Decimal: ", decimal);
|
122
122
|
|
123
123
|
return new BigIntArithmetics({
|
124
124
|
decimal,
|
@@ -172,24 +172,24 @@ export class BigIntArithmetics {
|
|
172
172
|
constructor(params: SKBigIntParams) {
|
173
173
|
let tag = TAG + " | constructor | ";
|
174
174
|
try {
|
175
|
-
console.log(tag + 'Constructor Params:', params);
|
175
|
+
////console.log(tag + 'Constructor Params:', params);
|
176
176
|
const value = getStringValue(params);
|
177
|
-
console.log(tag + 'String Value:', value);
|
177
|
+
////console.log(tag + 'String Value:', value);
|
178
178
|
const isComplex = typeof params === 'object' && params !== null;
|
179
179
|
this.decimal = isComplex ? (params as { decimal?: number }).decimal : undefined;
|
180
|
-
console.log(tag , 'Decimal:', this.decimal);
|
181
|
-
console.log(tag , 'isComplex:', isComplex);
|
180
|
+
////console.log(tag , 'Decimal:', this.decimal);
|
181
|
+
////console.log(tag , 'isComplex:', isComplex);
|
182
182
|
if (isComplex) {
|
183
183
|
this.decimalMultiplier = toMultiplier(this.decimal || DEFAULT_DECIMAL);
|
184
184
|
} else {
|
185
185
|
const maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
|
186
186
|
this.decimalMultiplier = toMultiplier(maxDecimals);
|
187
187
|
}
|
188
|
-
console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
188
|
+
////console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
189
189
|
|
190
190
|
this.setValue(value);
|
191
191
|
//@ts-ignore
|
192
|
-
console.log(tag + 'BigInt Value:', this.bigIntValue);
|
192
|
+
////console.log(tag + 'BigInt Value:', this.bigIntValue);
|
193
193
|
} catch (error) {
|
194
194
|
console.error(tag + 'Error in constructor:', error);
|
195
195
|
this.decimalMultiplier = BigInt(1);
|
@@ -200,24 +200,24 @@ export class BigIntArithmetics {
|
|
200
200
|
// constructor(params: SKBigIntParams) {
|
201
201
|
// let tag = TAG + " | constructor | ";
|
202
202
|
// try {
|
203
|
-
// console.log(tag + 'Constructor Params:', params);
|
203
|
+
// //console.log(tag + 'Constructor Params:', params);
|
204
204
|
// const value = getStringValue(params);
|
205
|
-
// console.log(tag + 'String Value:', value);
|
205
|
+
// //console.log(tag + 'String Value:', value);
|
206
206
|
// const isComplex = typeof params === 'object' && params !== null;
|
207
207
|
// this.decimal = isComplex ? (params as { decimal?: number }).decimal : undefined;
|
208
|
-
// console.log(tag , 'Decimal:', this.decimal);
|
209
|
-
// console.log(tag , 'isComplex:', isComplex);
|
208
|
+
// //console.log(tag , 'Decimal:', this.decimal);
|
209
|
+
// //console.log(tag , 'isComplex:', isComplex);
|
210
210
|
// if (isComplex) {
|
211
211
|
// this.decimalMultiplier = this.decimal;
|
212
212
|
// } else {
|
213
213
|
// const maxDecimals = Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0);
|
214
214
|
// this.decimalMultiplier = toMultiplier(maxDecimals);
|
215
215
|
// }
|
216
|
-
// console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
216
|
+
// //console.log(tag + 'Decimal Multiplier:', this.decimalMultiplier);
|
217
217
|
//
|
218
218
|
// this.setValue(value);
|
219
219
|
// //@ts-ignore
|
220
|
-
// console.log(tag + 'BigInt Value:', this.bigIntValue);
|
220
|
+
// //console.log(tag + 'BigInt Value:', this.bigIntValue);
|
221
221
|
// } catch (error) {
|
222
222
|
// console.error(tag + 'Error in constructor:', error);
|
223
223
|
// this.decimalMultiplier = BigInt(1);
|
@@ -329,14 +329,14 @@ export class BigIntArithmetics {
|
|
329
329
|
getValue<T extends AllowedNumberTypes>(type: T): NumberPrimitivesType[T] {
|
330
330
|
let tag = TAG + " | getValue | ";
|
331
331
|
try {
|
332
|
-
console.log(tag,'getValue type:', type);
|
333
|
-
console.log(tag,'decimalMultiplier: ', this.decimalMultiplier);
|
332
|
+
//console.log(tag,'getValue type:', type);
|
333
|
+
//console.log(tag,'decimalMultiplier: ', this.decimalMultiplier);
|
334
334
|
const value = formatBigIntToSafeValue({
|
335
335
|
value: this.bigIntValue,
|
336
336
|
bigIntDecimal: toMultiplier(this.decimal || DEFAULT_DECIMAL),
|
337
337
|
decimal: this.decimal || DEFAULT_DECIMAL,
|
338
338
|
});
|
339
|
-
console.log(tag,'value:', value);
|
339
|
+
//console.log(tag,'value:', value);
|
340
340
|
switch (type) {
|
341
341
|
case 'number':
|
342
342
|
return Number(value) as NumberPrimitivesType[T];
|
@@ -575,10 +575,10 @@ export class BigIntArithmetics {
|
|
575
575
|
private setValue(value: any): void {
|
576
576
|
let tag = TAG + " | setValue | ";
|
577
577
|
try {
|
578
|
-
console.log(tag, 'value:', value);
|
579
|
-
console.log(tag, ' this.decimal:', this.decimal);
|
578
|
+
//console.log(tag, 'value:', value);
|
579
|
+
//console.log(tag, ' this.decimal:', this.decimal);
|
580
580
|
const safeValue = formatBigIntToSafeValue({value:value, decimal: this.decimal})
|
581
|
-
console.log(tag, 'safeValue:', safeValue);
|
581
|
+
//console.log(tag, 'safeValue:', safeValue);
|
582
582
|
this.bigIntValue = this.toBigInt(safeValue);
|
583
583
|
} catch (error) {
|
584
584
|
console.error(tag + 'Error in setValue:', error);
|