mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
onchaind: don't create zero-output txs if fees overwhelm us.
They're illegal. Instead do OP_RETURN so we don't pollute the UTXO. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
27c4e926bd
commit
45e145df5e
3 changed files with 17 additions and 4 deletions
|
@ -22,6 +22,7 @@
|
|||
#define OP_NOTIF 0x64
|
||||
#define OP_ELSE 0x67
|
||||
#define OP_ENDIF 0x68
|
||||
#define OP_RETURN 0x6a
|
||||
#define OP_2DROP 0x6d
|
||||
#define OP_DEPTH 0x74
|
||||
#define OP_DROP 0x75
|
||||
|
@ -214,6 +215,14 @@ u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr)
|
|||
return script;
|
||||
}
|
||||
|
||||
u8 *scriptpubkey_opreturn(const tal_t *ctx)
|
||||
{
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
|
||||
add_op(&script, OP_RETURN);
|
||||
return script;
|
||||
}
|
||||
|
||||
/* Create an input script which spends p2pkh */
|
||||
u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
|
||||
const secp256k1_ecdsa_signature *sig)
|
||||
|
|
|
@ -29,6 +29,9 @@ u8 *scriptpubkey_p2sh_hash(const tal_t *ctx, const struct ripemd160 *redeemhash)
|
|||
/* Create an output script using p2pkh */
|
||||
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 an input script which spends p2pkh */
|
||||
u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
|
||||
const secp256k1_ecdsa_signature *sig);
|
||||
|
|
|
@ -243,10 +243,11 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
|||
+ 1 + 3 + 73 + 0 + tal_len(wscript))
|
||||
/ 1000;
|
||||
|
||||
/* Result is trivial? Just eliminate output. */
|
||||
if (tx->output[0].amount < dust_limit_satoshis + fee)
|
||||
tal_resize(&tx->output, 0);
|
||||
else
|
||||
/* Result is trivial? Spent to OP_RETURN to avoid leaving dust. */
|
||||
if (tx->output[0].amount < dust_limit_satoshis + fee) {
|
||||
tx->output[0].amount = 0;
|
||||
tx->output[0].script = scriptpubkey_opreturn(tx->output);
|
||||
} else
|
||||
tx->output[0].amount -= fee;
|
||||
|
||||
sign_tx_input(tx, 0, NULL, wscript, privkey, pubkey, &sig);
|
||||
|
|
Loading…
Add table
Reference in a new issue