diff --git a/src/api/routes/inscriptions.ts b/src/api/routes/inscriptions.ts index 5c321067..b8fdf23b 100644 --- a/src/api/routes/inscriptions.ts +++ b/src/api/routes/inscriptions.ts @@ -4,7 +4,6 @@ import { Value } from '@sinclair/typebox/value'; import { FastifyPluginAsync, FastifyPluginCallback } from 'fastify'; import { Server } from 'http'; import { - AddressParam, InscriptionResponse, LimitParam, NotFoundResponse, @@ -26,6 +25,9 @@ import { OrdinalParam, InscriptionNumberParam, TimestampParam, + AddressesParam, + InscriptionIdsParam, + InscriptionNumbersParam, } from '../schemas'; import { handleInscriptionCache, handleInscriptionTransfersCache } from '../util/cache'; import { @@ -45,6 +47,10 @@ function blockParam(param: string | undefined, name: string) { return out; } +function inscriptionIdArrayParam(param: string | number) { + return InscriptionIdParamCType.Check(param) ? { genesis_id: [param] } : { number: [param] }; +} + function inscriptionIdParam(param: string | number) { return InscriptionIdParamCType.Check(param) ? { genesis_id: param } : { number: param }; } @@ -78,8 +84,10 @@ const IndexRoutes: FastifyPluginCallback, Server, TypeBoxTy to_sat_coinbase_height: Type.Optional(BlockHeightParam), from_number: Type.Optional(InscriptionNumberParam), to_number: Type.Optional(InscriptionNumberParam), + id: Type.Optional(InscriptionIdsParam), + number: Type.Optional(InscriptionNumbersParam), output: Type.Optional(OutputParam), - address: Type.Optional(AddressParam), + address: Type.Optional(AddressesParam), mime_type: Type.Optional(MimeTypesParam), rarity: Type.Optional(SatoshiRaritiesParam), // Pagination @@ -110,6 +118,8 @@ const IndexRoutes: FastifyPluginCallback, Server, TypeBoxTy to_sat_ordinal: bigIntParam(request.query.to_sat_ordinal), from_number: request.query.from_number, to_number: request.query.to_number, + genesis_id: request.query.id, + number: request.query.number, output: request.query.output, address: request.query.address, mime_type: request.query.mime_type, @@ -155,7 +165,7 @@ const ShowRoutes: FastifyPluginCallback, Server, TypeBoxTyp }, async (request, reply) => { const inscription = await fastify.db.getInscriptions({ - ...inscriptionIdParam(request.params.id), + ...inscriptionIdArrayParam(request.params.id), limit: 1, offset: 0, }); diff --git a/src/api/schemas.ts b/src/api/schemas.ts index cd7ed5f0..ef714c33 100644 --- a/src/api/schemas.ts +++ b/src/api/schemas.ts @@ -44,6 +44,17 @@ export const AddressParam = Type.String({ examples: ['bc1p8aq8s3z9xl87e74twfk93mljxq6alv4a79yheadx33t9np4g2wkqqt8kc5'], }); +export const AddressesParam = Type.Array(AddressParam, { + title: 'Addresses', + description: 'Array of Bitcoin addresses', + examples: [ + [ + 'bc1p8aq8s3z9xl87e74twfk93mljxq6alv4a79yheadx33t9np4g2wkqqt8kc5', + 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + ], + ], +}); + export const InscriptionIdParam = Type.RegEx(/^[a-fA-F0-9]{64}i[0-9]+$/, { title: 'Inscription ID', description: 'Inscription ID', @@ -51,6 +62,17 @@ export const InscriptionIdParam = Type.RegEx(/^[a-fA-F0-9]{64}i[0-9]+$/, { }); export const InscriptionIdParamCType = TypeCompiler.Compile(InscriptionIdParam); +export const InscriptionIdsParam = Type.Array(InscriptionIdParam, { + title: 'Inscription IDs', + description: 'Array of inscription IDs', + examples: [ + [ + '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85i0', + ], + ], +}); + export const InscriptionNumberParam = Type.Integer({ minimum: 0, title: 'Inscription Number', @@ -59,6 +81,12 @@ export const InscriptionNumberParam = Type.Integer({ }); export const InscriptionNumberParamCType = TypeCompiler.Compile(InscriptionNumberParam); +export const InscriptionNumbersParam = Type.Array(InscriptionNumberParam, { + title: 'Inscription Numbers', + description: 'Array of inscription numbers', + examples: [['10500', '65']], +}); + export const InscriptionIdentifierParam = Type.Union([InscriptionIdParam, InscriptionNumberParam], { title: 'Inscription Identifier', description: 'Inscription unique identifier (number or ID)', @@ -195,6 +223,9 @@ export const InscriptionResponse = Type.Object({ }), genesis_fee: Type.String({ examples: ['3179'] }), genesis_timestamp: Type.Integer({ exmaples: [1677733170000] }), + tx_id: Type.String({ + examples: ['1463d48e9248159084929294f64bda04487503d30ce7ab58365df1dc6fd58218'], + }), location: Type.String({ examples: ['1463d48e9248159084929294f64bda04487503d30ce7ab58365df1dc6fd58218:0:0'], }), diff --git a/src/api/util/helpers.ts b/src/api/util/helpers.ts index 4ab0082a..a701dc65 100644 --- a/src/api/util/helpers.ts +++ b/src/api/util/helpers.ts @@ -16,6 +16,7 @@ export function parseDbInscriptions( genesis_tx_id: i.genesis_tx_id, genesis_fee: i.genesis_fee.toString(), genesis_timestamp: i.genesis_timestamp.valueOf(), + tx_id: i.tx_id, location: `${i.output}:${i.offset}`, output: i.output, value: i.value.toString(), diff --git a/src/chainhook/server.ts b/src/chainhook/server.ts index f6e6bfd0..9396c12c 100644 --- a/src/chainhook/server.ts +++ b/src/chainhook/server.ts @@ -1,6 +1,11 @@ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'; import { randomUUID } from 'crypto'; -import Fastify, { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'; +import Fastify, { + FastifyInstance, + FastifyPluginCallback, + FastifyReply, + FastifyRequest, +} from 'fastify'; import { Server } from 'http'; import { request } from 'undici'; import { ENV } from '../env'; @@ -12,7 +17,10 @@ import { processInscriptionRevealed, processInscriptionTransferred } from './hel export const CHAINHOOK_BASE_PATH = `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`; export const REVEAL__PREDICATE_UUID = randomUUID(); -async function waitForChainhookNode() { +/** + * Ping the chainhooks node indefinitely until it's ready. + */ +async function waitForChainhookNode(this: FastifyInstance) { logger.info(`EventServer connecting to chainhook node...`); while (true) { try { @@ -29,8 +37,11 @@ async function waitForChainhookNode() { * Register required ordinals predicates in the chainhooks node. This is executed before starting * the events server. */ -async function registerChainhookPredicates() { - logger.info(`EventServer registering predicates...`); +async function registerChainhookPredicates(this: FastifyInstance) { + const lastObservedBlockHeight = await this.db.getChainTipBlockHeight(); + logger.info( + `EventServer registering predicates starting from block ${lastObservedBlockHeight}...` + ); await request(`${CHAINHOOK_BASE_PATH}/v1/chainhooks`, { method: 'POST', body: JSON.stringify({ @@ -38,6 +49,7 @@ async function registerChainhookPredicates() { uuid: REVEAL__PREDICATE_UUID, name: 'inscription_revealed', version: 1, + start_block: lastObservedBlockHeight, networks: { mainnet: { if_this: { @@ -63,7 +75,7 @@ async function registerChainhookPredicates() { /** * Remove previously registered predicates. This is executed before closing the events server. */ -async function removeChainhookPredicates() { +async function removeChainhookPredicates(this: FastifyInstance) { logger.info(`EventServer closing predicates...`); await request(`${CHAINHOOK_BASE_PATH}/v1/chainhooks/bitcoin/${REVEAL__PREDICATE_UUID}`, { method: 'DELETE', diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index fb175e18..a2e00ec8 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -173,7 +173,7 @@ export class PgStore extends BasePgStore { } async getInscriptions(args: { - genesis_id?: string; + genesis_id?: string[]; genesis_block_height?: number; genesis_block_hash?: string; from_genesis_block_height?: number; @@ -182,10 +182,10 @@ export class PgStore extends BasePgStore { to_genesis_timestamp?: number; from_sat_coinbase_height?: number; to_sat_coinbase_height?: number; - number?: number; + number?: number[]; from_number?: number; to_number?: number; - address?: string; + address?: string[]; mime_type?: string[]; output?: string; sat_rarity?: SatoshiRarity[]; @@ -223,6 +223,7 @@ export class PgStore extends BasePgStore { gen.tx_id AS genesis_tx_id, gen.timestamp AS genesis_timestamp, gen.address AS genesis_address, + loc.tx_id, loc.address, loc.output, loc.offset, @@ -236,7 +237,11 @@ export class PgStore extends BasePgStore { INNER JOIN locations AS loc ON loc.inscription_id = i.id INNER JOIN locations AS gen ON gen.inscription_id = i.id WHERE loc.current = TRUE AND gen.genesis = TRUE - ${args.genesis_id ? this.sql`AND i.genesis_id = ${args.genesis_id}` : this.sql``} + ${ + args.genesis_id?.length + ? this.sql`AND i.genesis_id IN ${this.sql(args.genesis_id)}` + : this.sql`` + } ${ args.genesis_block_height ? this.sql`AND gen.block_height = ${args.genesis_block_height}` @@ -285,10 +290,12 @@ export class PgStore extends BasePgStore { ${ args.to_sat_ordinal ? this.sql`AND loc.sat_ordinal <= ${args.to_sat_ordinal}` : this.sql`` } - ${args.number ? this.sql`AND i.number = ${args.number}` : this.sql``} + ${args.number?.length ? this.sql`AND i.number IN ${this.sql(args.number)}` : this.sql``} ${args.from_number ? this.sql`AND i.number >= ${args.from_number}` : this.sql``} ${args.to_number ? this.sql`AND i.number <= ${args.to_number}` : this.sql``} - ${args.address ? this.sql`AND loc.address = ${args.address}` : this.sql``} + ${ + args.address?.length ? this.sql`AND loc.address IN ${this.sql(args.address)}` : this.sql`` + } ${ args.mime_type?.length ? this.sql`AND i.mime_type IN ${this.sql(args.mime_type)}` diff --git a/src/pg/types.ts b/src/pg/types.ts index 2049b2d4..875fd979 100644 --- a/src/pg/types.ts +++ b/src/pg/types.ts @@ -15,6 +15,7 @@ export type DbFullyLocatedInscriptionResult = { genesis_address: string; number: number; address: string; + tx_id: string; output: string; offset: bigint; value: bigint; diff --git a/tests/inscriptions.test.ts b/tests/inscriptions.test.ts index 9c066999..38eb54e5 100644 --- a/tests/inscriptions.test.ts +++ b/tests/inscriptions.test.ts @@ -18,1217 +18,1532 @@ describe('/inscriptions', () => { await db.close(); }); - test('shows inscription', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', + describe('show', () => { + test('shows inscription', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 188, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + const expected = { + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + genesis_block_height: 775617, content_length: 5, - number: 188, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', mime_type: 'image/png', content_type: 'image/png', - content_length: 5, + genesis_fee: '2805', + id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + offset: '0', number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + value: '10000', tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + sat_ordinal: '257418248345364', + sat_coinbase_height: 650000, output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, + location: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - const expected = { - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - genesis_block_height: 775617, - content_length: 5, - mime_type: 'image/png', - content_type: 'image/png', - genesis_fee: '2805', - id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - offset: '0', - number: 7, - value: '10000', - sat_ordinal: '257418248345364', - sat_coinbase_height: 650000, - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - location: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', - sat_rarity: 'common', - timestamp: 1676913207000, - genesis_timestamp: 1676913207000, - genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - }; + timestamp: 1676913207000, + genesis_timestamp: 1676913207000, + genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + }; - // By inscription id - const response = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - }); - expect(response.statusCode).toBe(200); - expect(response.json()).toStrictEqual(expected); + // By inscription id + const response = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + }); + expect(response.statusCode).toBe(200); + expect(response.json()).toStrictEqual(expected); - // By inscription number - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions/7', + // By inscription number + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions/7', + }); + expect(response2.statusCode).toBe(200); + expect(response2.json()).toStrictEqual(expected); }); - expect(response2.statusCode).toBe(200); - expect(response2.json()).toStrictEqual(expected); - }); - test('index filtered by mime type', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', + test('shows correct inscription data after a transfer', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + // Transfer 1 + await db.updateInscriptionLocation({ + location: { + inscription_id: 1, + block_height: 775700, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7bbbb', + tx_id: 'bdda0d240132bab2af7f797d1507beb1acab6ad43e2c0ef7f96291aea5cc3444', + address: 'bc1p3xqwzmddceqrd6x9yxplqzkl5vucta2gqm5szpkmpuvcvgs7g8psjf8htd', + output: 'bdda0d240132bab2af7f797d1507beb1acab6ad43e2c0ef7f96291aea5cc3444:0', + offset: 0n, + value: 9000n, + timestamp: 1678122360, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: false, + current: true, + }, + }); + const response = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + }); + expect(response.statusCode).toBe(200); + expect(response.json()).toStrictEqual({ + address: 'bc1p3xqwzmddceqrd6x9yxplqzkl5vucta2gqm5szpkmpuvcvgs7g8psjf8htd', + genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + genesis_block_height: 775617, content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', mime_type: 'image/png', content_type: 'image/png', - content_length: 5, - number: 1, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', + genesis_fee: '2805', + id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + offset: '0', + number: 7, + value: '9000', + tx_id: 'bdda0d240132bab2af7f797d1507beb1acab6ad43e2c0ef7f96291aea5cc3444', + sat_ordinal: '257418248345364', sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?mime_type=text/plain', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - const result1 = { - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - genesis_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - genesis_block_height: 778575, - content_length: 5, - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - genesis_fee: '705', - id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - offset: '0', - number: 7, - value: '10000', - sat_ordinal: '257418248345364', - sat_coinbase_height: 650000, - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - location: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0', - sat_rarity: 'common', - timestamp: 1676913207000, - genesis_timestamp: 1676913207000, - genesis_tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - }; - expect(responseJson1.results[0]).toStrictEqual(result1); - - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?mime_type=image/png', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - const result2 = { - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - genesis_block_height: 775617, - content_length: 5, - mime_type: 'image/png', - content_type: 'image/png', - genesis_fee: '2805', - id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - offset: '0', - number: 1, - value: '10000', - sat_ordinal: '257418248345364', - sat_coinbase_height: 650000, - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - location: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', - sat_rarity: 'common', - timestamp: 1676913207000, - genesis_timestamp: 1676913207000, - genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - }; - expect(responseJson2.results[0]).toStrictEqual(result2); - - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?mime_type=image/png&mime_type=text/plain', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(2); - expect(responseJson3.results[0]).toStrictEqual(result1); - expect(responseJson3.results[1]).toStrictEqual(result2); - }); + output: 'bdda0d240132bab2af7f797d1507beb1acab6ad43e2c0ef7f96291aea5cc3444:0', + location: 'bdda0d240132bab2af7f797d1507beb1acab6ad43e2c0ef7f96291aea5cc3444:0:0', + sat_rarity: 'common', + timestamp: 1678122360000, + genesis_timestamp: 1676913207000, + genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + }); - test('index filtered by sat rarity', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', + // Transfer 2 + await db.updateInscriptionLocation({ + location: { + inscription_id: 1, + block_height: 775701, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7cccc', + tx_id: 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85', + address: 'bc1pkjq7cerr6h53qm86k9t3dq0gqg8lcfz5jx7z4aj2mpqrjggrnass0u7qqj', + output: 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85:0', + offset: 0n, + value: 8000n, + timestamp: 1678124000, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: false, + current: true, + }, + }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + }); + expect(response2.statusCode).toBe(200); + expect(response2.json()).toStrictEqual({ + address: 'bc1pkjq7cerr6h53qm86k9t3dq0gqg8lcfz5jx7z4aj2mpqrjggrnass0u7qqj', + genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + genesis_block_height: 775617, content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', mime_type: 'image/png', content_type: 'image/png', - content_length: 5, + genesis_fee: '2805', + id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + offset: '0', number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', + tx_id: 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85', + value: '8000', + sat_ordinal: '257418248345364', sat_coinbase_height: 650000, - genesis: true, - current: true, - }, + output: 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85:0', + location: 'e3af144354367de58c675e987febcb49f17d6c19e645728b833fe95408feab85:0:0', + sat_rarity: 'common', + timestamp: 1678124000000, + genesis_timestamp: 1676913207000, + genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + }); }); + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?rarity=common', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - expect(responseJson1.results[0].sat_rarity).toBe('common'); + describe('index', () => { + describe('filters', () => { + test('index filtered by mime type', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 1, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?rarity=epic', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].sat_rarity).toBe('epic'); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?mime_type=text/plain', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + const result1 = { + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + genesis_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + genesis_block_height: 778575, + content_length: 5, + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + genesis_fee: '705', + id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + offset: '0', + number: 7, + value: '10000', + sat_ordinal: '257418248345364', + sat_coinbase_height: 650000, + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + location: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0', + sat_rarity: 'common', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + timestamp: 1676913207000, + genesis_timestamp: 1676913207000, + genesis_tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + }; + expect(responseJson1.results[0]).toStrictEqual(result1); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?rarity=epic&rarity=common', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(2); - }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?mime_type=image/png', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + const result2 = { + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + genesis_block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + genesis_block_height: 775617, + content_length: 5, + mime_type: 'image/png', + content_type: 'image/png', + genesis_fee: '2805', + id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + offset: '0', + number: 1, + value: '10000', + sat_ordinal: '257418248345364', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + sat_coinbase_height: 650000, + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + location: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', + sat_rarity: 'common', + timestamp: 1676913207000, + genesis_timestamp: 1676913207000, + genesis_tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + }; + expect(responseJson2.results[0]).toStrictEqual(result2); - test('index filtered by block height', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?mime_type=image/png&mime_type=text/plain', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(2); + expect(responseJson3.results[0]).toStrictEqual(result1); + expect(responseJson3.results[1]).toStrictEqual(result2); + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?genesis_block=775617', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - expect(responseJson1.results[0].genesis_block_height).toBe(775617); + test('index filtered by sat rarity', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?from_genesis_block_height=778000', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].genesis_block_height).toBe(778575); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?rarity=common', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].sat_rarity).toBe('common'); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?to_genesis_block_height=778000', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(1); - expect(responseJson3.results[0].genesis_block_height).toBe(775617); - }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?rarity=epic', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].sat_rarity).toBe('epic'); - test('index filtered by block hash', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?rarity=epic&rarity=common', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(2); + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?genesis_block=000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - expect(responseJson1.results[0].genesis_block_hash).toBe( - '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7' - ); - }); + test('index filtered by inscription id', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - test('index filtered by timestamp range', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1677731361, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1675312161, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?id=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].id).toBe( + '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0' + ); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?from_genesis_timestamp=1675571361', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].genesis_timestamp).toBe(1677731361000); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?id=38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].id).toBe( + '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0' + ); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?to_genesis_timestamp=1675571361', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(1); - expect(responseJson3.results[0].genesis_timestamp).toBe(1675312161000); - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?id=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0&id=38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(2); + }); - test('index filtered by sat ordinal range', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1677731361, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1675312161, - sat_ordinal: 1000000000000n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + test('index filtered by inscription number', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 50, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?from_sat_ordinal=1000400000000', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].sat_ordinal).toBe('257418248345364'); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?number=7', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].number).toBe(7); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?to_sat_ordinal=1000400000000', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(1); - expect(responseJson3.results[0].sat_ordinal).toBe('1000000000000'); - }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?number=50', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].number).toBe(50); - test('index filtered by sat coinbase height range', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1677731361, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1675312161, - sat_ordinal: 1000000000000n, - sat_rarity: 'epic', - sat_coinbase_height: 750000, - genesis: true, - current: true, - }, - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?number=7&number=50', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(2); + }); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?from_sat_coinbase_height=655000', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].sat_coinbase_height).toBe(750000); + test('index filtered by block height', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?to_sat_coinbase_height=655000', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(1); - expect(responseJson3.results[0].sat_coinbase_height).toBe(650000); - }); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?genesis_block=775617', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].genesis_block_height).toBe(775617); - test('index filtered by inscription number range', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1677731361, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 50, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1675312161, - sat_ordinal: 1000000000000n, - sat_rarity: 'epic', - sat_coinbase_height: 750000, - genesis: true, - current: true, - }, - }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?from_genesis_block_height=778000', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].genesis_block_height).toBe(778575); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?from_number=10', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(1); - expect(responseJson2.results[0].number).toBe(50); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?to_genesis_block_height=778000', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(1); + expect(responseJson3.results[0].genesis_block_height).toBe(775617); + }); - const response3 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?to_number=10', - }); - expect(response3.statusCode).toBe(200); - const responseJson3 = response3.json(); - expect(responseJson3.total).toBe(1); - expect(responseJson3.results[0].number).toBe(7); - }); + test('index filtered by block hash', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - test('index filtered by output', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?genesis_block=000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].genesis_block_hash).toBe( + '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7' + ); + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?output=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - expect(responseJson1.results[0].output).toBe( - '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0' - ); - }); + test('index filtered by timestamp range', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1677731361, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1675312161, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - test('index filtered by address', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?from_genesis_timestamp=1675571361', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].genesis_timestamp).toBe(1677731361000); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?address=bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(1); - expect(responseJson1.results[0].address).toBe( - 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj' - ); - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?to_genesis_timestamp=1675571361', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(1); + expect(responseJson3.results[0].genesis_timestamp).toBe(1675312161000); + }); - test('index ordered by sat rarity', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - content: '0x48656C6C6F', - number: 7, - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 257418248345364n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 778583, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', - address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', - output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 0n, - sat_rarity: 'mythic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + test('index filtered by sat ordinal range', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1677731361, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1675312161, + sat_ordinal: 1000000000000n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=rarity&order=asc', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(3); - expect(responseJson1.results[0].sat_rarity).toStrictEqual('common'); - expect(responseJson1.results[1].sat_rarity).toStrictEqual('epic'); - expect(responseJson1.results[2].sat_rarity).toStrictEqual('mythic'); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?from_sat_ordinal=1000400000000', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].sat_ordinal).toBe('257418248345364'); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=rarity&order=desc', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(3); - expect(responseJson2.results[0].sat_rarity).toStrictEqual('mythic'); - expect(responseJson2.results[1].sat_rarity).toStrictEqual('epic'); - expect(responseJson2.results[2].sat_rarity).toStrictEqual('common'); - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?to_sat_ordinal=1000400000000', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(1); + expect(responseJson3.results[0].sat_ordinal).toBe('1000000000000'); + }); - test('index ordered by sat ordinal', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 3n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 5n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 778583, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', - address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', - output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 0n, - sat_rarity: 'mythic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + test('index filtered by sat coinbase height range', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1677731361, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1675312161, + sat_ordinal: 1000000000000n, + sat_rarity: 'epic', + sat_coinbase_height: 750000, + genesis: true, + current: true, + }, + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=ordinal&order=asc', - }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(3); - expect(responseJson1.results[0].sat_ordinal).toStrictEqual('0'); - expect(responseJson1.results[1].sat_ordinal).toStrictEqual('3'); - expect(responseJson1.results[2].sat_ordinal).toStrictEqual('5'); + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?from_sat_coinbase_height=655000', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].sat_coinbase_height).toBe(750000); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=ordinal&order=desc', - }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(3); - expect(responseJson2.results[0].sat_ordinal).toStrictEqual('5'); - expect(responseJson2.results[1].sat_ordinal).toStrictEqual('3'); - expect(responseJson2.results[2].sat_ordinal).toStrictEqual('0'); - }); + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?to_sat_coinbase_height=655000', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(1); + expect(responseJson3.results[0].sat_coinbase_height).toBe(650000); + }); - test('index ordered by genesis block height', async () => { - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - mime_type: 'text/plain', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 705n, - }, - location: { - inscription_id: 0, - block_height: 778575, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 3n, - sat_rarity: 'common', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 775617, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 5n, - sat_rarity: 'epic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); - await db.insertInscriptionGenesis({ - inscription: { - genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', - mime_type: 'image/png', - content_type: 'image/png', - content_length: 5, - number: 7, - content: '0x48656C6C6F', - fee: 2805n, - }, - location: { - inscription_id: 0, - block_height: 778583, - block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', - address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', - output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', - offset: 0n, - value: 10000n, - timestamp: 1676913207, - sat_ordinal: 0n, - sat_rarity: 'mythic', - sat_coinbase_height: 650000, - genesis: true, - current: true, - }, - }); + test('index filtered by inscription number range', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1677731361, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 50, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1675312161, + sat_ordinal: 1000000000000n, + sat_rarity: 'epic', + sat_coinbase_height: 750000, + genesis: true, + current: true, + }, + }); - const response1 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=asc', + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?from_number=10', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(1); + expect(responseJson2.results[0].number).toBe(50); + + const response3 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?to_number=10', + }); + expect(response3.statusCode).toBe(200); + const responseJson3 = response3.json(); + expect(responseJson3.total).toBe(1); + expect(responseJson3.results[0].number).toBe(7); + }); + + test('index filtered by output', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?output=9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].output).toBe( + '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0' + ); + }); + + test('index filtered by address', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '000000000000000000039b3051705a16fcf310a70dee55742339e6da70181bf7', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?address=bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(1); + expect(responseJson1.results[0].address).toBe( + 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj' + ); + + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?address=bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj&address=bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(2); + }); }); - expect(response1.statusCode).toBe(200); - const responseJson1 = response1.json(); - expect(responseJson1.total).toBe(3); - expect(responseJson1.results[0].genesis_block_height).toStrictEqual(775617); - expect(responseJson1.results[1].genesis_block_height).toStrictEqual(778575); - expect(responseJson1.results[2].genesis_block_height).toStrictEqual(778583); - const response2 = await fastify.inject({ - method: 'GET', - url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=desc', + describe('ordering', () => { + test('index ordered by sat rarity', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + content: '0x48656C6C6F', + number: 7, + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 257418248345364n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 778583, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', + address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', + output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 0n, + sat_rarity: 'mythic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=rarity&order=asc', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(3); + expect(responseJson1.results[0].sat_rarity).toStrictEqual('common'); + expect(responseJson1.results[1].sat_rarity).toStrictEqual('epic'); + expect(responseJson1.results[2].sat_rarity).toStrictEqual('mythic'); + + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=rarity&order=desc', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(3); + expect(responseJson2.results[0].sat_rarity).toStrictEqual('mythic'); + expect(responseJson2.results[1].sat_rarity).toStrictEqual('epic'); + expect(responseJson2.results[2].sat_rarity).toStrictEqual('common'); + }); + + test('index ordered by sat ordinal', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 3n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 5n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 778583, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', + address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', + output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 0n, + sat_rarity: 'mythic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=ordinal&order=asc', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(3); + expect(responseJson1.results[0].sat_ordinal).toStrictEqual('0'); + expect(responseJson1.results[1].sat_ordinal).toStrictEqual('3'); + expect(responseJson1.results[2].sat_ordinal).toStrictEqual('5'); + + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=ordinal&order=desc', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(3); + expect(responseJson2.results[0].sat_ordinal).toStrictEqual('5'); + expect(responseJson2.results[1].sat_ordinal).toStrictEqual('3'); + expect(responseJson2.results[2].sat_ordinal).toStrictEqual('0'); + }); + + test('index ordered by genesis block height', async () => { + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', + mime_type: 'text/plain', + content_type: 'text/plain;charset=utf-8', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 705n, + }, + location: { + inscription_id: 0, + block_height: 778575, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', + address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', + output: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 3n, + sat_rarity: 'common', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 775617, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', + address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', + output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 5n, + sat_rarity: 'epic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + await db.insertInscriptionGenesis({ + inscription: { + genesis_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1i0', + mime_type: 'image/png', + content_type: 'image/png', + content_length: 5, + number: 7, + content: '0x48656C6C6F', + fee: 2805n, + }, + location: { + inscription_id: 0, + block_height: 778583, + block_hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', + tx_id: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1', + address: 'bc1pxq6t85qp57aw8yf8eh9t7vsgd9zm5a8372rdll5jzrmc3cxqdpmqfucdry', + output: '567c7605439dfdc3a289d13fd2132237852f4a56e784b9364ba94499d5f9baf1:0', + offset: 0n, + value: 10000n, + timestamp: 1676913207, + sat_ordinal: 0n, + sat_rarity: 'mythic', + sat_coinbase_height: 650000, + genesis: true, + current: true, + }, + }); + + const response1 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=asc', + }); + expect(response1.statusCode).toBe(200); + const responseJson1 = response1.json(); + expect(responseJson1.total).toBe(3); + expect(responseJson1.results[0].genesis_block_height).toStrictEqual(775617); + expect(responseJson1.results[1].genesis_block_height).toStrictEqual(778575); + expect(responseJson1.results[2].genesis_block_height).toStrictEqual(778583); + + const response2 = await fastify.inject({ + method: 'GET', + url: '/ordinals/v1/inscriptions?order_by=genesis_block_height&order=desc', + }); + expect(response2.statusCode).toBe(200); + const responseJson2 = response2.json(); + expect(responseJson2.total).toBe(3); + expect(responseJson2.results[0].genesis_block_height).toStrictEqual(778583); + expect(responseJson2.results[1].genesis_block_height).toStrictEqual(778575); + expect(responseJson2.results[2].genesis_block_height).toStrictEqual(775617); + }); }); - expect(response2.statusCode).toBe(200); - const responseJson2 = response2.json(); - expect(responseJson2.total).toBe(3); - expect(responseJson2.results[0].genesis_block_height).toStrictEqual(778583); - expect(responseJson2.results[1].genesis_block_height).toStrictEqual(778575); - expect(responseJson2.results[2].genesis_block_height).toStrictEqual(775617); }); test('returns not found for invalid inscriptions', async () => { diff --git a/tests/server.test.ts b/tests/server.test.ts index e6f3196c..e524a373 100644 --- a/tests/server.test.ts +++ b/tests/server.test.ts @@ -177,7 +177,7 @@ describe('EventServer', () => { expect(response.statusCode).toBe(200); const query = await db.getInscriptions({ - genesis_id: '0268dd9743c862d80ab02cb1d0228036cfe172522850eb96be60cfee14b31fb8i0', + genesis_id: ['0268dd9743c862d80ab02cb1d0228036cfe172522850eb96be60cfee14b31fb8i0'], limit: 1, offset: 0, });