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

fix: calculate transfer type correctly upon reveal #326

Merged
merged 1 commit into from
Mar 8, 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
23 changes: 18 additions & 5 deletions src/pg/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PgBytea, toEnumValue } from '@hirosystems/api-toolkit';
import { PgBytea, logger, toEnumValue } from '@hirosystems/api-toolkit';
import { hexToBuffer, normalizedHexString, parseSatPoint } from '../api/util/helpers';
import {
BadPayloadRequestError,
Expand Down Expand Up @@ -98,12 +98,25 @@
const satoshi = new OrdinalSatoshi(args.reveal.ordinal_number);
const satpoint = parseSatPoint(args.reveal.satpoint_post_inscription);
const recursive_refs = getInscriptionRecursion(args.reveal.content_bytes);
const contentType = removeNullBytes(args.reveal.content_type);
const content_type = removeNullBytes(args.reveal.content_type);
let transfer_type = DbLocationTransferType.transferred;
if (args.reveal.inscriber_address == null || args.reveal.inscriber_address == '') {
if (args.reveal.inscription_output_value == 0) {
if (args.reveal.inscription_pointer !== 0 && args.reveal.inscription_pointer !== null) {
logger.warn(
`Detected inscription reveal with no address and no output value but a valid pointer ${args.reveal.inscription_id}`
);
}
transfer_type = DbLocationTransferType.spentInFees;

Check warning on line 110 in src/pg/helpers.ts

View check run for this annotation

Codecov / codecov/patch

src/pg/helpers.ts#L105-L110

Added lines #L105 - L110 were not covered by tests
} else {
transfer_type = DbLocationTransferType.burnt;
}
}
return {
inscription: {
genesis_id: args.reveal.inscription_id,
mime_type: contentType.split(';')[0],
content_type: contentType,
mime_type: content_type.split(';')[0],
content_type,
content_length: args.reveal.content_length,
number: args.reveal.inscription_number.jubilee,
classic_number: args.reveal.inscription_number.classic,
Expand Down Expand Up @@ -131,7 +144,7 @@
prev_offset: null,
value: args.reveal.inscription_output_value.toString(),
timestamp: args.timestamp,
transfer_type: DbLocationTransferType.transferred,
transfer_type,
},
recursive_refs,
};
Expand Down
98 changes: 98 additions & 0 deletions tests/brc-20/brc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,104 @@ describe('BRC-20', () => {
expect(brc20FromInscription(insert)).toBeUndefined();
});

test('ignores inscriptions spent as fees', () => {
const content = Buffer.from(
JSON.stringify({
p: 'brc-20',
op: 'deploy',
tick: 'PEPE',
max: '21000000',
}),
'utf-8'
);
const insert: InscriptionRevealData = {
inscription: {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
number: 0,
classic_number: 0,
mime_type: 'application/json',
content_type: 'application/json',
content_length: content.length,
content: `0x${content.toString('hex')}`,
fee: '200',
curse_type: null,
sat_ordinal: '2000000',
sat_rarity: 'common',
sat_coinbase_height: 110,
recursive: false,
metadata: null,
parent: null,
},
recursive_refs: [],
location: {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
block_height: 830000,
block_hash: '00000000000000000002c5c0aba96f981642a6dca109e6b3564925c21a98aa3e',
tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
tx_index: 0,
address: '',
output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0',
offset: '0',
prev_output: null,
prev_offset: null,
value: '0',
transfer_type: DbLocationTransferType.spentInFees,
block_transfer_index: null,
timestamp: 1091091019,
},
};
expect(brc20FromInscription(insert)).toBeUndefined();
});

test('ignores burnt inscriptions', () => {
const content = Buffer.from(
JSON.stringify({
p: 'brc-20',
op: 'deploy',
tick: 'PEPE',
max: '21000000',
}),
'utf-8'
);
const insert: InscriptionRevealData = {
inscription: {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
number: 0,
classic_number: 0,
mime_type: 'application/json',
content_type: 'application/json',
content_length: content.length,
content: `0x${content.toString('hex')}`,
fee: '200',
curse_type: null,
sat_ordinal: '2000000',
sat_rarity: 'common',
sat_coinbase_height: 110,
recursive: false,
metadata: null,
parent: null,
},
recursive_refs: [],
location: {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
block_height: 830000,
block_hash: '00000000000000000002c5c0aba96f981642a6dca109e6b3564925c21a98aa3e',
tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
tx_index: 0,
address: '',
output: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0',
offset: '0',
prev_output: null,
prev_offset: null,
value: '1000',
transfer_type: DbLocationTransferType.burnt,
block_transfer_index: null,
timestamp: 1091091019,
},
};
expect(brc20FromInscription(insert)).toBeUndefined();
});

test('ignores incorrect p field', () => {
const insert = testInsert({
p: 'brc20', // incorrect
Expand Down
Loading