@hardkas/sdk 0.7.0-alpha → 0.7.3-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.
Files changed (2) hide show
  1. package/dist/index.js +67 -17
  2. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -75,16 +75,34 @@ var HardkasTx = class {
75
75
  if (!fromAccount.address) throw new Error(`From account ${fromAccount.name} has no address.`);
76
76
  if (!toAccount.address) throw new Error(`To account ${toAccount.name} has no address.`);
77
77
  const amountSompi = typeof options.amount === "string" ? parseKasToSompi(options.amount) : typeof options.amount === "number" ? BigInt(options.amount) : options.amount;
78
- const rpcUtxos = await this.sdk.rpc.getUtxosByAddress(fromAccount.address);
79
- const builderUtxos = rpcUtxos.map((u) => ({
80
- outpoint: {
81
- transactionId: u.outpoint.transactionId,
82
- index: u.outpoint.index
83
- },
84
- address: u.address,
85
- amountSompi: u.amountSompi,
86
- scriptPublicKey: u.scriptPublicKey || ""
87
- }));
78
+ let builderUtxos = [];
79
+ if (this.sdk.network === "simulated") {
80
+ const { loadOrCreateLocalnetState, getSpendableUtxos } = await import("@hardkas/localnet");
81
+ const localState = await loadOrCreateLocalnetState({ cwd: this.sdk.workspace.root });
82
+ const unspent = getSpendableUtxos(localState, fromAccount.address);
83
+ builderUtxos = unspent.map((u) => {
84
+ const parts = u.id.split(":");
85
+ const index = Number(parts[parts.length - 1]);
86
+ const transactionId = parts.slice(0, -1).join(":");
87
+ return {
88
+ outpoint: { transactionId, index },
89
+ address: u.address,
90
+ amountSompi: BigInt(u.amountSompi),
91
+ scriptPublicKey: "mock-script"
92
+ };
93
+ });
94
+ } else {
95
+ const rpcUtxos = await this.sdk.rpc.getUtxosByAddress(fromAccount.address);
96
+ builderUtxos = rpcUtxos.map((u) => ({
97
+ outpoint: {
98
+ transactionId: u.outpoint.transactionId,
99
+ index: u.outpoint.index
100
+ },
101
+ address: u.address,
102
+ amountSompi: u.amountSompi,
103
+ scriptPublicKey: u.scriptPublicKey || ""
104
+ }));
105
+ }
88
106
  const builderPlan = buildPaymentPlan({
89
107
  fromAddress: fromAccount.address,
90
108
  availableUtxos: builderUtxos,
@@ -143,7 +161,7 @@ var HardkasTx = class {
143
161
  saveSimulatedTrace
144
162
  } = await import("@hardkas/localnet");
145
163
  const path4 = await import("path");
146
- const state = await loadOrCreateLocalnetState();
164
+ const state = await loadOrCreateLocalnetState({ cwd: this.sdk.workspace.root });
147
165
  const startTime = Date.now();
148
166
  const events = [
149
167
  { type: "phase.started", phase: "send", timestamp: startTime }
@@ -213,6 +231,22 @@ var HardkasTx = class {
213
231
  events,
214
232
  receiptPath
215
233
  });
234
+ coreEvents.normalizeAndEmit({
235
+ kind: "artifact.created",
236
+ schema: receipt.schema,
237
+ artifactId: receipt.txId,
238
+ network: receipt.networkId,
239
+ mode: receipt.mode,
240
+ path: receiptPath
241
+ });
242
+ coreEvents.normalizeAndEmit({
243
+ kind: "tx.confirmed",
244
+ txId: receipt.txId,
245
+ network: receipt.networkId,
246
+ mode: receipt.mode,
247
+ amountSompi: receipt.amountSompi,
248
+ feeSompi: receipt.feeSompi
249
+ });
216
250
  return {
217
251
  receipt,
218
252
  receiptPath,
@@ -356,12 +390,28 @@ var HardkasReplay = class {
356
390
  * against the mathematically reconstructed localnet state.
357
391
  */
358
392
  async verify(options) {
359
- const artifactDir = options.path ? path.resolve(this.sdk.config.cwd, options.path) : this.sdk.config.cwd;
360
- if (options.path && !fs.existsSync(path.join(artifactDir, "hardkas.config.ts"))) {
361
- throw new Error(`Workspace not found at ${options.path}`);
393
+ let artifactDir = this.sdk.config.cwd;
394
+ let planPath = path.join(artifactDir, "tx-plan.json");
395
+ let receiptPath = path.join(artifactDir, "tx-receipt.json");
396
+ if (options.path) {
397
+ const fullPath = path.resolve(this.sdk.config.cwd, options.path);
398
+ if (fs.existsSync(fullPath)) {
399
+ if (fs.statSync(fullPath).isFile()) {
400
+ planPath = fullPath;
401
+ artifactDir = path.dirname(fullPath);
402
+ receiptPath = fullPath.replace("tx-plan", "tx-receipt");
403
+ } else {
404
+ artifactDir = fullPath;
405
+ planPath = path.join(artifactDir, "tx-plan.json");
406
+ receiptPath = path.join(artifactDir, "tx-receipt.json");
407
+ }
408
+ } else {
409
+ throw new Error(`Path not found: ${options.path}`);
410
+ }
411
+ }
412
+ if (!fs.existsSync(path.join(this.sdk.config.cwd, "hardkas.config.ts"))) {
413
+ throw new Error(`Workspace not found at ${this.sdk.config.cwd}`);
362
414
  }
363
- const planPath = path.join(artifactDir, "tx-plan.json");
364
- const receiptPath = path.join(artifactDir, "tx-receipt.json");
365
415
  const canonicalDirs = [
366
416
  path.join(artifactDir, ".hardkas", "receipts"),
367
417
  path.join(artifactDir, ".hardkas", "traces"),
@@ -470,7 +520,7 @@ var HardkasReplay = class {
470
520
  try {
471
521
  const { loadOrCreateLocalnetState, reconstructStateAtDaa, verifyReplay } = await import("@hardkas/localnet");
472
522
  const { systemRuntimeContext: systemRuntimeContext2 } = await import("@hardkas/core");
473
- let state = await loadOrCreateLocalnetState();
523
+ let state = await loadOrCreateLocalnetState({ cwd: this.sdk.workspace.root });
474
524
  if (receipt.mode === "simulated" && receipt.daaScore) {
475
525
  const receiptDaa = BigInt(receipt.daaScore);
476
526
  const targetDaa = receiptDaa - 1n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/sdk",
3
- "version": "0.7.0-alpha",
3
+ "version": "0.7.3-alpha",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -23,17 +23,17 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@hardkas/config": "0.7.0-alpha",
27
- "@hardkas/core": "0.7.0-alpha",
28
- "@hardkas/l2": "0.7.0-alpha",
29
- "@hardkas/accounts": "0.7.0-alpha",
30
- "@hardkas/artifacts": "0.7.0-alpha",
31
- "@hardkas/query": "0.7.0-alpha",
32
- "@hardkas/kaspa-rpc": "0.7.0-alpha",
33
- "@hardkas/localnet": "0.7.0-alpha",
34
- "@hardkas/tx-builder": "0.7.0-alpha",
35
- "@hardkas/wallet-adapter": "0.7.0-alpha",
36
- "@hardkas/simulator": "0.7.0-alpha"
26
+ "@hardkas/accounts": "0.7.3-alpha",
27
+ "@hardkas/config": "0.7.3-alpha",
28
+ "@hardkas/core": "0.7.3-alpha",
29
+ "@hardkas/artifacts": "0.7.3-alpha",
30
+ "@hardkas/query": "0.7.3-alpha",
31
+ "@hardkas/l2": "0.7.3-alpha",
32
+ "@hardkas/localnet": "0.7.3-alpha",
33
+ "@hardkas/simulator": "0.7.3-alpha",
34
+ "@hardkas/kaspa-rpc": "0.7.3-alpha",
35
+ "@hardkas/wallet-adapter": "0.7.3-alpha",
36
+ "@hardkas/tx-builder": "0.7.3-alpha"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^8.3.5",