Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
45e145df5e
  1. 9
      bitcoin/script.c
  2. 3
      bitcoin/script.h
  3. 9
      onchaind/onchain.c

9
bitcoin/script.c

@ -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)

3
bitcoin/script.h

@ -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);

9
onchaind/onchain.c

@ -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…
Cancel
Save