Skip to content

Commit

Permalink
Add %iB for UTXO height.
Browse files Browse the repository at this point in the history
This lets us do analysis like "how long to UTXO entries last".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Dec 29, 2015
1 parent ba2d6c8 commit c53e63d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions doc/bitcoin-iterate.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: bitcoin-iterate
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 06/21/2015
.\" Date: 12/29/2015
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "BITCOIN\-ITERATE" "1" "06/21/2015" "\ \&" "\ \&"
.TH "BITCOIN\-ITERATE" "1" "12/29/2015" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -101,6 +101,7 @@ Print out the format string for each transaction input (in the order they are in
%il: input script length
%is: input script as a hex string
%iN: input number within transaction
%iB: input UTXO block number (0 for coinbase)
%iX: input as a hex string
.fi
.if n \{\
Expand Down Expand Up @@ -198,6 +199,9 @@ bitcoin\-iterate \-\-output=%ol
\fBExample\ \&6.\ \&Print out <block number>,<transaction hash>,<script> for each output\fR
.sp
bitcoin\-iterate \-\-output=%bn,%th,%os
.SH "NOTES"
.sp
Use of \fB%tF\fR or \fB%iB\fR significantly slows iteration, as this requires \fBbitcoin\-iterate\fR to track unspent outputs\&.
.SH "BUGS"
.sp
This manpage documents how it should work, not how it does work\&.
Expand Down
6 changes: 6 additions & 0 deletions doc/bitcoin-iterate.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ OPTIONS
%il: input script length
%is: input script as a hex string
%iN: input number within transaction
%iB: input UTXO block number (0 for coinbase)
%iX: input as a hex string

*--output*='FORMAT'::
Expand Down Expand Up @@ -143,6 +144,11 @@ bitcoin-iterate --output=%ol
bitcoin-iterate --output=%bn,%th,%os
===================================================================

NOTES
-----
Use of *%tF* or *%iB* significantly slows iteration, as this requires
*bitcoin-iterate* to track unspent outputs.

BUGS
----
This manpage documents how it should work, not how it does work.
Expand Down
17 changes: 16 additions & 1 deletion iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ struct utxo {
/* txid */
u8 tx[SHA256_DIGEST_LENGTH];

/* Height. */
unsigned int height;

/* Number of outputs. */
u32 num_outputs;

Expand Down Expand Up @@ -105,6 +108,7 @@ static void add_utxo(struct utxo_map *utxo_map,

memcpy(utxo->tx, t->sha256, sizeof(utxo->tx));
utxo->num_outputs = utxo->unspent_outputs = t->output_count;
utxo->height = b->height;
for (i = 0; i < utxo->num_outputs; i++)
utxo->amount[i] = t->output[i].amount;

Expand Down Expand Up @@ -352,6 +356,14 @@ static void print_format(const char *format,
case 'X':
dump_tx_input(i);
break;
case 'B':
/* Coinbase doesn't have valid input. */
if (i - t->input != 0) {
struct utxo *utxo = utxo_map_get(utxo_map, i->hash);
printf("%u", utxo->height);
} else
printf("0");
break;
default:
goto bad_fmt;
}
Expand Down Expand Up @@ -450,6 +462,7 @@ int main(int argc, char *argv[])
" %is: input script as a hex string\n"
" %iN: input number\n"
" %iX: input in hex\n"
" %iB: input UTXO block number (0 for coinbase)\n"
"Valid output format:\n"
" %oa: output amount\n"
" %ol: output script length\n"
Expand Down Expand Up @@ -631,11 +644,13 @@ int main(int argc, char *argv[])
needs_utxo = false;

/* We need it for fee calculation (can be asked by tx, input
* or output) */
* or output) or UTXO block number */
if (txfmt && strstr(txfmt, "%tF"))
needs_utxo = true;
if (inputfmt && strstr(inputfmt, "%tF"))
needs_utxo = true;
if (inputfmt && strstr(inputfmt, "%iB"))
needs_utxo = true;
if (outputfmt && strstr(outputfmt, "%tF"))
needs_utxo = true;

Expand Down

0 comments on commit c53e63d

Please sign in to comment.