Store hex in coinbase raw - Improve scripsig parsing
This commit is contained in:
parent
94dbec46cf
commit
ffb5db69a8
@ -108,7 +108,7 @@ class Blocks {
|
|||||||
const blockExtended: BlockExtended = Object.assign({ extras: {} }, block);
|
const blockExtended: BlockExtended = Object.assign({ extras: {} }, block);
|
||||||
blockExtended.extras.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0);
|
blockExtended.extras.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0);
|
||||||
blockExtended.extras.coinbaseTx = transactionUtils.stripCoinbaseTransaction(transactions[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) {
|
if (block.height === 0) {
|
||||||
blockExtended.extras.medianFee = 0; // 50th percentiles
|
blockExtended.extras.medianFee = 0; // 50th percentiles
|
||||||
|
@ -175,12 +175,6 @@ class DatabaseMigration {
|
|||||||
await this.$executeQuery(connection, 'ALTER TABLE `hashrates` MODIFY `pool_id` SMALLINT UNSIGNED NOT NULL DEFAULT "0"');
|
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();
|
connection.release();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
connection.release();
|
connection.release();
|
||||||
|
@ -45,21 +45,12 @@ class TransactionUtils {
|
|||||||
return transactionExtended;
|
return transactionExtended;
|
||||||
}
|
}
|
||||||
|
|
||||||
public hex2ascii(hex: string): string {
|
public hex2ascii(hex: string) {
|
||||||
const opPush = hex.split(' ').filter((_, i, a) => i > 0 && /^OP_PUSH/.test(a[i - 1]));
|
let str = '';
|
||||||
|
|
||||||
if (opPush[0]) {
|
|
||||||
hex = opPush[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hex) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
const bytes: number[] = [];
|
|
||||||
for (let i = 0; i < hex.length; i += 2) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class BlocksRepository {
|
|||||||
block.size,
|
block.size,
|
||||||
block.weight,
|
block.weight,
|
||||||
block.tx_count,
|
block.tx_count,
|
||||||
connection.escape(block.extras.coinbaseRaw),
|
block.extras.coinbaseRaw,
|
||||||
block.difficulty,
|
block.difficulty,
|
||||||
block.extras.pool?.id, // Should always be set to something
|
block.extras.pool?.id, // Should always be set to something
|
||||||
block.extras.totalFees,
|
block.extras.totalFees,
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
onError="this.src = './resources/mining-pools/default.svg'">
|
onError="this.src = './resources/mining-pools/default.svg'">
|
||||||
<span class="pool-name">{{ block.extras.pool.name }}</span>
|
<span class="pool-name">{{ block.extras.pool.name }}</span>
|
||||||
</a>
|
</a>
|
||||||
<span class="tooltiptext">{{ block.extras.coinbaseRaw }}</span>
|
<span class="tooltiptext">{{ block.extras.coinbaseRaw | hex2ascii }}</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="timestamp" *ngIf="!widget">
|
<td class="timestamp" *ngIf="!widget">
|
||||||
|
@ -19,7 +19,7 @@ export class Hex2asciiPipe implements PipeTransform {
|
|||||||
for (let i = 0; i < hex.length; i += 2) {
|
for (let i = 0; i < hex.length; i += 2) {
|
||||||
bytes.push(parseInt(hex.substr(i, 2), 16));
|
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, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user