From db89802e91c7598b5ca4824ced4ccb1282194890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Wed, 28 Apr 2021 17:18:01 +0200 Subject: [PATCH] blocks: WIP attempt to identify miner (via payout address) --- blocks/index.ts | 14 +++++++++++--- index.ts | 2 +- jsonrpc/index.ts | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/blocks/index.ts b/blocks/index.ts index 8281d7d..1e9565c 100644 --- a/blocks/index.ts +++ b/blocks/index.ts @@ -20,7 +20,8 @@ async function createBlock(height: number): Promise { const generationTransactionTxId = block.tx[0]; const generationTransaction = await getrawtransaction(generationTransactionTxId, block.hash); - const coinbase = hexToAscii(generationTransaction.vin[0].coinbase ?? ""); + const payoutAddress = generationTransaction.vout[0]?.scriptPubKey?.addresses?.[0] ?? ""; + const coinbase = hexToAscii(generationTransaction.vin?.[0]?.coinbase ?? ""); const miner = (() => { for (const [tag, minerInfo] of Object.entries(miners.coinbase_tags)) { @@ -28,6 +29,13 @@ async function createBlock(height: number): Promise { return minerInfo.name; } } + + for (const [tag, minerInfo] of Object.entries(miners.payout_addresses)) { + if (payoutAddress == tag) { + return minerInfo.name; + } + } + return undefined; })(); @@ -43,6 +51,7 @@ async function createBlock(height: number): Promise { async function setupPeriod(blockCount: number, startHeight: number, endHeight: number): Promise { const blocks: IBlock[] = []; for (let i = startHeight; i < endHeight; i++) { + console.log(`Fetching: ${i}`); if (i > blockCount) { blocks.push({ height: i, @@ -78,7 +87,6 @@ export async function bootstrapBlocks() { console.log("Found new block"); if (newBlockCount % 2016 === 0) { blockCount = newBlockCount; - console.log("New block period!"); const difficultyPeriodStartHeight = blockCount - (blockCount % 2016); const difficultyPeriodEndHeight = difficultyPeriodStartHeight + 2016; @@ -96,7 +104,7 @@ export async function bootstrapBlocks() { } }, 10 * 1000); - console.log("Done."); + console.log("Bootstrapping done."); } export function getBlocks() { diff --git a/index.ts b/index.ts index 97ea41f..5dd78b8 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,7 @@ import config from "./config/config.ts"; import router from "./api/index.ts"; import { bootstrapBlocks } from "./blocks/index.ts"; -await bootstrapBlocks(); +bootstrapBlocks(); const app = new Application(); diff --git a/jsonrpc/index.ts b/jsonrpc/index.ts index 9834555..1d8bb0a 100644 --- a/jsonrpc/index.ts +++ b/jsonrpc/index.ts @@ -103,7 +103,7 @@ interface IGetrawtransaction { { value: number; n: number; - scriptPubKey: { + scriptPubKey?: { asm: string; hex: string; reqSigs: number;