Browse Source

feerate: add a 'common_weight' calculation for a tx

The bits of a transaction that are paid by the opener!
bump-pyln-proto
niftynei 4 years ago
committed by Rusty Russell
parent
commit
b2170cf3f4
  1. 10
      bitcoin/feerate.c
  2. 5
      bitcoin/feerate.h

10
bitcoin/feerate.c

@ -1,4 +1,5 @@
#include <bitcoin/feerate.h>
#include <bitcoin/varint.h>
#include <limits.h>
#include <stdlib.h>
@ -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
bitcoin/feerate.h

@ -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

Loading…
Cancel
Save