diff --git a/src/db/nodeDb.js b/src/db/nodeDb.js index 3ff2ac42..47c29690 100644 --- a/src/db/nodeDb.js +++ b/src/db/nodeDb.js @@ -5,7 +5,6 @@ const logger = require('../logger')('node-db'); let eventsDb = null; let stateDb = null; -let warpStateDb = null; module.exports = { createNodeDbEventsTables: async (knex) => { @@ -91,19 +90,6 @@ module.exports = { return stateDb; }, - connectWarpCacheDb: () => { - if (warpStateDb == null) { - warpStateDb = knex({ - client: 'better-sqlite3', - connection: { - filename: `cache/warp/sqlite/state.db` - }, - useNullAsDefault: true - }); - } - return warpStateDb; - }, - connectEvents: () => { if (eventsDb == null) { eventsDb = knex({ @@ -221,18 +207,6 @@ module.exports = { await eventsDb.raw('DELETE FROM events WHERE contract_tx_id = ?;', [contractTxId]); }, - getLastStateFromWarpCache: async (nodeDb, contractTxId) => { - const result = await warpStateDb.raw( - `select sort_key AS sortKey, value AS cachedValue - from sort_key_cache - where key = ? - ORDER BY sort_key DESC - LIMIT 1;`, - [contractTxId] - ); - return result.length === 0 ? null : result[0]; - }, - getLastStateFromDreCache: async (nodeDb, contractTxId) => { const result = await nodeDb('states') .where({ diff --git a/src/listener.js b/src/listener.js index d627fe9a..92ce135e 100644 --- a/src/listener.js +++ b/src/listener.js @@ -19,8 +19,7 @@ const { hasContract, connectEvents, createNodeDbEventsTables, - doBlacklist, - connectWarpCacheDb + doBlacklist } = require('./db/nodeDb'); const logger = require('./logger')('listener'); @@ -49,7 +48,6 @@ async function runListener() { const nodeDb = connect(); const nodeDbEvents = connectEvents(); - const nodeWarpState = connectWarpCacheDb(); await createNodeDbTables(nodeDb); await createNodeDbEventsTables(nodeDbEvents); diff --git a/src/routes/contract.js b/src/routes/contract.js index 255f6b63..890efda5 100644 --- a/src/routes/contract.js +++ b/src/routes/contract.js @@ -1,13 +1,7 @@ const { JSONPath } = require('jsonpath-plus'); -const { - getLastStateFromDreCache, - getContractErrors, - getFailures, - events, - getLastStateFromWarpCache, - insertState -} = require('../db/nodeDb'); +const { getLastStateFromDreCache, getContractErrors, getFailures, events, insertState } = require('../db/nodeDb'); const { config } = require('../config'); +const warp = require('../warp'); const registrationStatus = { 'not-registered': 'not-registered', @@ -36,11 +30,10 @@ module.exports = async (ctx) => { response.status = registrationStatus['blacklisted']; response.errors = await getContractErrors(nodeDb, contractId); } else { - const warpState = await getLastStateFromWarpCache(nodeDb, contractId); + const warpState = await warp.stateEvaluator.latestAvailableState(contractId); let result = await getLastStateFromDreCache(nodeDb, contractId); let parsed = false; if (warpState && (!result || result.sort_key.localeCompare(warpState.sortKey) < 0)) { - warpState.cachedValue = JSON.parse(warpState.cachedValue); result = await insertState(nodeDb, contractId, warpState); parsed = true; }