mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
create-steal-tx: fix it.
Couldn't be tested until we could generate updates; fixed now. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
975a5b2041
commit
96585e1b00
@ -24,8 +24,9 @@
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||||
struct sha256 revoke, revoke_hash;
|
struct sha256 revoke_preimage, revoke_hash;
|
||||||
OpenChannel *o2;
|
OpenChannel *o1, *o2;
|
||||||
|
Pkt *pkt;
|
||||||
struct bitcoin_tx *commit, *tx;
|
struct bitcoin_tx *commit, *tx;
|
||||||
u8 *tx_arr, *redeemscript, *p2sh;
|
u8 *tx_arr, *redeemscript, *p2sh;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -38,20 +39,30 @@ int main(int argc, char *argv[])
|
|||||||
err_set_progname(argv[0]);
|
err_set_progname(argv[0]);
|
||||||
|
|
||||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||||
"<commit-tx> <revocation-preimage> <privkey> <open-channel-file2> <outpubkey>\n"
|
"<commit-tx> <revocation-preimage> <final-privkey> <open-channel-file1> <open-channel-file2> <outpubkey>\n"
|
||||||
"Create a transaction which spends commit-tx's revocable output, and sends it P2SH to outpubkey",
|
"Create a transaction which spends commit-tx's revocable output, and sends it P2SH to outpubkey",
|
||||||
"Print this message.");
|
"Print this message.");
|
||||||
|
|
||||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||||
|
|
||||||
if (argc != 6)
|
if (argc != 7)
|
||||||
opt_usage_exit_fail("Expected 5 arguments");
|
opt_usage_exit_fail("Expected 6 arguments");
|
||||||
|
|
||||||
commit = bitcoin_tx_from_file(ctx, argv[1]);
|
commit = bitcoin_tx_from_file(ctx, argv[1]);
|
||||||
|
|
||||||
if (!hex_decode(argv[2], strlen(argv[2]), &revoke, sizeof(revoke)))
|
pkt = any_pkt_from_file(argv[2]);
|
||||||
errx(1, "Invalid revokation hash '%s' - need 256 hex bits",
|
switch (pkt->pkt_case) {
|
||||||
argv[2]);
|
case PKT__PKT_UPDATE_SIGNATURE:
|
||||||
|
proto_to_sha256(pkt->update_signature->revocation_preimage,
|
||||||
|
&revoke_preimage);
|
||||||
|
break;
|
||||||
|
case PKT__PKT_UPDATE_COMPLETE:
|
||||||
|
proto_to_sha256(pkt->update_complete->revocation_preimage,
|
||||||
|
&revoke_preimage);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errx(1, "Expected update or update-complete in %s", argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
privkey = key_from_base58(argv[3], strlen(argv[3]), &testnet, &pubkey1);
|
privkey = key_from_base58(argv[3], strlen(argv[3]), &testnet, &pubkey1);
|
||||||
if (!privkey)
|
if (!privkey)
|
||||||
@ -59,19 +70,20 @@ int main(int argc, char *argv[])
|
|||||||
if (!testnet)
|
if (!testnet)
|
||||||
errx(1, "Private key '%s' not on testnet!", argv[3]);
|
errx(1, "Private key '%s' not on testnet!", argv[3]);
|
||||||
|
|
||||||
o2 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
o1 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
||||||
|
o2 = pkt_from_file(argv[5], PKT__PKT_OPEN)->open;
|
||||||
|
|
||||||
if (!pubkey_from_hexstr(argv[5], &outpubkey))
|
if (!pubkey_from_hexstr(argv[6], &outpubkey))
|
||||||
errx(1, "Invalid bitcoin pubkey '%s'", argv[5]);
|
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
|
||||||
|
|
||||||
if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2))
|
if (!proto_to_pubkey(o2->final, &pubkey2))
|
||||||
errx(1, "Invalid anchor1 pubkey");
|
errx(1, "Invalid o2 final pubkey");
|
||||||
|
|
||||||
/* Now, which commit output? Match redeem script. */
|
/* Now, which commit output? Match redeem script. */
|
||||||
sha256(&revoke_hash, &revoke, sizeof(revoke));
|
sha256(&revoke_hash, &revoke_preimage, sizeof(revoke_preimage));
|
||||||
redeemscript = bitcoin_redeem_revocable(ctx, &pubkey1,
|
redeemscript = bitcoin_redeem_revocable(ctx, &pubkey2,
|
||||||
o2->locktime_seconds,
|
o2->locktime_seconds,
|
||||||
&pubkey2, &revoke_hash);
|
&pubkey1, &revoke_hash);
|
||||||
p2sh = scriptpubkey_p2sh(ctx, redeemscript);
|
p2sh = scriptpubkey_p2sh(ctx, redeemscript);
|
||||||
|
|
||||||
for (i = 0; i < commit->output_count; i++) {
|
for (i = 0; i < commit->output_count; i++) {
|
||||||
@ -97,7 +109,7 @@ int main(int argc, char *argv[])
|
|||||||
privkey, &pubkey1, &sig.sig))
|
privkey, &pubkey1, &sig.sig))
|
||||||
errx(1, "Could not sign tx");
|
errx(1, "Could not sign tx");
|
||||||
sig.stype = SIGHASH_ALL;
|
sig.stype = SIGHASH_ALL;
|
||||||
tx->input[0].script = scriptsig_p2sh_revoke(tx, &revoke, &sig,
|
tx->input[0].script = scriptsig_p2sh_revoke(tx, &revoke_preimage, &sig,
|
||||||
redeemscript,
|
redeemscript,
|
||||||
tal_count(redeemscript));
|
tal_count(redeemscript));
|
||||||
tx->input[0].script_length = tal_count(tx->input[0].script);
|
tx->input[0].script_length = tal_count(tx->input[0].script);
|
||||||
|
Loading…
Reference in New Issue
Block a user