2015-05-28 23:38:27 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_SCRIPT_H
|
|
|
|
#define LIGHTNING_BITCOIN_SCRIPT_H
|
2016-01-21 21:08:08 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "signature.h"
|
2016-04-24 12:24:35 +02:00
|
|
|
#include "tx.h"
|
2015-05-28 23:38:27 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
|
|
|
|
struct bitcoin_address;
|
2016-04-12 05:37:04 +02:00
|
|
|
struct bitcoin_tx_input;
|
2015-06-02 06:03:21 +02:00
|
|
|
struct pubkey;
|
2015-06-02 06:08:38 +02:00
|
|
|
struct sha256;
|
2016-01-21 21:08:08 +01:00
|
|
|
struct rel_locktime;
|
|
|
|
struct abs_locktime;
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2015-06-04 08:16:49 +02:00
|
|
|
/* A bitcoin signature includes one byte for the type. */
|
|
|
|
struct bitcoin_signature {
|
|
|
|
struct signature sig;
|
|
|
|
enum sighash_type stype;
|
|
|
|
};
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
/* tal_count() gives the length of the script. */
|
|
|
|
u8 *bitcoin_redeem_2of2(const tal_t *ctx,
|
2015-06-02 06:03:21 +02:00
|
|
|
const struct pubkey *key1,
|
|
|
|
const struct pubkey *key2);
|
2015-05-28 23:38:27 +02:00
|
|
|
|
|
|
|
/* tal_count() gives the length of the script. */
|
2015-06-02 06:03:21 +02:00
|
|
|
u8 *bitcoin_redeem_single(const tal_t *ctx, const struct pubkey *key);
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2015-07-24 08:30:10 +02:00
|
|
|
/* A common script pattern: A can have it with secret, or B can have
|
|
|
|
* it after delay. */
|
|
|
|
u8 *bitcoin_redeem_secret_or_delay(const tal_t *ctx,
|
|
|
|
const struct pubkey *delayed_key,
|
2016-01-21 21:08:08 +01:00
|
|
|
const struct rel_locktime *locktime,
|
2015-07-24 08:30:10 +02:00
|
|
|
const struct pubkey *key_if_secret_known,
|
|
|
|
const struct sha256 *hash_of_secret);
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
/* Create an output script using p2sh for this redeem script. */
|
|
|
|
u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript);
|
|
|
|
|
2016-04-12 05:37:04 +02:00
|
|
|
/* Create the redeemscript for a P2SH + P2WPKH. */
|
|
|
|
u8 *bitcoin_redeem_p2wpkh(const tal_t *ctx, const struct pubkey *key);
|
|
|
|
|
|
|
|
/* Create a witness which spends the 2of2. */
|
|
|
|
void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
|
|
|
|
struct bitcoin_tx_input *input,
|
|
|
|
const struct bitcoin_signature *sig,
|
|
|
|
const struct pubkey *key);
|
|
|
|
|
2016-04-12 05:36:51 +02:00
|
|
|
/* Create scriptcode (fake witness, basically) for P2WPKH */
|
|
|
|
u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key);
|
|
|
|
|
2015-08-07 05:15:30 +02:00
|
|
|
u8 *scriptpubkey_htlc_send(const tal_t *ctx,
|
|
|
|
const struct pubkey *ourkey,
|
|
|
|
const struct pubkey *theirkey,
|
2016-01-21 21:08:08 +01:00
|
|
|
const struct abs_locktime *htlc_abstimeout,
|
|
|
|
const struct rel_locktime *locktime,
|
2015-08-07 05:15:30 +02:00
|
|
|
const struct sha256 *commit_revoke,
|
|
|
|
const struct sha256 *rhash);
|
|
|
|
|
|
|
|
/* Create a script for our HTLC output: receiving. */
|
|
|
|
u8 *scriptpubkey_htlc_recv(const tal_t *ctx,
|
|
|
|
const struct pubkey *ourkey,
|
|
|
|
const struct pubkey *theirkey,
|
2016-01-21 21:08:08 +01:00
|
|
|
const struct abs_locktime *htlc_abstimeout,
|
|
|
|
const struct rel_locktime *locktime,
|
2015-08-07 05:15:30 +02:00
|
|
|
const struct sha256 *commit_revoke,
|
|
|
|
const struct sha256 *rhash);
|
|
|
|
|
2016-04-24 12:24:35 +02:00
|
|
|
/* Create an output script for a 32-byte witness. */
|
|
|
|
u8 *scriptpubkey_p2wsh(const tal_t *ctx, const u8 *witnessscript);
|
|
|
|
|
|
|
|
/* Create a witness which spends the 2of2. */
|
|
|
|
u8 **bitcoin_witness_2of2(const tal_t *ctx,
|
|
|
|
const struct bitcoin_signature *sig1,
|
|
|
|
const struct bitcoin_signature *sig2,
|
|
|
|
const struct pubkey *key1,
|
|
|
|
const struct pubkey *key2);
|
|
|
|
|
2015-06-02 06:10:00 +02:00
|
|
|
/* Create an input script to accept pay to pubkey */
|
|
|
|
u8 *scriptsig_p2sh_2of2(const tal_t *ctx,
|
2015-06-04 08:16:49 +02:00
|
|
|
const struct bitcoin_signature *sig1,
|
|
|
|
const struct bitcoin_signature *sig2,
|
2015-06-02 06:10:00 +02:00
|
|
|
const struct pubkey *key1,
|
|
|
|
const struct pubkey *key2);
|
|
|
|
|
2015-07-24 08:30:10 +02:00
|
|
|
/* Create an input script to solve by secret */
|
|
|
|
u8 *scriptsig_p2sh_secret(const tal_t *ctx,
|
|
|
|
const void *secret, size_t secret_len,
|
2015-06-05 09:52:54 +02:00
|
|
|
const struct bitcoin_signature *sig,
|
2015-07-24 08:30:10 +02:00
|
|
|
const u8 *redeemscript,
|
2015-06-05 09:52:54 +02:00
|
|
|
size_t redeem_len);
|
|
|
|
|
2015-06-02 06:10:00 +02:00
|
|
|
/* Is this a pay to script hash? */
|
|
|
|
bool is_p2sh(const u8 *script, size_t script_len);
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_SCRIPT_H */
|