Skip to content

Commit

Permalink
feat: consume inscription reveals from chainhook node (#13)
Browse files Browse the repository at this point in the history
* feat: draft

* fix: cache and server progress

* feat: more progress

* fix: env var

* fix: default port

* fix: add missing properties

* feat: add ping before server

* fix: final schema

* feat: rollback
  • Loading branch information
rafaelcr authored Mar 3, 2023
1 parent f8453b6 commit a99b4a4
Show file tree
Hide file tree
Showing 17 changed files with 504 additions and 395 deletions.
8 changes: 4 additions & 4 deletions src/api/routes/inscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
BlockHashParamCType,
BlockHeightParamCType,
InscriptionIdParamCType,
BlockParam,
BlockHeightParam,
TimestampParam,
BlockParam,
OrdinalParam,
InscriptionNumberParam,
TimestampParam,
} from '../schemas';
import { handleChainTipCache, handleInscriptionCache } from '../util/cache';
import { handleInscriptionCache, handleInscriptionTransfersCache } from '../util/cache';
import {
DEFAULT_API_LIMIT,
hexToBuffer,
Expand Down Expand Up @@ -58,7 +58,7 @@ const IndexRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTy
options,
done
) => {
fastify.addHook('preHandler', handleChainTipCache);
fastify.addHook('preHandler', handleInscriptionTransfersCache);
fastify.get(
'/inscriptions',
{
Expand Down
22 changes: 11 additions & 11 deletions src/api/util/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { logger } from '../../logger';
import { InscriptionIdParamCType, InscriptionNumberParamCType } from '../schemas';

export enum ETagType {
chainTip,
inscriptionTransfers,
inscription,
}

Expand All @@ -19,8 +19,11 @@ export async function handleInscriptionCache(request: FastifyRequest, reply: Fas
return handleCache(ETagType.inscription, request, reply);
}

export async function handleChainTipCache(request: FastifyRequest, reply: FastifyReply) {
return handleCache(ETagType.chainTip, request, reply);
export async function handleInscriptionTransfersCache(
request: FastifyRequest,
reply: FastifyReply
) {
return handleCache(ETagType.inscriptionTransfers, request, reply);
}

async function handleCache(type: ETagType, request: FastifyRequest, reply: FastifyReply) {
Expand All @@ -30,8 +33,8 @@ async function handleCache(type: ETagType, request: FastifyRequest, reply: Fasti
case ETagType.inscription:
etag = await getInscriptionLocationEtag(request);
break;
case ETagType.chainTip:
etag = await getChainTipEtag(request);
case ETagType.inscriptionTransfers:
etag = await getInscriptionTransfersEtag(request);
break;
}
if (etag) {
Expand Down Expand Up @@ -73,16 +76,13 @@ async function getInscriptionLocationEtag(request: FastifyRequest): Promise<stri
}

/**
* Get an ETag based on the last observed chain tip.
* Get an ETag based on the last state of inscription transfers.
* @param request - Fastify request
* @returns ETag string
*/
async function getChainTipEtag(request: FastifyRequest): Promise<string | undefined> {
async function getInscriptionTransfersEtag(request: FastifyRequest): Promise<string | undefined> {
try {
const blockHeight = await request.server.db.getChainTipBlockHeight();
if (blockHeight) {
return blockHeight.toString();
}
return await request.server.db.getInscriptionTransfersETag();
} catch (error) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function parseDbInscriptions(
genesis_block_hash: i.genesis_block_hash,
genesis_tx_id: i.genesis_tx_id,
genesis_fee: i.genesis_fee.toString(),
genesis_timestamp: i.genesis_timestamp,
genesis_timestamp: i.genesis_timestamp.valueOf(),
location: `${i.output}:${i.offset}`,
output: i.output,
value: i.value.toString(),
Expand All @@ -26,7 +26,7 @@ export function parseDbInscriptions(
mime_type: i.mime_type,
content_type: i.content_type,
content_length: i.content_length,
timestamp: i.timestamp,
timestamp: i.timestamp.valueOf(),
}));
}
export function parseDbInscription(item: DbFullyLocatedInscriptionResult): InscriptionResponseType {
Expand Down
54 changes: 0 additions & 54 deletions src/bitcoin/bitcoin-rpc-client.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/bitcoin/helpers.ts

This file was deleted.

136 changes: 0 additions & 136 deletions src/bitcoin/inscriptions-importer.ts

This file was deleted.

53 changes: 0 additions & 53 deletions src/bitcoin/types.ts

This file was deleted.

Loading

0 comments on commit a99b4a4

Please sign in to comment.