Browse Source
Really only for our silly little utils. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
10 years ago
6 changed files with 52 additions and 50 deletions
@ -0,0 +1,24 @@ |
|||
#include "find_p2sh_out.h" |
|||
#include "bitcoin_tx.h" |
|||
#include "bitcoin_script.h" |
|||
#include <string.h> |
|||
#include <ccan/err/err.h> |
|||
#include <ccan/tal/tal.h> |
|||
|
|||
u32 find_p2sh_out(const struct bitcoin_tx *tx, u8 *redeemscript) |
|||
{ |
|||
/* This is the scriptPubKey commit tx will have */ |
|||
u8 *p2sh = scriptpubkey_p2sh(NULL, redeemscript); |
|||
u32 i; |
|||
|
|||
for (i = 0; i < tx->output_count; i++) { |
|||
if (tx->output[i].script_length != tal_count(p2sh)) |
|||
continue; |
|||
if (memcmp(tx->output[i].script, p2sh, tal_count(p2sh)) == 0) |
|||
break; |
|||
} |
|||
if (i == tx->output_count) |
|||
errx(1, "No matching output in tx"); |
|||
tal_free(p2sh); |
|||
return i; |
|||
} |
@ -0,0 +1,11 @@ |
|||
#ifndef LIGHTNING_FIND_P2SH_OUT_H |
|||
#define LIGHTNING_FIND_P2SH_OUT_H |
|||
#include <ccan/short_types/short_types.h> |
|||
|
|||
struct bitcoin_tx; |
|||
|
|||
/* Normally we'd simply remember which output of the anchor or commit
|
|||
* tx is the one which pays to this script. But for these examples, |
|||
* we have to figure it out by recreating the output and matching. */ |
|||
u32 find_p2sh_out(const struct bitcoin_tx *tx, u8 *redeemscript); |
|||
#endif /* LIGHTNING_FIND_P2SH_OUT_H */ |
Loading…
Reference in new issue