Skip to content

Commit

Permalink
feerate: add a 'common_weight' calculation for a tx
Browse files Browse the repository at this point in the history
The bits of a transaction that are paid by the opener!
  • Loading branch information
niftynei authored and rustyrussell committed Sep 9, 2020
1 parent 6cfac5d commit b2170cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bitcoin/feerate.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <bitcoin/feerate.h>
#include <bitcoin/varint.h>
#include <limits.h>
#include <stdlib.h>

Expand Down Expand Up @@ -38,3 +39,12 @@ const char *feerate_style_name(enum feerate_style style)
}
abort();
}

size_t common_weight(size_t num_inputs, size_t num_outputs)
{
/*(nVersion + num inputs + num outputs + locktime) * 4
* + SegWit marker + SegWit flag */
return (4 + varint_size(num_inputs) +
varint_size(num_outputs) + 4) * 4
+ 1 + 1;
}
5 changes: 5 additions & 0 deletions bitcoin/feerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*/
#define FEERATE_FLOOR 253

/*
* This is the net common weight of a transaction.
*/
size_t common_weight(size_t num_inputs, size_t num_outputs);

enum feerate_style {
FEERATE_PER_KSIPA,
FEERATE_PER_KBYTE
Expand Down

0 comments on commit b2170cf

Please sign in to comment.