@xyo-network/xl1-protocol-sdk 1.26.30 → 1.26.32

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.
@@ -107,7 +107,7 @@ var ActorV3 = class extends AbstractCreatable {
107
107
  this._intervals.set(timerName, intervalId);
108
108
  }, dueTimeMs);
109
109
  this._timeouts.set(timerName, timeoutId);
110
- this.logger?.log(
110
+ this.logger?.debug(
111
111
  `Timer '${this.name}:${timerName}' registered: first call after ${dueTimeMs}ms, recurring every ${periodMs}ms.`
112
112
  );
113
113
  }
@@ -117,11 +117,11 @@ var ActorV3 = class extends AbstractCreatable {
117
117
  */
118
118
  async stopHandler() {
119
119
  await super.stopHandler();
120
- this.logger?.log("Stopping all timers...");
120
+ this.logger?.debug("Stopping all timers...");
121
121
  await Promise.all(
122
122
  [...this._semaphores.values()].map(async (semaphore) => {
123
123
  while (semaphore.isLocked()) {
124
- this.logger?.log("Waiting for running timer task to complete...");
124
+ this.logger?.debug("Waiting for running timer task to complete...");
125
125
  await delay(500);
126
126
  }
127
127
  await semaphore.acquire();
@@ -136,7 +136,7 @@ var ActorV3 = class extends AbstractCreatable {
136
136
  clearInterval(intervalRef);
137
137
  }
138
138
  this._intervals.clear();
139
- this.logger?.log("Stopped.");
139
+ this.logger?.debug("Stopped.");
140
140
  }
141
141
  };
142
142
  var Actor = class extends ActorV3 {
@@ -1074,9 +1074,7 @@ var blockRate = (startBlock, endBlock, timeUnit) => {
1074
1074
  };
1075
1075
  var getBlockRateBlocks = async (viewer, startBlockHeight, endBlockHeight) => {
1076
1076
  if (endBlockHeight <= startBlockHeight) {
1077
- console.error("startBlockHeight", startBlockHeight);
1078
- console.error("endBlockHeight", endBlockHeight);
1079
- throw new Error("End block height must be greater than start block height");
1077
+ throw new Error(`End block height must be greater than start block height [start=${startBlockHeight}, end=${endBlockHeight}]`);
1080
1078
  }
1081
1079
  const startingBlock = await viewer.blockByNumber(startBlockHeight);
1082
1080
  const endingBlock = await viewer.blockByNumber(endBlockHeight);
@@ -1145,7 +1143,6 @@ var calculateTimeRate = async (viewer, timeConfig, startBlockNumber, timeUnit, t
1145
1143
  );
1146
1144
  };
1147
1145
  var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBlocksBack, toleranceMs, attemptsRemaining) => {
1148
- console.log(`Attempts remaining: ${attemptsRemaining}, Estimated blocks back: ${estimatedBlocksBack}`);
1149
1146
  assertEx9(attemptsRemaining >= 0, () => "Maximum attempts reached while searching for end block");
1150
1147
  const startBlockEpoch = startBlock.$epoch;
1151
1148
  const estimatedEndBlockNumber = asXL1BlockNumber3(startBlock.block - estimatedBlocksBack, true);
@@ -1201,7 +1198,7 @@ async function getWindowedChain(context, blockViewer, maxWindowSize, previousCha
1201
1198
  const previousChainByHash = new Map(previousChain.map((block) => [block[0]._hash, block]));
1202
1199
  const head = await blockViewer.currentBlock();
1203
1200
  let currentBlock = head;
1204
- console.debug("[getWindowedChain] Current Block:", currentBlock?.[0]._hash);
1201
+ context.logger?.debug("[getWindowedChain] Current Block:", currentBlock?.[0]._hash);
1205
1202
  while (currentBlock !== null && newChain.length < maxWindowSize) {
1206
1203
  const currentBlockNumber = currentBlock[0].block;
1207
1204
  const nextBlock = newChain[0];
@@ -2199,12 +2196,12 @@ var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
2199
2196
  var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
2200
2197
  var confirmSubmittedTransaction = async (viewer, txHash, options) => {
2201
2198
  const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options ?? {};
2202
- options?.logger?.log("\u{1F680} confirming transaction:", txHash, "\n");
2199
+ options?.logger?.debug("Confirming transaction", txHash);
2203
2200
  let attempts = 0;
2204
2201
  while (true) {
2205
2202
  const tx = await viewer.transaction.byHash(txHash) ?? void 0;
2206
2203
  if (isDefined14(tx)) {
2207
- options?.logger?.log("\u2705 Transaction confirmed:", txHash, "\n");
2204
+ options?.logger?.debug("Transaction confirmed", txHash);
2208
2205
  return tx;
2209
2206
  } else {
2210
2207
  attempts++;
@@ -2212,7 +2209,7 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
2212
2209
  options?.logger?.error(`\u26A0\uFE0F Transaction not confirmed after ${maxAttempts} attempts`);
2213
2210
  throw new Error(`Transaction ${txHash} not confirmed after ${maxAttempts} attempts`);
2214
2211
  } else {
2215
- options?.logger?.log(`\u{1F504} Transaction not confirmed yet, attempt ${attempts}. Retrying...`, "\n");
2212
+ options?.logger?.debug(`Transaction not confirmed yet, attempt ${attempts}. Retrying...`, txHash);
2216
2213
  await delay2(attemptDelay);
2217
2214
  }
2218
2215
  }
@@ -2712,7 +2709,7 @@ var registerCreatableProviderFactory = (registry, factory, labels, primary = fal
2712
2709
  const primaryMonikers = primary !== true && isTruthy(primary) ? Array.isArray(primary) ? primary : [primary] : [];
2713
2710
  for (const primaryMoniker of primaryMonikers) {
2714
2711
  if (!factory.monikers.includes(primaryMoniker)) {
2715
- console.warn(`Primary moniker ${String(primary)} not found in factory monikers`);
2712
+ throw new Error(`Primary moniker ${String(primaryMoniker)} not found in factory monikers`);
2716
2713
  }
2717
2714
  }
2718
2715
  const isPrimaryForMoniker = (moniker) => {
@@ -2853,7 +2850,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
2853
2850
  if (this.context.singletons[factory.uniqueId]) {
2854
2851
  return this.context.singletons[factory.uniqueId];
2855
2852
  }
2856
- this.logger?.info(`Creating provider instance for moniker [${moniker}]${labels ? ` with labels [${JSON.stringify(labels)}]` : ""} using factory [${factory.uniqueId.description}]`);
2853
+ this.logger?.debug(`Creating provider instance for moniker [${moniker}]${labels ? ` with labels [${JSON.stringify(labels)}]` : ""} using factory [${factory.uniqueId.description}]`);
2857
2854
  const result = await factory.getInstance(resolvedParams, { start });
2858
2855
  this.context.singletons[factory.uniqueId] = result;
2859
2856
  return result;
@@ -4015,7 +4012,9 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
4015
4012
  const windowedUncleChain = await this.updateWindowedChainCache();
4016
4013
  const uncles = findUncles(this.context, windowedUncleChain, blocks);
4017
4014
  if (uncles.length !== 1) {
4018
- this.logger?.warn(JSON.stringify({ uncles, blocks: blocks.length }, null, 2));
4015
+ this.logger?.warn(`Unexpected uncle count during block validation [uncles=${uncles.length}, blocks=${blocks.length}]`);
4016
+ this.logger?.debug(JSON.stringify({ uncles, blocks: blocks.length }, null, 2));
4017
+ this.logger?.debug(JSON.stringify(windowedUncleChain, null, 2));
4019
4018
  throw new Error(`No uncles or greater than one uncle found in block validation, which is not supported [${uncles.length}, ${blocks.length}]`);
4020
4019
  }
4021
4020
  return await Promise.all(uncles[0].map(async (block) => {
@@ -4381,7 +4380,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
4381
4380
  const cache = this.hydratedBlockCache;
4382
4381
  const block = await cache.get(currentHead._hash);
4383
4382
  if (!block) {
4384
- console.log(`Could not find current block with hash ${currentHead._hash}`);
4383
+ this.logger?.error(`Could not find current block with hash ${currentHead._hash}`);
4385
4384
  }
4386
4385
  return assertEx36(block, () => "Could not find current block");
4387
4386
  }, this.context);
@@ -4623,7 +4622,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4623
4622
  cursor,
4624
4623
  order: "desc"
4625
4624
  });
4626
- this.logger?.info(`Starting prunePendingBlocks with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`);
4625
+ this.logger?.debug(`Starting prunePendingBlocks with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`);
4627
4626
  while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
4628
4627
  const blocksAndBundles = await this.simpleBlockValidationCheck(batch);
4629
4628
  const blocks = blocksAndBundles.map(([b]) => b);
@@ -4647,8 +4646,8 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4647
4646
  for (const [i, r] of validationResults.entries()) {
4648
4647
  const validated = isSignedHydratedBlockWithHashMeta(r);
4649
4648
  if (!validated) {
4650
- this.logger?.info(`Pruning block ${bundles[remainingBlockMap[i]]._hash} during block validation`);
4651
- this.logger?.info(` - validation result: ${r.at(0)?.message}`);
4649
+ this.logger?.debug(`Pruning block ${bundles[remainingBlockMap[i]]._hash} during block validation`);
4650
+ this.logger?.debug(` - validation result: ${r.at(0)?.message}`);
4652
4651
  }
4653
4652
  valid[remainingBlockMap[i]] = validated;
4654
4653
  }
@@ -4667,7 +4666,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4667
4666
  order: "desc"
4668
4667
  }) : [];
4669
4668
  }
4670
- this.logger?.info(`prunePendingBlocks completed: pruned=${pruned}, totalChecked=${total}`);
4669
+ this.logger?.debug(`prunePendingBlocks completed: pruned=${pruned}, totalChecked=${total}`);
4671
4670
  return [pruned, total];
4672
4671
  }
4673
4672
  async prunePendingTransactions({
@@ -4683,7 +4682,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4683
4682
  cursor,
4684
4683
  order: "desc"
4685
4684
  });
4686
- this.logger?.info(`Starting prunePendingTransactions with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`);
4685
+ this.logger?.debug(`Starting prunePendingTransactions with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`);
4687
4686
  while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
4688
4687
  const transactionsAndBundles = await this.simpleTransactionValidationCheck(batch);
4689
4688
  const transactions = transactionsAndBundles.map(([t]) => t);
@@ -4707,8 +4706,8 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4707
4706
  for (const [i, r] of validationResults.entries()) {
4708
4707
  const validated = isSignedHydratedTransactionWithHashMeta(r);
4709
4708
  if (!validated) {
4710
- this.logger?.info(`Pruning transaction ${bundles[remainingTransactionMap[i]]._hash} during transaction validation`);
4711
- this.logger?.info(` - validation result: ${r.at(0)?.message}`);
4709
+ this.logger?.debug(`Pruning transaction ${bundles[remainingTransactionMap[i]]._hash} during transaction validation`);
4710
+ this.logger?.debug(` - validation result: ${r.at(0)?.message}`);
4712
4711
  }
4713
4712
  valid[remainingTransactionMap[i]] = validated;
4714
4713
  }
@@ -4727,7 +4726,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4727
4726
  order: "desc"
4728
4727
  }) : [];
4729
4728
  }
4730
- this.logger?.info(`prunePendingTransactions completed: pruned=${pruned}, totalChecked=${total}`);
4729
+ this.logger?.debug(`prunePendingTransactions completed: pruned=${pruned}, totalChecked=${total}`);
4731
4730
  return [pruned, total];
4732
4731
  }
