2015-06-12 12:26:59 +09:30
|
|
|
#include "bitcoin/script.h"
|
|
|
|
#include "bitcoin/tx.h"
|
|
|
|
#include "find_p2sh_out.h"
|
2016-01-22 06:38:08 +10:30
|
|
|
#include <ccan/err/err.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
#include <string.h>
|
2015-06-08 15:24:10 +09:30
|
|
|
|
2016-04-24 19:56:35 +09:30
|
|
|
static u32 find_output(const struct bitcoin_tx *tx, const u8 *scriptpubkey)
|
2015-06-08 15:24:10 +09:30
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < tx->output_count; i++) {
|
2016-05-02 15:59:56 +09:30
|
|
|
if (scripteq(tx->output[i].script,
|
|
|
|
tx->output[i].script_length,
|
|
|
|
scriptpubkey,
|
|
|
|
tal_count(scriptpubkey)))
|
2015-06-08 15:24:10 +09:30
|
|
|
break;
|
|
|
|
}
|
2016-01-22 06:45:28 +10:30
|
|
|
/* FIXME: Return failure! */
|
2015-06-08 15:24:10 +09:30
|
|
|
if (i == tx->output_count)
|
|
|
|
errx(1, "No matching output in tx");
|
2016-04-24 19:56:35 +09:30
|
|
|
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;
|
|
|
|
}
|