Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: fixed cache was not updated when tx status change #151

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "btc-assets-api",
"version": "2.2.0",
"version": "2.2.1",
"title": "Bitcoin/RGB++ Assets API",
"description": "",
"main": "index.js",
Expand Down
12 changes: 8 additions & 4 deletions src/routes/bitcoin/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
const { min_satoshi, no_cache } = request.query;

let utxosCache = null;
if (env.UTXO_SYNC_DATA_CACHE_ENABLE && no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(address);
if (env.UTXO_SYNC_DATA_CACHE_ENABLE) {
if (no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(address);
}
await fastify.utxoSyncer.enqueueSyncJob(address);
}
const utxos = utxosCache ? utxosCache : await fastify.bitcoin.getAddressTxsUtxo({ address });
Expand Down Expand Up @@ -103,8 +105,10 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
const { only_confirmed, min_satoshi, no_cache } = request.query;

let utxosCache = null;
if (env.UTXO_SYNC_DATA_CACHE_ENABLE && no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(address);
if (env.UTXO_SYNC_DATA_CACHE_ENABLE) {
if (no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(address);
}
await fastify.utxoSyncer.enqueueSyncJob(address);
}
let utxos = utxosCache ? utxosCache : await fastify.bitcoin.getAddressTxsUtxo({ address });
Expand Down
12 changes: 8 additions & 4 deletions src/routes/rgbpp/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ const addressRoutes: FastifyPluginCallback<Record<never, never>, Server, ZodType
}

let utxosCache = null;
if (env.UTXO_SYNC_DATA_CACHE_ENABLE && no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(btc_address);
if (env.UTXO_SYNC_DATA_CACHE_ENABLE) {
if (no_cache !== 'true') {
utxosCache = await fastify.utxoSyncer.getUTXOsFromCache(btc_address);
}
await fastify.utxoSyncer.enqueueSyncJob(btc_address);
}
const utxos = utxosCache ? utxosCache : await fastify.bitcoin.getAddressTxsUtxo({ address: btc_address });

let rgbppCache = null;
if (env.RGBPP_COLLECT_DATA_CACHE_ENABLE && no_cache !== 'true') {
rgbppCache = await fastify.rgbppCollector.getRgbppCellsFromCache(btc_address);
if (env.RGBPP_COLLECT_DATA_CACHE_ENABLE) {
if (no_cache !== 'true') {
rgbppCache = await fastify.rgbppCollector.getRgbppCellsFromCache(btc_address);
}
await fastify.rgbppCollector.enqueueCollectJob(btc_address, utxos);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class UTXOSyncer extends BaseQueueWorker<IUTXOSyncRequest, IUTXOS
}

const txs = await this.cradle.bitcoin.getAddressTxs({ address: btcAddress });
const txsHash = sha256(Buffer.from(txs.map((tx) => tx.txid).join(','))).toString();
const txsHash = sha256(Buffer.from(txs.map((tx) => tx.txid + JSON.stringify(tx.status)).join(','))).toString();

// check if the data is updated
const cached = await this.dataCache.get(btcAddress);
Expand Down
Loading