@fleet-sdk/common 0.2.2 → 0.2.3
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 +6 -0
- package/package.json +2 -2
- package/src/index.ts +0 -3
- package/src/models/collection.ts +0 -107
- package/src/models/index.ts +0 -1
- package/src/types/block.ts +0 -44
- package/src/types/boxes.ts +0 -31
- package/src/types/common.ts +0 -31
- package/src/types/contextExtension.ts +0 -3
- package/src/types/index.ts +0 -9
- package/src/types/inputs.ts +0 -42
- package/src/types/proverResult.ts +0 -7
- package/src/types/registers.ts +0 -10
- package/src/types/token.ts +0 -21
- package/src/types/transactions.ts +0 -32
- package/src/utils/array.ts +0 -196
- package/src/utils/assertions.ts +0 -90
- package/src/utils/bigInt.ts +0 -186
- package/src/utils/bytes.bench.ts +0 -43
- package/src/utils/bytes.ts +0 -34
- package/src/utils/index.ts +0 -6
- package/src/utils/object.ts +0 -28
- package/src/utils/utxo.ts +0 -183
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fleet-sdk/common",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.3",
|
4
4
|
"description": "Internal utility functions, constants and types shared across @fleet-sdk packages.",
|
5
5
|
"main": "./dist/index.cjs.js",
|
6
6
|
"module": "./dist/index.esm.js",
|
7
7
|
"types": "./dist/index.d.ts",
|
8
8
|
"exports": {
|
9
|
+
"types": "./dist/index.d.ts",
|
9
10
|
"require": "./dist/index.cjs.js",
|
10
11
|
"import": "./dist/index.esm.js"
|
11
12
|
},
|
@@ -24,7 +25,6 @@
|
|
24
25
|
"node": ">=14"
|
25
26
|
},
|
26
27
|
"files": [
|
27
|
-
"src",
|
28
28
|
"dist",
|
29
29
|
"!**/*.spec.*",
|
30
30
|
"!**/*.json",
|
package/src/index.ts
DELETED
package/src/models/collection.ts
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
import { OneOrMore } from "../types";
|
2
|
-
import { isDefined } from "../utils";
|
3
|
-
|
4
|
-
export type CollectionAddOptions = { index?: number };
|
5
|
-
|
6
|
-
export abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {
|
7
|
-
protected readonly _items: InternalType[];
|
8
|
-
|
9
|
-
constructor() {
|
10
|
-
this._items = [];
|
11
|
-
}
|
12
|
-
|
13
|
-
protected _isIndexOutOfBounds(index: number): boolean {
|
14
|
-
return index < 0 || index >= this._items.length;
|
15
|
-
}
|
16
|
-
|
17
|
-
[Symbol.iterator](): Iterator<InternalType> {
|
18
|
-
let counter = 0;
|
19
|
-
|
20
|
-
return {
|
21
|
-
next: () => {
|
22
|
-
return {
|
23
|
-
done: counter >= this.length,
|
24
|
-
value: this._items[counter++]
|
25
|
-
};
|
26
|
-
}
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
public get length(): number {
|
31
|
-
return this._items.length;
|
32
|
-
}
|
33
|
-
|
34
|
-
public get isEmpty(): boolean {
|
35
|
-
return this.length === 0;
|
36
|
-
}
|
37
|
-
|
38
|
-
public at(index: number): InternalType {
|
39
|
-
if (this._isIndexOutOfBounds(index)) {
|
40
|
-
throw new RangeError(`Index '${index}' is out of range.`);
|
41
|
-
}
|
42
|
-
|
43
|
-
return this._items[index];
|
44
|
-
}
|
45
|
-
|
46
|
-
public add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {
|
47
|
-
return this._addOneOrMore(items, options);
|
48
|
-
}
|
49
|
-
|
50
|
-
abstract remove(item: unknown): number;
|
51
|
-
|
52
|
-
protected abstract _map(item: ExternalType | InternalType): InternalType;
|
53
|
-
|
54
|
-
protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number {
|
55
|
-
if (isDefined(options) && isDefined(options.index)) {
|
56
|
-
if (options.index === this.length) {
|
57
|
-
this._items.push(this._map(item));
|
58
|
-
|
59
|
-
return this.length;
|
60
|
-
}
|
61
|
-
|
62
|
-
if (this._isIndexOutOfBounds(options.index)) {
|
63
|
-
throw new RangeError(`Index '${options.index}' is out of range.`);
|
64
|
-
}
|
65
|
-
|
66
|
-
this._items.splice(options.index, 0, this._map(item));
|
67
|
-
|
68
|
-
return this.length;
|
69
|
-
}
|
70
|
-
|
71
|
-
this._items.push(this._map(item));
|
72
|
-
|
73
|
-
return this._items.length;
|
74
|
-
}
|
75
|
-
|
76
|
-
protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number {
|
77
|
-
if (Array.isArray(items)) {
|
78
|
-
if (isDefined(options) && isDefined(options.index)) {
|
79
|
-
items = items.reverse();
|
80
|
-
}
|
81
|
-
|
82
|
-
for (const item of items) {
|
83
|
-
this._addOne(item, options);
|
84
|
-
}
|
85
|
-
} else {
|
86
|
-
this._addOne(items, options);
|
87
|
-
}
|
88
|
-
|
89
|
-
return this.length;
|
90
|
-
}
|
91
|
-
|
92
|
-
public toArray(): InternalType[] {
|
93
|
-
return [...this._items];
|
94
|
-
}
|
95
|
-
|
96
|
-
public reduce<U>(
|
97
|
-
callbackFn: (
|
98
|
-
accumulator: U,
|
99
|
-
currentValue: InternalType,
|
100
|
-
currentIndex: number,
|
101
|
-
array: InternalType[]
|
102
|
-
) => U,
|
103
|
-
initialValue: U
|
104
|
-
): U {
|
105
|
-
return this._items.reduce(callbackFn, initialValue);
|
106
|
-
}
|
107
|
-
}
|
package/src/models/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./collection";
|
package/src/types/block.ts
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
import { HexString } from "./common";
|
2
|
-
import { SignedTransaction } from "./transactions";
|
3
|
-
|
4
|
-
export type PoWSolution = {
|
5
|
-
pk: HexString;
|
6
|
-
w: HexString;
|
7
|
-
n: string;
|
8
|
-
d: number;
|
9
|
-
};
|
10
|
-
|
11
|
-
export type BlockHeaderId = string;
|
12
|
-
|
13
|
-
export type BlockTransactions = {
|
14
|
-
headerId: BlockHeaderId;
|
15
|
-
transactions: SignedTransaction[];
|
16
|
-
};
|
17
|
-
|
18
|
-
export type BlockHeader = {
|
19
|
-
id: BlockHeaderId;
|
20
|
-
timestamp: number;
|
21
|
-
version: number;
|
22
|
-
adProofsRoot: HexString;
|
23
|
-
stateRoot: HexString;
|
24
|
-
transactionsRoot: HexString;
|
25
|
-
nBits: number;
|
26
|
-
extensionHash: HexString;
|
27
|
-
powSolutions: PoWSolution;
|
28
|
-
height: number;
|
29
|
-
difficulty: string;
|
30
|
-
parentId: BlockHeaderId;
|
31
|
-
votes: string;
|
32
|
-
size: number;
|
33
|
-
extensionId: HexString;
|
34
|
-
transactionsId: HexString;
|
35
|
-
adProofsId: HexString;
|
36
|
-
};
|
37
|
-
|
38
|
-
export type Block = {
|
39
|
-
header: BlockHeader;
|
40
|
-
blockTransactions: BlockTransactions;
|
41
|
-
adProofs: unknown; // TODO
|
42
|
-
extension: unknown; // TODO
|
43
|
-
size: number;
|
44
|
-
};
|
package/src/types/boxes.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { ErgoTreeHex } from "./common";
|
2
|
-
import { NonMandatoryRegisters } from "./registers";
|
3
|
-
import { TokenAmount } from "./token";
|
4
|
-
import { TransactionId } from "./transactions";
|
5
|
-
|
6
|
-
export type BoxId = string;
|
7
|
-
export type AmountType = string | bigint;
|
8
|
-
|
9
|
-
type BoxBaseType<T extends AmountType, R extends NonMandatoryRegisters> = {
|
10
|
-
ergoTree: ErgoTreeHex;
|
11
|
-
creationHeight: number;
|
12
|
-
value: T;
|
13
|
-
assets: TokenAmount<T>[];
|
14
|
-
additionalRegisters: R;
|
15
|
-
};
|
16
|
-
|
17
|
-
export type BoxCandidate<
|
18
|
-
T extends AmountType,
|
19
|
-
R extends NonMandatoryRegisters = NonMandatoryRegisters
|
20
|
-
> = BoxBaseType<T, R> & {
|
21
|
-
boxId?: BoxId;
|
22
|
-
};
|
23
|
-
|
24
|
-
export type Box<
|
25
|
-
T extends AmountType,
|
26
|
-
R extends NonMandatoryRegisters = NonMandatoryRegisters
|
27
|
-
> = BoxBaseType<T, R> & {
|
28
|
-
boxId: BoxId;
|
29
|
-
transactionId: TransactionId;
|
30
|
-
index: number;
|
31
|
-
};
|
package/src/types/common.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
export type HexString = string;
|
2
|
-
export type ErgoTreeHex = string;
|
3
|
-
export type Base58String = string;
|
4
|
-
export type Amount = string | bigint;
|
5
|
-
|
6
|
-
export type OneOrMore<T> = T | T[];
|
7
|
-
|
8
|
-
export type SortingSelector<T> = (item: T) => string | number | bigint;
|
9
|
-
export type SortingDirection = "asc" | "desc";
|
10
|
-
|
11
|
-
export type FilterPredicate<T> = (item: T) => boolean;
|
12
|
-
|
13
|
-
export type BuildOutputType = "default" | "EIP-12";
|
14
|
-
|
15
|
-
export enum Network {
|
16
|
-
Mainnet = 0x00,
|
17
|
-
Testnet = 0x10
|
18
|
-
}
|
19
|
-
|
20
|
-
export enum AddressType {
|
21
|
-
P2PK = 1,
|
22
|
-
P2SH = 2,
|
23
|
-
P2S = 3
|
24
|
-
}
|
25
|
-
|
26
|
-
export const ergoTreeHeaderFlags = {
|
27
|
-
sizeInclusion: 0x08,
|
28
|
-
constantSegregation: 0x10
|
29
|
-
} as const;
|
30
|
-
|
31
|
-
export type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];
|
package/src/types/index.ts
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
export * from "./boxes";
|
2
|
-
export * from "./contextExtension";
|
3
|
-
export * from "./inputs";
|
4
|
-
export * from "./common";
|
5
|
-
export * from "./proverResult";
|
6
|
-
export * from "./registers";
|
7
|
-
export * from "./token";
|
8
|
-
export * from "./transactions";
|
9
|
-
export * from "./block";
|
package/src/types/inputs.ts
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import { BoxId } from "./boxes";
|
2
|
-
import { ErgoTreeHex } from "./common";
|
3
|
-
import { ContextExtension } from "./contextExtension";
|
4
|
-
import { ProverResult } from "./proverResult";
|
5
|
-
import { NonMandatoryRegisters } from "./registers";
|
6
|
-
import { TokenAmount } from "./token";
|
7
|
-
import { TransactionId } from "./transactions";
|
8
|
-
|
9
|
-
export type SignedInput = {
|
10
|
-
readonly boxId: BoxId;
|
11
|
-
readonly spendingProof: ProverResult;
|
12
|
-
};
|
13
|
-
|
14
|
-
export type UnsignedInput = {
|
15
|
-
boxId: BoxId;
|
16
|
-
extension: ContextExtension;
|
17
|
-
};
|
18
|
-
|
19
|
-
export type EIP12UnsignedInput = UnsignedInput & {
|
20
|
-
transactionId: TransactionId;
|
21
|
-
index: number;
|
22
|
-
ergoTree: ErgoTreeHex;
|
23
|
-
creationHeight: number;
|
24
|
-
value: string;
|
25
|
-
assets: TokenAmount<string>[];
|
26
|
-
additionalRegisters: NonMandatoryRegisters;
|
27
|
-
};
|
28
|
-
|
29
|
-
export type EIP12UnsignedDataInput = {
|
30
|
-
boxId: BoxId;
|
31
|
-
transactionId: TransactionId;
|
32
|
-
index: number;
|
33
|
-
ergoTree: ErgoTreeHex;
|
34
|
-
creationHeight: number;
|
35
|
-
value: string;
|
36
|
-
assets: TokenAmount<string>[];
|
37
|
-
additionalRegisters: NonMandatoryRegisters;
|
38
|
-
};
|
39
|
-
|
40
|
-
export type DataInput = {
|
41
|
-
boxId: BoxId;
|
42
|
-
};
|
package/src/types/registers.ts
DELETED
package/src/types/token.ts
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
export type TokenId = string;
|
2
|
-
|
3
|
-
type TokenBase<AmountType> = {
|
4
|
-
amount: AmountType;
|
5
|
-
};
|
6
|
-
|
7
|
-
export type TokenAmount<AmountType> = TokenBase<AmountType> & {
|
8
|
-
tokenId: TokenId;
|
9
|
-
};
|
10
|
-
|
11
|
-
export type NewToken<AmountType> = TokenBase<AmountType> & {
|
12
|
-
tokenId?: TokenId;
|
13
|
-
name?: string;
|
14
|
-
decimals?: number;
|
15
|
-
description?: string;
|
16
|
-
};
|
17
|
-
|
18
|
-
export type TokenTargetAmount<AmountType> = {
|
19
|
-
tokenId: TokenId;
|
20
|
-
amount?: AmountType;
|
21
|
-
};
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import { Box, BoxCandidate } from "./boxes";
|
2
|
-
import { Amount } from "./common";
|
3
|
-
import {
|
4
|
-
DataInput,
|
5
|
-
EIP12UnsignedDataInput,
|
6
|
-
EIP12UnsignedInput,
|
7
|
-
SignedInput,
|
8
|
-
UnsignedInput
|
9
|
-
} from "./inputs";
|
10
|
-
|
11
|
-
export type TransactionId = string;
|
12
|
-
|
13
|
-
export type UnsignedTransaction = {
|
14
|
-
id?: TransactionId;
|
15
|
-
inputs: UnsignedInput[];
|
16
|
-
dataInputs: DataInput[];
|
17
|
-
outputs: BoxCandidate<Amount>[];
|
18
|
-
};
|
19
|
-
|
20
|
-
export type EIP12UnsignedTransaction = {
|
21
|
-
id?: TransactionId;
|
22
|
-
inputs: EIP12UnsignedInput[];
|
23
|
-
dataInputs: EIP12UnsignedDataInput[];
|
24
|
-
outputs: BoxCandidate<string>[];
|
25
|
-
};
|
26
|
-
|
27
|
-
export type SignedTransaction = {
|
28
|
-
readonly id: TransactionId;
|
29
|
-
readonly inputs: SignedInput[];
|
30
|
-
readonly dataInputs: DataInput[];
|
31
|
-
readonly outputs: Box<Amount>[];
|
32
|
-
};
|
package/src/utils/array.ts
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
import { SortingDirection, SortingSelector } from "../types";
|
2
|
-
import { assert, isEmpty } from "./assertions";
|
3
|
-
|
4
|
-
type ObjectSelector<T> = (item: T) => T[keyof T];
|
5
|
-
|
6
|
-
export function first(array: undefined): undefined;
|
7
|
-
export function first<T>(array: ArrayLike<T>): T;
|
8
|
-
export function first<T>(array: ArrayLike<T> | undefined): T | number | undefined {
|
9
|
-
if (!array) return undefined;
|
10
|
-
assert(array.length > 0, "Empty array.");
|
11
|
-
|
12
|
-
return array[0];
|
13
|
-
}
|
14
|
-
|
15
|
-
export function last(array: undefined): undefined;
|
16
|
-
export function last<T>(array: ArrayLike<T>): T;
|
17
|
-
export function last<T>(array: ArrayLike<T> | undefined): T | undefined {
|
18
|
-
if (!array) return undefined;
|
19
|
-
assert(array.length > 0, "Empty array.");
|
20
|
-
|
21
|
-
return at(array, -1);
|
22
|
-
}
|
23
|
-
|
24
|
-
export function at(array: undefined, index: number): undefined;
|
25
|
-
export function at<T>(array: ArrayLike<T>, index: number): T;
|
26
|
-
export function at<T>(array: ArrayLike<T> | undefined, index: number): T | undefined {
|
27
|
-
const len = array?.length;
|
28
|
-
if (!len) return undefined;
|
29
|
-
|
30
|
-
if (index < 0) {
|
31
|
-
index += len;
|
32
|
-
}
|
33
|
-
|
34
|
-
return array[index];
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Check for duplicate elements using the equality operator
|
39
|
-
*/
|
40
|
-
export function hasDuplicates<T>(array: T[]): boolean {
|
41
|
-
return array.some((item, index) => {
|
42
|
-
return array.indexOf(item) !== index;
|
43
|
-
});
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Check for duplicate keys in complex elements
|
48
|
-
*/
|
49
|
-
export function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean {
|
50
|
-
return array.some((item, index) => {
|
51
|
-
return array.findIndex((x) => selector(x) === selector(item)) !== index;
|
52
|
-
});
|
53
|
-
}
|
54
|
-
|
55
|
-
export function chunk<T>(array: T[], size: number): T[][] {
|
56
|
-
if (array.length <= size) {
|
57
|
-
return [array];
|
58
|
-
}
|
59
|
-
|
60
|
-
const chunks: T[][] = [];
|
61
|
-
for (let i = 0; i < array.length; i += size) {
|
62
|
-
chunks.push(array.slice(i, i + size));
|
63
|
-
}
|
64
|
-
|
65
|
-
return chunks;
|
66
|
-
}
|
67
|
-
|
68
|
-
export function orderBy<T>(
|
69
|
-
array: T[],
|
70
|
-
iteratee: SortingSelector<T>,
|
71
|
-
order: SortingDirection = "asc"
|
72
|
-
): T[] {
|
73
|
-
return [...array].sort((a: T, b: T) => {
|
74
|
-
if (iteratee(a) > iteratee(b)) {
|
75
|
-
return order === "asc" ? 1 : -1;
|
76
|
-
} else if (iteratee(a) < iteratee(b)) {
|
77
|
-
return order === "asc" ? -1 : 1;
|
78
|
-
} else {
|
79
|
-
return 0;
|
80
|
-
}
|
81
|
-
});
|
82
|
-
}
|
83
|
-
|
84
|
-
export function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {
|
85
|
-
if (array1 === array2) {
|
86
|
-
return true;
|
87
|
-
}
|
88
|
-
|
89
|
-
if (array1.length != array2.length) {
|
90
|
-
return false;
|
91
|
-
}
|
92
|
-
|
93
|
-
for (let i = 0; i < array1.length; i++) {
|
94
|
-
if (array1[i] !== array2[i]) {
|
95
|
-
return false;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
return true;
|
100
|
-
}
|
101
|
-
|
102
|
-
export function areEqualBy<T>(
|
103
|
-
array1: ArrayLike<T>,
|
104
|
-
array2: ArrayLike<T>,
|
105
|
-
selector: ObjectSelector<T>
|
106
|
-
): boolean {
|
107
|
-
if (array1 === array2) {
|
108
|
-
return true;
|
109
|
-
}
|
110
|
-
|
111
|
-
if (array1.length != array2.length) {
|
112
|
-
return false;
|
113
|
-
}
|
114
|
-
|
115
|
-
for (let i = 0; i < array1.length; i++) {
|
116
|
-
if (selector(array1[i]) !== selector(array2[i])) {
|
117
|
-
return false;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
return true;
|
122
|
-
}
|
123
|
-
|
124
|
-
export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
|
125
|
-
if (array === target) {
|
126
|
-
return true;
|
127
|
-
}
|
128
|
-
|
129
|
-
if (target.length > array.length) {
|
130
|
-
return false;
|
131
|
-
}
|
132
|
-
|
133
|
-
for (let i = 0; i < target.length; i++) {
|
134
|
-
if (target[i] !== array[i]) {
|
135
|
-
return false;
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
|
-
return true;
|
140
|
-
}
|
141
|
-
|
142
|
-
export function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
|
143
|
-
if (array === target) {
|
144
|
-
return true;
|
145
|
-
}
|
146
|
-
|
147
|
-
if (target.length > array.length) {
|
148
|
-
return false;
|
149
|
-
}
|
150
|
-
|
151
|
-
const offset = array.length - target.length;
|
152
|
-
|
153
|
-
for (let i = target.length - 1; i >= 0; i--) {
|
154
|
-
if (target[i] !== array[i + offset]) {
|
155
|
-
return false;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
return true;
|
160
|
-
}
|
161
|
-
|
162
|
-
export function uniq<T>(array: Array<T>): Array<T> {
|
163
|
-
if (isEmpty(array)) {
|
164
|
-
return array;
|
165
|
-
}
|
166
|
-
|
167
|
-
return Array.from(new Set(array));
|
168
|
-
}
|
169
|
-
|
170
|
-
export function uniqBy<T>(
|
171
|
-
array: Array<T>,
|
172
|
-
selector: ObjectSelector<T>,
|
173
|
-
selection: "keep-first" | "keep-last" = "keep-first"
|
174
|
-
): Array<T> {
|
175
|
-
if (isEmpty(array)) {
|
176
|
-
return array;
|
177
|
-
}
|
178
|
-
|
179
|
-
return Array.from(
|
180
|
-
array
|
181
|
-
.reduce((map, e) => {
|
182
|
-
const key = selector(e);
|
183
|
-
|
184
|
-
if (selection === "keep-first" && map.has(key)) {
|
185
|
-
return map;
|
186
|
-
}
|
187
|
-
|
188
|
-
return map.set(key, e);
|
189
|
-
}, new Map())
|
190
|
-
.values()
|
191
|
-
);
|
192
|
-
}
|
193
|
-
|
194
|
-
export function depthOf(array: unknown | unknown[]): number {
|
195
|
-
return Array.isArray(array) ? 1 + Math.max(0, ...array.map(depthOf)) : 0;
|
196
|
-
}
|
package/src/utils/assertions.ts
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
export type AssertErrorMessageInput = string | Error | (() => string);
|
2
|
-
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
4
|
-
type Constructable = Function;
|
5
|
-
|
6
|
-
type JSPrimitiveTypes =
|
7
|
-
| "string"
|
8
|
-
| "number"
|
9
|
-
| "bigint"
|
10
|
-
| "boolean"
|
11
|
-
| "symbol"
|
12
|
-
| "undefined"
|
13
|
-
| "object"
|
14
|
-
| "function";
|
15
|
-
|
16
|
-
export function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition {
|
17
|
-
if (condition) return;
|
18
|
-
|
19
|
-
let err: Error | undefined = undefined;
|
20
|
-
switch (typeof error) {
|
21
|
-
case "string":
|
22
|
-
err = new Error(error);
|
23
|
-
break;
|
24
|
-
case "function":
|
25
|
-
err = new Error(error());
|
26
|
-
break;
|
27
|
-
default:
|
28
|
-
err = error;
|
29
|
-
}
|
30
|
-
|
31
|
-
throw err;
|
32
|
-
}
|
33
|
-
|
34
|
-
export function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj {
|
35
|
-
const type = typeof obj;
|
36
|
-
|
37
|
-
if (type !== expected) {
|
38
|
-
throw new Error(`Expected an object of type '${expected}', got '${type}'.`);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
const toString = (value: unknown) => Object.prototype.toString.call(value);
|
43
|
-
function getTypeName(value: unknown): string {
|
44
|
-
if (value === null) return "null";
|
45
|
-
const type = typeof value;
|
46
|
-
|
47
|
-
return type === "object" || type === "function" ? toString(value).slice(8, -1) : type;
|
48
|
-
}
|
49
|
-
|
50
|
-
export function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj {
|
51
|
-
const condition = obj instanceof expected;
|
52
|
-
|
53
|
-
if (!condition) {
|
54
|
-
throw new Error(`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
export function isEmpty<T extends object>(obj?: T): obj is undefined;
|
59
|
-
export function isEmpty<T>(array?: T[]): array is undefined;
|
60
|
-
export function isEmpty<T>(obj?: T[] | object): obj is undefined {
|
61
|
-
if (!obj) return true;
|
62
|
-
|
63
|
-
return Array.isArray(obj) ? obj.length === 0 : Object.keys(obj).length === 0;
|
64
|
-
}
|
65
|
-
|
66
|
-
export function some<T extends object>(obj?: T): obj is T;
|
67
|
-
export function some<T>(array?: T[]): array is T[];
|
68
|
-
export function some<T>(obj?: T[] | object): boolean {
|
69
|
-
return !isEmpty(obj);
|
70
|
-
}
|
71
|
-
|
72
|
-
export function isTruthy<T>(value?: T): value is NonNullable<T> {
|
73
|
-
return !!value;
|
74
|
-
}
|
75
|
-
|
76
|
-
export function isFalsy<T>(value?: T): value is undefined {
|
77
|
-
return !value;
|
78
|
-
}
|
79
|
-
|
80
|
-
export function isUndefined(v: unknown): v is undefined {
|
81
|
-
return v === undefined || v === null || Number.isNaN(v);
|
82
|
-
}
|
83
|
-
|
84
|
-
export function isDefined<T>(v: T | undefined): v is T {
|
85
|
-
return !isUndefined(v);
|
86
|
-
}
|
87
|
-
|
88
|
-
export function hasKey(o: unknown, key: PropertyKey): boolean {
|
89
|
-
return Object.prototype.hasOwnProperty.call(o, key);
|
90
|
-
}
|
package/src/utils/bigInt.ts
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
import { Amount } from "../types";
|
2
|
-
import { first } from "./array";
|
3
|
-
import { isEmpty, isUndefined } from "./assertions";
|
4
|
-
|
5
|
-
type NumberLike = string | number | bigint | boolean;
|
6
|
-
|
7
|
-
export const _0n = BigInt(0);
|
8
|
-
export const _1n = BigInt(1);
|
9
|
-
export const _7n = BigInt(7);
|
10
|
-
export const _10n = BigInt(10);
|
11
|
-
export const _63n = BigInt(63);
|
12
|
-
export const _127n = BigInt(127);
|
13
|
-
export const _128n = BigInt(128);
|
14
|
-
|
15
|
-
export function ensureBigInt(number: NumberLike): bigint {
|
16
|
-
return typeof number === "bigint" ? number : BigInt(number);
|
17
|
-
}
|
18
|
-
|
19
|
-
type ParsingOptions = {
|
20
|
-
/**
|
21
|
-
* Number of decimals.
|
22
|
-
*/
|
23
|
-
decimals?: number;
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Thousand mark char.
|
27
|
-
* Default: `.`
|
28
|
-
*/
|
29
|
-
decimalMark?: string;
|
30
|
-
};
|
31
|
-
|
32
|
-
export function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint {
|
33
|
-
if (!decimalStr) {
|
34
|
-
return _0n;
|
35
|
-
}
|
36
|
-
|
37
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
38
|
-
if (isUndefined(options)) {
|
39
|
-
options = {};
|
40
|
-
}
|
41
|
-
|
42
|
-
options.decimals = options.decimals || 0;
|
43
|
-
options.decimalMark = options.decimalMark || ".";
|
44
|
-
|
45
|
-
const fragments = decimalStr.split(options.decimalMark);
|
46
|
-
if (fragments.length > 2) {
|
47
|
-
throw new Error("Invalid numeric string.");
|
48
|
-
}
|
49
|
-
|
50
|
-
let [integer, decimal] = fragments;
|
51
|
-
integer = _removeLeadingZeros(integer);
|
52
|
-
const negative = integer.startsWith("-") ? "-" : "";
|
53
|
-
|
54
|
-
if (!decimal) {
|
55
|
-
decimal = "0".repeat(options.decimals);
|
56
|
-
} else if (decimal.length < options.decimals) {
|
57
|
-
decimal = decimal.padEnd(options.decimals, "0");
|
58
|
-
}
|
59
|
-
|
60
|
-
return BigInt(negative + _stripNonDigits(integer + decimal));
|
61
|
-
}
|
62
|
-
|
63
|
-
function _stripNonDigits(value: string): string {
|
64
|
-
return value.replace(/\D/g, "");
|
65
|
-
}
|
66
|
-
|
67
|
-
type FormattingOptions = {
|
68
|
-
/**
|
69
|
-
* Number of decimals.
|
70
|
-
*/
|
71
|
-
decimals: number;
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Thousand mark char.
|
75
|
-
*/
|
76
|
-
thousandMark?: string;
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Decimal mark char.
|
80
|
-
* Default: `.`
|
81
|
-
*/
|
82
|
-
decimalMark?: string;
|
83
|
-
};
|
84
|
-
|
85
|
-
export function decimalize(value: Amount, options?: FormattingOptions | number): string {
|
86
|
-
value = ensureBigInt(value);
|
87
|
-
if (!options) {
|
88
|
-
return value.toString();
|
89
|
-
}
|
90
|
-
|
91
|
-
options = typeof options == "number" ? { decimals: options } : options;
|
92
|
-
options.decimals = options.decimals || 0;
|
93
|
-
options.decimalMark = options.decimalMark || ".";
|
94
|
-
|
95
|
-
const pow = _10n ** BigInt(options.decimals);
|
96
|
-
const integer = value / pow;
|
97
|
-
const decimal = value - integer * pow;
|
98
|
-
|
99
|
-
return _buildFormattedDecimal(integer.toString(10), decimal.toString(10), options);
|
100
|
-
}
|
101
|
-
|
102
|
-
export function percent(value: bigint, percentage: bigint, precision = 2n) {
|
103
|
-
return (value * percentage) / 10n ** precision;
|
104
|
-
}
|
105
|
-
|
106
|
-
function _buildFormattedDecimal(
|
107
|
-
integer: string,
|
108
|
-
decimal: string,
|
109
|
-
options: FormattingOptions
|
110
|
-
): string {
|
111
|
-
const integerPart = _addThousandMarks(integer, options.thousandMark);
|
112
|
-
const decimalPart = _stripTrailingZeros(decimal.padStart(options.decimals, "0"));
|
113
|
-
|
114
|
-
if (decimalPart) {
|
115
|
-
return `${integerPart}${options.decimalMark}${decimalPart}`;
|
116
|
-
} else {
|
117
|
-
return integerPart;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
function _addThousandMarks(value: string, mark?: string): string {
|
122
|
-
if (!mark) {
|
123
|
-
return value;
|
124
|
-
}
|
125
|
-
|
126
|
-
return value.replace(/\B(?=(\d{3})+(?!\d))/g, mark);
|
127
|
-
}
|
128
|
-
|
129
|
-
function _stripTrailingZeros(value: string): string {
|
130
|
-
if (!value.endsWith("0")) {
|
131
|
-
return value;
|
132
|
-
}
|
133
|
-
|
134
|
-
return value.replace(/\.?0+$/, "");
|
135
|
-
}
|
136
|
-
|
137
|
-
function _removeLeadingZeros(value: string): string {
|
138
|
-
if (!value.startsWith("0")) {
|
139
|
-
return value;
|
140
|
-
}
|
141
|
-
|
142
|
-
return value.replace(/^0+\.?/, "");
|
143
|
-
}
|
144
|
-
|
145
|
-
export function sumBy<T>(
|
146
|
-
collection: readonly T[],
|
147
|
-
iteratee: (value: T) => bigint,
|
148
|
-
condition?: (value: T) => boolean
|
149
|
-
): bigint {
|
150
|
-
let acc = _0n;
|
151
|
-
if (isEmpty(collection)) {
|
152
|
-
return acc;
|
153
|
-
}
|
154
|
-
|
155
|
-
for (const item of collection) {
|
156
|
-
if (isUndefined(condition) || condition(item)) {
|
157
|
-
acc += iteratee(item);
|
158
|
-
}
|
159
|
-
}
|
160
|
-
|
161
|
-
return acc;
|
162
|
-
}
|
163
|
-
|
164
|
-
export function min<T extends bigint | number>(...numbers: T[]): T {
|
165
|
-
let min = first(numbers);
|
166
|
-
|
167
|
-
for (const num of numbers) {
|
168
|
-
if (num < min) {
|
169
|
-
min = num;
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
return min;
|
174
|
-
}
|
175
|
-
|
176
|
-
export function max<T extends bigint | number>(...numbers: T[]): T {
|
177
|
-
let max = first(numbers);
|
178
|
-
|
179
|
-
for (const num of numbers) {
|
180
|
-
if (num > max) {
|
181
|
-
max = num;
|
182
|
-
}
|
183
|
-
}
|
184
|
-
|
185
|
-
return max;
|
186
|
-
}
|
package/src/utils/bytes.bench.ts
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
import { bench, describe } from "vitest";
|
2
|
-
import { isHex } from "./bytes";
|
3
|
-
|
4
|
-
const HEX_PATTERN = /^[0-9A-Fa-f]+$/s;
|
5
|
-
export function isHexRegex(value?: string) {
|
6
|
-
if (!value || value.length % 2) return false;
|
7
|
-
|
8
|
-
return HEX_PATTERN.test(value);
|
9
|
-
}
|
10
|
-
|
11
|
-
const HEX_CHARSET = new Set("0123456789abcdefABCDEF");
|
12
|
-
function isHexChar(value: string) {
|
13
|
-
if (!value || value.length % 2) return false;
|
14
|
-
|
15
|
-
const valueSet = new Set(Array.from(value));
|
16
|
-
for (const c of valueSet) {
|
17
|
-
if (!HEX_CHARSET.has(c)) {
|
18
|
-
return false;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
return true;
|
23
|
-
}
|
24
|
-
|
25
|
-
describe("Hex string checking", () => {
|
26
|
-
const validHex = "0008cd026dc059d64a50d0dbf07755c2c4a4e557e3df8afa7141868b3ab200643d437ee7";
|
27
|
-
const invalidHex = "0008cd026dc059d64a50d0dbf07755c2c4a4e557e3df8afa7141868b3ab200643d437ee7tt";
|
28
|
-
|
29
|
-
bench("Using charset", () => {
|
30
|
-
isHexChar(validHex);
|
31
|
-
isHexChar(invalidHex);
|
32
|
-
});
|
33
|
-
|
34
|
-
bench("Using regex", () => {
|
35
|
-
isHexRegex(validHex);
|
36
|
-
isHexRegex(invalidHex);
|
37
|
-
});
|
38
|
-
|
39
|
-
bench("Using number constructor", () => {
|
40
|
-
isHex(validHex);
|
41
|
-
isHex(invalidHex);
|
42
|
-
});
|
43
|
-
});
|
package/src/utils/bytes.ts
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import { assertInstanceOf } from ".";
|
2
|
-
|
3
|
-
export function concatBytes(...arrays: Uint8Array[]): Uint8Array {
|
4
|
-
const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
|
5
|
-
|
6
|
-
let pad = 0;
|
7
|
-
for (const bytes of arrays) {
|
8
|
-
assertInstanceOf(bytes, Uint8Array);
|
9
|
-
|
10
|
-
r.set(bytes, pad);
|
11
|
-
pad += bytes.length;
|
12
|
-
}
|
13
|
-
|
14
|
-
return r;
|
15
|
-
}
|
16
|
-
|
17
|
-
export function isHex(value?: string) {
|
18
|
-
if (!value || value.length % 2) return false;
|
19
|
-
|
20
|
-
if (!value.startsWith("0x")) {
|
21
|
-
value = "0x" + value;
|
22
|
-
}
|
23
|
-
|
24
|
-
return !isNaN(Number(value));
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Get hex string size in bytes
|
29
|
-
* @param hex
|
30
|
-
* @returns the byte size if the hex string
|
31
|
-
*/
|
32
|
-
export function byteSizeOf(hex: string): number {
|
33
|
-
return hex.length / 2;
|
34
|
-
}
|
package/src/utils/index.ts
DELETED
package/src/utils/object.ts
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
import { isEmpty, isUndefined } from "./assertions";
|
2
|
-
|
3
|
-
export function clearUndefined(value: Record<string, unknown>) {
|
4
|
-
const result: Record<string, unknown> = {};
|
5
|
-
for (const key in value) {
|
6
|
-
const val = value[key];
|
7
|
-
if (!isUndefined(val)) {
|
8
|
-
result[key] = val;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
return result;
|
13
|
-
}
|
14
|
-
|
15
|
-
export function ensureDefaults<T extends Partial<R>, R extends object = Required<T>>(
|
16
|
-
options: T | undefined,
|
17
|
-
defaults: R
|
18
|
-
): R & T {
|
19
|
-
if (isEmpty(options)) return defaults as R & T;
|
20
|
-
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
22
|
-
const newObj: any = { ...defaults, ...options };
|
23
|
-
for (const key in newObj) {
|
24
|
-
newObj[key as keyof object] = options[key as keyof R] ?? defaults[key as keyof R];
|
25
|
-
}
|
26
|
-
|
27
|
-
return newObj;
|
28
|
-
}
|
package/src/utils/utxo.ts
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Amount,
|
3
|
-
AmountType,
|
4
|
-
Box,
|
5
|
-
BoxCandidate,
|
6
|
-
NonMandatoryRegisters,
|
7
|
-
TokenAmount,
|
8
|
-
TokenId
|
9
|
-
} from "../types";
|
10
|
-
import { isDefined, isEmpty, isUndefined } from "./assertions";
|
11
|
-
import { ensureBigInt } from "./bigInt";
|
12
|
-
import { _0n } from "./bigInt";
|
13
|
-
|
14
|
-
const NANOERGS_TOKEN_ID = "nanoErgs";
|
15
|
-
|
16
|
-
export function utxoSum(boxes: MinimalBoxAmounts): BoxSummary;
|
17
|
-
export function utxoSum(boxes: MinimalBoxAmounts, tokenId: TokenId): bigint;
|
18
|
-
export function utxoSum(boxes: MinimalBoxAmounts, tokenId?: TokenId): BoxSummary | bigint {
|
19
|
-
const balances: { [tokenId: string]: bigint } = {};
|
20
|
-
|
21
|
-
for (const box of boxes) {
|
22
|
-
if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {
|
23
|
-
balances[NANOERGS_TOKEN_ID] = (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);
|
24
|
-
}
|
25
|
-
|
26
|
-
if (tokenId !== NANOERGS_TOKEN_ID) {
|
27
|
-
for (const token of box.assets) {
|
28
|
-
if (isDefined(tokenId) && tokenId !== token.tokenId) {
|
29
|
-
continue;
|
30
|
-
}
|
31
|
-
|
32
|
-
balances[token.tokenId] = (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
if (isDefined(tokenId)) {
|
38
|
-
return balances[tokenId] || _0n;
|
39
|
-
}
|
40
|
-
|
41
|
-
return {
|
42
|
-
nanoErgs: balances[NANOERGS_TOKEN_ID] || _0n,
|
43
|
-
tokens: Object.keys(balances)
|
44
|
-
.filter((x) => x !== NANOERGS_TOKEN_ID)
|
45
|
-
.map((tokenId) => ({ tokenId, amount: balances[tokenId] }))
|
46
|
-
};
|
47
|
-
}
|
48
|
-
|
49
|
-
export function utxoDiff(
|
50
|
-
minuend: BoxSummary | Box<Amount>[],
|
51
|
-
subtrahend: BoxSummary | Box<Amount>[]
|
52
|
-
): BoxSummary {
|
53
|
-
if (Array.isArray(minuend)) {
|
54
|
-
minuend = utxoSum(minuend);
|
55
|
-
}
|
56
|
-
|
57
|
-
if (Array.isArray(subtrahend)) {
|
58
|
-
subtrahend = utxoSum(subtrahend);
|
59
|
-
}
|
60
|
-
|
61
|
-
const tokens: TokenAmount<bigint>[] = [];
|
62
|
-
const nanoErgs = minuend.nanoErgs - subtrahend.nanoErgs;
|
63
|
-
|
64
|
-
for (const token of minuend.tokens) {
|
65
|
-
const balance =
|
66
|
-
token.amount - (subtrahend.tokens.find((t) => t.tokenId === token.tokenId)?.amount || _0n);
|
67
|
-
|
68
|
-
if (balance !== _0n) {
|
69
|
-
tokens.push({ tokenId: token.tokenId, amount: balance });
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
return { nanoErgs, tokens };
|
74
|
-
}
|
75
|
-
|
76
|
-
const MIN_NON_MANDATORY_REGISTER_INDEX = 4;
|
77
|
-
const MAX_NON_MANDATORY_REGISTER_INDEX = 9;
|
78
|
-
|
79
|
-
export function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {
|
80
|
-
let lastIndex = 0;
|
81
|
-
for (let i = MIN_NON_MANDATORY_REGISTER_INDEX; i <= MAX_NON_MANDATORY_REGISTER_INDEX; i++) {
|
82
|
-
const key = `R${i}` as keyof NonMandatoryRegisters;
|
83
|
-
if (registers[key]) {
|
84
|
-
if (i === MIN_NON_MANDATORY_REGISTER_INDEX) {
|
85
|
-
lastIndex = i;
|
86
|
-
continue;
|
87
|
-
}
|
88
|
-
|
89
|
-
if (i - lastIndex > 1) {
|
90
|
-
return false;
|
91
|
-
}
|
92
|
-
|
93
|
-
lastIndex = i;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
return true;
|
98
|
-
}
|
99
|
-
|
100
|
-
export function utxoFilter<T extends AmountType>(
|
101
|
-
utxos: Box<T>[],
|
102
|
-
filterParams: UTxOFilterParams<T>
|
103
|
-
) {
|
104
|
-
if (isEmpty(filterParams) || isEmpty(utxos)) {
|
105
|
-
return utxos;
|
106
|
-
}
|
107
|
-
|
108
|
-
const { by, max } = filterParams;
|
109
|
-
let filtered = utxos;
|
110
|
-
|
111
|
-
if (by) {
|
112
|
-
filtered = utxos.filter(by);
|
113
|
-
if (isEmpty(filtered)) {
|
114
|
-
return filtered;
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
if (!max) {
|
119
|
-
return filtered;
|
120
|
-
}
|
121
|
-
|
122
|
-
if (isDefined(max.aggregatedDistinctTokens)) {
|
123
|
-
const tokenIds = _getDistinctTokenIds(filtered, max.aggregatedDistinctTokens);
|
124
|
-
filtered = filtered.filter(
|
125
|
-
(utxo) => isEmpty(utxo.assets) || utxo.assets.every((token) => tokenIds.has(token.tokenId))
|
126
|
-
);
|
127
|
-
}
|
128
|
-
|
129
|
-
if (isDefined(max.count) && filtered.length > max.count) {
|
130
|
-
filtered = filtered.slice(0, max.count);
|
131
|
-
}
|
132
|
-
|
133
|
-
return filtered;
|
134
|
-
}
|
135
|
-
|
136
|
-
function _getDistinctTokenIds(utxos: Box<AmountType>[], max: number): Set<string> {
|
137
|
-
const tokenIds = new Set<string>();
|
138
|
-
|
139
|
-
for (let i = 0; i < utxos.length && tokenIds.size < max; i++) {
|
140
|
-
if (isEmpty(utxos[i].assets) || utxos[i].assets.length > max) {
|
141
|
-
continue;
|
142
|
-
}
|
143
|
-
|
144
|
-
for (const token of utxos[i].assets) {
|
145
|
-
tokenIds.add(token.tokenId);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
return tokenIds;
|
150
|
-
}
|
151
|
-
|
152
|
-
export type UTxOFilterParams<T extends AmountType> = {
|
153
|
-
by?: (utxo: Box<T>) => boolean;
|
154
|
-
max?: {
|
155
|
-
count?: number;
|
156
|
-
aggregatedDistinctTokens?: number;
|
157
|
-
};
|
158
|
-
};
|
159
|
-
|
160
|
-
export type BoxSummary = {
|
161
|
-
nanoErgs: bigint;
|
162
|
-
tokens: TokenAmount<bigint>[];
|
163
|
-
};
|
164
|
-
|
165
|
-
export type MinimalBoxAmounts = readonly {
|
166
|
-
value: Amount;
|
167
|
-
assets: TokenAmount<Amount>[];
|
168
|
-
}[];
|
169
|
-
|
170
|
-
export function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;
|
171
|
-
export function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;
|
172
|
-
export function ensureUTxOBigInt(
|
173
|
-
box: Box<Amount> | BoxCandidate<Amount>
|
174
|
-
): BoxCandidate<bigint> | Box<bigint> {
|
175
|
-
return {
|
176
|
-
...box,
|
177
|
-
value: ensureBigInt(box.value),
|
178
|
-
assets: box.assets.map((token) => ({
|
179
|
-
tokenId: token.tokenId,
|
180
|
-
amount: ensureBigInt(token.amount)
|
181
|
-
}))
|
182
|
-
};
|
183
|
-
}
|