4733
4732
  async submitBlocks(blocks) {
@@ -4745,7 +4744,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4745
4744
  const maxExp = headNumber + this.maxExpAhead;
4746
4745
  const validTransactions = transactions.filter(([tx]) => {
4747
4746
  if (tx.exp > maxExp) {
4748
- this.logger?.info(`Rejecting transaction with exp ${tx.exp} exceeding max allowed ${maxExp}`);
4747
+ this.logger?.debug(`Rejecting transaction with exp ${tx.exp} exceeding max allowed ${maxExp}`);
4749
4748
  return false;
4750
4749
  }
4751
4750
  return true;
@@ -4789,11 +4788,11 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4789
4788
  const validationPassed = blockCheckPassed && chainIdPassed && blockNumberPassed && typeCheckPassed;
4790
4789
  const validatedBlock = validationPassed ? block : void 0;
4791
4790
  if (!validationPassed) {
4792
- this.logger?.info(`Pruning block bundle ${bundle3._hash} during simpleValidationCheck`);
4793
- this.logger?.info(` - chainId match: ${chainIdPassed}`);
4794
- this.logger?.info(` - blockNumber check: ${blockNumberPassed} [${headNumber}|${block?.[0].block}]`);
4795
- this.logger?.info(` - typeCheck: ${typeCheckPassed}`);
4796
- this.logger?.info(` - bundle hash: ${bundle3._hash}`);
4791
+ this.logger?.debug(`Pruning block bundle ${bundle3._hash} during simpleValidationCheck`);
4792
+ this.logger?.debug(` - chainId match: ${chainIdPassed}`);
4793
+ this.logger?.debug(` - blockNumber check: ${blockNumberPassed} [${headNumber}|${block?.[0].block}]`);
4794
+ this.logger?.debug(` - typeCheck: ${typeCheckPassed}`);
4795
+ this.logger?.debug(` - bundle hash: ${bundle3._hash}`);
4797
4796
  }
4798
4797
  return [validatedBlock, bundle3];
4799
4798
  });
@@ -4814,18 +4813,18 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4814
4813
  await validateTransactionsOpcodes(transaction ? [transaction] : []);
4815
4814
  opcodeCheckPassed = true;
4816
4815
  } catch (e) {
4817
- this.logger?.info(`Opcode validation failed for transaction ${bundle3._hash} during simpleValidationCheck`);
4818
- this.logger?.info(` - error: ${e.message}`);
4816
+ this.logger?.debug(`Opcode validation failed for transaction ${bundle3._hash} during simpleValidationCheck`);
4817
+ this.logger?.debug(` - error: ${e.message}`);
4819
4818
  }
