bitcoin/script.c: Add scriptpubkey_opreturn_padded, which creates an OP_RETURN with a pointless random 20-byte padding.

In the case of `donateutxo`, this is needed since a simple spend of a P2WPKH to an `OP_RETURN` would be below the minimum transaction size.
Sizes below 20 are not plausible as commitments.
This commit is contained in:
ZmnSCPxj jxPCSnmZ
2020-09-08 12:52:41 +09:30
committed by Rusty Russell
parent ee276bcb86
commit 6c13e9b300
2 changed files with 16 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
#include <common/utils.h>
#include <sodium/randombytes.h>
/* 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,