2015-06-12 03:56:59 +01:00
|
|
|
#include "bitcoin/script.h"
|
|
|
|
#include "bitcoin/tx.h"
|
|
|
|
#include "find_p2sh_out.h"
|
2016-01-21 20:08:08 +00:00
|
|
|
#include <ccan/err/err.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
#include <string.h>
|
2015-06-08 06:54:10 +01:00
|
|
|
|
2016-04-24 11:26:35 +01:00
|
|
|
static u32 find_output(const struct bitcoin_tx *tx, const u8 *scriptpubkey)
|
2015-06-08 06:54:10 +01:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
2017-01-24 23:35:43 +00:00
|
|
|
for (i = 0; i < tal_count(tx->output); i++) {
|
|
|
|
if (scripteq(tx->output[i].script, scriptpubkey))
|
2015-06-08 06:54:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-01-21 20:15:28 +00:00
|
|
|
/* FIXME: Return failure! */
|
2017-01-24 23:35:43 +00:00
|
|
|
if (i == tal_count(tx->output))
|
2015-06-08 06:54:10 +01:00
|
|
|
errx(1, "No matching output in tx");
|
2016-04-24 11:26:35 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 find_p2wsh_out(const struct bitcoin_tx *tx, const u8 *witnessscript)
|
|
|
|
{
|
|
|
|
/* This is the scriptPubKey commit tx will have */
|
|
|
|
u8 *p2wsh = scriptpubkey_p2wsh(NULL, witnessscript);
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
i = find_output(tx, p2wsh);
|
|
|
|
tal_free(p2wsh);
|
|
|
|
return i;
|
|
|
|
}
|