-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcountTransactionsManyInputs.php
55 lines (47 loc) · 1.68 KB
/
countTransactionsManyInputs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// This script examines all transactions in a given block height range
// and counts how many had over 50 inputs, categorizing them by segwit or nonsegwit spends
require 'vendor/autoload.php';
use Denpa\Bitcoin\Client as BitcoinClient;
$bitcoind = new BitcoinClient('http://username:password@localhost:8332/');
$startHeight = $height = 480000; // start height
$maxBlockHeight = $bitcoind->getBlockchaininfo()->get('blocks');
$heightRange = $maxBlockHeight - $height;
$txByBlock = array();
$segwitTxByBlock = array();
// initialize start block vars
$currentBlockHash = $bitcoind->getBlockhash($height)->get();
$block = $bitcoind->getBlock($currentBlockHash, 2);
$height++;
while ($height < $maxBlockHeight) {
$block = $bitcoind->getBlock($block->get('nextblockhash'), 2);
$txByBlock[$height] = $segwitTxByBlock[$height] = 0;
foreach ($block->get('tx') as $transaction) {
if (count($transaction['vin']) > 50) {
// if txid !== hash then it spends segwit inputs
if ($transaction['txid'] != $transaction['hash']) {
$segwitTxByBlock[$height]++;
} else {
$txByBlock[$height]++;
}
}
}
if ($height % 1000 == 0) {
$complete = round(100*(($height - $startHeight) / $heightRange),2);
echo "$complete%\n";
}
$height++;
}
ksort($txByBlock);
ksort($segwitTxByBlock);
$legacyTransactions = $segwitTransactions = 0;
echo "Block Height,Legacy Transactions, Segwit Transactions:\n";
foreach ($txByBlock as $height => $count) {
if ($height % 1000 != 0) {
$legacyTransactions += $count;
$segwitTransactions += $segwitTxByBlock[$height];
} else {
echo "$height,$legacyTransactions,$segwitTransactions\n";
$legacyTransactions = $segwitTransactions = 0;
}
}