4820
4819
  const validationPassed = transactionCheckPassed && chainIdPassed && expPassed && typeCheckPassed && opcodeCheckPassed;
4821
4820
  const validatedTransaction = validationPassed ? transaction : void 0;
4822
4821
  if (!validationPassed) {
4823
- this.logger?.info(`Pruning block bundle ${bundle3._hash} during simpleValidationCheck`);
4824
- this.logger?.info(` - chainId match: ${chainIdPassed}`);
4825
- this.logger?.info(` - exp check: ${expPassed}`);
4826
- this.logger?.info(` - opcode check: ${opcodeCheckPassed}`);
4827
- this.logger?.info(` - typeCheck: ${typeCheckPassed}`);
4828
- this.logger?.info(` - bundle hash: ${bundle3._hash}`);
4822
+ this.logger?.debug(`Pruning block bundle ${bundle3._hash} during simpleValidationCheck`);
4823
+ this.logger?.debug(` - chainId match: ${chainIdPassed}`);
4824
+ this.logger?.debug(` - exp check: ${expPassed}`);
4825
+ this.logger?.debug(` - opcode check: ${opcodeCheckPassed}`);
4826
+ this.logger?.debug(` - typeCheck: ${typeCheckPassed}`);
4827
+ this.logger?.debug(` - bundle hash: ${bundle3._hash}`);
4829
4828
  }
