<commit_before>import utils, { toBN } from 'web3-utils';
import { toPayload } from '../jsonrpc';
import EthCalls from '../web3Calls';
import * as locstore from 'store';
import sanitizeHex from '@/core/helpers/sanitizeHex';

export default async ({ payload, store, requestManager }, res, next) => {
  if (payload.method !== 'eth_getTransactionCount') return next();
  const ethCalls = new EthCalls(requestManager);
  const addr = payload.params[0].toLowerCase();
  let cached = {};
  const storeKey = utils.sha3(
    `${store.getters['global/network'].type.name}-${addr}`
  );
  if (!locstore.get(storeKey)) {
    cached = {
      nonce: '0x00',
      timestamp: 0
    };
    locstore.set(storeKey, cached);
  } else {
    cached = locstore.get(storeKey);
  }
  const timeDiff =
    Math.round((new Date().getTime() - cached.timestamp) / 1000) / 60;
  if (timeDiff > 1) {
    const liveNonce = await ethCalls.getTransactionCount(addr);
    console.log(liveNonce);
    const liveNonceBN = toBN(liveNonce);
    const cachedNonceBN = toBN(cached.nonce);
    if (timeDiff > 15) {
      cached = {
        nonce: sanitizeHex(liveNonceBN.toString(16)),
        timestamp: +new Date()
      };
    } else if (liveNonceBN.gt(cachedNonceBN)) {
      cached = {
        nonce: sanitizeHex(liveNonceBN.toString(16)),
        timestamp: +new Date()
      };
    }
    locstore.set(storeKey, cached);
  }
  res(null, toPayload(payload.id, cached.nonce));
};<commit_msg>fix: 🐛 build<commit_after>import utils, { toBN } from 'web3-utils';
import { toPayload } from '../jsonrpc';
import EthCalls from '../web3Calls';
import * as locstore from 'store';
import sanitizeHex from '@/core/helpers/sanitizeHex';

export default async ({ payload, store, requestManager }, res, next) => {
  if (payload.method !== 'eth_getTransactionCount') return next();
  const ethCalls = new EthCalls(requestManager);
  const addr = payload.params[0].toLowerCase();
  let cached = {};
  const storeKey = utils.sha3(
    `${store.getters['global/network'].type.name}-${addr}`
  );
  if (!locstore.get(storeKey)) {
    cached = {
      nonce: '0x00',
      timestamp: 0
    };
    locstore.set(storeKey, cached);
  } else {
    cached = locstore.get(storeKey);
  }
  const timeDiff =
    Math.round((new Date().getTime() - cached.timestamp) / 1000) / 60;
  if (timeDiff > 1) {
    const liveNonce = await ethCalls.getTransactionCount(addr);
    const liveNonceBN = toBN(liveNonce);
    const cachedNonceBN = toBN(cached.nonce);
    if (timeDiff > 15) {
      cached = {
        nonce: sanitizeHex(liveNonceBN.toString(16)),
        timestamp: +new Date()
      };
    } else if (liveNonceBN.gt(cachedNonceBN)) {
      cached = {
        nonce: sanitizeHex(liveNonceBN.toString(16)),
        timestamp: +new Date()
      };
    }
    locstore.set(storeKey, cached);
  }
  res(null, toPayload(payload.id, cached.nonce));
};
{'fraction_non_alphanumeric': 0.15272474835126693, 'fraction_numerical': 0.014578271433530025, 'mean_word_length': 3.2950819672131146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140161', 'n_tokens_mistral': 976, 'n_tokens_neox': 963, 'n_words': 209}