@hardkas/sdk 0.7.4-alpha → 0.7.5-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 +1 -0
- package/dist/index.js +30 -27
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -351,7 +351,8 @@ var HardkasTx = class {
|
|
|
351
351
|
const {
|
|
352
352
|
loadOrCreateLocalnetState,
|
|
353
353
|
saveLocalnetState,
|
|
354
|
-
|
|
354
|
+
getDefaultLocalnetStatePath,
|
|
355
|
+
applySimulatedPlan,
|
|
355
356
|
saveSimulatedReceipt,
|
|
356
357
|
saveSimulatedTrace
|
|
357
358
|
} = await import("@hardkas/localnet");
|
|
@@ -361,24 +362,26 @@ var HardkasTx = class {
|
|
|
361
362
|
const events = [
|
|
362
363
|
{ type: "phase.started", phase: "send", timestamp: startTime }
|
|
363
364
|
];
|
|
364
|
-
const
|
|
365
|
+
const planArtifact = await this.sdk.artifacts.read(signedArtifact.sourcePlanId);
|
|
366
|
+
const simResult = applySimulatedPlan(
|
|
365
367
|
state,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
amountSompi: BigInt(signedArtifact.amountSompi)
|
|
370
|
-
},
|
|
371
|
-
systemRuntimeContext
|
|
368
|
+
planArtifact,
|
|
369
|
+
systemRuntimeContext,
|
|
370
|
+
{ txId: signedArtifact.txId || `simulated-${signedArtifact.sourcePlanId}-tx` }
|
|
372
371
|
);
|
|
372
|
+
if (!simResult.ok) {
|
|
373
|
+
throw new Error(`Strict validation failed: ${simResult.errors?.join(", ")}`);
|
|
374
|
+
}
|
|
373
375
|
coreEvents.normalizeAndEmit({
|
|
374
376
|
kind: "workflow.submitted",
|
|
375
377
|
txId: simResult.receipt.txId,
|
|
376
378
|
endpoint: "simulated://local"
|
|
377
379
|
});
|
|
378
380
|
events.push({ type: "phase.completed", phase: "send", timestamp: Date.now() });
|
|
379
|
-
await saveLocalnetState(simResult.state);
|
|
381
|
+
await saveLocalnetState(simResult.state, getDefaultLocalnetStatePath(this.sdk.workspace.root));
|
|
380
382
|
const receiptPath = await saveSimulatedReceipt(
|
|
381
|
-
simResult.receipt
|
|
383
|
+
simResult.receipt,
|
|
384
|
+
{ cwd: this.sdk.workspace.root }
|
|
382
385
|
);
|
|
383
386
|
const tracePath = receiptPath.replace(".json", ".trace.json");
|
|
384
387
|
const receiptBase = {
|
|
@@ -432,7 +435,7 @@ var HardkasTx = class {
|
|
|
432
435
|
...traceBase,
|
|
433
436
|
events,
|
|
434
437
|
receiptPath
|
|
435
|
-
});
|
|
438
|
+
}, { cwd: this.sdk.workspace.root });
|
|
436
439
|
coreEvents.normalizeAndEmit({
|
|
437
440
|
kind: "artifact.created",
|
|
438
441
|
schema: receipt.schema,
|
|
@@ -830,12 +833,17 @@ var HardkasArtifactsManager = class {
|
|
|
830
833
|
this.workspace = workspace;
|
|
831
834
|
}
|
|
832
835
|
workspace;
|
|
836
|
+
cache = /* @__PURE__ */ new Map();
|
|
833
837
|
/**
|
|
834
838
|
* Writes a valid artifact to disk (canonical or custom path).
|
|
835
839
|
*/
|
|
836
840
|
async write(artifact, options = {}) {
|
|
837
841
|
const record = artifact;
|
|
838
842
|
const hash = record.contentHash || "unknown";
|
|
843
|
+
if (record.planId) this.cache.set(record.planId, artifact);
|
|
844
|
+
if (record.signedId) this.cache.set(record.signedId, artifact);
|
|
845
|
+
if (record.txId) this.cache.set(record.txId, artifact);
|
|
846
|
+
this.cache.set(hash, artifact);
|
|
839
847
|
if (options.dryRun) {
|
|
840
848
|
return {
|
|
841
849
|
dryRun: true,
|
|
@@ -889,6 +897,9 @@ var HardkasArtifactsManager = class {
|
|
|
889
897
|
* Reads an artifact by path or ID/hash from the workspace.
|
|
890
898
|
*/
|
|
891
899
|
async read(id) {
|
|
900
|
+
if (this.cache.has(id)) {
|
|
901
|
+
return this.cache.get(id);
|
|
902
|
+
}
|
|
892
903
|
const { readArtifact } = await import("@hardkas/artifacts");
|
|
893
904
|
let filePath = id;
|
|
894
905
|
if (!fs3.existsSync(filePath)) {
|
|
@@ -983,9 +994,7 @@ var HardkasWorkflow = class {
|
|
|
983
994
|
);
|
|
984
995
|
}
|
|
985
996
|
const plan = await this.sdk.tx.plan({ ...opts, workflowId });
|
|
986
|
-
|
|
987
|
-
await this.sdk.artifacts.write(plan);
|
|
988
|
-
}
|
|
997
|
+
await this.sdk.artifacts.write(plan, { dryRun: options.dryRun ?? false });
|
|
989
998
|
const planRecord = plan;
|
|
990
999
|
const id = planRecord.contentHash || planRecord.artifactId || plan.planId;
|
|
991
1000
|
if (id) producedArtifacts.push(id);
|
|
@@ -994,9 +1003,7 @@ var HardkasWorkflow = class {
|
|
|
994
1003
|
},
|
|
995
1004
|
sign: async (plan, account) => {
|
|
996
1005
|
const signed = await this.sdk.tx.sign(plan, account);
|
|
997
|
-
|
|
998
|
-
await this.sdk.artifacts.write(signed);
|
|
999
|
-
}
|
|
1006
|
+
await this.sdk.artifacts.write(signed, { dryRun: options.dryRun ?? false });
|
|
1000
1007
|
const signedRecord = signed;
|
|
1001
1008
|
const id = signedRecord.contentHash || signedRecord.artifactId || signed.signedId;
|
|
1002
1009
|
if (id) producedArtifacts.push(id);
|
|
@@ -1009,7 +1016,7 @@ var HardkasWorkflow = class {
|
|
|
1009
1016
|
"Workflow script requested real broadcast"
|
|
1010
1017
|
);
|
|
1011
1018
|
const res = this.sdk.network === "simulated" ? await this.sdk.tx.simulate(signed) : await this.sdk.tx.send(signed);
|
|
1012
|
-
|
|
1019
|
+
await this.sdk.artifacts.write(res.receipt, { dryRun: options.dryRun ?? false });
|
|
1013
1020
|
const receiptRecord = res.receipt;
|
|
1014
1021
|
const id = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1015
1022
|
if (id) producedArtifacts.push(id);
|
|
@@ -1017,7 +1024,7 @@ var HardkasWorkflow = class {
|
|
|
1017
1024
|
},
|
|
1018
1025
|
simulate: async (signed) => {
|
|
1019
1026
|
const res = await this.sdk.tx.simulate(signed);
|
|
1020
|
-
|
|
1027
|
+
await this.sdk.artifacts.write(res.receipt, { dryRun: options.dryRun ?? false });
|
|
1021
1028
|
const receiptRecord = res.receipt;
|
|
1022
1029
|
const id = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1023
1030
|
if (id) producedArtifacts.push(id);
|
|
@@ -1045,9 +1052,7 @@ var HardkasWorkflow = class {
|
|
|
1045
1052
|
amount: step.args?.amount || step.amount,
|
|
1046
1053
|
workflowId
|
|
1047
1054
|
});
|
|
1048
|
-
|
|
1049
|
-
await this.sdk.artifacts.write(lastPlan);
|
|
1050
|
-
}
|
|
1055
|
+
await this.sdk.artifacts.write(lastPlan, { dryRun: options.dryRun ?? false });
|
|
1051
1056
|
const planRecord = lastPlan;
|
|
1052
1057
|
producedArtifactId = planRecord.contentHash || planRecord.artifactId || lastPlan.planId;
|
|
1053
1058
|
if (producedArtifactId) producedArtifacts.push(producedArtifactId);
|
|
@@ -1062,22 +1067,20 @@ var HardkasWorkflow = class {
|
|
|
1062
1067
|
);
|
|
1063
1068
|
}
|
|
1064
1069
|
lastSigned = await this.sdk.tx.sign(lastPlan);
|
|
1065
|
-
|
|
1066
|
-
await this.sdk.artifacts.write(lastSigned);
|
|
1067
|
-
}
|
|
1070
|
+
await this.sdk.artifacts.write(lastSigned, { dryRun: options.dryRun ?? false });
|
|
1068
1071
|
const signedRecord = lastSigned;
|
|
1069
1072
|
const signedId = signedRecord.contentHash || signedRecord.artifactId || lastSigned.signedId;
|
|
1070
1073
|
if (signedId) producedArtifacts.push(signedId);
|
|
1071
1074
|
if (step.type === "tx.simulate") {
|
|
1072
1075
|
const { receipt } = await this.sdk.tx.simulate(lastSigned);
|
|
1073
|
-
|
|
1076
|
+
await this.sdk.artifacts.write(receipt, { dryRun: options.dryRun ?? false });
|
|
1074
1077
|
const receiptRecord = receipt;
|
|
1075
1078
|
producedArtifactId = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1076
1079
|
if (producedArtifactId) producedArtifacts.push(producedArtifactId);
|
|
1077
1080
|
result = receipt;
|
|
1078
1081
|
} else {
|
|
1079
1082
|
const { receipt } = this.sdk.network === "simulated" ? await this.sdk.tx.simulate(lastSigned) : await this.sdk.tx.send(lastSigned);
|
|
1080
|
-
|
|
1083
|
+
await this.sdk.artifacts.write(receipt, { dryRun: options.dryRun ?? false });
|
|
1081
1084
|
const receiptRecord = receipt;
|
|
1082
1085
|
producedArtifactId = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1083
1086
|
if (producedArtifactId) producedArtifacts.push(producedArtifactId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hardkas/accounts": "0.7.
|
|
27
|
-
"@hardkas/
|
|
28
|
-
"@hardkas/
|
|
29
|
-
"@hardkas/
|
|
30
|
-
"@hardkas/
|
|
31
|
-
"@hardkas/
|
|
32
|
-
"@hardkas/
|
|
33
|
-
"@hardkas/
|
|
34
|
-
"@hardkas/tx-builder": "0.7.
|
|
35
|
-
"@hardkas/
|
|
36
|
-
"@hardkas/wallet-adapter": "0.7.
|
|
26
|
+
"@hardkas/accounts": "0.7.5-alpha",
|
|
27
|
+
"@hardkas/artifacts": "0.7.5-alpha",
|
|
28
|
+
"@hardkas/l2": "0.7.5-alpha",
|
|
29
|
+
"@hardkas/core": "0.7.5-alpha",
|
|
30
|
+
"@hardkas/config": "0.7.5-alpha",
|
|
31
|
+
"@hardkas/query": "0.7.5-alpha",
|
|
32
|
+
"@hardkas/kaspa-rpc": "0.7.5-alpha",
|
|
33
|
+
"@hardkas/simulator": "0.7.5-alpha",
|
|
34
|
+
"@hardkas/tx-builder": "0.7.5-alpha",
|
|
35
|
+
"@hardkas/localnet": "0.7.5-alpha",
|
|
36
|
+
"@hardkas/wallet-adapter": "0.7.5-alpha"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.3.5",
|
|
40
40
|
"typescript": "^5.7.2",
|
|
41
41
|
"vitest": "^2.1.8",
|
|
42
|
-
"@hardkas/query-store": "0.7.
|
|
42
|
+
"@hardkas/query-store": "0.7.5-alpha"
|
|
43
43
|
},
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"author": "Javier Rodriguez",
|