@hardkas/sdk 0.7.12-alpha → 0.7.13-alpha
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/index.d.ts +6 -2
- package/dist/index.js +50 -31
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -287,11 +287,15 @@ declare class HardkasArtifactsManager {
|
|
|
287
287
|
/**
|
|
288
288
|
* Reads an artifact by path or ID/hash from the workspace.
|
|
289
289
|
*/
|
|
290
|
-
read(id: string
|
|
290
|
+
read(id: string, options?: {
|
|
291
|
+
expectedSchema?: string;
|
|
292
|
+
}): Promise<any>;
|
|
291
293
|
/**
|
|
292
294
|
* Alias for read().
|
|
293
295
|
*/
|
|
294
|
-
get(id: string
|
|
296
|
+
get(id: string, options?: {
|
|
297
|
+
expectedSchema?: string;
|
|
298
|
+
}): Promise<any>;
|
|
295
299
|
/**
|
|
296
300
|
* Lists all artifacts in the workspace.
|
|
297
301
|
*/
|
package/dist/index.js
CHANGED
|
@@ -107,6 +107,37 @@ import {
|
|
|
107
107
|
import { coreEvents } from "@hardkas/core";
|
|
108
108
|
import { signTxPlanArtifact } from "@hardkas/accounts";
|
|
109
109
|
import { parseKasToSompi } from "@hardkas/core";
|
|
110
|
+
function normalizeSimulatedPlanInput(target, fallbackId) {
|
|
111
|
+
if (target.schema === ARTIFACT_SCHEMAS.TX_PLAN && Array.isArray(target.inputs)) {
|
|
112
|
+
return target;
|
|
113
|
+
}
|
|
114
|
+
if (target.from && target.to && target.amountSompi) {
|
|
115
|
+
if (target.mode !== "simulated") {
|
|
116
|
+
throw new Error("Cannot simulate real signed artifact without parent plan. Missing plan inputs data.");
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
schema: ARTIFACT_SCHEMAS.TX_PLAN,
|
|
120
|
+
planId: target.planId || target.sourcePlanId || fallbackId,
|
|
121
|
+
networkId: target.networkId || "simnet",
|
|
122
|
+
mode: "simulated",
|
|
123
|
+
from: target.from,
|
|
124
|
+
to: target.to,
|
|
125
|
+
amountSompi: target.amountSompi,
|
|
126
|
+
estimatedFeeSompi: "0",
|
|
127
|
+
estimatedMass: "0",
|
|
128
|
+
inputs: [],
|
|
129
|
+
outputs: [{ address: target.to.address, amountSompi: target.amountSompi || "0" }],
|
|
130
|
+
plan: {
|
|
131
|
+
inputs: [],
|
|
132
|
+
outputs: [{ address: target.to.address, amountSompi: BigInt(target.amountSompi || 0) }],
|
|
133
|
+
feeSompi: 0n,
|
|
134
|
+
mass: 0n,
|
|
135
|
+
changeSompi: 0n
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw new Error("Cannot simulate signed artifact without parent plan or embedded plan data.");
|
|
140
|
+
}
|
|
110
141
|
var HardkasTx = class {
|
|
111
142
|
constructor(sdk) {
|
|
112
143
|
this.sdk = sdk;
|
|
@@ -428,7 +459,7 @@ var HardkasTx = class {
|
|
|
428
459
|
let targetObj = target;
|
|
429
460
|
if (typeof target === "string") {
|
|
430
461
|
try {
|
|
431
|
-
targetObj = await this.sdk.artifacts.read(target);
|
|
462
|
+
targetObj = await this.sdk.artifacts.read(target, { expectedSchema: ARTIFACT_SCHEMAS.TX_PLAN });
|
|
432
463
|
} catch (e) {
|
|
433
464
|
throw new Error(`Artifact '${target}' not found. If you already have an in-memory artifact, pass the object directly to tx.simulate(artifact).`);
|
|
434
465
|
}
|
|
@@ -438,30 +469,9 @@ var HardkasTx = class {
|
|
|
438
469
|
sourcePlanId = targetObj.sourcePlanId || "unknown";
|
|
439
470
|
txId = targetObj.txId || `simulated-${sourcePlanId}-tx`;
|
|
440
471
|
try {
|
|
441
|
-
planArtifact = await this.sdk.artifacts.read(sourcePlanId);
|
|
472
|
+
planArtifact = await this.sdk.artifacts.read(sourcePlanId, { expectedSchema: ARTIFACT_SCHEMAS.TX_PLAN });
|
|
442
473
|
} catch (e) {
|
|
443
|
-
|
|
444
|
-
planArtifact = {
|
|
445
|
-
schema: "hardkas.txPlan",
|
|
446
|
-
planId: sourcePlanId,
|
|
447
|
-
from: targetObj.from,
|
|
448
|
-
to: targetObj.to,
|
|
449
|
-
amountSompi: targetObj.amountSompi,
|
|
450
|
-
estimatedFeeSompi: "0",
|
|
451
|
-
estimatedMass: "0",
|
|
452
|
-
inputs: [],
|
|
453
|
-
outputs: [{ address: targetObj.to.address, amountSompi: targetObj.amountSompi || "0" }],
|
|
454
|
-
plan: {
|
|
455
|
-
inputs: [],
|
|
456
|
-
outputs: [{ address: targetObj.to.address, amountSompi: BigInt(targetObj.amountSompi || 0) }],
|
|
457
|
-
feeSompi: 0n,
|
|
458
|
-
mass: 0n,
|
|
459
|
-
changeSompi: 0n
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
} else {
|
|
463
|
-
throw new Error(`Cannot simulate signed artifact: source plan '${sourcePlanId}' not found in workspace and artifact lacks details.`);
|
|
464
|
-
}
|
|
474
|
+
planArtifact = targetObj;
|
|
465
475
|
}
|
|
466
476
|
} else {
|
|
467
477
|
planArtifact = targetObj;
|
|
@@ -472,9 +482,10 @@ var HardkasTx = class {
|
|
|
472
482
|
sourcePlanId = planArtifact.planId || "unknown";
|
|
473
483
|
}
|
|
474
484
|
}
|
|
485
|
+
const normalizedPlan = normalizeSimulatedPlanInput(planArtifact, sourcePlanId);
|
|
475
486
|
const simResult = applySimulatedPlan(
|
|
476
487
|
state,
|
|
477
|
-
|
|
488
|
+
normalizedPlan,
|
|
478
489
|
systemRuntimeContext,
|
|
479
490
|
{ txId }
|
|
480
491
|
);
|
|
@@ -1283,9 +1294,13 @@ var HardkasArtifactsManager = class {
|
|
|
1283
1294
|
/**
|
|
1284
1295
|
* Reads an artifact by path or ID/hash from the workspace.
|
|
1285
1296
|
*/
|
|
1286
|
-
async read(id) {
|
|
1297
|
+
async read(id, options) {
|
|
1287
1298
|
if (this.cache.has(id)) {
|
|
1288
|
-
|
|
1299
|
+
const cached = this.cache.get(id);
|
|
1300
|
+
if (options?.expectedSchema && cached.schema !== options.expectedSchema) {
|
|
1301
|
+
throw new Error(`Artifact ${id} has schema '${cached.schema}' but expected '${options.expectedSchema}'`);
|
|
1302
|
+
}
|
|
1303
|
+
return cached;
|
|
1289
1304
|
}
|
|
1290
1305
|
const { readArtifact } = await import("@hardkas/artifacts");
|
|
1291
1306
|
let filePath = id;
|
|
@@ -1303,7 +1318,7 @@ var HardkasArtifactsManager = class {
|
|
|
1303
1318
|
if (!fs3.existsSync(filePath)) {
|
|
1304
1319
|
if (fs3.existsSync(this.workspace.artifactsDir)) {
|
|
1305
1320
|
const files = fs3.readdirSync(this.workspace.artifactsDir);
|
|
1306
|
-
const found = files.find((f) => f.
|
|
1321
|
+
const found = files.find((f) => f === `${id}.json` || f.startsWith(`${id}-`) || f.startsWith(`${id}.`));
|
|
1307
1322
|
if (found) {
|
|
1308
1323
|
filePath = path3.join(this.workspace.artifactsDir, found);
|
|
1309
1324
|
} else {
|
|
@@ -1314,13 +1329,17 @@ var HardkasArtifactsManager = class {
|
|
|
1314
1329
|
}
|
|
1315
1330
|
}
|
|
1316
1331
|
}
|
|
1317
|
-
|
|
1332
|
+
const artifact = await readArtifact(filePath);
|
|
1333
|
+
if (options?.expectedSchema && artifact.schema !== options.expectedSchema) {
|
|
1334
|
+
throw new Error(`Artifact ${id} has schema '${artifact.schema}' but expected '${options.expectedSchema}'`);
|
|
1335
|
+
}
|
|
1336
|
+
return artifact;
|
|
1318
1337
|
}
|
|
1319
1338
|
/**
|
|
1320
1339
|
* Alias for read().
|
|
1321
1340
|
*/
|
|
1322
|
-
async get(id) {
|
|
1323
|
-
return this.read(id);
|
|
1341
|
+
async get(id, options) {
|
|
1342
|
+
return this.read(id, options);
|
|
1324
1343
|
}
|
|
1325
1344
|
/**
|
|
1326
1345
|
* Lists all artifacts in the workspace.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hardkas/accounts": "0.7.
|
|
27
|
-
"@hardkas/
|
|
28
|
-
"@hardkas/
|
|
29
|
-
"@hardkas/
|
|
30
|
-
"@hardkas/l2": "0.7.
|
|
31
|
-
"@hardkas/kaspa-rpc": "0.7.
|
|
32
|
-
"@hardkas/
|
|
33
|
-
"@hardkas/
|
|
34
|
-
"@hardkas/
|
|
35
|
-
"@hardkas/
|
|
36
|
-
"@hardkas/
|
|
37
|
-
"@hardkas/query-store": "0.7.
|
|
26
|
+
"@hardkas/accounts": "0.7.13-alpha",
|
|
27
|
+
"@hardkas/core": "0.7.13-alpha",
|
|
28
|
+
"@hardkas/artifacts": "0.7.13-alpha",
|
|
29
|
+
"@hardkas/config": "0.7.13-alpha",
|
|
30
|
+
"@hardkas/l2": "0.7.13-alpha",
|
|
31
|
+
"@hardkas/kaspa-rpc": "0.7.13-alpha",
|
|
32
|
+
"@hardkas/query": "0.7.13-alpha",
|
|
33
|
+
"@hardkas/simulator": "0.7.13-alpha",
|
|
34
|
+
"@hardkas/tx-builder": "0.7.13-alpha",
|
|
35
|
+
"@hardkas/wallet-adapter": "0.7.13-alpha",
|
|
36
|
+
"@hardkas/localnet": "0.7.13-alpha",
|
|
37
|
+
"@hardkas/query-store": "0.7.13-alpha"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsup": "^8.3.5",
|