diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 700cc4b63..922c0e639 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -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 diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 245f260f8..ffa9041e3 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -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(); diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index b5def870c..2e669d709 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -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; } } diff --git a/backend/src/repositories/BlocksRepository.ts b/backend/src/repositories/BlocksRepository.ts index add99f1fd..4ac0a9d9d 100644 --- a/backend/src/repositories/BlocksRepository.ts +++ b/backend/src/repositories/BlocksRepository.ts @@ -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, diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.html b/frontend/src/app/components/blocks-list/blocks-list.component.html index 4e81c44f2..cb301e992 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.html +++ b/frontend/src/app/components/blocks-list/blocks-list.component.html @@ -30,7 +30,7 @@ onError="this.src = './resources/mining-pools/default.svg'"> {{ block.extras.pool.name }} - {{ block.extras.coinbaseRaw }} + {{ block.extras.coinbaseRaw | hex2ascii }}