4830
4829
  return [validatedTransaction, bundle3];
4831
4830
  }));
@@ -4835,7 +4834,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4835
4834
  if (externalBlocks.length === 0) return;
4836
4835
  const bundles = externalBlocks.map((block) => hydratedBlockToPayloadBundle(block));
4837
4836
  await this.pendingBlocksArchivist.insert(bundles);
4838
- this.logger?.info(`Synced ${externalBlocks.length} blocks from external mempool`);
4837
+ this.logger?.debug(`Synced ${externalBlocks.length} blocks from external mempool`);
4839
4838
  }
4840
4839
  async syncFromExternal() {
4841
4840
  if (this._syncMutex.isLocked()) return;
@@ -4855,7 +4854,7 @@ var SimpleMempoolRunner = class extends AbstractCreatableProvider {
4855
4854
  if (externalTxs.length === 0) return;
4856
4855
  const bundles = externalTxs.map((tx) => hydratedTransactionToPayloadBundle(tx));
4857
4856
  await this.pendingTransactionsArchivist.insert(bundles);
4858
- this.logger?.info(`Synced ${externalTxs.length} transactions from external mempool`);
4857
+ this.logger?.debug(`Synced ${externalTxs.length} transactions from external mempool`);
4859
4858
  }
4860
4859
  };
4861
4860
  __publicField(SimpleMempoolRunner, "defaultMoniker", MempoolRunnerMoniker);
@@ -4920,13 +4919,13 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
4920
4919
  cursor = p._sequence;
4921
4920
  }
4922
4921
  }
