Store hex in coinbase raw - Improve scripsig parsing

This commit is contained in:
nymkappa 2022-03-16 12:10:18 +01:00
parent 94dbec46cf
commit ffb5db69a8
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
6 changed files with 8 additions and 23 deletions

View File

@ -108,7 +108,7 @@ class Blocks {
const blockExtended: BlockExtended = Object.assign({ extras: {} }, block);
blockExtended.extras.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0);
blockExtended.extras.coinbaseTx = transactionUtils.stripCoinbaseTransaction(transactions[0]);
blockExtended.extras.coinbaseRaw = transactionUtils.hex2ascii(blockExtended.extras.coinbaseTx.vin[0].scriptsig);
blockExtended.extras.coinbaseRaw = blockExtended.extras.coinbaseTx.vin[0].scriptsig;
if (block.height === 0) {
blockExtended.extras.medianFee = 0; // 50th percentiles

View File

@ -175,12 +175,6 @@ class DatabaseMigration {
await this.$executeQuery(connection, 'ALTER TABLE `hashrates` MODIFY `pool_id` SMALLINT UNSIGNED NOT NULL DEFAULT "0"');
}
if (databaseSchemaVersion < 15 && isBitcoin === true) {
logger.warn(`'blocks' table has been truncated. Re-indexing from scratch.`);
await this.$executeQuery(connection, 'TRUNCATE blocks;'); // Need to re-index
await this.$executeQuery(connection, 'ALTER TABLE `blocks` MODIFY `coinbase_raw` TEXT COLLATE "utf8mb4_general_ci" NULL ');
}
connection.release();
} catch (e) {
connection.release();

View File

@ -45,21 +45,12 @@ class TransactionUtils {
return transactionExtended;
}
public hex2ascii(hex: string): string {
const opPush = hex.split(' ').filter((_, i, a) => i > 0 && /^OP_PUSH/.test(a[i - 1]));
if (opPush[0]) {
hex = opPush[0];
}
if (!hex) {
return '';
}
const bytes: number[] = [];
public hex2ascii(hex: string) {
let str = '';
for (let i = 0; i < hex.length; i += 2) {
bytes.push(parseInt(hex.substr(i, 2), 16));
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return new TextDecoder('utf8').decode(Uint8Array.from(bytes));
return str;
}
}

View File

@ -32,7 +32,7 @@ class BlocksRepository {
block.size,
block.weight,
block.tx_count,
connection.escape(block.extras.coinbaseRaw),
block.extras.coinbaseRaw,
block.difficulty,
block.extras.pool?.id, // Should always be set to something
block.extras.totalFees,

View File

@ -30,7 +30,7 @@
onError="this.src = './resources/mining-pools/default.svg'">
<span class="pool-name">{{ block.extras.pool.name }}</span>
</a>
<span class="tooltiptext">{{ block.extras.coinbaseRaw }}</span>
<span class="tooltiptext">{{ block.extras.coinbaseRaw | hex2ascii }}</span>
</div>
</td>
<td class="timestamp" *ngIf="!widget">

View File

@ -19,7 +19,7 @@ export class Hex2asciiPipe implements PipeTransform {
for (let i = 0; i < hex.length; i += 2) {
bytes.push(parseInt(hex.substr(i, 2), 16));
}
return new TextDecoder('utf8').decode(Uint8Array.from(bytes));
return new TextDecoder('utf8').decode(Uint8Array.from(bytes)).replace(/\uFFFD/g, '').replace(/\\0/g, '');
}
}