@hardkas/localnet 0.7.8-alpha → 0.7.10-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 CHANGED
@@ -2,7 +2,7 @@ import * as _hardkas_artifacts from '@hardkas/artifacts';
2
2
  import { HardkasArtifactBase, Snapshot as Snapshot$1, TxPlan, ARTIFACT_SCHEMAS, TxReceipt } from '@hardkas/artifacts';
3
3
  import * as _hardkas_simulator from '@hardkas/simulator';
4
4
  import { ExecutionMode, NetworkId, RuntimeContext } from '@hardkas/core';
5
- import { KaspaRpcClient } from '@hardkas/kaspa-rpc';
5
+ import { KaspaRpcClient, KaspaNodeInfo, KaspaRpcHealth, KaspaAddressBalance, KaspaRpcUtxo, KaspaSubmitTransactionResult, MempoolEntry, BlockDagInfo, ServerInfo } from '@hardkas/kaspa-rpc';
6
6
 
7
7
  interface HardkasAccount {
8
8
  readonly name: string;
@@ -372,7 +372,7 @@ declare function moveSink(dag: SimulatedDag, newSinkId: string, txProvider: (txI
372
372
  inputs: string[];
373
373
  } | undefined): SimulatedDag;
374
374
  /**
375
- * Deterministic Conflict Resolution (Approximation for 0.7.7-alpha)
375
+ * Deterministic Conflict Resolution (Approximation for 0.7.10-alpha)
376
376
  * Priority:
377
377
  * 1. sink ancestry priority (is part of selectedPathToSink?)
378
378
  * 2. deterministic block order (daaScore then block ID)
@@ -413,4 +413,21 @@ interface ForkOptions {
413
413
  }
414
414
  declare function forkFromNetwork(rpc: KaspaRpcClient, opts: ForkOptions): Promise<LocalnetState>;
415
415
 
416
- export { type CreateInitialStateOptions, DUST_LIMIT_SOMPI, type ForkOptions, type FundAddressInput, type HardkasAccount, type HardkasDevnet, type LocalnetAccount, type LocalnetState, type LocalnetUtxo, type ReplayInvariantResult, type ReplayVerificationReport, type SimulatedBlock, type SimulatedDag, SimulatedKaspaChain, type SimulatedPaymentInput, type SimulatedReplaySummary, type SimulatedUtxo, type SimulationResult, type Snapshot, type SnapshotRestoreResult, type SnapshotVerificationResult, type StateTransition, type StoredSimulatedTxReceipt, type StoredSimulatedTxTrace, type StoredTraceEvent, addSimulatedBlock, applySimulatedPayment, applySimulatedPlan, calculateAccountsHash, calculateStateHash, calculateUtxoSetHash, createDeterministicAccounts, createInitialLocalnetState, createLocalnetSnapshot, createSimulatedDag, findBestTip, forkFromNetwork, fundAddress, getAccountBalanceSompi, getAddressBalanceSompi, getDagColoring, getDefaultLocalnetDir, getDefaultLocalnetStatePath, getDefaultReceiptsDir, getDefaultTracesDir, getReceiptPath, getSelectedChain, getSimulatedReplaySummary, getSpendableUtxos, getTracePath, listSimulatedReceipts, listSimulatedTraces, loadLocalnetState, loadOrCreateLocalnetState, loadSimulatedReceipt, loadSimulatedTrace, moveSink, reconstructStateAtDaa, resetLocalnetState, resolveAccountAddress, resolveAccountAddressFromState, resolveConflictsDeterministically, restoreLocalnetSnapshot, saveLocalnetState, saveSimulatedReceipt, saveSimulatedTrace, startSimulatedDevnet, verifyReplay, verifySnapshot };
416
+ declare class LocalnetSimulatedProvider implements KaspaRpcClient {
417
+ private readonly workspacePath;
418
+ constructor(workspacePath: string);
419
+ getInfo(): Promise<KaspaNodeInfo>;
420
+ healthCheck(): Promise<KaspaRpcHealth>;
421
+ getBalanceByAddress(address: string): Promise<KaspaAddressBalance>;
422
+ getBalancesByAddresses(addresses: string[]): Promise<KaspaAddressBalance[]>;
423
+ getUtxosByAddress(address: string): Promise<KaspaRpcUtxo[]>;
424
+ getUtxosByAddresses(addresses: string[]): Promise<KaspaRpcUtxo[]>;
425
+ submitTransaction(rawTransaction: string): Promise<KaspaSubmitTransactionResult>;
426
+ getMempoolEntry(txId: string): Promise<MempoolEntry | null>;
427
+ getTransaction(txId: string): Promise<unknown | null>;
428
+ getBlockDagInfo(): Promise<BlockDagInfo>;
429
+ getServerInfo(): Promise<ServerInfo>;
430
+ close(): Promise<void>;
431
+ }
432
+
433
+ export { type CreateInitialStateOptions, DUST_LIMIT_SOMPI, type ForkOptions, type FundAddressInput, type HardkasAccount, type HardkasDevnet, type LocalnetAccount, LocalnetSimulatedProvider, type LocalnetState, type LocalnetUtxo, type ReplayInvariantResult, type ReplayVerificationReport, type SimulatedBlock, type SimulatedDag, SimulatedKaspaChain, type SimulatedPaymentInput, type SimulatedReplaySummary, type SimulatedUtxo, type SimulationResult, type Snapshot, type SnapshotRestoreResult, type SnapshotVerificationResult, type StateTransition, type StoredSimulatedTxReceipt, type StoredSimulatedTxTrace, type StoredTraceEvent, addSimulatedBlock, applySimulatedPayment, applySimulatedPlan, calculateAccountsHash, calculateStateHash, calculateUtxoSetHash, createDeterministicAccounts, createInitialLocalnetState, createLocalnetSnapshot, createSimulatedDag, findBestTip, forkFromNetwork, fundAddress, getAccountBalanceSompi, getAddressBalanceSompi, getDagColoring, getDefaultLocalnetDir, getDefaultLocalnetStatePath, getDefaultReceiptsDir, getDefaultTracesDir, getReceiptPath, getSelectedChain, getSimulatedReplaySummary, getSpendableUtxos, getTracePath, listSimulatedReceipts, listSimulatedTraces, loadLocalnetState, loadOrCreateLocalnetState, loadSimulatedReceipt, loadSimulatedTrace, moveSink, reconstructStateAtDaa, resetLocalnetState, resolveAccountAddress, resolveAccountAddressFromState, resolveConflictsDeterministically, restoreLocalnetSnapshot, saveLocalnetState, saveSimulatedReceipt, saveSimulatedTrace, startSimulatedDevnet, verifyReplay, verifySnapshot };
package/dist/index.js CHANGED
@@ -1158,8 +1158,109 @@ async function forkFromNetwork(rpc, opts) {
1158
1158
  };
1159
1159
  return state;
1160
1160
  }
1161
+
1162
+ // src/provider.ts
1163
+ var LocalnetSimulatedProvider = class {
1164
+ constructor(workspacePath) {
1165
+ this.workspacePath = workspacePath;
1166
+ }
1167
+ workspacePath;
1168
+ async getInfo() {
1169
+ return {
1170
+ serverVersion: "hardkas-simulated-1.0.0",
1171
+ isSynced: true,
1172
+ isUtxoIndexed: true,
1173
+ p2pId: "simulated-node-1"
1174
+ };
1175
+ }
1176
+ async healthCheck() {
1177
+ return {
1178
+ endpoint: "simulated://local",
1179
+ status: "healthy",
1180
+ latencyMs: 1,
1181
+ circuitState: "closed",
1182
+ stale: false,
1183
+ info: await this.getInfo(),
1184
+ reachable: true
1185
+ };
1186
+ }
1187
+ async getBalanceByAddress(address) {
1188
+ const statePath = getDefaultLocalnetStatePath(this.workspacePath);
1189
+ const state = await loadLocalnetState(statePath);
1190
+ if (!state) {
1191
+ return { address, balanceSompi: 0n };
1192
+ }
1193
+ const balance = getAddressBalanceSompi(state, address);
1194
+ return {
1195
+ address,
1196
+ balanceSompi: balance
1197
+ };
1198
+ }
1199
+ async getBalancesByAddresses(addresses) {
1200
+ const statePath = getDefaultLocalnetStatePath(this.workspacePath);
1201
+ const state = await loadLocalnetState(statePath);
1202
+ if (!state) {
1203
+ return addresses.map((address) => ({ address, balanceSompi: 0n }));
1204
+ }
1205
+ return addresses.map((address) => ({
1206
+ address,
1207
+ balanceSompi: getAddressBalanceSompi(state, address)
1208
+ }));
1209
+ }
1210
+ async getUtxosByAddress(address) {
1211
+ const statePath = getDefaultLocalnetStatePath(this.workspacePath);
1212
+ const state = await loadLocalnetState(statePath);
1213
+ if (!state) return [];
1214
+ const utxos = getSpendableUtxos(state, address);
1215
+ return utxos.map((u) => ({
1216
+ address: u.address,
1217
+ amountSompi: BigInt(u.amountSompi),
1218
+ outpoint: {
1219
+ transactionId: u.id.split(":")[1] || "unknown",
1220
+ index: Number(u.id.split(":")[2]) || 0
1221
+ },
1222
+ blockDaaScore: u.createdAtDaaScore,
1223
+ isCoinbase: false,
1224
+ scriptPublicKey: ""
1225
+ }));
1226
+ }
1227
+ async getUtxosByAddresses(addresses) {
1228
+ const allUtxos = [];
1229
+ for (const address of addresses) {
1230
+ const utxos = await this.getUtxosByAddress(address);
1231
+ allUtxos.push(...utxos);
1232
+ }
1233
+ return allUtxos;
1234
+ }
1235
+ async submitTransaction(rawTransaction) {
1236
+ throw new Error("submitTransaction not implemented on SimulatedProvider. Use sdk.tx.simulate instead.");
1237
+ }
1238
+ async getMempoolEntry(txId) {
1239
+ return null;
1240
+ }
1241
+ async getTransaction(txId) {
1242
+ return null;
1243
+ }
1244
+ async getBlockDagInfo() {
1245
+ return {
1246
+ networkId: "simnet",
1247
+ virtualDaaScore: 1n,
1248
+ tipHashes: []
1249
+ };
1250
+ }
1251
+ async getServerInfo() {
1252
+ return {
1253
+ serverVersion: "simulated",
1254
+ networkId: "simnet",
1255
+ isSynced: true
1256
+ };
1257
+ }
1258
+ async close() {
1259
+ }
1260
+ };
1161
1261
  export {
1162
1262
  DUST_LIMIT_SOMPI,
1263
+ LocalnetSimulatedProvider,
1163
1264
  SimulatedKaspaChain,
1164
1265
  addSimulatedBlock,
1165
1266
  applySimulatedPayment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/localnet",
3
- "version": "0.7.8-alpha",
3
+ "version": "0.7.10-alpha",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,12 +8,12 @@
8
8
  ".": "./dist/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@hardkas/artifacts": "0.7.8-alpha",
12
- "@hardkas/core": "0.7.8-alpha",
13
- "@hardkas/kaspa-rpc": "0.7.8-alpha",
14
- "@hardkas/simulator": "0.7.8-alpha",
15
- "@hardkas/query": "0.7.8-alpha",
16
- "@hardkas/tx-builder": "0.7.8-alpha"
11
+ "@hardkas/artifacts": "0.7.10-alpha",
12
+ "@hardkas/core": "0.7.10-alpha",
13
+ "@hardkas/kaspa-rpc": "0.7.10-alpha",
14
+ "@hardkas/query": "0.7.10-alpha",
15
+ "@hardkas/simulator": "0.7.10-alpha",
16
+ "@hardkas/tx-builder": "0.7.10-alpha"
17
17
  },
18
18
  "devDependencies": {
19
19
  "fast-check": "^4.8.0",