diff --git a/bitcoin_script.c b/bitcoin_script.c index 321cad60a..dea52d29a 100644 --- a/bitcoin_script.c +++ b/bitcoin_script.c @@ -166,19 +166,19 @@ u8 *scriptsig_pay_to_pubkeyhash(const tal_t *ctx, } /* Is this a normal pay to pubkey hash? */ -bool is_pay_to_pubkey_hash(const ProtobufCBinaryData *script) +bool is_pay_to_pubkey_hash(const u8 *script, size_t script_len) { - if (script->len != 25) + if (script_len != 25) return false; - if (script->data[0] != OP_DUP) + if (script[0] != OP_DUP) return false; - if (script->data[1] != OP_HASH160) + if (script[1] != OP_HASH160) return false; - if (script->data[2] != OP_PUSHBYTES(20)) + if (script[2] != OP_PUSHBYTES(20)) return false; - if (script->data[23] != OP_EQUALVERIFY) + if (script[23] != OP_EQUALVERIFY) return false; - if (script->data[24] != OP_CHECKSIG) + if (script[24] != OP_CHECKSIG) return false; return true; } @@ -191,15 +191,12 @@ u8 *bitcoin_redeem_revocable(const tal_t *ctx, const struct pubkey *mykey, u32 locktime, const struct pubkey *theirkey, - const Sha256Hash *revocation_hash) + const struct sha256 *rhash) { u8 *script = tal_arr(ctx, u8, 0); - struct sha256 rhash; u8 rhash_ripemd[RIPEMD160_DIGEST_LENGTH]; le32 locktime_le = cpu_to_le32(locktime); - proto_to_sha256(revocation_hash, &rhash); - /* If there are two args: */ add_op(&script, OP_DEPTH); add_op(&script, OP_1SUB); @@ -212,7 +209,7 @@ u8 *bitcoin_redeem_revocable(const tal_t *ctx, add_op(&script, OP_IF); /* Must hash to revocation_hash, and be signed by them. */ - RIPEMD160(rhash.u.u8, sizeof(rhash.u), rhash_ripemd); + RIPEMD160(rhash->u.u8, sizeof(rhash->u), rhash_ripemd); add_op(&script, OP_HASH160); add_push_bytes(&script, rhash_ripemd, sizeof(rhash_ripemd)); add_op(&script, OP_EQUALVERIFY); diff --git a/bitcoin_script.h b/bitcoin_script.h index 2465cc0e9..6277d9770 100644 --- a/bitcoin_script.h +++ b/bitcoin_script.h @@ -2,11 +2,11 @@ #define LIGHTNING_BITCOIN_SCRIPT_H #include #include -#include "lightning.pb-c.h" struct bitcoin_address; struct pubkey; struct signature; +struct sha256; /* tal_count() gives the length of the script. */ u8 *bitcoin_redeem_2of2(const tal_t *ctx, @@ -24,7 +24,7 @@ u8 *bitcoin_redeem_revocable(const tal_t *ctx, const struct pubkey *mykey, u32 locktime, const struct pubkey *theirkey, - const Sha256Hash *revocation_hash); + const struct sha256 *revocation_hash); /* Create an output script using p2sh for this redeem script. */ u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript); @@ -39,6 +39,6 @@ u8 *scriptsig_pay_to_pubkeyhash(const tal_t *ctx, const struct signature *sig); /* Is this a normal pay to pubkey hash? */ -bool is_pay_to_pubkey_hash(const ProtobufCBinaryData *script); +bool is_pay_to_pubkey_hash(const u8 *script, size_t script_len); #endif /* LIGHTNING_BITCOIN_SCRIPT_H */ diff --git a/commit_tx.c b/commit_tx.c index e5b8ab9c5..52e371bda 100644 --- a/commit_tx.c +++ b/commit_tx.c @@ -4,6 +4,7 @@ #include "bitcoin_script.h" #include "permute_tx.h" #include "pubkey.h" +#include "pkt.h" struct bitcoin_tx *create_commit_tx(const tal_t *ctx, OpenChannel *ours, @@ -14,6 +15,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, struct bitcoin_tx *tx; const u8 *redeemscript; struct pubkey ourkey, theirkey; + struct sha256 redeem; /* Now create commitment tx: one input, two outputs. */ tx = bitcoin_tx(ctx, 1, 2); @@ -26,12 +28,13 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, return tal_free(tx); if (!proto_to_pubkey(theirs->anchor->pubkey, &theirkey)) return tal_free(tx); + proto_to_sha256(ours->revocation_hash, &redeem); /* First output is a P2SH to a complex redeem script (usu. for me) */ redeemscript = bitcoin_redeem_revocable(tx, &ourkey, ours->locktime_seconds, &theirkey, - ours->revocation_hash); + &redeem); tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript); tx->output[0].script_length = tal_count(tx->output[0].script); diff --git a/open-anchor-sig.c b/open-anchor-sig.c index 105685aa1..ad4363899 100644 --- a/open-anchor-sig.c +++ b/open-anchor-sig.c @@ -35,7 +35,7 @@ static u8 *tx_scriptsig(const tal_t *ctx, if (!sig) return NULL; - if (!is_pay_to_pubkey_hash(&input->subscript)) + if (!is_pay_to_pubkey_hash(input->subscript.data, input->subscript.len)) errx(1, "FIXME: Don't know how to handle input"); bitcoin_address(pubkey, &addr); return scriptsig_pay_to_pubkeyhash(ctx, &addr, sig);