Browse Source

blocks: WIP attempt to identify miner (via payout address)

refactor
Hampus Sjöberg 4 years ago
parent
commit
db89802e91
  1. 14
      blocks/index.ts
  2. 2
      index.ts
  3. 2
      jsonrpc/index.ts

14
blocks/index.ts

@ -20,7 +20,8 @@ async function createBlock(height: number): Promise<IBlock> {
const generationTransactionTxId = block.tx[0]; const generationTransactionTxId = block.tx[0];
const generationTransaction = await getrawtransaction(generationTransactionTxId, block.hash); 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 = (() => { const miner = (() => {
for (const [tag, minerInfo] of Object.entries(miners.coinbase_tags)) { for (const [tag, minerInfo] of Object.entries(miners.coinbase_tags)) {
@ -28,6 +29,13 @@ async function createBlock(height: number): Promise<IBlock> {
return minerInfo.name; return minerInfo.name;
} }
} }
for (const [tag, minerInfo] of Object.entries(miners.payout_addresses)) {
if (payoutAddress == tag) {
return minerInfo.name;
}
}
return undefined; return undefined;
})(); })();
@ -43,6 +51,7 @@ async function createBlock(height: number): Promise<IBlock> {
async function setupPeriod(blockCount: number, startHeight: number, endHeight: number): Promise<IBlock[]> { async function setupPeriod(blockCount: number, startHeight: number, endHeight: number): Promise<IBlock[]> {
const blocks: IBlock[] = []; const blocks: IBlock[] = [];
for (let i = startHeight; i < endHeight; i++) { for (let i = startHeight; i < endHeight; i++) {
console.log(`Fetching: ${i}`);
if (i > blockCount) { if (i > blockCount) {
blocks.push({ blocks.push({
height: i, height: i,
@ -78,7 +87,6 @@ export async function bootstrapBlocks() {
console.log("Found new block"); console.log("Found new block");
if (newBlockCount % 2016 === 0) { if (newBlockCount % 2016 === 0) {
blockCount = newBlockCount; blockCount = newBlockCount;
console.log("New block period!");
const difficultyPeriodStartHeight = blockCount - (blockCount % 2016); const difficultyPeriodStartHeight = blockCount - (blockCount % 2016);
const difficultyPeriodEndHeight = difficultyPeriodStartHeight + 2016; const difficultyPeriodEndHeight = difficultyPeriodStartHeight + 2016;
@ -96,7 +104,7 @@ export async function bootstrapBlocks() {
} }
}, 10 * 1000); }, 10 * 1000);
console.log("Done."); console.log("Bootstrapping done.");
} }
export function getBlocks() { export function getBlocks() {

2
index.ts

@ -4,7 +4,7 @@ import config from "./config/config.ts";
import router from "./api/index.ts"; import router from "./api/index.ts";
import { bootstrapBlocks } from "./blocks/index.ts"; import { bootstrapBlocks } from "./blocks/index.ts";
await bootstrapBlocks(); bootstrapBlocks();
const app = new Application(); const app = new Application();

2
jsonrpc/index.ts

@ -103,7 +103,7 @@ interface IGetrawtransaction {
{ {
value: number; value: number;
n: number; n: number;
scriptPubKey: { scriptPubKey?: {
asm: string; asm: string;
hex: string; hex: string;
reqSigs: number; reqSigs: number;

Loading…
Cancel
Save