4923
- this.logger?.info(`Fetching pending transactions from cursor: ${cursor}`);
4922
+ this.logger?.debug(`Fetching pending transactions from cursor: ${cursor}`);
4924
4923
  const bundles = await this.pendingTransactionsArchivist.next({
4925
4924
  order: "asc",
4926
4925
  limit: limit * 5,
4927
4926
  cursor
4928
4927
  });
4929
- this.logger?.info(`Fetched pending transactions: ${bundles.length} bundles`);
4928
+ this.logger?.debug(`Fetched pending transactions: ${bundles.length} bundles`);
4930
4929
  const filteredBundles = bundles.filter(isPayloadBundle2).filter(isHashMeta2);
4931
4930
  const hydratedWithBundle = (await Promise.all(
4932
4931
  filteredBundles.map(async (bundle3) => {
@@ -4944,11 +4943,11 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
4944
4943
  );
4945
4944
  const validTransactions = evaluated.filter((x) => !x.deletable);
4946
4945
  const deletionCandidates = evaluated.filter((x) => x.deletable);
4947
- this.logger?.info(`Pending transactions: ${validTransactions.length} valid, ${deletionCandidates.length} not deletable`);
4946
+ this.logger?.debug(`Pending transactions: ${validTransactions.length} valid, ${deletionCandidates.length} not deletable`);
4948
4947
  await Promise.all(
4949
4948
  deletionCandidates.map(async ({ bundle: bundle3, tx }) => {
4950
4949
  await this.deleteBundledTransaction(bundle3);
4951
- this.logger?.info(`Purged completed/expired bundled transaction: ${bundle3._hash}/${tx[0]._hash}`);
4950
+ this.logger?.debug(`Purged completed/expired bundled transaction: ${bundle3._hash}/${tx[0]._hash}`);
4952
4951
  })
4953
4952
  );
4954
4953
  const inclusionCandidates = (await Promise.all(validTransactions.map((x) => x.tx).map(async (tx) => {
@@ -4961,7 +4960,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
4961
4960
  inclusionCandidates.filter(() => Math.random() < selectionRatio)
4962
4961
  ).slice(0, effectiveLimit);
4963
4962
  const result = randomInclusionCandidates.length > 0 ? randomInclusionCandidates : deduplicateBySigner(inclusionCandidates).slice(0, 1);
4964
- this.logger?.info(`Inclusion candidates: ${inclusionCandidates.length}`);
4963
+ this.logger?.debug(`Inclusion candidates: ${inclusionCandidates.length}`);
4965
4964
  return result;
4966
4965
  }
4967
4966
  async deleteBundledTransaction(bundle3) {
@@ -5055,10 +5054,15 @@ var StatusNetworks = {
5055
5054
 
5056
5055
  // src/simple/network/SimpleXyoNetwork.ts
5057
5056
  var SimpleXyoNetwork = class {
5057
+ _logger;
5058
5058
  _networkId;
5059
- constructor(networkId) {
5059
+ constructor(networkId, logger) {
5060
+ this._logger = logger;
5060
5061
  this._networkId = networkId;
5061
5062
  }
5063
+ get logger() {
5064
+ return this._logger;
5065
+ }
5062
5066
  async status() {
5063
5067
  const statusNetwork = StatusNetworks[this._networkId];
5064
5068
  if (isUndefined7(statusNetwork)) {
@@ -5073,13 +5077,13 @@ var SimpleXyoNetwork = class {
5073
5077
  return response.data;
5074
5078
  } else {
5075
5079
  if (response.status === 200) {
5076
- console.error("Unknown network status response:", response.data);
5080
+ this.logger?.error("Unknown network status response", response.data);
5077
5081
  return unknownStatus;
5078
5082
  }
5079
5083
  return errorStatus;
5080
5084
  }
5081
5085
  } catch (error) {
5082
- console.error("Error fetching network status:", error);
5086
+ this.logger?.error("Error fetching network status", error);
5083
5087
  return errorStatus;
5084
5088
  }
5085
5089
  }
@@ -6030,7 +6034,7 @@ var SimpleWindowedBlockViewer = class extends AbstractCreatableProvider {
6030
6034
  this.addBlock(block);
6031
6035
  }
6032
6036
  } catch (ex) {
6033
- console.error("Error during sync:", ex);
6037
+ this.logger?.error("Error during sync", ex);
6034
6038
  }
6035
6039
  });
6036
6040
  }