Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: return parent and metadata in inscription responses #350

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ export const InscriptionResponse = Type.Object(
})
)
),
parent: Nullable(
Type.String({
examples: ['1463d48e9248159084929294f64bda04487503d30ce7ab58365df1dc6fd58218i0'],
})
),
metadata: Nullable(Type.Any()),
},
{ title: 'Inscription Response' }
);
Expand Down
2 changes: 2 additions & 0 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function parseDbInscriptions(
curse_type: i.curse_type,
recursive: i.recursive,
recursion_refs: i.recursion_refs?.split(',') ?? null,
parent: i.parent,
metadata: i.metadata ? JSON.parse(i.metadata) : null,
}));
}
export function parseDbInscription(item: DbFullyLocatedInscriptionResult): InscriptionResponseType {
Expand Down
2 changes: 2 additions & 0 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ export class PgStore extends BasePgStore {
i.fee AS genesis_fee,
i.curse_type,
i.ordinal_number AS sat_ordinal,
i.parent,
i.metadata,
s.rarity AS sat_rarity,
s.coinbase_height AS sat_coinbase_height,
i.recursive,
Expand Down
2 changes: 2 additions & 0 deletions src/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export type DbFullyLocatedInscriptionResult = {
curse_type: string | null;
recursive: boolean;
recursion_refs: string | null;
parent: string | null;
metadata: string | null;
};

export enum DbLocationTransferType {
Expand Down
147 changes: 147 additions & 0 deletions tests/api/inscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
};

// By inscription id
Expand Down Expand Up @@ -280,6 +282,8 @@ describe('/inscriptions', () => {
'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
'b4b27b9a15f928b95a8ce4b418946553b7b313a345254cd9b23d79489175fa5ai0',
],
parent: null,
metadata: null,
};

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

test('shows inscription with parent', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 778575,
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
timestamp: 1676913207,
})
.transaction({
hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201',
})
.inscriptionRevealed({
content_bytes: `0x010101`,
content_type: 'text/plain;charset=utf-8',
content_length: 5,
inscription_number: { classic: 0, jubilee: 0 },
inscription_fee: 705,
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
inscription_output_value: 10000,
inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
ordinal_number: 257418248345364,
ordinal_block_height: 650000,
ordinal_offset: 0,
satpoint_post_inscription:
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0',
tx_index: 0,
inscription_input_index: 0,
transfers_pre_inscription: 0,
curse_type: null,
inscription_pointer: null,
delegate: null,
metaprotocol: null,
metadata: null,
parent: null,
})
.transaction({
hash: '0xf351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421',
})
.inscriptionRevealed({
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: { classic: 1, jubilee: 1 },
inscription_fee: 2805,
inscription_id: 'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
inscription_output_value: 10000,
inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
ordinal_number: 257418248345364,
ordinal_block_height: 51483,
ordinal_offset: 0,
satpoint_post_inscription:
'f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421:0:0',
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
inscription_pointer: null,
delegate: null,
metaprotocol: null,
metadata: null,
parent: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
})
.build()
);
const response = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/f351d86c6e6cae3c64e297e7463095732f216875bcc1f3c03f950a492bb25421i0',
});
expect(response.statusCode).toBe(200);
expect(response.json().parent).toBe(
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0'
);
});

test('shows inscription with metadata', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: 778575,
hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
timestamp: 1676913207,
})
.transaction({
hash: '0x9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201',
})
.inscriptionRevealed({
content_bytes: `0x010101`,
content_type: 'text/plain;charset=utf-8',
content_length: 5,
inscription_number: { classic: 0, jubilee: 0 },
inscription_fee: 705,
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
inscription_output_value: 10000,
inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
ordinal_number: 257418248345364,
ordinal_block_height: 650000,
ordinal_offset: 0,
satpoint_post_inscription:
'9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0',
tx_index: 0,
inscription_input_index: 0,
transfers_pre_inscription: 0,
curse_type: null,
inscription_pointer: null,
delegate: null,
metaprotocol: null,
metadata: { foo: 'bar', test: 1337 },
parent: null,
})
.build()
);
const response = await fastify.inject({
method: 'GET',
url: '/ordinals/v1/inscriptions/9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
});
expect(response.statusCode).toBe(200);
expect(response.json().metadata).toStrictEqual({ foo: 'bar', test: 1337 });
});

test('shows inscription with empty genesis address', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
Expand Down Expand Up @@ -362,6 +487,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
};

// By inscription id
Expand Down Expand Up @@ -444,6 +571,8 @@ describe('/inscriptions', () => {
curse_type: '88',
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
};

// By inscription id
Expand Down Expand Up @@ -555,6 +684,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
});

// Transfer 2
Expand Down Expand Up @@ -610,6 +741,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
});
});

Expand Down Expand Up @@ -720,6 +853,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
});
});

Expand Down Expand Up @@ -815,6 +950,8 @@ describe('/inscriptions', () => {
curse_type: '{"tag":66}',
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
});

// Transfer 2
Expand Down Expand Up @@ -870,6 +1007,8 @@ describe('/inscriptions', () => {
curse_type: '{"tag":66}',
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
});
});
});
Expand Down Expand Up @@ -1515,6 +1654,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
},
{
address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj',
Expand All @@ -1541,6 +1682,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
},
]);
});
Expand Down Expand Up @@ -1654,6 +1797,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
};
expect(responseJson1.results[0]).toStrictEqual(result1);

Expand Down Expand Up @@ -1689,6 +1834,8 @@ describe('/inscriptions', () => {
curse_type: null,
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
};
expect(responseJson2.results[0]).toStrictEqual(result2);

Expand Down
4 changes: 4 additions & 0 deletions tests/api/sats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ describe('/sats', () => {
curse_type: '"p2wsh"',
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
},
{
address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
Expand Down Expand Up @@ -211,6 +213,8 @@ describe('/sats', () => {
curse_type: '"p2wsh"',
recursive: false,
recursion_refs: null,
parent: null,
metadata: null,
},
]);

Expand Down
Loading