@fleet-sdk/common 0.1.0-alpha.12
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/types/boxes.d.ts +21 -0
- package/dist/cjs/types/boxes.js +3 -0
- package/dist/cjs/types/common.d.ts +17 -0
- package/dist/cjs/types/common.js +15 -0
- package/dist/cjs/types/contextExtension.d.ts +4 -0
- package/dist/cjs/types/contextExtension.js +3 -0
- package/dist/cjs/types/index.d.ts +8 -0
- package/dist/cjs/types/index.js +25 -0
- package/dist/cjs/types/inputs.d.ts +37 -0
- package/dist/cjs/types/inputs.js +3 -0
- package/dist/cjs/types/proverResult.d.ts +6 -0
- package/dist/cjs/types/proverResult.js +3 -0
- package/dist/cjs/types/registers.d.ts +9 -0
- package/dist/cjs/types/registers.js +3 -0
- package/dist/cjs/types/token.d.ts +18 -0
- package/dist/cjs/types/token.js +3 -0
- package/dist/cjs/types/transactions.d.ts +22 -0
- package/dist/cjs/types/transactions.js +3 -0
- package/dist/cjs/utils/arrayUtils.d.ts +21 -0
- package/dist/cjs/utils/arrayUtils.js +114 -0
- package/dist/cjs/utils/bigIntLiterals.d.ts +5 -0
- package/dist/cjs/utils/bigIntLiterals.js +10 -0
- package/dist/cjs/utils/bigIntUtils.d.ts +2 -0
- package/dist/cjs/utils/bigIntUtils.js +24 -0
- package/dist/cjs/utils/boxUtils.d.ts +17 -0
- package/dist/cjs/utils/boxUtils.js +53 -0
- package/dist/cjs/utils/index.d.ts +6 -0
- package/dist/cjs/utils/index.js +23 -0
- package/dist/cjs/utils/objectUtils.d.ts +3 -0
- package/dist/cjs/utils/objectUtils.js +23 -0
- package/dist/cjs/utils/stringUtils.d.ts +1 -0
- package/dist/cjs/utils/stringUtils.js +12 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/types/boxes.d.ts +21 -0
- package/dist/esm/types/boxes.js +2 -0
- package/dist/esm/types/common.d.ts +17 -0
- package/dist/esm/types/common.js +12 -0
- package/dist/esm/types/contextExtension.d.ts +4 -0
- package/dist/esm/types/contextExtension.js +2 -0
- package/dist/esm/types/index.d.ts +8 -0
- package/dist/esm/types/index.js +9 -0
- package/dist/esm/types/inputs.d.ts +37 -0
- package/dist/esm/types/inputs.js +2 -0
- package/dist/esm/types/proverResult.d.ts +6 -0
- package/dist/esm/types/proverResult.js +2 -0
- package/dist/esm/types/registers.d.ts +9 -0
- package/dist/esm/types/registers.js +2 -0
- package/dist/esm/types/token.d.ts +18 -0
- package/dist/esm/types/token.js +2 -0
- package/dist/esm/types/transactions.d.ts +22 -0
- package/dist/esm/types/transactions.js +2 -0
- package/dist/esm/utils/arrayUtils.d.ts +21 -0
- package/dist/esm/utils/arrayUtils.js +101 -0
- package/dist/esm/utils/bigIntLiterals.d.ts +5 -0
- package/dist/esm/utils/bigIntLiterals.js +7 -0
- package/dist/esm/utils/bigIntUtils.d.ts +2 -0
- package/dist/esm/utils/bigIntUtils.js +19 -0
- package/dist/esm/utils/boxUtils.d.ts +17 -0
- package/dist/esm/utils/boxUtils.js +48 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/objectUtils.d.ts +3 -0
- package/dist/esm/utils/objectUtils.js +17 -0
- package/dist/esm/utils/stringUtils.d.ts +1 -0
- package/dist/esm/utils/stringUtils.js +8 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +52 -0
- package/src/index.ts +2 -0
- package/src/types/boxes.ts +24 -0
- package/src/types/common.ts +22 -0
- package/src/types/contextExtension.ts +3 -0
- package/src/types/index.ts +8 -0
- package/src/types/inputs.ts +42 -0
- package/src/types/proverResult.ts +7 -0
- package/src/types/registers.ts +10 -0
- package/src/types/token.ts +21 -0
- package/src/types/transactions.ts +32 -0
- package/src/utils/arrayUtils.ts +135 -0
- package/src/utils/bigIntLiterals.ts +7 -0
- package/src/utils/bigIntUtils.ts +26 -0
- package/src/utils/boxUtils.ts +77 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/objectUtils.ts +19 -0
- package/src/utils/stringUtils.ts +9 -0
package/package.json
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"name": "@fleet-sdk/common",
|
3
|
+
"version": "0.1.0-alpha.12",
|
4
|
+
"description": "Internal utility functions, constants and types shared across @fleet-sdk packages.",
|
5
|
+
"main": "dist/cjs/index.js",
|
6
|
+
"module": "dist/esm/index.js",
|
7
|
+
"typings": "dist/esm/index.d.ts",
|
8
|
+
"sideEffects": false,
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "https://github.com/fleet-sdk/fleet.git",
|
12
|
+
"directory": "packages/common"
|
13
|
+
},
|
14
|
+
"license": "MIT",
|
15
|
+
"publishConfig": {
|
16
|
+
"access": "public"
|
17
|
+
},
|
18
|
+
"keywords": [
|
19
|
+
"ergo",
|
20
|
+
"blockchain"
|
21
|
+
],
|
22
|
+
"engines": {
|
23
|
+
"node": ">=10"
|
24
|
+
},
|
25
|
+
"files": [
|
26
|
+
"src",
|
27
|
+
"dist",
|
28
|
+
"!**/*.spec.*",
|
29
|
+
"!**/*.json",
|
30
|
+
"!tests",
|
31
|
+
"CHANGELOG.md",
|
32
|
+
"LICENSE",
|
33
|
+
"README.md"
|
34
|
+
],
|
35
|
+
"scripts": {
|
36
|
+
"build": "run-p build:*",
|
37
|
+
"build:cjs": "tsc -p tsconfig.json",
|
38
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
39
|
+
"fix": "run-s fix:*",
|
40
|
+
"fix:prettier": "prettier src/**/*.ts --write",
|
41
|
+
"fix:lint": "eslint src --ext .ts --fix",
|
42
|
+
"test": "run-s build test:*",
|
43
|
+
"test:lint": "eslint src --ext .ts",
|
44
|
+
"test:prettier": "prettier src/**/*.ts --list-different",
|
45
|
+
"test:unit": "jest",
|
46
|
+
"watch:build": "tsc -p tsconfig.json -w",
|
47
|
+
"watch:test": "jest --watch",
|
48
|
+
"cov:html": "jest --coverage --coverageReporters=html ; open-cli coverage/index.html",
|
49
|
+
"cov:json": "jest --coverage --coverageReporters=json",
|
50
|
+
"cov:check": "jest --coverage --coverageReporters=text"
|
51
|
+
}
|
52
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { ErgoTree } from "./common";
|
2
|
+
import { NonMandatoryRegisters } from "./registers";
|
3
|
+
import { TokenAmount } from "./token";
|
4
|
+
import { TransactionId } from "./transactions";
|
5
|
+
|
6
|
+
export type BoxId = string;
|
7
|
+
|
8
|
+
type BoxBaseType<AmountType> = {
|
9
|
+
ergoTree: ErgoTree;
|
10
|
+
creationHeight: number;
|
11
|
+
value: AmountType;
|
12
|
+
assets: TokenAmount<AmountType>[];
|
13
|
+
additionalRegisters: NonMandatoryRegisters;
|
14
|
+
};
|
15
|
+
|
16
|
+
export type BoxCandidate<AmountType> = BoxBaseType<AmountType> & {
|
17
|
+
boxId?: BoxId;
|
18
|
+
};
|
19
|
+
|
20
|
+
export type Box<AmountType> = BoxBaseType<AmountType> & {
|
21
|
+
boxId: BoxId;
|
22
|
+
transactionId: TransactionId;
|
23
|
+
index: number;
|
24
|
+
};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export type HexString = string;
|
2
|
+
export type ErgoTree = string;
|
3
|
+
export type Base58String = string;
|
4
|
+
export type Amount = string | bigint;
|
5
|
+
|
6
|
+
export type SortingSelector<T> = (item: T) => string | number | bigint;
|
7
|
+
export type SortingDirection = "asc" | "desc";
|
8
|
+
|
9
|
+
export type FilterPredicate<T> = (item: T) => boolean;
|
10
|
+
|
11
|
+
export type BuildOutputType = "default" | "EIP-12";
|
12
|
+
|
13
|
+
export enum Network {
|
14
|
+
Mainnet = 0 << 4,
|
15
|
+
Testnet = 1 << 4
|
16
|
+
}
|
17
|
+
|
18
|
+
export enum AddressType {
|
19
|
+
P2PK = 1,
|
20
|
+
P2SH = 2,
|
21
|
+
P2S = 3
|
22
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { BoxId } from "./boxes";
|
2
|
+
import { ErgoTree } 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: ErgoTree;
|
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: ErgoTree;
|
34
|
+
creationHeight: number;
|
35
|
+
value: string;
|
36
|
+
assets: TokenAmount<string>[];
|
37
|
+
additionalRegisters: NonMandatoryRegisters;
|
38
|
+
};
|
39
|
+
|
40
|
+
export type DataInput = {
|
41
|
+
boxId: BoxId;
|
42
|
+
};
|
@@ -0,0 +1,21 @@
|
|
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
|
+
};
|
@@ -0,0 +1,32 @@
|
|
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
|
+
};
|
@@ -0,0 +1,135 @@
|
|
1
|
+
import { SortingDirection, SortingSelector } from "../types";
|
2
|
+
|
3
|
+
export function isEmpty<T extends object>(obj?: T): obj is undefined;
|
4
|
+
export function isEmpty<T>(array?: T[]): array is undefined;
|
5
|
+
export function isEmpty<T>(obj?: T[] | object): obj is undefined {
|
6
|
+
if (!obj) {
|
7
|
+
return true;
|
8
|
+
}
|
9
|
+
|
10
|
+
return Array.isArray(obj) ? obj.length === 0 : Object.keys(obj).length === 0;
|
11
|
+
}
|
12
|
+
|
13
|
+
export function some<T extends object>(obj?: T): obj is T;
|
14
|
+
export function some<T>(array?: T[]): array is T[];
|
15
|
+
export function some<T>(obj?: T[] | object): boolean {
|
16
|
+
return !isEmpty(obj);
|
17
|
+
}
|
18
|
+
|
19
|
+
export function first(array: undefined): undefined;
|
20
|
+
export function first(array: Uint8Array): number;
|
21
|
+
export function first<T>(array: ArrayLike<T>): T;
|
22
|
+
export function first<T>(array?: ArrayLike<T> | Uint8Array): T | number | undefined {
|
23
|
+
if (!array) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!array[0]) {
|
28
|
+
throw Error("Empty array.");
|
29
|
+
}
|
30
|
+
|
31
|
+
return array[0];
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Check for duplicate elements using the equality operator
|
36
|
+
*/
|
37
|
+
export function hasDuplicates<T>(array: T[]): boolean {
|
38
|
+
return array.some((item, index) => {
|
39
|
+
return array.indexOf(item) !== index;
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Check for duplicate keys in complex elements
|
45
|
+
*/
|
46
|
+
export function hasDuplicatesBy<T>(array: T[], selector: (value: T) => unknown): boolean {
|
47
|
+
return array.some((item, index) => {
|
48
|
+
return array.findIndex((x) => selector(x) === selector(item)) !== index;
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
export function chunk<T>(array: T[], size: number): T[][] {
|
53
|
+
if (array.length <= size) {
|
54
|
+
return [array];
|
55
|
+
}
|
56
|
+
|
57
|
+
const chunks: T[][] = [];
|
58
|
+
for (let i = 0; i < array.length; i += size) {
|
59
|
+
chunks.push(array.slice(i, i + size));
|
60
|
+
}
|
61
|
+
|
62
|
+
return chunks;
|
63
|
+
}
|
64
|
+
|
65
|
+
export function orderBy<T>(
|
66
|
+
array: T[],
|
67
|
+
iteratee: SortingSelector<T>,
|
68
|
+
order: SortingDirection = "asc"
|
69
|
+
): T[] {
|
70
|
+
return array.sort((a: T, b: T) => {
|
71
|
+
if (iteratee(a) > iteratee(b)) {
|
72
|
+
return order === "asc" ? 1 : -1;
|
73
|
+
} else if (iteratee(a) < iteratee(b)) {
|
74
|
+
return order === "asc" ? -1 : 1;
|
75
|
+
} else {
|
76
|
+
return 0;
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
export function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean {
|
82
|
+
if (array1 === array2) {
|
83
|
+
return true;
|
84
|
+
}
|
85
|
+
|
86
|
+
if (array1.length != array2.length) {
|
87
|
+
return false;
|
88
|
+
}
|
89
|
+
|
90
|
+
for (let i = 0; i < array1.length; i++) {
|
91
|
+
if (array1[i] !== array2[i]) {
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
|
99
|
+
export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
|
100
|
+
if (array === target) {
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (target.length > array.length) {
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
|
108
|
+
for (let i = 0; i < target.length; i++) {
|
109
|
+
if (target[i] !== array[i]) {
|
110
|
+
return false;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
|
117
|
+
export function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
|
118
|
+
if (array === target) {
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
|
122
|
+
if (target.length > array.length) {
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
|
126
|
+
const offset = array.length - target.length;
|
127
|
+
|
128
|
+
for (let i = target.length - 1; i >= 0; i--) {
|
129
|
+
if (target[i] !== array[i + offset]) {
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
return true;
|
135
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { isEmpty } from "./arrayUtils";
|
2
|
+
import { _0n } from "./bigIntLiterals";
|
3
|
+
import { isUndefined } from "./objectUtils";
|
4
|
+
|
5
|
+
export function ensureBigInt(number: string | number | bigint | boolean): bigint {
|
6
|
+
return typeof number === "bigint" ? number : BigInt(number);
|
7
|
+
}
|
8
|
+
|
9
|
+
export function sumBy<T>(
|
10
|
+
collection: T[],
|
11
|
+
iteratee: (value: T) => bigint,
|
12
|
+
condition?: (value: T) => boolean
|
13
|
+
): bigint {
|
14
|
+
let acc = _0n;
|
15
|
+
if (isEmpty(collection)) {
|
16
|
+
return acc;
|
17
|
+
}
|
18
|
+
|
19
|
+
for (const item of collection) {
|
20
|
+
if (isUndefined(condition) || condition(item)) {
|
21
|
+
acc += iteratee(item);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
return acc;
|
26
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { Amount, NonMandatoryRegisters, TokenId } from "../types";
|
2
|
+
import { _0n } from "./bigIntLiterals";
|
3
|
+
import { ensureBigInt } from "./bigIntUtils";
|
4
|
+
import { isDefined, isUndefined } from "./objectUtils";
|
5
|
+
|
6
|
+
const NANOERGS_TOKEN_ID = "nanoErgs";
|
7
|
+
|
8
|
+
export function utxoSum(boxes: MinimalBoxAmountFields[]): BoxAmounts;
|
9
|
+
export function utxoSum(boxes: MinimalBoxAmountFields[], tokenId: TokenId): bigint;
|
10
|
+
export function utxoSum(boxes: MinimalBoxAmountFields[], tokenId?: TokenId): BoxAmounts | bigint {
|
11
|
+
const balances: { [tokenId: string]: bigint } = {};
|
12
|
+
|
13
|
+
for (const box of boxes) {
|
14
|
+
if (isUndefined(tokenId) || tokenId === NANOERGS_TOKEN_ID) {
|
15
|
+
balances[NANOERGS_TOKEN_ID] = (balances[NANOERGS_TOKEN_ID] || _0n) + ensureBigInt(box.value);
|
16
|
+
}
|
17
|
+
|
18
|
+
if (tokenId !== NANOERGS_TOKEN_ID) {
|
19
|
+
for (const token of box.assets) {
|
20
|
+
if (isDefined(tokenId) && tokenId !== token.tokenId) {
|
21
|
+
continue;
|
22
|
+
}
|
23
|
+
|
24
|
+
balances[token.tokenId] = (balances[token.tokenId] || _0n) + ensureBigInt(token.amount);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
if (isDefined(tokenId)) {
|
30
|
+
return balances[tokenId] || _0n;
|
31
|
+
}
|
32
|
+
|
33
|
+
return {
|
34
|
+
nanoErgs: balances[NANOERGS_TOKEN_ID],
|
35
|
+
tokens: Object.keys(balances)
|
36
|
+
.filter((x) => x !== NANOERGS_TOKEN_ID)
|
37
|
+
.map((tokenId) => ({ tokenId, amount: balances[tokenId] }))
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
const MIN_REGISTER_NUMBER = 4;
|
42
|
+
const MAX_REGISTER_NUMBER = 9;
|
43
|
+
|
44
|
+
export function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean {
|
45
|
+
let lastValueIndex = 0;
|
46
|
+
for (let i = MIN_REGISTER_NUMBER; i <= MAX_REGISTER_NUMBER; i++) {
|
47
|
+
if (registers[`R${i}` as keyof NonMandatoryRegisters]) {
|
48
|
+
if (i === MIN_REGISTER_NUMBER) {
|
49
|
+
lastValueIndex = i;
|
50
|
+
continue;
|
51
|
+
}
|
52
|
+
|
53
|
+
if (i - lastValueIndex > 1) {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
lastValueIndex = i;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
|
64
|
+
type TokenAmount<AmountType> = {
|
65
|
+
tokenId: TokenId;
|
66
|
+
amount: AmountType;
|
67
|
+
};
|
68
|
+
|
69
|
+
export type BoxAmounts = {
|
70
|
+
nanoErgs: bigint;
|
71
|
+
tokens: TokenAmount<bigint>[];
|
72
|
+
};
|
73
|
+
|
74
|
+
type MinimalBoxAmountFields = {
|
75
|
+
value: Amount;
|
76
|
+
assets: TokenAmount<Amount>[];
|
77
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export function removeUndefined(value: Record<string, unknown>) {
|
2
|
+
const result: Record<string, unknown> = {};
|
3
|
+
for (const key in value) {
|
4
|
+
const val = value[key];
|
5
|
+
if (!isUndefined(val)) {
|
6
|
+
result[key] = val;
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
return result;
|
11
|
+
}
|
12
|
+
|
13
|
+
export function isUndefined(value: unknown): value is undefined {
|
14
|
+
return value === undefined || value === null || Number.isNaN(value);
|
15
|
+
}
|
16
|
+
|
17
|
+
export function isDefined<T>(value: T | undefined): value is T {
|
18
|
+
return !isUndefined(value);
|
19
|
+
}
|