@xyo-network/chain-validation 1.5.35 → 1.5.36
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/index.mjs +193 -140
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/block/validateBlock.d.ts.map +1 -1
- package/dist/types/block/validators/AllowedPayloadSchemas.d.ts.map +1 -1
- package/dist/types/block/validators/Fields.d.ts.map +1 -1
- package/dist/types/block/validators/JsonSchema.d.ts.map +1 -1
- package/dist/types/block/validators/PreviousHash.d.ts.map +1 -1
- package/dist/types/boundwitness/validators/BoundWitnessReferences.d.ts.map +1 -1
- package/dist/types/boundwitness/validators/BoundWitnessSignatures.d.ts.map +1 -1
- package/dist/types/elevatedPayload/lib/validateElevatedFromBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/lib/validateElevatedFromTransaction.d.ts.map +1 -1
- package/dist/types/elevatedPayload/lib/validateTransactionInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateChainStakeIntentInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateHashInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateSchemaInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateTransferInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/validatePayloadInBlock.d.ts.map +1 -1
- package/dist/types/hydratedBlock/validateHydratedBlock.d.ts.map +1 -1
- package/dist/types/hydratedBlock/validators/Payloads.d.ts.map +1 -1
- package/dist/types/hydratedBlockState/validateHydratedBlockState.d.ts +2 -2
- package/dist/types/hydratedBlockState/validateHydratedBlockState.d.ts.map +1 -1
- package/dist/types/hydratedBlockState/validators/RequiredBalance.d.ts +2 -2
- package/dist/types/hydratedBlockState/validators/RequiredBalance.d.ts.map +1 -1
- package/dist/types/transaction/validateTransaction.d.ts +1 -1
- package/dist/types/transaction/validateTransaction.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionDurationValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionElevationValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionFromValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionGasValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionJsonSchemaValidator.d.ts.map +1 -1
- package/package.json +29 -27
- package/src/block/validateBlock.ts +7 -4
- package/src/block/validators/AllowedPayloadSchemas.ts +4 -3
- package/src/block/validators/Fields.ts +4 -3
- package/src/block/validators/JsonSchema.ts +23 -20
- package/src/block/validators/PreviousHash.ts +7 -5
- package/src/boundwitness/validators/BoundWitnessReferences.ts +5 -3
- package/src/boundwitness/validators/BoundWitnessSignatures.ts +6 -4
- package/src/elevatedPayload/lib/validateElevatedFromBlock.ts +12 -7
- package/src/elevatedPayload/lib/validateElevatedFromTransaction.ts +14 -8
- package/src/elevatedPayload/lib/validateIncludedInBlock.ts +2 -2
- package/src/elevatedPayload/lib/validateTransactionInBlock.ts +12 -8
- package/src/elevatedPayload/lib/validateTypedPayloadInBlock.ts +2 -2
- package/src/elevatedPayload/payloads/validateChainStakeIntentInBlock.ts +9 -5
- package/src/elevatedPayload/payloads/validateHashInBlock.ts +9 -5
- package/src/elevatedPayload/payloads/validateSchemaInBlock.ts +9 -5
- package/src/elevatedPayload/payloads/validateTransferInBlock.ts +9 -5
- package/src/elevatedPayload/validatePayloadInBlock.ts +8 -6
- package/src/hydratedBlock/validateHydratedBlock.ts +13 -6
- package/src/hydratedBlock/validators/Payloads.ts +13 -4
- package/src/hydratedBlockState/validateHydratedBlockState.ts +21 -10
- package/src/hydratedBlockState/validators/RequiredBalance.ts +15 -13
- package/src/transaction/validateTransaction.ts +2 -2
- package/src/transaction/validators/TransactionDurationValidator.ts +4 -3
- package/src/transaction/validators/TransactionElevationValidator.ts +4 -3
- package/src/transaction/validators/TransactionFromValidator.ts +4 -3
- package/src/transaction/validators/TransactionGasValidator.ts +4 -3
- package/src/transaction/validators/TransactionJsonSchemaValidator.ts +3 -5
- package/src/transaction/validators/TransactionProtocolValidator.ts +2 -2
package/dist/neutral/index.mjs
CHANGED
|
@@ -55,10 +55,12 @@ var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) =>
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
} catch (ex) {
|
|
58
|
-
|
|
58
|
+
const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
59
59
|
bw,
|
|
60
60
|
payloadSet
|
|
61
|
-
],
|
|
61
|
+
], `validation excepted: ${ex}`);
|
|
62
|
+
error.cause = ex;
|
|
63
|
+
errors.push(error);
|
|
62
64
|
}
|
|
63
65
|
return errors;
|
|
64
66
|
}, "BoundWitnessReferencesValidator");
|
|
@@ -80,10 +82,12 @@ var BoundWitnessSignaturesValidator = /* @__PURE__ */ __name(async (bw) => {
|
|
|
80
82
|
];
|
|
81
83
|
}));
|
|
82
84
|
for (const [, bwErrors] of results) {
|
|
83
|
-
|
|
85
|
+
for (const bwError of bwErrors) {
|
|
86
|
+
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation errors", bwError));
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
} catch (ex) {
|
|
86
|
-
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation excepted"
|
|
90
|
+
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation excepted", ex));
|
|
87
91
|
}
|
|
88
92
|
return errors;
|
|
89
93
|
}, "BoundWitnessSignaturesValidator");
|
|
@@ -99,8 +103,8 @@ var BlockAllowedPayloadSchemasValidator = /* @__PURE__ */ __name((block) => {
|
|
|
99
103
|
errors.push(new BlockValidationError(block?._hash ?? ZERO_HASH3, block, `payload schema not allowed in block: ${schema}`));
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
|
-
} catch (
|
|
103
|
-
errors.push(new BlockValidationError(block?._hash ?? ZERO_HASH3, block, `
|
|
106
|
+
} catch (ex) {
|
|
107
|
+
errors.push(new BlockValidationError(block?._hash ?? ZERO_HASH3, block, `validation excepted: ${ex}`, ex));
|
|
104
108
|
}
|
|
105
109
|
return errors;
|
|
106
110
|
}, "BlockAllowedPayloadSchemasValidator");
|
|
@@ -125,35 +129,41 @@ var BlockFieldsValidator = /* @__PURE__ */ __name((block, chainId) => {
|
|
|
125
129
|
if (new Set(txHashes).size < txHashes.length) {
|
|
126
130
|
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH4, block, `Duplicate Transaction Hashes: ${txHashes}`));
|
|
127
131
|
}
|
|
128
|
-
} catch (
|
|
129
|
-
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH4, block, `
|
|
132
|
+
} catch (ex) {
|
|
133
|
+
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH4, block, `validation excepted: ${ex}`, ex));
|
|
130
134
|
}
|
|
131
135
|
return errors;
|
|
132
136
|
}, "BlockFieldsValidator");
|
|
133
137
|
|
|
134
138
|
// src/block/validators/JsonSchema.ts
|
|
135
139
|
import { ZERO_HASH as ZERO_HASH5 } from "@xylabs/hex";
|
|
136
|
-
import { toJsonString } from "@xylabs/object";
|
|
137
140
|
import { BlockBoundWitnessWithStorageMetaJsonSchema } from "@xyo-network/chain-schema";
|
|
138
141
|
import { BlockValidationError as BlockValidationError3 } from "@xyo-network/xl1-protocol";
|
|
139
142
|
import { Ajv } from "ajv";
|
|
140
|
-
var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWitnessWithStorageMetaJsonSchema) =>
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
143
|
+
var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWitnessWithStorageMetaJsonSchema) => {
|
|
144
|
+
const ajv2 = new Ajv({
|
|
145
|
+
allErrors: true,
|
|
146
|
+
strict: true
|
|
147
|
+
});
|
|
148
|
+
const validate2 = ajv2.compile(jsonSchema);
|
|
149
|
+
return async (block) => {
|
|
150
|
+
const errors = [];
|
|
151
|
+
try {
|
|
152
|
+
await validate2(block);
|
|
153
|
+
if ((validate2.errors ?? []).length > 0) {
|
|
154
|
+
const error = new BlockValidationError3(block?._hash ?? ZERO_HASH5, block, `failed JSON schema validation: ${ajv2.errorsText(validate2.errors, {
|
|
155
|
+
separator: "\n"
|
|
156
|
+
})}`);
|
|
157
|
+
error.cause = validate2.errors;
|
|
158
|
+
errors.push(error);
|
|
159
|
+
}
|
|
160
|
+
} catch (ex) {
|
|
161
|
+
const error = new BlockValidationError3(block?._hash ?? ZERO_HASH5, block, `validation excepted: ${ex}`);
|
|
162
|
+
error.cause = ex;
|
|
163
|
+
errors.push(error);
|
|
164
|
+
}
|
|
165
|
+
return errors;
|
|
166
|
+
};
|
|
157
167
|
}, "BlockJsonSchemaValidator");
|
|
158
168
|
|
|
159
169
|
// src/block/validators/PreviousHash.ts
|
|
@@ -174,8 +184,10 @@ var BlockPreviousHashValidator = /* @__PURE__ */ __name((block) => {
|
|
|
174
184
|
} else {
|
|
175
185
|
errors.push(new BlockValidationError4(block?._hash ?? ZERO_HASH6, block, "invalid block number"));
|
|
176
186
|
}
|
|
177
|
-
} catch (
|
|
178
|
-
|
|
187
|
+
} catch (ex) {
|
|
188
|
+
const error = new BlockValidationError4(block?._hash ?? ZERO_HASH6, block, `Failed BlockPreviousHashValidator: ${ex}`);
|
|
189
|
+
error.cause = ex;
|
|
190
|
+
errors.push(error);
|
|
179
191
|
}
|
|
180
192
|
return errors;
|
|
181
193
|
}, "BlockPreviousHashValidator");
|
|
@@ -184,8 +196,11 @@ var BlockPreviousHashValidator = /* @__PURE__ */ __name((block) => {
|
|
|
184
196
|
var validateBlock = /* @__PURE__ */ __name(async (block, chainId) => {
|
|
185
197
|
const errors = [];
|
|
186
198
|
try {
|
|
199
|
+
const bwErrors = await BoundWitnessSignaturesValidator(block);
|
|
200
|
+
for (const bwError of bwErrors) {
|
|
201
|
+
errors.push(new BlockValidationError5(block?._hash ?? ZERO_HASH7, block, "BoundWitness validation failed", bwError));
|
|
202
|
+
}
|
|
187
203
|
const validators = [
|
|
188
|
-
BoundWitnessSignaturesValidator,
|
|
189
204
|
BlockFieldsValidator,
|
|
190
205
|
BlockPreviousHashValidator,
|
|
191
206
|
BlockJsonSchemaValidator(),
|
|
@@ -193,24 +208,24 @@ var validateBlock = /* @__PURE__ */ __name(async (block, chainId) => {
|
|
|
193
208
|
];
|
|
194
209
|
errors.push(...(await Promise.all(validators.map((validator) => validator(block, chainId)))).flat());
|
|
195
210
|
} catch (ex) {
|
|
196
|
-
errors.push(new BlockValidationError5(block?._hash ?? ZERO_HASH7, block, "validation excepted"
|
|
211
|
+
errors.push(new BlockValidationError5(block?._hash ?? ZERO_HASH7, block, "validation excepted", ex));
|
|
197
212
|
}
|
|
198
213
|
return errors;
|
|
199
214
|
}, "validateBlock");
|
|
200
215
|
|
|
201
216
|
// src/hydratedBlock/validateHydratedBlock.ts
|
|
202
|
-
import { ZERO_HASH as
|
|
217
|
+
import { ZERO_HASH as ZERO_HASH15 } from "@xylabs/hex";
|
|
203
218
|
import { HydratedBlockValidationError as HydratedBlockValidationError2 } from "@xyo-network/xl1-protocol";
|
|
204
219
|
|
|
205
220
|
// src/hydratedBlock/validators/Payloads.ts
|
|
206
|
-
import { ZERO_HASH as
|
|
221
|
+
import { ZERO_HASH as ZERO_HASH14 } from "@xylabs/hex";
|
|
207
222
|
import { HydratedBlockValidationError } from "@xyo-network/xl1-protocol";
|
|
208
223
|
|
|
209
224
|
// src/elevatedPayload/validatePayloadInBlock.ts
|
|
210
|
-
import { ZERO_HASH as
|
|
225
|
+
import { ZERO_HASH as ZERO_HASH13 } from "@xylabs/hex";
|
|
211
226
|
import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
|
|
212
227
|
import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
|
|
213
|
-
import { ChainStakeIntentSchema, HashSchema, InBlockPayloadValidationError as
|
|
228
|
+
import { ChainStakeIntentSchema, HashSchema, InBlockPayloadValidationError as InBlockPayloadValidationError8, TransferSchema } from "@xyo-network/xl1-protocol";
|
|
214
229
|
|
|
215
230
|
// src/elevatedPayload/lib/isElevatedFromBlock.ts
|
|
216
231
|
import { isTransactionBoundWitness } from "@xyo-network/xl1-protocol";
|
|
@@ -225,23 +240,25 @@ var isElevatedFromBlock = /* @__PURE__ */ __name((payload, [, payloads]) => {
|
|
|
225
240
|
}, "isElevatedFromBlock");
|
|
226
241
|
|
|
227
242
|
// src/elevatedPayload/lib/validateElevatedFromBlock.ts
|
|
228
|
-
import {
|
|
243
|
+
import { InBlockPayloadValidationError } from "@xyo-network/xl1-protocol";
|
|
244
|
+
import { transactionsFromHydratedBlock } from "@xyo-network/xl1-protocol-sdk";
|
|
229
245
|
var validateElevatedFromBlock = /* @__PURE__ */ __name((payload, block) => {
|
|
230
246
|
const errors = [];
|
|
231
247
|
try {
|
|
232
248
|
const txs = transactionsFromHydratedBlock(block);
|
|
233
249
|
const allTxPayloadHashes = new Set(txs.flatMap((tx) => tx.payload_hashes));
|
|
234
250
|
if (allTxPayloadHashes.has(payload._hash)) {
|
|
235
|
-
errors.push(new
|
|
251
|
+
errors.push(new InBlockPayloadValidationError(block[0]?._hash, block, payload, `Transaction may not include block payload hash [${payload.schema}]: ${payload._hash}`));
|
|
236
252
|
}
|
|
237
|
-
} catch (
|
|
238
|
-
errors.push(new
|
|
253
|
+
} catch (ex) {
|
|
254
|
+
errors.push(new InBlockPayloadValidationError(block[0]?._hash, block, payload, `validation excepted: ${ex}`, ex));
|
|
239
255
|
}
|
|
240
256
|
return errors;
|
|
241
257
|
}, "validateElevatedFromBlock");
|
|
242
258
|
|
|
243
259
|
// src/elevatedPayload/lib/validateElevatedFromTransaction.ts
|
|
244
|
-
import {
|
|
260
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError2 } from "@xyo-network/xl1-protocol";
|
|
261
|
+
import { transactionsFromHydratedBlock as transactionsFromHydratedBlock2 } from "@xyo-network/xl1-protocol-sdk";
|
|
245
262
|
var validateElevatedFromTransaction = /* @__PURE__ */ __name((payload, block) => {
|
|
246
263
|
const errors = [];
|
|
247
264
|
try {
|
|
@@ -249,30 +266,34 @@ var validateElevatedFromTransaction = /* @__PURE__ */ __name((payload, block) =>
|
|
|
249
266
|
if (txs.length > 0) {
|
|
250
267
|
const hashes = txs.flatMap((tx) => tx.payload_hashes);
|
|
251
268
|
if (!hashes.includes(payload._hash)) {
|
|
252
|
-
errors.push(new
|
|
269
|
+
errors.push(new InBlockPayloadValidationError2(payload._hash, block, payload, "Transaction does not include payload"));
|
|
253
270
|
}
|
|
254
271
|
} else {
|
|
255
|
-
errors.push(new
|
|
272
|
+
errors.push(new InBlockPayloadValidationError2(payload._hash, block, payload, "No Transactions in block"));
|
|
256
273
|
}
|
|
257
|
-
} catch (
|
|
258
|
-
errors.push(new
|
|
274
|
+
} catch (ex) {
|
|
275
|
+
errors.push(new InBlockPayloadValidationError2(payload._hash, block, payload, `Failed validateElevatedFromTransaction: ${ex}`, ex));
|
|
259
276
|
}
|
|
260
277
|
return errors;
|
|
261
278
|
}, "validateElevatedFromTransaction");
|
|
262
279
|
|
|
263
280
|
// src/elevatedPayload/lib/validateTransactionInBlock.ts
|
|
281
|
+
import { ZERO_HASH as ZERO_HASH8 } from "@xylabs/hex";
|
|
264
282
|
import { isStorageMeta } from "@xyo-network/payload-model";
|
|
265
|
-
import { isTransactionBoundWitness as isTransactionBoundWitness2 } from "@xyo-network/xl1-protocol";
|
|
266
|
-
var validateTransactionInBlock = /* @__PURE__ */ __name(async (payload,
|
|
283
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError3, isTransactionBoundWitness as isTransactionBoundWitness2 } from "@xyo-network/xl1-protocol";
|
|
284
|
+
var validateTransactionInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
267
285
|
const errors = [];
|
|
268
286
|
try {
|
|
269
287
|
if (isTransactionBoundWitness2(payload) && isStorageMeta(payload)) {
|
|
270
|
-
|
|
288
|
+
const txErrors = await BoundWitnessSignaturesValidator(payload);
|
|
289
|
+
for (const txError of txErrors) {
|
|
290
|
+
errors.push(new InBlockPayloadValidationError3(payload._hash, block, payload, `BoundWitnessSignaturesValidator error: ${txError}`, txError));
|
|
291
|
+
}
|
|
271
292
|
} else {
|
|
272
|
-
errors.push(new
|
|
293
|
+
errors.push(new InBlockPayloadValidationError3(payload._hash, block, payload, "Payload failed isTransactionBoundWitness or isStorageMeta"));
|
|
273
294
|
}
|
|
274
|
-
} catch (
|
|
275
|
-
errors.push(new
|
|
295
|
+
} catch (ex) {
|
|
296
|
+
errors.push(new InBlockPayloadValidationError3(payload._hash ?? ZERO_HASH8, block, payload, `validation excepted: ${ex}`, ex));
|
|
276
297
|
}
|
|
277
298
|
return errors;
|
|
278
299
|
}, "validateTransactionInBlock");
|
|
@@ -291,61 +312,73 @@ var validateTypedPayloadInBlock = /* @__PURE__ */ __name(async (payload, block,
|
|
|
291
312
|
} else {
|
|
292
313
|
errors.push(new Error("Payload failed identityFunction or isElevated or isStorageMeta"));
|
|
293
314
|
}
|
|
294
|
-
} catch (
|
|
295
|
-
errors.push(new Error(`Failed validateTypedPayloadInBlock: ${
|
|
315
|
+
} catch (ex) {
|
|
316
|
+
errors.push(new Error(`Failed validateTypedPayloadInBlock: ${ex}`));
|
|
296
317
|
}
|
|
297
318
|
return errors;
|
|
298
319
|
}, "validateTypedPayloadInBlock");
|
|
299
320
|
|
|
300
321
|
// src/elevatedPayload/payloads/validateChainStakeIntentInBlock.ts
|
|
301
|
-
import { ZERO_HASH as
|
|
302
|
-
import { InBlockPayloadValidationError, isChainStakeIntent } from "@xyo-network/xl1-protocol";
|
|
322
|
+
import { ZERO_HASH as ZERO_HASH9 } from "@xylabs/hex";
|
|
323
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError4, isChainStakeIntent } from "@xyo-network/xl1-protocol";
|
|
303
324
|
var validateChainStakeIntentInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
304
325
|
const errors = [];
|
|
305
326
|
try {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
327
|
+
const typedErrors = await validateTypedPayloadInBlock(payload, block, isChainStakeIntent);
|
|
328
|
+
for (const typedError of typedErrors) {
|
|
329
|
+
errors.push(new InBlockPayloadValidationError4(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
330
|
+
}
|
|
331
|
+
} catch (ex) {
|
|
332
|
+
errors.push(new InBlockPayloadValidationError4(block[0]?._hash ?? ZERO_HASH9, block, payload, `validation excepted: ${ex}`, ex));
|
|
309
333
|
}
|
|
310
334
|
return errors;
|
|
311
335
|
}, "validateChainStakeIntentInBlock");
|
|
312
336
|
|
|
313
337
|
// src/elevatedPayload/payloads/validateHashInBlock.ts
|
|
314
|
-
import { ZERO_HASH as
|
|
315
|
-
import { InBlockPayloadValidationError as
|
|
338
|
+
import { ZERO_HASH as ZERO_HASH10 } from "@xylabs/hex";
|
|
339
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError5, isHashPayload } from "@xyo-network/xl1-protocol";
|
|
316
340
|
var validateHashInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
317
341
|
const errors = [];
|
|
318
342
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
343
|
+
const typedErrors = await validateTypedPayloadInBlock(payload, block, isHashPayload);
|
|
344
|
+
for (const typedError of typedErrors) {
|
|
345
|
+
errors.push(new InBlockPayloadValidationError5(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
346
|
+
}
|
|
347
|
+
} catch (ex) {
|
|
348
|
+
errors.push(new InBlockPayloadValidationError5(block?.[0]?._hash ?? ZERO_HASH10, block, payload, `validation excepted: ${ex}`, ex));
|
|
322
349
|
}
|
|
323
350
|
return errors;
|
|
324
351
|
}, "validateHashInBlock");
|
|
325
352
|
|
|
326
353
|
// src/elevatedPayload/payloads/validateSchemaInBlock.ts
|
|
327
|
-
import { ZERO_HASH as
|
|
354
|
+
import { ZERO_HASH as ZERO_HASH11 } from "@xylabs/hex";
|
|
328
355
|
import { isSchemaPayload } from "@xyo-network/schema-payload-plugin";
|
|
329
|
-
import { InBlockPayloadValidationError as
|
|
356
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError6 } from "@xyo-network/xl1-protocol";
|
|
330
357
|
var validateSchemaInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
331
358
|
const errors = [];
|
|
332
359
|
try {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
360
|
+
const typedErrors = await validateTypedPayloadInBlock(payload, block, isSchemaPayload);
|
|
361
|
+
for (const typedError of typedErrors) {
|
|
362
|
+
errors.push(new InBlockPayloadValidationError6(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
363
|
+
}
|
|
364
|
+
} catch (ex) {
|
|
365
|
+
errors.push(new InBlockPayloadValidationError6(block?.[0]?._hash ?? ZERO_HASH11, block, payload, `Failed validateSchemaInBlock: ${ex}`, ex));
|
|
336
366
|
}
|
|
337
367
|
return errors;
|
|
338
368
|
}, "validateSchemaInBlock");
|
|
339
369
|
|
|
340
370
|
// src/elevatedPayload/payloads/validateTransferInBlock.ts
|
|
341
|
-
import { ZERO_HASH as
|
|
342
|
-
import { InBlockPayloadValidationError as
|
|
371
|
+
import { ZERO_HASH as ZERO_HASH12 } from "@xylabs/hex";
|
|
372
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError7, isTransfer } from "@xyo-network/xl1-protocol";
|
|
343
373
|
var validateTransferInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
344
374
|
const errors = [];
|
|
345
375
|
try {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
376
|
+
const typedErrors = await validateTypedPayloadInBlock(payload, block, isTransfer);
|
|
377
|
+
for (const typedError of typedErrors) {
|
|
378
|
+
errors.push(new InBlockPayloadValidationError7(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
379
|
+
}
|
|
380
|
+
} catch (ex) {
|
|
381
|
+
errors.push(new InBlockPayloadValidationError7(block?.[0]?._hash ?? ZERO_HASH12, block, payload, `Failed validateTransferInBlock: ${ex}`, ex));
|
|
349
382
|
}
|
|
350
383
|
return errors;
|
|
351
384
|
}, "validateTransferInBlock");
|
|
@@ -365,10 +398,12 @@ var validatePayloadInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
365
398
|
if (validator) {
|
|
366
399
|
errors.push(...await validator(payload, block));
|
|
367
400
|
} else {
|
|
368
|
-
errors.push(new
|
|
401
|
+
errors.push(new InBlockPayloadValidationError8(block?.[0]?._hash ?? ZERO_HASH13, block, payload, `Unsupported payload schema: ${payload.schema}`));
|
|
369
402
|
}
|
|
370
|
-
} catch (
|
|
371
|
-
|
|
403
|
+
} catch (ex) {
|
|
404
|
+
const error = new InBlockPayloadValidationError8(block?.[0]?._hash ?? ZERO_HASH13, block, payload, `validation excepted: ${ex}`);
|
|
405
|
+
error.cause = ex;
|
|
406
|
+
errors.push(error);
|
|
372
407
|
}
|
|
373
408
|
return errors;
|
|
374
409
|
}, "validatePayloadInBlock");
|
|
@@ -389,29 +424,35 @@ var PayloadsInBlockValidator = /* @__PURE__ */ __name(async ([block, payloads])
|
|
|
389
424
|
const schema = block.payload_schemas[i];
|
|
390
425
|
const payload = payloadMap[hash];
|
|
391
426
|
if (payload) {
|
|
392
|
-
|
|
427
|
+
const payloadInBlockErrors = await validatePayloadInBlock(payload, [
|
|
393
428
|
block,
|
|
394
429
|
payloads
|
|
395
|
-
])
|
|
430
|
+
]);
|
|
431
|
+
for (const payloadInBlockError of payloadInBlockErrors) {
|
|
432
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH14, [
|
|
433
|
+
block,
|
|
434
|
+
payloads
|
|
435
|
+
], `validatePayloadInBlock error: ${payloadInBlockError}`, payloadInBlockError));
|
|
436
|
+
}
|
|
396
437
|
delete remainingPayloads[hash];
|
|
397
438
|
} else {
|
|
398
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
439
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH14, [
|
|
399
440
|
block,
|
|
400
441
|
payloads
|
|
401
442
|
], `missing payload ${hash} ${schema}`));
|
|
402
443
|
}
|
|
403
444
|
}
|
|
404
445
|
if (Object.keys(remainingPayloads).length > 0) {
|
|
405
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
446
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH14, [
|
|
406
447
|
block,
|
|
407
448
|
payloads
|
|
408
449
|
], `extra payloads ${Object.keys(payloadMap).join(", ")}`));
|
|
409
450
|
}
|
|
410
|
-
} catch (
|
|
411
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
451
|
+
} catch (ex) {
|
|
452
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH14, [
|
|
412
453
|
block,
|
|
413
454
|
payloads
|
|
414
|
-
], `Failed PayloadsInBlockValidator: ${
|
|
455
|
+
], `Failed PayloadsInBlockValidator: ${ex}`, ex));
|
|
415
456
|
}
|
|
416
457
|
return errors;
|
|
417
458
|
}, "PayloadsInBlockValidator");
|
|
@@ -420,28 +461,34 @@ var PayloadsInBlockValidator = /* @__PURE__ */ __name(async ([block, payloads])
|
|
|
420
461
|
var validateHydratedBlock = /* @__PURE__ */ __name(async (hydratedBlock, chainId, additionalValidators = []) => {
|
|
421
462
|
const errors = [];
|
|
422
463
|
try {
|
|
423
|
-
|
|
464
|
+
const validateBlockErrors = await validateBlock(hydratedBlock[0], chainId);
|
|
465
|
+
for (const validateBlockError of validateBlockErrors) {
|
|
466
|
+
errors.push(new HydratedBlockValidationError2(hydratedBlock[0]._hash, hydratedBlock, `validateBlock error: ${validateBlockError}`, validateBlockError));
|
|
467
|
+
}
|
|
468
|
+
const bwRefErrors = await BoundWitnessReferencesValidator()(hydratedBlock);
|
|
469
|
+
for (const bwRefError of bwRefErrors) {
|
|
470
|
+
errors.push(new HydratedBlockValidationError2(hydratedBlock[0]._hash, hydratedBlock, `boundwitness reference error: ${bwRefError}`, bwRefError));
|
|
471
|
+
}
|
|
424
472
|
const validators = [
|
|
425
|
-
BoundWitnessReferencesValidator(),
|
|
426
473
|
PayloadsInBlockValidator,
|
|
427
474
|
...additionalValidators
|
|
428
475
|
];
|
|
429
476
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId)))).flat());
|
|
430
|
-
} catch (
|
|
431
|
-
errors.push(new HydratedBlockValidationError2(hydratedBlock?.[0]?._hash ??
|
|
477
|
+
} catch (ex) {
|
|
478
|
+
errors.push(new HydratedBlockValidationError2(hydratedBlock?.[0]?._hash ?? ZERO_HASH15, hydratedBlock, `Failed validateHydratedBlock: ${ex}`, ex));
|
|
432
479
|
}
|
|
433
480
|
return errors;
|
|
434
481
|
}, "validateHydratedBlock");
|
|
435
482
|
|
|
436
483
|
// src/hydratedBlockState/validateHydratedBlockState.ts
|
|
437
|
-
import { ZERO_HASH as
|
|
484
|
+
import { ZERO_HASH as ZERO_HASH17 } from "@xylabs/hex";
|
|
438
485
|
import { HydratedBlockStateValidationError as HydratedBlockStateValidationError2 } from "@xyo-network/xl1-protocol";
|
|
439
486
|
|
|
440
487
|
// src/hydratedBlockState/validators/RequiredBalance.ts
|
|
441
|
-
import {
|
|
442
|
-
import { netBalancesForPayloads } from "@xyo-network/chain-protocol";
|
|
488
|
+
import { ZERO_HASH as ZERO_HASH16 } from "@xylabs/hex";
|
|
443
489
|
import { XYO_ZERO_ADDRESS } from "@xyo-network/chain-utils";
|
|
444
|
-
import { HydratedBlockStateValidationError } from "@xyo-network/xl1-protocol";
|
|
490
|
+
import { AttoXL1, HydratedBlockStateValidationError } from "@xyo-network/xl1-protocol";
|
|
491
|
+
import { netBalancesForPayloads } from "@xyo-network/xl1-protocol-sdk";
|
|
445
492
|
var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, chainId, services) => {
|
|
446
493
|
const errors = [];
|
|
447
494
|
try {
|
|
@@ -455,16 +502,18 @@ var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, ch
|
|
|
455
502
|
}
|
|
456
503
|
const previous = block[0].previous;
|
|
457
504
|
if (previous === null) return [
|
|
458
|
-
new HydratedBlockStateValidationError(block?.[0]?._hash ??
|
|
505
|
+
new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH16, chainId, block, "Insufficient funds because first block")
|
|
459
506
|
];
|
|
460
507
|
for (const [address, reqBalance] of Object.entries(requiredBalances)) {
|
|
461
|
-
const
|
|
508
|
+
const result = await services.accountBalance.balances(previous, [
|
|
509
|
+
address
|
|
510
|
+
]);
|
|
511
|
+
const balance = result[address] ?? AttoXL1(0n);
|
|
462
512
|
if (address !== XYO_ZERO_ADDRESS && reqBalance > balance) {
|
|
463
|
-
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ??
|
|
513
|
+
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH16, chainId, block, `insufficient balance for ${address} ${balance} < ${requiredBalances[address]}`));
|
|
464
514
|
}
|
|
465
515
|
}
|
|
466
|
-
}
|
|
467
|
-
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH15, chainId, block, `Failed RequiredBalanceBlockStateValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
516
|
+
} finally {
|
|
468
517
|
}
|
|
469
518
|
return await Promise.resolve(errors);
|
|
470
519
|
}, "RequiredBalanceBlockStateValidator");
|
|
@@ -473,14 +522,17 @@ var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, ch
|
|
|
473
522
|
var validateHydratedBlockState = /* @__PURE__ */ __name(async (hydratedBlock, chainId, services, additionalValidators = []) => {
|
|
474
523
|
const errors = [];
|
|
475
524
|
try {
|
|
476
|
-
|
|
525
|
+
const validateHydratedBlockErrors = await validateHydratedBlock(hydratedBlock, chainId);
|
|
526
|
+
for (const validateHydratedBlockError of validateHydratedBlockErrors) {
|
|
527
|
+
errors.push(new HydratedBlockStateValidationError2(hydratedBlock[0]._hash, chainId, hydratedBlock, `validateBlock error: ${validateHydratedBlockError}`, validateHydratedBlockError));
|
|
528
|
+
}
|
|
477
529
|
const validators = [
|
|
478
530
|
RequiredBalanceBlockStateValidator,
|
|
479
531
|
...additionalValidators
|
|
480
532
|
];
|
|
481
533
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId, services)))).flat());
|
|
482
|
-
} catch (
|
|
483
|
-
errors.push(new HydratedBlockStateValidationError2(hydratedBlock?.[0]?._hash ??
|
|
534
|
+
} catch (ex) {
|
|
535
|
+
errors.push(new HydratedBlockStateValidationError2(hydratedBlock?.[0]?._hash ?? ZERO_HASH17, chainId, hydratedBlock, `Failed validateHydratedBlockState: ${ex}`, ex));
|
|
484
536
|
}
|
|
485
537
|
return errors;
|
|
486
538
|
}, "validateHydratedBlockState");
|
|
@@ -489,24 +541,24 @@ var validateHydratedBlockState = /* @__PURE__ */ __name(async (hydratedBlock, ch
|
|
|
489
541
|
import { isTransactionBoundWitness as isTransactionBoundWitness3 } from "@xyo-network/xl1-protocol";
|
|
490
542
|
|
|
491
543
|
// src/transaction/validators/TransactionDurationValidator.ts
|
|
492
|
-
import { ZERO_HASH as
|
|
544
|
+
import { ZERO_HASH as ZERO_HASH18 } from "@xylabs/hex";
|
|
493
545
|
import { HydratedTransactionValidationError } from "@xyo-network/xl1-protocol";
|
|
494
546
|
var TransactionDurationValidator = /* @__PURE__ */ __name((tx) => {
|
|
495
547
|
const errors = [];
|
|
496
548
|
try {
|
|
497
549
|
const { exp, nbf } = tx[0];
|
|
498
|
-
if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ??
|
|
499
|
-
if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ??
|
|
500
|
-
if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ??
|
|
501
|
-
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ??
|
|
502
|
-
} catch (
|
|
503
|
-
errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ??
|
|
550
|
+
if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction nbf must be positive"));
|
|
551
|
+
if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must be positive"));
|
|
552
|
+
if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must greater than nbf"));
|
|
553
|
+
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must not be too far in the future"));
|
|
554
|
+
} catch (ex) {
|
|
555
|
+
errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, `Failed TransactionDurationValidator: ${ex}`, ex));
|
|
504
556
|
}
|
|
505
557
|
return errors;
|
|
506
558
|
}, "TransactionDurationValidator");
|
|
507
559
|
|
|
508
560
|
// src/transaction/validators/TransactionElevationValidator.ts
|
|
509
|
-
import { ZERO_HASH as
|
|
561
|
+
import { ZERO_HASH as ZERO_HASH19 } from "@xylabs/hex";
|
|
510
562
|
import { extractElevatedHashes } from "@xyo-network/chain-protocol";
|
|
511
563
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol";
|
|
512
564
|
var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
@@ -515,67 +567,66 @@ var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
515
567
|
try {
|
|
516
568
|
extractElevatedHashes(tx);
|
|
517
569
|
} catch {
|
|
518
|
-
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ??
|
|
570
|
+
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH19, tx, "Hydrated transaction does not include all script hashes"));
|
|
519
571
|
}
|
|
520
|
-
} catch (
|
|
521
|
-
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ??
|
|
572
|
+
} catch (ex) {
|
|
573
|
+
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH19, tx, `Failed TransactionElevationValidator: ${ex}`, ex));
|
|
522
574
|
}
|
|
523
575
|
return errors;
|
|
524
576
|
}, "TransactionElevationValidator");
|
|
525
577
|
|
|
526
578
|
// src/transaction/validators/TransactionFromValidator.ts
|
|
527
|
-
import { asAddress, ZERO_HASH as
|
|
579
|
+
import { asAddress, ZERO_HASH as ZERO_HASH20 } from "@xylabs/hex";
|
|
528
580
|
import { addressesContains } from "@xyo-network/boundwitness-validator";
|
|
529
581
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol";
|
|
530
582
|
var TransactionFromValidator = /* @__PURE__ */ __name((tx) => {
|
|
531
583
|
const errors = [];
|
|
532
584
|
try {
|
|
533
585
|
const from = asAddress(tx[0].from);
|
|
534
|
-
if (from === void 0) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ??
|
|
535
|
-
else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ??
|
|
536
|
-
} catch (
|
|
537
|
-
errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ??
|
|
586
|
+
if (from === void 0) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, "Transaction from is not a valid address"));
|
|
587
|
+
else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, "Transaction from address must be listed in addresses"));
|
|
588
|
+
} catch (ex) {
|
|
589
|
+
errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, `Failed TransactionFromValidator: ${ex}`, ex));
|
|
538
590
|
}
|
|
539
591
|
return errors;
|
|
540
592
|
}, "TransactionFromValidator");
|
|
541
593
|
|
|
542
594
|
// src/transaction/validators/TransactionGasValidator.ts
|
|
543
|
-
import { hexToBigInt
|
|
544
|
-
import { AttoXL1, HydratedTransactionValidationError as HydratedTransactionValidationError4, minTransactionFees } from "@xyo-network/xl1-protocol";
|
|
595
|
+
import { hexToBigInt, ZERO_HASH as ZERO_HASH21 } from "@xylabs/hex";
|
|
596
|
+
import { AttoXL1 as AttoXL12, HydratedTransactionValidationError as HydratedTransactionValidationError4, minTransactionFees } from "@xyo-network/xl1-protocol";
|
|
545
597
|
var TransactionGasValidator = /* @__PURE__ */ __name((tx) => {
|
|
546
598
|
const errors = [];
|
|
547
599
|
try {
|
|
548
600
|
if (tx?.[0].fees === void 0) {
|
|
549
|
-
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
601
|
+
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "Missing fees"));
|
|
550
602
|
} else {
|
|
551
603
|
const { base, gasLimit, gasPrice, priority } = parseFees(tx[0].fees);
|
|
552
|
-
if (base === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
553
|
-
else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
554
|
-
if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
555
|
-
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
556
|
-
if (gasPrice === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
557
|
-
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
558
|
-
if (priority === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
559
|
-
else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
560
|
-
}
|
|
561
|
-
} catch (
|
|
562
|
-
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ??
|
|
604
|
+
if (base === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.base must be defined and a valid number"));
|
|
605
|
+
else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.base must be >= ${minTransactionFees.base}`));
|
|
606
|
+
if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.gasLimit must be defined and a valid number"));
|
|
607
|
+
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`));
|
|
608
|
+
if (gasPrice === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.gasPrice must be defined and a valid number"));
|
|
609
|
+
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`));
|
|
610
|
+
if (priority === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.priority must be defined and a valid number"));
|
|
611
|
+
else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.priority must be >= ${minTransactionFees.priority}`));
|
|
612
|
+
}
|
|
613
|
+
} catch (ex) {
|
|
614
|
+
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `Failed TransactionGasValidator: ${ex}`, ex));
|
|
563
615
|
}
|
|
564
616
|
return errors;
|
|
565
617
|
}, "TransactionGasValidator");
|
|
566
618
|
var parseFees = /* @__PURE__ */ __name((fees) => {
|
|
567
619
|
const ret = {};
|
|
568
620
|
const { base, gasLimit, gasPrice, priority } = fees;
|
|
569
|
-
if (base !== void 0) ret.base =
|
|
570
|
-
if (gasLimit !== void 0) ret.gasLimit =
|
|
571
|
-
if (gasPrice !== void 0) ret.gasPrice =
|
|
572
|
-
if (priority !== void 0) ret.priority =
|
|
621
|
+
if (base !== void 0) ret.base = AttoXL12(hexToBigInt(base));
|
|
622
|
+
if (gasLimit !== void 0) ret.gasLimit = AttoXL12(hexToBigInt(gasLimit));
|
|
623
|
+
if (gasPrice !== void 0) ret.gasPrice = AttoXL12(hexToBigInt(gasPrice));
|
|
624
|
+
if (priority !== void 0) ret.priority = AttoXL12(hexToBigInt(priority));
|
|
573
625
|
return ret;
|
|
574
626
|
}, "parseFees");
|
|
575
627
|
|
|
576
628
|
// src/transaction/validators/TransactionJsonSchemaValidator.ts
|
|
577
|
-
import { ZERO_HASH as
|
|
578
|
-
import { toJsonString as toJsonString2 } from "@xylabs/object";
|
|
629
|
+
import { ZERO_HASH as ZERO_HASH22 } from "@xylabs/hex";
|
|
579
630
|
import { TransactionBoundWitnessJsonSchema } from "@xyo-network/chain-schema";
|
|
580
631
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
581
632
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError5 } from "@xyo-network/xl1-protocol";
|
|
@@ -590,27 +641,29 @@ var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
590
641
|
try {
|
|
591
642
|
if (validate === void 0) validate = ajv.compile(TransactionBoundWitnessJsonSchema);
|
|
592
643
|
if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {
|
|
593
|
-
const error = new HydratedTransactionValidationError5(tx?.[0]?._hash ??
|
|
644
|
+
const error = new HydratedTransactionValidationError5(tx?.[0]?._hash ?? ZERO_HASH22, tx, `failed JSON schema validation: ${ajv.errorsText(validate.errors, {
|
|
645
|
+
separator: "\n"
|
|
646
|
+
})}`);
|
|
594
647
|
error.cause = validate.errors;
|
|
595
648
|
errors.push(error);
|
|
596
649
|
}
|
|
597
650
|
} catch (ex) {
|
|
598
|
-
errors.push(new HydratedTransactionValidationError5(tx?.[0]?._hash ??
|
|
651
|
+
errors.push(new HydratedTransactionValidationError5(tx?.[0]?._hash ?? ZERO_HASH22, tx, "validation excepted", ex));
|
|
599
652
|
}
|
|
600
653
|
return errors;
|
|
601
654
|
}, "TransactionJsonSchemaValidator");
|
|
602
655
|
|
|
603
656
|
// src/transaction/validators/TransactionProtocolValidator.ts
|
|
604
|
-
import { ZERO_HASH as
|
|
657
|
+
import { ZERO_HASH as ZERO_HASH23 } from "@xylabs/hex";
|
|
605
658
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol";
|
|
606
659
|
var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, chainId) => {
|
|
607
660
|
const errors = [];
|
|
608
661
|
try {
|
|
609
662
|
if (chainId !== void 0 && tx[0].chain !== chainId) {
|
|
610
|
-
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ??
|
|
663
|
+
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH23, tx, "invalid chain id"));
|
|
611
664
|
}
|
|
612
665
|
} catch (ex) {
|
|
613
|
-
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ??
|
|
666
|
+
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH23, tx, "validation excepted", ex));
|
|
614
667
|
}
|
|
615
668
|
return await Promise.resolve(errors);
|
|
616
669
|
}, "TransactionProtocolValidator");
|
|
@@ -633,9 +686,9 @@ async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
|
633
686
|
...additionalValidators
|
|
634
687
|
];
|
|
635
688
|
return (await Promise.all(validators.map((v) => v(tx, chainId)))).flat();
|
|
636
|
-
} catch (
|
|
689
|
+
} catch (ex) {
|
|
637
690
|
return [
|
|
638
|
-
new Error(`Failed TransactionGasValidator: ${
|
|
691
|
+
new Error(`Failed TransactionGasValidator: ${ex}`)
|
|
639
692
|
];
|
|
640
693
|
}
|
|
641
694
|
}
|