Skip to content

Commit

Permalink
fix: display delegate content
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jul 29, 2024
1 parent 96ac172 commit 27b3941
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,22 @@ export class PgStore extends BasePgStore {
args: InscriptionIdentifier
): Promise<DbInscriptionContent | undefined> {
const result = await this.sql<DbInscriptionContent[]>`
WITH content_id AS (
SELECT
CASE
WHEN delegate IS NOT NULL THEN delegate
ELSE genesis_id
END AS genesis_id
FROM inscriptions
WHERE ${
'genesis_id' in args
? this.sql`genesis_id = ${args.genesis_id}`
: this.sql`number = ${args.number}`
}
)
SELECT content, content_type, content_length
FROM inscriptions
WHERE ${
'genesis_id' in args
? this.sql`genesis_id = ${args.genesis_id}`
: this.sql`number = ${args.number}`
}
WHERE genesis_id = (SELECT genesis_id FROM content_id)
`;
if (result.count > 0) {
return result[0];
Expand Down
131 changes: 131 additions & 0 deletions tests/api/inscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,137 @@ describe('/inscriptions', () => {
delegate: null,
});
});

test('shows inscription content', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 775617,
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
timestamp: 1676913207,
})
.transaction({
hash: '0x38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
})
.inscriptionRevealed({
content_bytes: '0x48656C6C6F', // Hello
content_type: 'text/plain',
content_length: 5,
inscription_number: { classic: 0, jubilee: 0 },
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
ordinal_number: 257418248345364,
ordinal_block_height: 51483,
ordinal_offset: 0,
satpoint_post_inscription:
'38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0',
curse_type: { tag: 66 },
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
inscription_pointer: null,
delegate: null,
metaprotocol: null,
metadata: null,
parent: null,
})
.build()
);
const response = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0/content',
});
expect(response.statusCode).toBe(200);
expect(response.headers['content-length']).toBe('5');
expect(response.body).toBe('Hello');
});

test('shows delegate inscription content', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 775617,
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
timestamp: 1676913207,
})
.transaction({
hash: '0x38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
})
.inscriptionRevealed({
content_bytes: '0x48656C6C6F', // Hello
content_type: 'text/plain',
content_length: 5,
inscription_number: { classic: 0, jubilee: 0 },
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
ordinal_number: 257418248345364,
ordinal_block_height: 51483,
ordinal_offset: 0,
satpoint_post_inscription:
'38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0',
curse_type: { tag: 66 },
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
inscription_pointer: null,
delegate: null,
metaprotocol: null,
metadata: null,
parent: null,
})
.build()
);
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 775618,
hash: '0x00000000000000000000ceb7a81bf3696de0b2260078942f3ab36a7127aff296',
timestamp: 1676913207,
})
.transaction({
hash: '0x42174ecc8a245841035793390bb53d63b3c2acb61366446f601b09e73b94b656',
})
.inscriptionRevealed({
content_bytes: '',
content_type: 'text/plain',
content_length: 0,
inscription_number: { classic: 1, jubilee: 1 },
inscription_fee: 2805,
inscription_id: '42174ecc8a245841035793390bb53d63b3c2acb61366446f601b09e73b94b656i0',
inscription_output_value: 10000,
inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
ordinal_number: 257418248345364,
ordinal_block_height: 51483,
ordinal_offset: 0,
satpoint_post_inscription:
'42174ecc8a245841035793390bb53d63b3c2acb61366446f601b09e73b94b656:0:0',
curse_type: { tag: 66 },
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
inscription_pointer: null,
delegate: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
metaprotocol: null,
metadata: null,
parent: null,
})
.build()
);
const response = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/42174ecc8a245841035793390bb53d63b3c2acb61366446f601b09e73b94b656i0/content',
});
expect(response.statusCode).toBe(200);
expect(response.headers['content-length']).toBe('5');
expect(response.body).toBe('Hello');
});
});

describe('transfers', () => {
Expand Down

0 comments on commit 27b3941

Please sign in to comment.