Browse Source
This behavior will be specified in BOLT #3. Closes: #14 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
9 years ago
4 changed files with 45 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||
#include "remove_dust.h" |
|||
#include <assert.h> |
|||
#include <stdbool.h> |
|||
#include <string.h> |
|||
|
|||
void remove_dust(struct bitcoin_tx *tx, int *map) |
|||
{ |
|||
size_t i, j, num = tx->output_count; |
|||
|
|||
assert(tal_count(map) == num); |
|||
/* Do it in map order so we can remove from map, too */ |
|||
for (i = 0; i < num; i++) { |
|||
assert(map[i] < tx->output_count); |
|||
if (tx->output[map[i]].amount >= DUST_THRESHOLD) |
|||
continue; |
|||
|
|||
/* Eliminate that output from tx */ |
|||
tx->output_count--; |
|||
memmove(tx->output + map[i], tx->output + map[i] + 1, |
|||
(tx->output_count-map[i]) * sizeof(*tx->output)); |
|||
|
|||
/* Fixup map. */ |
|||
for (j = 0; j < num; j++) |
|||
if (map[j] > map[i]) |
|||
map[j]--; |
|||
map[i] = -1; |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
#ifndef LIGHTNING_REMOVE_DUST_H |
|||
#define LIGHTNING_REMOVE_DUST_H |
|||
#include "config.h" |
|||
#include "bitcoin/tx.h" |
|||
|
|||
/* Remove all dust outputs from tx */ |
|||
void remove_dust(struct bitcoin_tx *tx, int *map); |
|||
|
|||
/* Less than this is dust. */ |
|||
#define DUST_THRESHOLD 546 |
|||
|
|||
#endif /* LIGHTNING_REMOVE_DUST_H */ |
Loading…
Reference in new issue