@xyo-network/xl1-protocol-sdk 1.11.0 → 1.12.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/dist/neutral/config/Api.d.ts +5 -13
- package/dist/neutral/config/Api.d.ts.map +1 -1
- package/dist/neutral/config/App.d.ts +4 -7
- package/dist/neutral/config/App.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +3 -6
- package/dist/neutral/config/Chain.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +39 -225
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Evm.d.ts +11 -49
- package/dist/neutral/config/Evm.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +12 -7
- package/dist/neutral/config/Log.d.ts.map +1 -1
- package/dist/neutral/config/Producer.d.ts +7 -20
- package/dist/neutral/config/Producer.d.ts.map +1 -1
- package/dist/neutral/config/Telemetry.d.ts +8 -24
- package/dist/neutral/config/Telemetry.d.ts.map +1 -1
- package/dist/neutral/config/UsageMeta.d.ts +27 -0
- package/dist/neutral/config/UsageMeta.d.ts.map +1 -0
- package/dist/neutral/config/index.d.ts +1 -0
- package/dist/neutral/config/index.d.ts.map +1 -1
- package/dist/neutral/config/storage/Storage.d.ts +4 -34
- package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
- package/dist/neutral/config/storage/driver/Mongo.d.ts +3 -15
- package/dist/neutral/config/storage/driver/Mongo.d.ts.map +1 -1
- package/dist/neutral/index.mjs +477 -204
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/payload/netBalancesForPayloads.d.ts +5 -2
- package/dist/neutral/payload/netBalancesForPayloads.d.ts.map +1 -1
- package/dist/neutral/transaction/buildTransaction.d.ts +3 -3
- package/dist/neutral/transaction/buildTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/buildUnsignedTransaction.d.ts +3 -3
- package/dist/neutral/transaction/buildUnsignedTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/hydrateTransaction.d.ts +7 -7
- package/dist/neutral/transaction/hydrateTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/primitives/transactionBlockByteCount.d.ts +2 -2
- package/dist/neutral/transaction/primitives/transactionBlockByteCount.d.ts.map +1 -1
- package/dist/neutral/transaction/primitives/transactionElevatedPayloads.d.ts +2 -2
- package/dist/neutral/transaction/primitives/transactionElevatedPayloads.d.ts.map +1 -1
- package/dist/neutral/transaction/primitives/transactionRequiredGas.d.ts +3 -3
- package/dist/neutral/transaction/primitives/transactionRequiredGas.d.ts.map +1 -1
- package/dist/neutral/validation/schema/Mnemonic.d.ts +2 -2
- package/dist/neutral/validation/schema/Mnemonic.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/config/Api.ts +21 -7
- package/src/config/App.ts +11 -2
- package/src/config/Chain.ts +10 -3
- package/src/config/Config.ts +19 -25
- package/src/config/Evm.ts +29 -12
- package/src/config/Log.ts +18 -2
- package/src/config/Producer.ts +36 -9
- package/src/config/Telemetry.ts +10 -6
- package/src/config/UsageMeta.ts +41 -0
- package/src/config/index.ts +1 -0
- package/src/config/storage/Storage.ts +10 -6
- package/src/config/storage/driver/Mongo.ts +28 -8
- package/src/transaction/buildTransaction.ts +5 -4
- package/src/transaction/buildUnsignedTransaction.ts +5 -4
- package/src/transaction/hydrateTransaction.ts +12 -12
- package/src/transaction/primitives/spec/transactionBlockByteCount.spec.ts +7 -7
- package/src/transaction/primitives/transactionBlockByteCount.ts +2 -2
- package/src/transaction/primitives/transactionElevatedPayloads.ts +2 -2
- package/src/transaction/primitives/transactionRequiredGas.ts +3 -3
- package/src/validation/schema/Mnemonic.ts +2 -2
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,69 +1,97 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/block/hydrateBlock.ts
|
|
2
5
|
import { filterAs } from "@xylabs/array";
|
|
3
6
|
import { assertEx } from "@xylabs/assert";
|
|
4
|
-
import {
|
|
5
|
-
asTransactionBoundWitnessWithStorageMeta,
|
|
6
|
-
isBlockBoundWitnessWithStorageMeta,
|
|
7
|
-
isTransactionBoundWitnessWithStorageMeta
|
|
8
|
-
} from "@xyo-network/xl1-protocol";
|
|
7
|
+
import { asTransactionBoundWitnessWithStorageMeta, isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
9
8
|
function allHashesPresent(hashes, payloads) {
|
|
10
9
|
const payloadHashes = new Set(payloads.map((p) => p._hash));
|
|
11
10
|
return hashes.every((hash) => payloadHashes.has(hash));
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
__name(allHashesPresent, "allHashesPresent");
|
|
13
|
+
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
14
14
|
assertEx(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
15
|
-
const bw = (await archivist.get([
|
|
15
|
+
const bw = (await archivist.get([
|
|
16
|
+
hash
|
|
17
|
+
])).find(isBlockBoundWitnessWithStorageMeta);
|
|
16
18
|
if (!bw) return void 0;
|
|
17
|
-
if (maxDepth === 0) return [
|
|
19
|
+
if (maxDepth === 0) return [
|
|
20
|
+
bw,
|
|
21
|
+
[]
|
|
22
|
+
];
|
|
18
23
|
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
19
|
-
if (maxDepth === 1) return [
|
|
24
|
+
if (maxDepth === 1) return [
|
|
25
|
+
bw,
|
|
26
|
+
blkPayloads
|
|
27
|
+
];
|
|
20
28
|
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
|
|
21
29
|
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
22
30
|
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
23
|
-
const allPayloadsHashes = new Set([
|
|
24
|
-
|
|
31
|
+
const allPayloadsHashes = new Set([
|
|
32
|
+
...blkPayloads,
|
|
33
|
+
...transactionsPayloads
|
|
34
|
+
].flatMap((p) => p._hash));
|
|
35
|
+
const allPayloads = await archivist.get([
|
|
36
|
+
...allPayloadsHashes
|
|
37
|
+
]);
|
|
25
38
|
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
26
|
-
return [
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
return [
|
|
40
|
+
bw,
|
|
41
|
+
allPayloadsFiltered
|
|
42
|
+
];
|
|
43
|
+
}, "tryHydrateBlock");
|
|
44
|
+
var hydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
29
45
|
assertEx(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
30
46
|
assertEx(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
31
47
|
assertEx(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
32
|
-
const bw = assertEx(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
48
|
+
const bw = assertEx((await archivist.get([
|
|
49
|
+
hash
|
|
50
|
+
])).find(isBlockBoundWitnessWithStorageMeta), () => `block ${hash} not found`);
|
|
51
|
+
if (maxDepth === 0) return [
|
|
52
|
+
bw,
|
|
53
|
+
[]
|
|
54
|
+
];
|
|
37
55
|
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
38
56
|
if (minDepth === 1) assertEx(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
39
|
-
if (maxDepth === 1) return [
|
|
57
|
+
if (maxDepth === 1) return [
|
|
58
|
+
bw,
|
|
59
|
+
blkPayloads
|
|
60
|
+
];
|
|
40
61
|
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta);
|
|
41
62
|
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
42
63
|
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
43
64
|
assertEx(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
44
|
-
const allPayloadsHashes = new Set([
|
|
45
|
-
|
|
65
|
+
const allPayloadsHashes = new Set([
|
|
66
|
+
...blkPayloads,
|
|
67
|
+
...transactionsPayloads
|
|
68
|
+
].flatMap((p) => p._hash));
|
|
69
|
+
const allPayloads = await archivist.get([
|
|
70
|
+
...allPayloadsHashes
|
|
71
|
+
]);
|
|
46
72
|
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
47
|
-
if (maxDepth === 2) assertEx(allHashesPresent(
|
|
48
|
-
|
|
73
|
+
if (maxDepth === 2) assertEx(allHashesPresent([
|
|
74
|
+
...allPayloadsHashes
|
|
75
|
+
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
76
|
+
return [
|
|
77
|
+
bw,
|
|
49
78
|
allPayloadsFiltered
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var flattenHydratedBlock = (hydratedBlock) => {
|
|
79
|
+
];
|
|
80
|
+
}, "hydrateBlock");
|
|
81
|
+
var flattenHydratedBlock = /* @__PURE__ */ __name((hydratedBlock) => {
|
|
54
82
|
const [blk, blkPayloads] = hydratedBlock;
|
|
55
|
-
return [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
return [
|
|
84
|
+
...blkPayloads,
|
|
85
|
+
blk
|
|
86
|
+
];
|
|
87
|
+
}, "flattenHydratedBlock");
|
|
88
|
+
var flattenHydratedBlocks = /* @__PURE__ */ __name((hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk)), "flattenHydratedBlocks");
|
|
89
|
+
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
59
90
|
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
60
|
-
};
|
|
61
|
-
var blockPayloadsFromHydratedBlock = (block) => {
|
|
62
|
-
return block[0].payload_hashes.map((hash) => assertEx(
|
|
63
|
-
|
|
64
|
-
() => `missing payload ${hash}`
|
|
65
|
-
)).filter((x) => !isTransactionBoundWitnessWithStorageMeta(x));
|
|
66
|
-
};
|
|
91
|
+
}, "transactionsFromHydratedBlock");
|
|
92
|
+
var blockPayloadsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
93
|
+
return block[0].payload_hashes.map((hash) => assertEx(block[1].find((p) => p._hash === hash), () => `missing payload ${hash}`)).filter((x) => !isTransactionBoundWitnessWithStorageMeta(x));
|
|
94
|
+
}, "blockPayloadsFromHydratedBlock");
|
|
67
95
|
|
|
68
96
|
// src/block/primitives/balanceStepSummaryFromRange.ts
|
|
69
97
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
@@ -72,12 +100,9 @@ import { isAnyPayload } from "@xyo-network/payload-model";
|
|
|
72
100
|
import { StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol";
|
|
73
101
|
|
|
74
102
|
// src/payload/netBalancesForPayloads.ts
|
|
75
|
-
import {
|
|
76
|
-
hexToBigInt,
|
|
77
|
-
toAddress
|
|
78
|
-
} from "@xylabs/hex";
|
|
103
|
+
import { hexToBigInt, toAddress } from "@xylabs/hex";
|
|
79
104
|
import { isTransfer } from "@xyo-network/xl1-protocol";
|
|
80
|
-
var netBalancesForPayloads = (payloads) => {
|
|
105
|
+
var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
81
106
|
const balances = {};
|
|
82
107
|
for (const payload of payloads) {
|
|
83
108
|
if (isTransfer(payload)) {
|
|
@@ -89,21 +114,18 @@ var netBalancesForPayloads = (payloads) => {
|
|
|
89
114
|
}
|
|
90
115
|
}
|
|
91
116
|
return balances;
|
|
92
|
-
};
|
|
117
|
+
}, "netBalancesForPayloads");
|
|
93
118
|
|
|
94
119
|
// src/SignedBigInt.ts
|
|
95
|
-
import {
|
|
96
|
-
hexToBigInt as hexToBigInt2,
|
|
97
|
-
toHex
|
|
98
|
-
} from "@xylabs/hex";
|
|
120
|
+
import { hexToBigInt as hexToBigInt2, toHex } from "@xylabs/hex";
|
|
99
121
|
import { isObject } from "@xylabs/object";
|
|
100
|
-
var isNegativeBigInt = (value) => {
|
|
122
|
+
var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
|
|
101
123
|
return isObject(value) && "negative" in value && typeof value.negative === "string";
|
|
102
|
-
};
|
|
103
|
-
var isPositiveBigInt = (value) => {
|
|
124
|
+
}, "isNegativeBigInt");
|
|
125
|
+
var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
104
126
|
return isObject(value) && "positive" in value && typeof value.positive === "string";
|
|
105
|
-
};
|
|
106
|
-
var parseSignedBigInt = (value) => {
|
|
127
|
+
}, "isPositiveBigInt");
|
|
128
|
+
var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
107
129
|
if (isNegativeBigInt(value)) {
|
|
108
130
|
return -hexToBigInt2(value.negative);
|
|
109
131
|
} else if (isPositiveBigInt(value)) {
|
|
@@ -111,22 +133,32 @@ var parseSignedBigInt = (value) => {
|
|
|
111
133
|
} else {
|
|
112
134
|
throw new Error("Invalid balance type");
|
|
113
135
|
}
|
|
114
|
-
};
|
|
115
|
-
var toSignedBigInt = (value) => {
|
|
116
|
-
return value < 0n ? {
|
|
117
|
-
|
|
118
|
-
|
|
136
|
+
}, "parseSignedBigInt");
|
|
137
|
+
var toSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
138
|
+
return value < 0n ? {
|
|
139
|
+
negative: toHex(-value)
|
|
140
|
+
} : {
|
|
141
|
+
positive: toHex(value)
|
|
142
|
+
};
|
|
143
|
+
}, "toSignedBigInt");
|
|
144
|
+
var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
119
145
|
if (isNegativeBigInt(value)) {
|
|
120
|
-
return {
|
|
146
|
+
return {
|
|
147
|
+
positive: toHex(0n)
|
|
148
|
+
};
|
|
121
149
|
}
|
|
122
150
|
if (isPositiveBigInt(value)) {
|
|
123
|
-
return {
|
|
151
|
+
return {
|
|
152
|
+
positive: value.positive
|
|
153
|
+
};
|
|
124
154
|
}
|
|
125
155
|
if (typeof value === "bigint") {
|
|
126
|
-
return {
|
|
156
|
+
return {
|
|
157
|
+
positive: toHex(value)
|
|
158
|
+
};
|
|
127
159
|
}
|
|
128
160
|
throw new Error("Invalid value for positive big int");
|
|
129
|
-
};
|
|
161
|
+
}, "toPositiveBigInt");
|
|
130
162
|
|
|
131
163
|
// src/block/primitives/frames/calculateFramesFromRange.ts
|
|
132
164
|
import { stepSize } from "@xyo-network/xl1-protocol";
|
|
@@ -137,23 +169,38 @@ function calculateFramesFromRange(range, step) {
|
|
|
137
169
|
const remaining = [];
|
|
138
170
|
if (start !== range[0]) {
|
|
139
171
|
start += size;
|
|
140
|
-
remaining.push([
|
|
172
|
+
remaining.push([
|
|
173
|
+
range[0],
|
|
174
|
+
Math.min(start - 1, range[1])
|
|
175
|
+
]);
|
|
141
176
|
}
|
|
142
177
|
for (let i = start; i <= range[1]; i += size) {
|
|
143
178
|
if (i + size - 1 <= range[1]) {
|
|
144
|
-
fitted.push([
|
|
179
|
+
fitted.push([
|
|
180
|
+
i,
|
|
181
|
+
Math.min(i + size - 1, range[1])
|
|
182
|
+
]);
|
|
145
183
|
} else {
|
|
146
|
-
remaining.push([
|
|
184
|
+
remaining.push([
|
|
185
|
+
i,
|
|
186
|
+
range[1]
|
|
187
|
+
]);
|
|
147
188
|
}
|
|
148
189
|
}
|
|
149
|
-
return [
|
|
190
|
+
return [
|
|
191
|
+
fitted,
|
|
192
|
+
remaining
|
|
193
|
+
];
|
|
150
194
|
}
|
|
195
|
+
__name(calculateFramesFromRange, "calculateFramesFromRange");
|
|
151
196
|
|
|
152
197
|
// src/block/primitives/frames/deepCalculateFramesFromRange.ts
|
|
153
198
|
import { StepSizes } from "@xyo-network/xl1-protocol";
|
|
154
199
|
function deepCalculateFramesFromRange(range, startingStep = StepSizes.length - 1) {
|
|
155
200
|
const fitted = [];
|
|
156
|
-
let remaining = [
|
|
201
|
+
let remaining = [
|
|
202
|
+
range
|
|
203
|
+
];
|
|
157
204
|
for (let step = startingStep; step >= 0; step--) {
|
|
158
205
|
const newRemaining = [];
|
|
159
206
|
for (const range2 of remaining) {
|
|
@@ -165,19 +212,27 @@ function deepCalculateFramesFromRange(range, startingStep = StepSizes.length - 1
|
|
|
165
212
|
}
|
|
166
213
|
for (const range2 of remaining) {
|
|
167
214
|
for (let i = range2[0]; i <= range2[1]; i++) {
|
|
168
|
-
fitted.push([
|
|
215
|
+
fitted.push([
|
|
216
|
+
i,
|
|
217
|
+
i
|
|
218
|
+
]);
|
|
169
219
|
}
|
|
170
220
|
}
|
|
171
221
|
return fitted.toSorted((a, b) => a[0] - b[0]);
|
|
172
222
|
}
|
|
223
|
+
__name(deepCalculateFramesFromRange, "deepCalculateFramesFromRange");
|
|
173
224
|
|
|
174
225
|
// src/block/primitives/hashFromBlockNumber.ts
|
|
175
226
|
import { asHash } from "@xylabs/hex";
|
|
176
227
|
import { toSafeJsonString } from "@xylabs/object";
|
|
177
228
|
import { asBlockBoundWitnessWithStorageMeta, StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
178
229
|
async function hashFromBlockNumber(context, blockNumber) {
|
|
179
|
-
const result = await context.chainArchivist.get([
|
|
180
|
-
|
|
230
|
+
const result = await context.chainArchivist.get([
|
|
231
|
+
context.head
|
|
232
|
+
]);
|
|
233
|
+
let currentBlock = asBlockBoundWitnessWithStorageMeta(result.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
234
|
+
required: true
|
|
235
|
+
});
|
|
181
236
|
while (currentBlock.block > blockNumber) {
|
|
182
237
|
let jumpHash = currentBlock.previous;
|
|
183
238
|
let jumpBlockNumber = currentBlock.block - 1;
|
|
@@ -191,7 +246,9 @@ async function hashFromBlockNumber(context, blockNumber) {
|
|
|
191
246
|
const [newBlock] = await context.chainArchivist.get([
|
|
192
247
|
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
193
248
|
]);
|
|
194
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
249
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
250
|
+
required: true
|
|
251
|
+
});
|
|
195
252
|
if (currentBlock.block === blockNumber) {
|
|
196
253
|
break;
|
|
197
254
|
}
|
|
@@ -201,6 +258,7 @@ async function hashFromBlockNumber(context, blockNumber) {
|
|
|
201
258
|
}
|
|
202
259
|
return currentBlock._hash;
|
|
203
260
|
}
|
|
261
|
+
__name(hashFromBlockNumber, "hashFromBlockNumber");
|
|
204
262
|
|
|
205
263
|
// src/block/primitives/payloads.ts
|
|
206
264
|
import { AsObjectFactory } from "@xylabs/object";
|
|
@@ -209,9 +267,9 @@ var StepSummarySchema = "network.xyo.step.summary";
|
|
|
209
267
|
var BalancesStepSummarySchema = "network.xyo.step.summary.balances";
|
|
210
268
|
var isBalancesStepSummary = isPayloadOfSchemaType(BalancesStepSummarySchema);
|
|
211
269
|
var asBalancesStepSummary = AsObjectFactory.create(isBalancesStepSummary);
|
|
212
|
-
var isBalancesStepSummaryWithStorageMeta = (value) => {
|
|
270
|
+
var isBalancesStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
213
271
|
return isBalancesStepSummary(value) && isStorageMeta(value);
|
|
214
|
-
};
|
|
272
|
+
}, "isBalancesStepSummaryWithStorageMeta");
|
|
215
273
|
var asBalancesStepSummaryWithStorageMeta = AsObjectFactory.create(isBalancesStepSummaryWithStorageMeta);
|
|
216
274
|
|
|
217
275
|
// src/block/primitives/balanceStepSummaryFromRange.ts
|
|
@@ -235,15 +293,14 @@ async function balanceStepSummaryFromRange(context, range) {
|
|
|
235
293
|
} else {
|
|
236
294
|
const step = StepSizes3.indexOf(frameSize);
|
|
237
295
|
assertEx2(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes3.join(", ")}`);
|
|
238
|
-
const [summaryResult] = await context.summaryRepository.get([
|
|
296
|
+
const [summaryResult] = await context.summaryRepository.get([
|
|
297
|
+
frameHeadHash
|
|
298
|
+
]);
|
|
239
299
|
if (isAnyPayload(summaryResult)) {
|
|
240
300
|
result = summaryResult;
|
|
241
301
|
} else {
|
|
242
302
|
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
243
|
-
const promises = subRanges.map((subRange) => balanceStepSummaryFromRange(
|
|
244
|
-
context,
|
|
245
|
-
subRange
|
|
246
|
-
));
|
|
303
|
+
const promises = subRanges.map((subRange) => balanceStepSummaryFromRange(context, subRange));
|
|
247
304
|
const subResults = await Promise.all(promises);
|
|
248
305
|
const bigIntBalances = {};
|
|
249
306
|
for (const subResult of subResults) {
|
|
@@ -261,22 +318,32 @@ async function balanceStepSummaryFromRange(context, range) {
|
|
|
261
318
|
stepSize: frameSize,
|
|
262
319
|
balances
|
|
263
320
|
};
|
|
264
|
-
await context.summaryRepository.insert([
|
|
321
|
+
await context.summaryRepository.insert([
|
|
322
|
+
result
|
|
323
|
+
]);
|
|
265
324
|
}
|
|
266
325
|
}
|
|
267
326
|
const finalResult = await PayloadBuilder.addStorageMeta(result);
|
|
268
327
|
return finalResult;
|
|
269
328
|
}
|
|
329
|
+
__name(balanceStepSummaryFromRange, "balanceStepSummaryFromRange");
|
|
270
330
|
|
|
271
331
|
// src/block/primitives/balanceSummary.ts
|
|
272
332
|
import { asAddress } from "@xylabs/hex";
|
|
273
333
|
import { isDefined } from "@xylabs/typeof";
|
|
274
334
|
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
275
335
|
async function balanceSummary(context) {
|
|
276
|
-
const headResult = await context.chainArchivist.get([
|
|
277
|
-
|
|
336
|
+
const headResult = await context.chainArchivist.get([
|
|
337
|
+
context.head
|
|
338
|
+
]);
|
|
339
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult.at(0), () => `Head block not found for hash: ${context.head}`, {
|
|
340
|
+
required: true
|
|
341
|
+
});
|
|
278
342
|
const rangeStart = isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0;
|
|
279
|
-
const ranges = deepCalculateFramesFromRange([
|
|
343
|
+
const ranges = deepCalculateFramesFromRange([
|
|
344
|
+
rangeStart,
|
|
345
|
+
headBoundWitness.block
|
|
346
|
+
]);
|
|
280
347
|
const summaries = await Promise.all(ranges.map((range) => balanceStepSummaryFromRange(context, range)));
|
|
281
348
|
const balances = {};
|
|
282
349
|
for (let summary of summaries) {
|
|
@@ -287,134 +354,287 @@ async function balanceSummary(context) {
|
|
|
287
354
|
}
|
|
288
355
|
return balances;
|
|
289
356
|
}
|
|
357
|
+
__name(balanceSummary, "balanceSummary");
|
|
290
358
|
|
|
291
359
|
// src/config/Config.ts
|
|
292
|
-
import
|
|
293
|
-
import z10 from "zod";
|
|
360
|
+
import z11 from "zod";
|
|
294
361
|
|
|
295
362
|
// src/config/Api.ts
|
|
296
|
-
import z2 from "zod";
|
|
363
|
+
import z2, { globalRegistry } from "zod";
|
|
297
364
|
|
|
298
365
|
// src/validation/lib/isLocalhost.ts
|
|
299
|
-
var isLocalhost = (hostname) => {
|
|
366
|
+
var isLocalhost = /* @__PURE__ */ __name((hostname) => {
|
|
300
367
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname.endsWith(".localhost");
|
|
301
|
-
};
|
|
368
|
+
}, "isLocalhost");
|
|
302
369
|
|
|
303
370
|
// src/validation/lib/getUrl.ts
|
|
304
|
-
var getUrl = (host, port) => {
|
|
371
|
+
var getUrl = /* @__PURE__ */ __name((host, port) => {
|
|
305
372
|
const scheme = isLocalhost(host) ? "http" : "https";
|
|
306
373
|
return `${scheme}://${host}:${port}`;
|
|
307
|
-
};
|
|
374
|
+
}, "getUrl");
|
|
308
375
|
|
|
309
376
|
// src/validation/schema/Address.ts
|
|
310
377
|
var TODO = true;
|
|
311
378
|
|
|
312
379
|
// src/validation/schema/Mnemonic.ts
|
|
313
380
|
import { z } from "zod";
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
381
|
+
var MnemonicStringZod = z.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine((s) => [
|
|
382
|
+
12,
|
|
383
|
+
15,
|
|
384
|
+
18,
|
|
385
|
+
21,
|
|
386
|
+
24
|
|
387
|
+
].includes(s.split(" ").length), {
|
|
388
|
+
message: "Mnemonic must contain 12, 15, 18, 21, or 24 words."
|
|
389
|
+
}).describe("BIP-39 mnemonic string");
|
|
318
390
|
|
|
319
391
|
// src/config/Api.ts
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
392
|
+
var ApiConfigZod = z2.object({
|
|
393
|
+
host: z2.string().default("localhost").register(globalRegistry, {
|
|
394
|
+
default: "localhost",
|
|
395
|
+
description: "Host for the API",
|
|
396
|
+
title: "api.host",
|
|
397
|
+
type: "string"
|
|
398
|
+
}),
|
|
399
|
+
mnemonic: MnemonicStringZod.optional().register(globalRegistry, {
|
|
400
|
+
description: "Mnemonic for the API wallet",
|
|
401
|
+
title: "api.mnemonic",
|
|
402
|
+
type: "string"
|
|
403
|
+
}),
|
|
404
|
+
port: z2.coerce.number().default(8080).register(globalRegistry, {
|
|
405
|
+
default: 8080,
|
|
406
|
+
description: "Port for the API",
|
|
407
|
+
title: "api.port",
|
|
408
|
+
type: "number"
|
|
409
|
+
})
|
|
324
410
|
});
|
|
325
411
|
|
|
326
412
|
// src/config/App.ts
|
|
327
|
-
import z3 from "zod";
|
|
328
|
-
var
|
|
413
|
+
import z3, { globalRegistry as globalRegistry2 } from "zod";
|
|
414
|
+
var AppConfigZod = z3.object({
|
|
415
|
+
port: z3.coerce.number().default(3e3).register(globalRegistry2, {
|
|
416
|
+
default: 3e3,
|
|
417
|
+
description: "Port for the application",
|
|
418
|
+
title: "app.port",
|
|
419
|
+
type: "number"
|
|
420
|
+
})
|
|
421
|
+
});
|
|
329
422
|
|
|
330
423
|
// src/config/Chain.ts
|
|
331
|
-
import z4 from "zod";
|
|
332
|
-
var
|
|
333
|
-
id: z4.string().optional().
|
|
424
|
+
import z4, { globalRegistry as globalRegistry3 } from "zod";
|
|
425
|
+
var ChainConfigZod = z4.object({
|
|
426
|
+
id: z4.string().optional().register(globalRegistry3, {
|
|
427
|
+
description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
|
|
428
|
+
title: "chain.id",
|
|
429
|
+
type: "string"
|
|
430
|
+
})
|
|
334
431
|
});
|
|
335
432
|
|
|
336
433
|
// src/config/Evm.ts
|
|
337
|
-
import z5 from "zod";
|
|
338
|
-
var
|
|
339
|
-
|
|
340
|
-
|
|
434
|
+
import z5, { globalRegistry as globalRegistry4 } from "zod";
|
|
435
|
+
var EvmInfuraConfigZod = z5.object({
|
|
436
|
+
projectId: z5.string().optional().register(globalRegistry4, {
|
|
437
|
+
description: "Infura project ID",
|
|
438
|
+
title: "evm.infura.projectId",
|
|
439
|
+
type: "string"
|
|
440
|
+
}),
|
|
441
|
+
projectSecret: z5.string().optional().register(globalRegistry4, {
|
|
442
|
+
description: "Infura project secret",
|
|
443
|
+
title: "evm.infura.projectSecret",
|
|
444
|
+
type: "string"
|
|
445
|
+
})
|
|
341
446
|
});
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
|
|
447
|
+
var EvmJsonRpcConfigZod = z5.object({
|
|
448
|
+
url: z5.url().optional().register(globalRegistry4, {
|
|
449
|
+
description: "JSON-RPC URL",
|
|
450
|
+
title: "evm.jsonRpc.url",
|
|
451
|
+
type: "string"
|
|
452
|
+
})
|
|
345
453
|
});
|
|
346
|
-
var
|
|
347
|
-
chainId: z5.string().optional().
|
|
348
|
-
|
|
349
|
-
|
|
454
|
+
var EvmConfigZod = z5.object({
|
|
455
|
+
chainId: z5.string().optional().register(globalRegistry4, {
|
|
456
|
+
description: "EVM chain ID",
|
|
457
|
+
title: "evm.chainId",
|
|
458
|
+
type: "string"
|
|
459
|
+
}),
|
|
460
|
+
infura: EvmInfuraConfigZod.optional().describe("Infura Provider configuration"),
|
|
461
|
+
jsonRpc: EvmJsonRpcConfigZod.optional().describe("JSON-RPC Provider configuration")
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// src/config/Log.ts
|
|
465
|
+
import { LogLevel } from "@xylabs/logger";
|
|
466
|
+
import z6, { globalRegistry as globalRegistry5 } from "zod";
|
|
467
|
+
var LogLevels = Object.keys(LogLevel);
|
|
468
|
+
var LogConfigZod = z6.object({
|
|
469
|
+
logLevel: z6.enum(LogLevels).default("info").register(globalRegistry5, {
|
|
470
|
+
choices: LogLevels,
|
|
471
|
+
default: "info",
|
|
472
|
+
description: "Desired process verbosity",
|
|
473
|
+
title: "logLevel",
|
|
474
|
+
type: "string"
|
|
475
|
+
}),
|
|
476
|
+
silent: z6.boolean().default(false).register(globalRegistry5, {
|
|
477
|
+
default: false,
|
|
478
|
+
description: "Whether to run in silent mode",
|
|
479
|
+
title: "silent",
|
|
480
|
+
type: "boolean"
|
|
481
|
+
})
|
|
350
482
|
});
|
|
351
483
|
|
|
352
484
|
// src/config/Producer.ts
|
|
353
|
-
import
|
|
354
|
-
var
|
|
485
|
+
import z7, { globalRegistry as globalRegistry6 } from "zod";
|
|
486
|
+
var ProducerConfigZod = z7.object({
|
|
487
|
+
disableIntentRedeclaration: z7.boolean().optional().register(globalRegistry6, {
|
|
488
|
+
description: "Should the producer skip redeclaring their intent to continue producing blocks",
|
|
489
|
+
title: "producer.disableIntentRedeclaration",
|
|
490
|
+
type: "boolean"
|
|
491
|
+
}),
|
|
355
492
|
// TODO: Port schema
|
|
356
|
-
healthCheckPort:
|
|
493
|
+
healthCheckPort: z7.coerce.number().optional().register(globalRegistry6, {
|
|
494
|
+
description: "Port for the Producer health checks",
|
|
495
|
+
title: "producer.healthCheckPort",
|
|
496
|
+
type: "number"
|
|
497
|
+
}),
|
|
357
498
|
// TODO: BigInt schema
|
|
358
|
-
minStake:
|
|
359
|
-
|
|
499
|
+
minStake: z7.coerce.number().default(1).register(globalRegistry6, {
|
|
500
|
+
description: "Minimum stake required to be a Producer",
|
|
501
|
+
title: "producer.minStake",
|
|
502
|
+
type: "number"
|
|
503
|
+
}),
|
|
504
|
+
mnemonic: MnemonicStringZod.optional().register(globalRegistry6, {
|
|
505
|
+
description: "Mnemonic for the Producer wallet",
|
|
506
|
+
title: "producer.mnemonic",
|
|
507
|
+
type: "string"
|
|
508
|
+
}),
|
|
360
509
|
// TODO: Port schema
|
|
361
|
-
port:
|
|
362
|
-
|
|
510
|
+
port: z7.coerce.number().default(8081).register(globalRegistry6, {
|
|
511
|
+
default: 8081,
|
|
512
|
+
description: "Port for the Producer",
|
|
513
|
+
title: "producer.port",
|
|
514
|
+
type: "number"
|
|
515
|
+
}),
|
|
363
516
|
// TODO: Address schema
|
|
364
|
-
rewardAddress:
|
|
517
|
+
rewardAddress: z7.string().optional().register(globalRegistry6, {
|
|
518
|
+
description: "Address to receive block rewards",
|
|
519
|
+
title: "producer.rewardAddress",
|
|
520
|
+
type: "string"
|
|
521
|
+
})
|
|
365
522
|
});
|
|
366
523
|
|
|
367
524
|
// src/config/storage/driver/Mongo.ts
|
|
368
525
|
import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
|
|
369
|
-
import
|
|
370
|
-
var hasMongoConfig = (config) => {
|
|
526
|
+
import z8, { globalRegistry as globalRegistry7 } from "zod";
|
|
527
|
+
var hasMongoConfig = /* @__PURE__ */ __name((config) => {
|
|
371
528
|
if (isUndefined(config)) return false;
|
|
372
529
|
return isDefined2(config.connectionString) && isDefined2(config.database) && isDefined2(config.domain) && isDefined2(config.password) && isDefined2(config.username);
|
|
373
|
-
};
|
|
374
|
-
var
|
|
530
|
+
}, "hasMongoConfig");
|
|
531
|
+
var MongoConfigZod = z8.object({
|
|
375
532
|
// TODO: Create from other arguments
|
|
376
|
-
connectionString:
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
533
|
+
connectionString: z8.string().min(1).optional().register(globalRegistry7, {
|
|
534
|
+
description: "MongoDB connection string",
|
|
535
|
+
title: "storage.mongo.connectionString",
|
|
536
|
+
type: "string"
|
|
537
|
+
}),
|
|
538
|
+
database: z8.string().min(1).optional().register(globalRegistry7, {
|
|
539
|
+
description: "MongoDB database name",
|
|
540
|
+
title: "storage.mongo.database",
|
|
541
|
+
type: "string"
|
|
542
|
+
}),
|
|
543
|
+
domain: z8.string().min(1).optional().register(globalRegistry7, {
|
|
544
|
+
description: "MongoDB domain",
|
|
545
|
+
title: "storage.mongo.domain",
|
|
546
|
+
type: "string"
|
|
547
|
+
}),
|
|
548
|
+
password: z8.string().min(1).optional().register(globalRegistry7, {
|
|
549
|
+
description: "MongoDB password",
|
|
550
|
+
title: "storage.mongo.password",
|
|
551
|
+
type: "string"
|
|
552
|
+
}),
|
|
553
|
+
username: z8.string().min(1).optional().register(globalRegistry7, {
|
|
554
|
+
description: "MongoDB username",
|
|
555
|
+
title: "storage.mongo.username",
|
|
556
|
+
type: "string"
|
|
557
|
+
})
|
|
381
558
|
});
|
|
382
559
|
|
|
383
560
|
// src/config/storage/Storage.ts
|
|
384
|
-
import
|
|
385
|
-
var
|
|
386
|
-
mongo:
|
|
387
|
-
root:
|
|
561
|
+
import z9, { globalRegistry as globalRegistry8 } from "zod";
|
|
562
|
+
var StorageConfigZod = z9.object({
|
|
563
|
+
mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
|
|
564
|
+
root: z9.string().optional().register(globalRegistry8, {
|
|
565
|
+
description: "Root directory for local storage",
|
|
566
|
+
title: "storage.root",
|
|
567
|
+
type: "string"
|
|
568
|
+
})
|
|
388
569
|
}).describe("Storage configuration options");
|
|
389
570
|
|
|
390
571
|
// src/config/Telemetry.ts
|
|
391
|
-
import
|
|
392
|
-
var
|
|
572
|
+
import z10, { globalRegistry as globalRegistry9 } from "zod";
|
|
573
|
+
var OpenTelemetryConfigZod = z10.object({
|
|
393
574
|
// OpenTelemetry options
|
|
394
|
-
otlpEndpoint:
|
|
575
|
+
otlpEndpoint: z10.url().optional().register(globalRegistry9, {
|
|
576
|
+
description: "OTLP endpoint for exporting telemetry data",
|
|
577
|
+
title: "telemetry.otel.otlpEndpoint",
|
|
578
|
+
type: "string"
|
|
579
|
+
})
|
|
395
580
|
});
|
|
396
|
-
var
|
|
581
|
+
var TelemetryConfigZod = z10.object({
|
|
397
582
|
// OpenTelemetry configuration
|
|
398
|
-
otel:
|
|
583
|
+
otel: OpenTelemetryConfigZod.optional().describe("OpenTelemetry configuration")
|
|
399
584
|
}).describe("Telemetry configuration options");
|
|
400
585
|
|
|
401
586
|
// src/config/Config.ts
|
|
402
|
-
var
|
|
403
|
-
|
|
404
|
-
silent: z10.boolean().default(false).describe("Whether to run in silent mode"),
|
|
405
|
-
logLevel: z10.enum(LogLevels).default("info").describe("Desired process verbosity")
|
|
587
|
+
var Xl1CommonConfigSchema = z11.object({
|
|
588
|
+
...LogConfigZod.shape
|
|
406
589
|
}).describe("XL1 common configuration options");
|
|
407
|
-
var
|
|
590
|
+
var ConfigZod = z11.object({
|
|
408
591
|
...Xl1CommonConfigSchema.shape,
|
|
409
|
-
api:
|
|
410
|
-
app:
|
|
411
|
-
chain:
|
|
412
|
-
evm:
|
|
413
|
-
producer:
|
|
414
|
-
storage:
|
|
415
|
-
telemetry:
|
|
592
|
+
api: ApiConfigZod.default(ApiConfigZod.parse({})).describe("Configuration for the API node"),
|
|
593
|
+
app: AppConfigZod.default(AppConfigZod.parse({})).describe("Configuration for the application"),
|
|
594
|
+
chain: ChainConfigZod.default(ChainConfigZod.parse({})).describe("Configuration for the chain"),
|
|
595
|
+
evm: EvmConfigZod.default(EvmConfigZod.parse({})).describe("Configuration for EVM-backed services"),
|
|
596
|
+
producer: ProducerConfigZod.default(ProducerConfigZod.parse({})).describe("Configuration for the producer"),
|
|
597
|
+
storage: StorageConfigZod.default(StorageConfigZod.parse({})).describe("Configuration for the storage"),
|
|
598
|
+
telemetry: TelemetryConfigZod.default(TelemetryConfigZod.parse({})).describe("Configuration for telemetry")
|
|
416
599
|
});
|
|
417
|
-
var getDefaultConfig = () =>
|
|
600
|
+
var getDefaultConfig = /* @__PURE__ */ __name(() => ConfigZod.parse({}), "getDefaultConfig");
|
|
601
|
+
|
|
602
|
+
// src/config/UsageMeta.ts
|
|
603
|
+
import z12 from "zod";
|
|
604
|
+
var DescriptionSchema = z12.string();
|
|
605
|
+
var TitleSchema = z12.string();
|
|
606
|
+
var JSONSchemaMetaSchema = z12.object({
|
|
607
|
+
id: z12.string().optional(),
|
|
608
|
+
title: TitleSchema.optional(),
|
|
609
|
+
description: DescriptionSchema.optional(),
|
|
610
|
+
deprecated: z12.boolean().optional()
|
|
611
|
+
}).catchall(z12.unknown());
|
|
612
|
+
var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
|
|
613
|
+
var ChoicesSchema = z12.array(z12.union([
|
|
614
|
+
z12.string(),
|
|
615
|
+
z12.number(),
|
|
616
|
+
z12.literal(true),
|
|
617
|
+
z12.undefined()
|
|
618
|
+
])).readonly();
|
|
619
|
+
var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
620
|
+
choices: ChoicesSchema.optional(),
|
|
621
|
+
default: z12.unknown().optional(),
|
|
622
|
+
description: DescriptionSchema,
|
|
623
|
+
group: z12.string().optional(),
|
|
624
|
+
hidden: z12.boolean().optional(),
|
|
625
|
+
title: TitleSchema,
|
|
626
|
+
type: z12.union([
|
|
627
|
+
z12.literal("array"),
|
|
628
|
+
z12.literal("count"),
|
|
629
|
+
z12.literal("boolean"),
|
|
630
|
+
z12.literal("number"),
|
|
631
|
+
z12.literal("string")
|
|
632
|
+
])
|
|
633
|
+
});
|
|
634
|
+
function isUsageMeta(v) {
|
|
635
|
+
return UsageMetaSchema.safeParse(v).success;
|
|
636
|
+
}
|
|
637
|
+
__name(isUsageMeta, "isUsageMeta");
|
|
418
638
|
|
|
419
639
|
// src/transaction/buildTransaction.ts
|
|
420
640
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
@@ -449,9 +669,20 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
449
669
|
if (script.length > 0) {
|
|
450
670
|
fields.script = script;
|
|
451
671
|
}
|
|
452
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
|
|
453
|
-
|
|
672
|
+
const [tx, txPayloads] = await new BoundWitnessBuilder().fields(fields).meta({
|
|
673
|
+
$signatures: []
|
|
674
|
+
}).payloads([
|
|
675
|
+
...onChainPayloads,
|
|
676
|
+
...offChainPayloads
|
|
677
|
+
]).signers(Array.isArray(signer) ? signer : [
|
|
678
|
+
signer
|
|
679
|
+
]).build();
|
|
680
|
+
return [
|
|
681
|
+
await PayloadBuilder2.addStorageMeta(tx),
|
|
682
|
+
await PayloadBuilder2.addStorageMeta(txPayloads)
|
|
683
|
+
];
|
|
454
684
|
}
|
|
685
|
+
__name(buildTransaction, "buildTransaction");
|
|
455
686
|
|
|
456
687
|
// src/transaction/buildUnsignedTransaction.ts
|
|
457
688
|
import { toHex as toHex3 } from "@xylabs/hex";
|
|
@@ -482,9 +713,18 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
482
713
|
if (script.length > 0) {
|
|
483
714
|
fields.script = script;
|
|
484
715
|
}
|
|
485
|
-
const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
|
|
486
|
-
|
|
716
|
+
const [tx, txPayloads] = await new BoundWitnessBuilder2().fields(fields).meta({
|
|
717
|
+
$signatures: []
|
|
718
|
+
}).payloads([
|
|
719
|
+
...onChainPayloads,
|
|
720
|
+
...offChainPayloads
|
|
721
|
+
]).build();
|
|
722
|
+
return [
|
|
723
|
+
await PayloadBuilder3.addStorageMeta(tx),
|
|
724
|
+
await PayloadBuilder3.addStorageMeta(txPayloads)
|
|
725
|
+
];
|
|
487
726
|
}
|
|
727
|
+
__name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
488
728
|
|
|
489
729
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
490
730
|
import { delay } from "@xylabs/delay";
|
|
@@ -492,7 +732,7 @@ import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
|
492
732
|
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
493
733
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
494
734
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
495
|
-
var confirmSubmittedTransaction = async (viewer, transaction, options) => {
|
|
735
|
+
var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, transaction, options) => {
|
|
496
736
|
const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options || {};
|
|
497
737
|
const txBWHash = await PayloadBuilder4.hash(transaction);
|
|
498
738
|
options?.logger?.log("\u{1F680} confirming transaction:", txBWHash, "\n");
|
|
@@ -513,32 +753,27 @@ var confirmSubmittedTransaction = async (viewer, transaction, options) => {
|
|
|
513
753
|
}
|
|
514
754
|
}
|
|
515
755
|
}
|
|
516
|
-
};
|
|
756
|
+
}, "confirmSubmittedTransaction");
|
|
517
757
|
|
|
518
758
|
// src/transaction/hydrateTransaction.ts
|
|
519
759
|
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
520
760
|
import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
|
|
521
|
-
import { isAllowedBlockPayload,
|
|
522
|
-
var tryHydrateTransaction = async (archivist, hash) => {
|
|
523
|
-
return await tryHydrateTypedBoundWitness(
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
var hydrateTransaction = async (archivist, hash) => {
|
|
530
|
-
return await hydrateTypedBoundWitness(
|
|
531
|
-
archivist,
|
|
532
|
-
hash,
|
|
533
|
-
isTransactionBoundWitnessWithStorageMeta2
|
|
534
|
-
);
|
|
535
|
-
};
|
|
536
|
-
var flattenHydratedTransaction = (hydratedTransaction) => {
|
|
761
|
+
import { isAllowedBlockPayload, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
762
|
+
var tryHydrateTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
763
|
+
return await tryHydrateTypedBoundWitness(archivist, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
764
|
+
}, "tryHydrateTransaction");
|
|
765
|
+
var hydrateTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
766
|
+
return await hydrateTypedBoundWitness(archivist, hash, isSignedTransactionBoundWitnessWithStorageMeta);
|
|
767
|
+
}, "hydrateTransaction");
|
|
768
|
+
var flattenHydratedTransaction = /* @__PURE__ */ __name((hydratedTransaction) => {
|
|
537
769
|
const [tx, txPayloads] = hydratedTransaction;
|
|
538
|
-
return [
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
770
|
+
return [
|
|
771
|
+
...txPayloads,
|
|
772
|
+
tx
|
|
773
|
+
];
|
|
774
|
+
}, "flattenHydratedTransaction");
|
|
775
|
+
var flattenHydratedTransactions = /* @__PURE__ */ __name((hydratedTransactions) => hydratedTransactions.flatMap((tx) => flattenHydratedTransaction(tx)), "flattenHydratedTransactions");
|
|
776
|
+
var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
542
777
|
const hydratedTransaction = await tryHydrateTransaction(archivist, hash);
|
|
543
778
|
if (!hydratedTransaction) {
|
|
544
779
|
return void 0;
|
|
@@ -556,13 +791,16 @@ var tryHydrateElevatedTransaction = async (archivist, hash) => {
|
|
|
556
791
|
}
|
|
557
792
|
}
|
|
558
793
|
if (opCodes.length === elevatedPayloads.length) {
|
|
559
|
-
return [
|
|
794
|
+
return [
|
|
795
|
+
transaction,
|
|
796
|
+
elevatedPayloads
|
|
797
|
+
];
|
|
560
798
|
}
|
|
561
799
|
return void 0;
|
|
562
|
-
};
|
|
563
|
-
var hydrateElevatedTransaction = async (archivist, hash) => {
|
|
800
|
+
}, "tryHydrateElevatedTransaction");
|
|
801
|
+
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (archivist, hash) => {
|
|
564
802
|
return assertEx4(await tryHydrateElevatedTransaction(archivist, hash), () => "Hydration failed");
|
|
565
|
-
};
|
|
803
|
+
}, "hydrateElevatedTransaction");
|
|
566
804
|
|
|
567
805
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
568
806
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
@@ -572,6 +810,7 @@ function transactionBlockByteCount([transaction, payloads]) {
|
|
|
572
810
|
const cleanPayloads = PayloadBuilder5.omitStorageMeta(payloads);
|
|
573
811
|
return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
|
|
574
812
|
}
|
|
813
|
+
__name(transactionBlockByteCount, "transactionBlockByteCount");
|
|
575
814
|
|
|
576
815
|
// src/transaction/primitives/transactionElevatedPayloads.ts
|
|
577
816
|
import { asHash as asHash2 } from "@xylabs/hex";
|
|
@@ -582,65 +821,77 @@ function crackOperation(operation) {
|
|
|
582
821
|
if (parts.length < 2) {
|
|
583
822
|
throw new Error(`Invalid operation format: ${operation}`);
|
|
584
823
|
}
|
|
585
|
-
return [
|
|
824
|
+
return [
|
|
825
|
+
parts[0],
|
|
826
|
+
parts.slice(1)
|
|
827
|
+
];
|
|
586
828
|
}
|
|
829
|
+
__name(crackOperation, "crackOperation");
|
|
587
830
|
function crackOperations(operations) {
|
|
588
831
|
return operations.map((op) => crackOperation(op));
|
|
589
832
|
}
|
|
833
|
+
__name(crackOperations, "crackOperations");
|
|
590
834
|
|
|
591
835
|
// src/transaction/primitives/transactionElevatedPayloads.ts
|
|
592
836
|
function transactionElevatedPayloadHashes(transaction) {
|
|
593
837
|
const elevateOperations = crackOperations(transaction.script ?? []).filter((op) => op[0] === "elevate");
|
|
594
838
|
return elevateOperations.map((op) => asHash2(op[1][0], true));
|
|
595
839
|
}
|
|
840
|
+
__name(transactionElevatedPayloadHashes, "transactionElevatedPayloadHashes");
|
|
596
841
|
function transactionElevatedPayloads([transaction, payloads]) {
|
|
597
842
|
const hashes = transactionElevatedPayloadHashes(transaction);
|
|
598
843
|
const elevatedPayloads = payloads.filter((payload) => hashes.includes(payload._hash));
|
|
599
844
|
return elevatedPayloads;
|
|
600
845
|
}
|
|
846
|
+
__name(transactionElevatedPayloads, "transactionElevatedPayloads");
|
|
601
847
|
|
|
602
848
|
// src/transaction/primitives/transactionRequiredGas.ts
|
|
603
849
|
import { AttoXL1, TransactionGasCosts } from "@xyo-network/xl1-protocol";
|
|
604
850
|
function transactionBytesRequiredGas([transaction, payloads]) {
|
|
605
|
-
const transactionBlockBytes = transactionBlockByteCount([
|
|
851
|
+
const transactionBlockBytes = transactionBlockByteCount([
|
|
852
|
+
transaction,
|
|
853
|
+
payloads
|
|
854
|
+
]);
|
|
606
855
|
return AttoXL1(TransactionGasCosts.characterStorage * BigInt(transactionBlockBytes));
|
|
607
856
|
}
|
|
857
|
+
__name(transactionBytesRequiredGas, "transactionBytesRequiredGas");
|
|
608
858
|
function transactionRequiredGas(hydratedTransaction) {
|
|
609
859
|
const elevatedPayloads = transactionElevatedPayloads(hydratedTransaction);
|
|
610
860
|
const hashes = elevatedPayloads.length + 1;
|
|
611
861
|
const signatures = hydratedTransaction[0].addresses.length;
|
|
612
862
|
return AttoXL1(transactionBytesRequiredGas(hydratedTransaction) + TransactionGasCosts.hashValidation * BigInt(hashes) + TransactionGasCosts.signatureValidation * BigInt(signatures) + TransactionGasCosts.payloadValidation * BigInt(elevatedPayloads.length));
|
|
613
863
|
}
|
|
864
|
+
__name(transactionRequiredGas, "transactionRequiredGas");
|
|
614
865
|
|
|
615
866
|
// src/transaction/script.ts
|
|
616
867
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
617
868
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
618
869
|
import { asHash as asHash3 } from "@xylabs/hex";
|
|
619
870
|
import { isAllowedBlockPayloadWithHashStorageMeta } from "@xyo-network/xl1-protocol";
|
|
620
|
-
var tryExtractElevatedHashesFromScript = (strings) => {
|
|
871
|
+
var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
621
872
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
622
873
|
return filterAs2(hashes, (h) => asHash3(h));
|
|
623
|
-
};
|
|
624
|
-
var extractElevatedHashesFromScript = (strings) => {
|
|
874
|
+
}, "tryExtractElevatedHashesFromScript");
|
|
875
|
+
var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
625
876
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
626
877
|
const filtered = filterAs2(hashes, (h) => asHash3(h));
|
|
627
878
|
assertEx5(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
628
879
|
return filtered;
|
|
629
|
-
};
|
|
630
|
-
var tryExtractElevatedHashes = (tx) => {
|
|
880
|
+
}, "extractElevatedHashesFromScript");
|
|
881
|
+
var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
631
882
|
const [bw, payloads] = tx;
|
|
632
883
|
const { script } = bw;
|
|
633
884
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
634
885
|
return payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashStorageMeta);
|
|
635
|
-
};
|
|
636
|
-
var extractElevatedHashes = (tx) => {
|
|
886
|
+
}, "tryExtractElevatedHashes");
|
|
887
|
+
var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
637
888
|
const [bw, payloads] = tx;
|
|
638
889
|
const { script } = bw;
|
|
639
890
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
640
891
|
const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashStorageMeta);
|
|
641
892
|
assertEx5(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
642
893
|
return filtered;
|
|
643
|
-
};
|
|
894
|
+
}, "extractElevatedHashes");
|
|
644
895
|
|
|
645
896
|
// src/transaction/signTransaction.ts
|
|
646
897
|
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
@@ -650,42 +901,63 @@ import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder"
|
|
|
650
901
|
async function signTransaction(tx, account) {
|
|
651
902
|
assertEx6(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
652
903
|
const signedTx = structuredClone(tx);
|
|
653
|
-
signedTx.addresses = [
|
|
654
|
-
|
|
904
|
+
signedTx.addresses = [
|
|
905
|
+
account.address
|
|
906
|
+
];
|
|
907
|
+
signedTx.previous_hashes = [
|
|
908
|
+
account.previousHash ?? null
|
|
909
|
+
];
|
|
655
910
|
const hash = await PayloadBuilder6.hash(signedTx);
|
|
656
911
|
const hashBytes = toArrayBuffer(hash);
|
|
657
912
|
const [signature] = await account.sign(hashBytes);
|
|
658
|
-
signedTx.$signatures = [
|
|
913
|
+
signedTx.$signatures = [
|
|
914
|
+
hexFromArrayBuffer(signature)
|
|
915
|
+
];
|
|
659
916
|
return signedTx;
|
|
660
917
|
}
|
|
918
|
+
__name(signTransaction, "signTransaction");
|
|
661
919
|
|
|
662
920
|
// src/wallet/generateXyoBaseWalletFromPhrase.ts
|
|
663
921
|
import { HDWallet } from "@xyo-network/wallet";
|
|
664
922
|
|
|
665
923
|
// src/wallet/paths.ts
|
|
666
924
|
var WALLET_COMPLIANCE = "44'";
|
|
667
|
-
var COIN_TYPES = {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
var
|
|
925
|
+
var COIN_TYPES = {
|
|
926
|
+
Ethereum: "60'"
|
|
927
|
+
};
|
|
928
|
+
var ACCOUNT_TYPE = {
|
|
929
|
+
GANACHE: "0'",
|
|
930
|
+
XYO: "0'"
|
|
931
|
+
};
|
|
932
|
+
var CHANGE_ADDRESS = {
|
|
933
|
+
META_MASK: "0",
|
|
934
|
+
XYO: "0"
|
|
935
|
+
};
|
|
936
|
+
var ADDRESS_INDEX = {
|
|
937
|
+
META_MASK: "0",
|
|
938
|
+
XYO: "0"
|
|
939
|
+
};
|
|
671
940
|
var DEFAULT_WALLET_PATH = `m/${WALLET_COMPLIANCE}/${COIN_TYPES.Ethereum}/${ACCOUNT_TYPE.XYO}/${CHANGE_ADDRESS.XYO}`;
|
|
672
941
|
|
|
673
942
|
// src/wallet/generateXyoBaseWalletFromPhrase.ts
|
|
674
|
-
var generateXyoBaseWalletFromPhrase = (walletPhrase) => {
|
|
943
|
+
var generateXyoBaseWalletFromPhrase = /* @__PURE__ */ __name((walletPhrase) => {
|
|
675
944
|
const wallet = HDWallet.fromPhrase(walletPhrase, DEFAULT_WALLET_PATH);
|
|
676
945
|
return wallet;
|
|
677
|
-
};
|
|
946
|
+
}, "generateXyoBaseWalletFromPhrase");
|
|
678
947
|
export {
|
|
679
948
|
ACCOUNT_TYPE,
|
|
680
949
|
ADDRESS_INDEX,
|
|
681
950
|
BalancesStepSummarySchema,
|
|
682
951
|
CHANGE_ADDRESS,
|
|
683
952
|
COIN_TYPES,
|
|
684
|
-
|
|
953
|
+
ConfigZod,
|
|
685
954
|
DEFAULT_WALLET_PATH,
|
|
686
|
-
|
|
955
|
+
GlobalMetaSchema,
|
|
956
|
+
JSONSchemaMetaSchema,
|
|
957
|
+
MnemonicStringZod,
|
|
687
958
|
StepSummarySchema,
|
|
688
959
|
TODO,
|
|
960
|
+
UsageMetaSchema,
|
|
689
961
|
WALLET_COMPLIANCE,
|
|
690
962
|
Xl1CommonConfigSchema,
|
|
691
963
|
allHashesPresent,
|
|
@@ -720,6 +992,7 @@ export {
|
|
|
720
992
|
isLocalhost,
|
|
721
993
|
isNegativeBigInt,
|
|
722
994
|
isPositiveBigInt,
|
|
995
|
+
isUsageMeta,
|
|
723
996
|
netBalancesForPayloads,
|
|
724
997
|
parseSignedBigInt,
|
|
725
998
|
signTransaction,
|