diff --git a/bitcoin/script.c b/bitcoin/script.c index d10fa6b5f..0ba9dcdc3 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -9,6 +9,7 @@ #include #include #include +#include /* Some standard ops */ #define OP_0 0x00 @@ -221,6 +222,16 @@ u8 *scriptpubkey_opreturn(const tal_t *ctx) add_op(&script, OP_RETURN); return script; } +u8 *scriptpubkey_opreturn_padded(const tal_t *ctx) +{ + u8 *script = tal_arr(ctx, u8, 0); + u8 random[20]; + randombytes_buf(random, sizeof(random)); + + add_op(&script, OP_RETURN); + script_push_bytes(&script, random, sizeof(random)); + return script; +} /* Create an input script which spends p2pkh */ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey, diff --git a/bitcoin/script.h b/bitcoin/script.h index 6a7e14fe1..30b4c3f6c 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -30,6 +30,11 @@ u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr); /* Create a prunable output script */ u8 *scriptpubkey_opreturn(const tal_t *ctx); +/* Create a prunable output script with 20 random bytes. + * This is needed since a spend from a p2wpkh to an `OP_RETURN` without + * any other outputs would result in a transaction smaller than the + * minimum size. */ +u8 *scriptpubkey_opreturn_padded(const tal_t *ctx); /* Create an input script which spends p2pkh */ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,