Skip to content

Commit 4ca8faf

Browse files
committed
feat: return parent and metadata in inscription responses (#350)
* fix: show parent * fix: metadata * fix: tests
1 parent ba98e8e commit 4ca8faf

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

src/api/schemas.ts

+6
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ export const InscriptionResponse = Type.Object(
326326
})
327327
)
328328
),
329+
parent: Nullable(
330+
Type.String({
331+
examples: ['1463d48e9248159084929294f64bda04487503d30ce7ab58365df1dc6fd58218i0'],
332+
})
333+
),
334+
metadata: Nullable(Type.Any()),
329335
},
330336
{ title: 'Inscription Response' }
331337
);

src/api/util/helpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function parseDbInscriptions(
5555
curse_type: i.curse_type,
5656
recursive: i.recursive,
5757
recursion_refs: i.recursion_refs?.split(',') ?? null,
58+
parent: i.parent,
59+
metadata: i.metadata ? JSON.parse(i.metadata) : null,
5860
}));
5961
}
6062
export function parseDbInscription(item: DbFullyLocatedInscriptionResult): InscriptionResponseType {

src/pg/pg-store.ts

+2
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ export class PgStore extends BasePgStore {
589589
i.fee AS genesis_fee,
590590
i.curse_type,
591591
i.ordinal_number AS sat_ordinal,
592+
i.parent,
593+
i.metadata,
592594
s.rarity AS sat_rarity,
593595
s.coinbase_height AS sat_coinbase_height,
594596
i.recursive,

src/pg/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export type DbFullyLocatedInscriptionResult = {
100100
curse_type: string | null;
101101
recursive: boolean;
102102
recursion_refs: string | null;
103+
parent: string | null;
104+
metadata: string | null;
103105
};
104106

105107
export enum DbLocationTransferType {

tests/api/inscriptions.test.ts

+147
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ describe('/inscriptions', () => {
124124
curse_type: null,
125125
recursive: false,
126126
recursion_refs: null,
127+
parent: null,
128+
metadata: null,
127129
};
128130

129131
// By inscription id
@@ -280,6 +282,8 @@ describe('/inscriptions', () => {
280282
'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
281283
'b4b27b9a15f928b95a8ce4b418946553b7b313a345254cd9b23d79489175fa5ai0',
282284
],
285+
parent: null,
286+
metadata: null,
283287
};
284288

285289
// By inscription id
@@ -299,6 +303,127 @@ describe('/inscriptions', () => {
299303
expect(response2.json()).toStrictEqual(expected);
300304
});
301305

306+
test('shows inscription with parent', async () => {
307+
await db.updateInscriptions(
308+
new TestChainhookPayloadBuilder()
309+
.apply()
310+
.block({
311+
height: 778575,
312+
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
313+
timestamp: 1676913207,
314+
})
315+
.transaction({
316+
hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201',
317+
})
318+
.inscriptionRevealed({
319+
content_bytes: `0x010101`,
320+
content_type: 'text/plain;charset=utf-8',
321+
content_length: 5,
322+
inscription_number: { classic: 0, jubilee: 0 },
323+
inscription_fee: 705,
324+
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
325+
inscription_output_value: 10000,
326+
inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
327+
ordinal_number: 257418248345364,
328+
ordinal_block_height: 650000,
329+
ordinal_offset: 0,
330+
satpoint_post_inscription:
331+
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0',
332+
tx_index: 0,
333+
inscription_input_index: 0,
334+
transfers_pre_inscription: 0,
335+
curse_type: null,
336+
inscription_pointer: null,
337+
delegate: null,
338+
metaprotocol: null,
339+
metadata: null,
340+
parent: null,
341+
})
342+
.transaction({
343+
hash: '0xf351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421',
344+
})
345+
.inscriptionRevealed({
346+
content_bytes: '0x48656C6C6F',
347+
content_type: 'image/png',
348+
content_length: 5,
349+
inscription_number: { classic: 1, jubilee: 1 },
350+
inscription_fee: 2805,
351+
inscription_id: 'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
352+
inscription_output_value: 10000,
353+
inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
354+
ordinal_number: 257418248345364,
355+
ordinal_block_height: 51483,
356+
ordinal_offset: 0,
357+
satpoint_post_inscription:
358+
'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421:0:0',
359+
inscription_input_index: 0,
360+
transfers_pre_inscription: 0,
361+
tx_index: 0,
362+
curse_type: null,
363+
inscription_pointer: null,
364+
delegate: null,
365+
metaprotocol: null,
366+
metadata: null,
367+
parent: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
368+
})
369+
.build()
370+
);
371+
const response = await fastify.inject({
372+
method: 'GET',
373+
url: '/ordinals/v1/inscriptions/f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
374+
});
375+
expect(response.statusCode).toBe(200);
376+
expect(response.json().parent).toBe(
377+
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0'
378+
);
379+
});
380+
381+
test('shows inscription with metadata', async () => {
382+
await db.updateInscriptions(
383+
new TestChainhookPayloadBuilder()
384+
.apply()
385+
.block({
386+
height: 778575,
387+
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
388+
timestamp: 1676913207,
389+
})
390+
.transaction({
391+
hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201',
392+
})
393+
.inscriptionRevealed({
394+
content_bytes: `0x010101`,
395+
content_type: 'text/plain;charset=utf-8',
396+
content_length: 5,
397+
inscription_number: { classic: 0, jubilee: 0 },
398+
inscription_fee: 705,
399+
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
400+
inscription_output_value: 10000,
401+
inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
402+
ordinal_number: 257418248345364,
403+
ordinal_block_height: 650000,
404+
ordinal_offset: 0,
405+
satpoint_post_inscription:
406+
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0',
407+
tx_index: 0,
408+
inscription_input_index: 0,
409+
transfers_pre_inscription: 0,
410+
curse_type: null,
411+
inscription_pointer: null,
412+
delegate: null,
413+
metaprotocol: null,
414+
metadata: { foo: 'bar', test: 1337 },
415+
parent: null,
416+
})
417+
.build()
418+
);
419+
const response = await fastify.inject({
420+
method: 'GET',
421+
url: '/ordinals/v1/inscriptions/9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
422+
});
423+
expect(response.statusCode).toBe(200);
424+
expect(response.json().metadata).toStrictEqual({ foo: 'bar', test: 1337 });
425+
});
426+
302427
test('shows inscription with empty genesis address', async () => {
303428
await db.updateInscriptions(
304429
new TestChainhookPayloadBuilder()
@@ -362,6 +487,8 @@ describe('/inscriptions', () => {
362487
curse_type: null,
363488
recursive: false,
364489
recursion_refs: null,
490+
parent: null,
491+
metadata: null,
365492
};
366493

367494
// By inscription id
@@ -444,6 +571,8 @@ describe('/inscriptions', () => {
444571
curse_type: '88',
445572
recursive: false,
446573
recursion_refs: null,
574+
parent: null,
575+
metadata: null,
447576
};
448577

449578
// By inscription id
@@ -555,6 +684,8 @@ describe('/inscriptions', () => {
555684
curse_type: null,
556685
recursive: false,
557686
recursion_refs: null,
687+
parent: null,
688+
metadata: null,
558689
});
559690

560691
// Transfer 2
@@ -610,6 +741,8 @@ describe('/inscriptions', () => {
610741
curse_type: null,
611742
recursive: false,
612743
recursion_refs: null,
744+
parent: null,
745+
metadata: null,
613746
});
614747
});
615748

@@ -720,6 +853,8 @@ describe('/inscriptions', () => {
720853
curse_type: null,
721854
recursive: false,
722855
recursion_refs: null,
856+
parent: null,
857+
metadata: null,
723858
});
724859
});
725860

@@ -815,6 +950,8 @@ describe('/inscriptions', () => {
815950
curse_type: '{"tag":66}',
816951
recursive: false,
817952
recursion_refs: null,
953+
parent: null,
954+
metadata: null,
818955
});
819956

820957
// Transfer 2
@@ -870,6 +1007,8 @@ describe('/inscriptions', () => {
8701007
curse_type: '{"tag":66}',
8711008
recursive: false,
8721009
recursion_refs: null,
1010+
parent: null,
1011+
metadata: null,
8731012
});
8741013
});
8751014
});
@@ -1515,6 +1654,8 @@ describe('/inscriptions', () => {
15151654
curse_type: null,
15161655
recursive: false,
15171656
recursion_refs: null,
1657+
parent: null,
1658+
metadata: null,
15181659
},
15191660
{
15201661
address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
@@ -1541,6 +1682,8 @@ describe('/inscriptions', () => {
15411682
curse_type: null,
15421683
recursive: false,
15431684
recursion_refs: null,
1685+
parent: null,
1686+
metadata: null,
15441687
},
15451688
]);
15461689
});
@@ -1654,6 +1797,8 @@ describe('/inscriptions', () => {
16541797
curse_type: null,
16551798
recursive: false,
16561799
recursion_refs: null,
1800+
parent: null,
1801+
metadata: null,
16571802
};
16581803
expect(responseJson1.results[0]).toStrictEqual(result1);
16591804

@@ -1689,6 +1834,8 @@ describe('/inscriptions', () => {
16891834
curse_type: null,
16901835
recursive: false,
16911836
recursion_refs: null,
1837+
parent: null,
1838+
metadata: null,
16921839
};
16931840
expect(responseJson2.results[0]).toStrictEqual(result2);
16941841

tests/api/sats.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ describe('/sats', () => {
184184
curse_type: '"p2wsh"',
185185
recursive: false,
186186
recursion_refs: null,
187+
parent: null,
188+
metadata: null,
187189
},
188190
{
189191
address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
@@ -211,6 +213,8 @@ describe('/sats', () => {
211213
curse_type: '"p2wsh"',
212214
recursive: false,
213215
recursion_refs: null,
216+
parent: null,
217+
metadata: null,
214218
},
215219
]);
216220

0 commit comments

Comments
 (0)