@mentaproject/client 0.1.36 → 0.1.37

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.cjs CHANGED
@@ -916,6 +916,12 @@ var ClientEvents = {
916
916
 
917
917
  // src/utils/withCache.ts
918
918
  var import_actions7 = require("@mentaproject/core/actions");
919
+ var GET_NONCE_SELECTOR = "0x35567e1a";
920
+ function isNonceCall(method, params) {
921
+ if (method !== "eth_call") return false;
922
+ const callData = params?.[0]?.data;
923
+ return typeof callData === "string" && callData.startsWith(GET_NONCE_SELECTOR);
924
+ }
919
925
  function withCache(client, cache) {
920
926
  (0, import_actions7.watchBlockNumber)(client, {
921
927
  onBlockNumber: (blockNumber) => {
@@ -926,14 +932,17 @@ function withCache(client, cache) {
926
932
  const originalRequest = client.request;
927
933
  client.request = (async (args) => {
928
934
  const { method, params } = args;
935
+ const shouldSkipCache = method === "eth_blockNumber" || isNonceCall(method, params);
929
936
  const cacheKey = `${client.chain.id}:${method}:${JSON.stringify(params || [], (_, v) => typeof v === "bigint" ? v.toString() : v)}`;
930
937
  let result;
931
- if (method !== "eth_blockNumber") result = cache.get(cacheKey);
938
+ if (!shouldSkipCache) {
939
+ result = cache.get(cacheKey);
940
+ }
932
941
  if (!result) {
933
942
  result = await originalRequest(args);
934
943
  }
935
944
  ;
936
- if (result !== null && result !== void 0 && method !== "eth_blockNumber") {
945
+ if (result !== null && result !== void 0 && !shouldSkipCache) {
937
946
  const ttl = cache.config.ttlPolicies[method] || cache.config.defaultTtl;
938
947
  await cache.set(cacheKey, result, ttl);
939
948
  }