mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
close_tx: don't use protobufs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
9aa0eac814
commit
e1eef5db65
29
close_tx.c
29
close_tx.c
@ -8,42 +8,33 @@
|
|||||||
|
|
||||||
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
||||||
const tal_t *ctx,
|
const tal_t *ctx,
|
||||||
OpenChannel *ours,
|
const struct pubkey *our_final,
|
||||||
OpenChannel *theirs,
|
const struct pubkey *their_final,
|
||||||
OpenAnchor *anchor,
|
const struct sha256_double *anchor_txid,
|
||||||
|
unsigned int anchor_index,
|
||||||
|
u64 anchor_satoshis,
|
||||||
uint64_t to_us, uint64_t to_them)
|
uint64_t to_us, uint64_t to_them)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
const u8 *redeemscript;
|
const u8 *redeemscript;
|
||||||
struct pubkey ourkey, theirkey;
|
|
||||||
struct sha256 redeem;
|
|
||||||
|
|
||||||
/* Now create close tx: one input, two outputs. */
|
/* Now create close tx: one input, two outputs. */
|
||||||
tx = bitcoin_tx(ctx, 1, 2);
|
tx = bitcoin_tx(ctx, 1, 2);
|
||||||
|
|
||||||
/* Our input spends the anchor tx output. */
|
/* Our input spends the anchor tx output. */
|
||||||
proto_to_sha256(anchor->txid, &tx->input[0].txid.sha);
|
tx->input[0].txid = *anchor_txid;
|
||||||
tx->input[0].index = anchor->output_index;
|
tx->input[0].index = anchor_index;
|
||||||
tx->input[0].input_amount = anchor->amount;
|
tx->input[0].input_amount = anchor_satoshis;
|
||||||
|
|
||||||
/* Outputs goes to final pubkey */
|
|
||||||
if (!proto_to_pubkey(secpctx, ours->final_key, &ourkey))
|
|
||||||
return tal_free(tx);
|
|
||||||
if (!proto_to_pubkey(secpctx, theirs->final_key, &theirkey))
|
|
||||||
return tal_free(tx);
|
|
||||||
|
|
||||||
|
|
||||||
proto_to_sha256(ours->revocation_hash, &redeem);
|
|
||||||
|
|
||||||
/* One output is to us. */
|
/* One output is to us. */
|
||||||
tx->output[0].amount = to_us;
|
tx->output[0].amount = to_us;
|
||||||
redeemscript = bitcoin_redeem_single(tx, &ourkey);
|
redeemscript = bitcoin_redeem_single(tx, our_final);
|
||||||
tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript);
|
tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript);
|
||||||
tx->output[0].script_length = tal_count(tx->output[0].script);
|
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||||||
|
|
||||||
/* Other output is to them. */
|
/* Other output is to them. */
|
||||||
tx->output[1].amount = to_them;
|
tx->output[1].amount = to_them;
|
||||||
redeemscript = bitcoin_redeem_single(tx, &theirkey);
|
redeemscript = bitcoin_redeem_single(tx, their_final);
|
||||||
tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript);
|
tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript);
|
||||||
tx->output[1].script_length = tal_count(tx->output[1].script);
|
tx->output[1].script_length = tal_count(tx->output[1].script);
|
||||||
|
|
||||||
|
@ -11,8 +11,10 @@ struct sha256_double;
|
|||||||
* input scriptsig. */
|
* input scriptsig. */
|
||||||
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx,
|
||||||
const tal_t *ctx,
|
const tal_t *ctx,
|
||||||
OpenChannel *ours,
|
const struct pubkey *our_final,
|
||||||
OpenChannel *theirs,
|
const struct pubkey *their_final,
|
||||||
OpenAnchor *anchor,
|
const struct sha256_double *anchor_txid,
|
||||||
|
unsigned int anchor_index,
|
||||||
|
u64 anchor_satoshis,
|
||||||
uint64_t to_us, uint64_t to_them);
|
uint64_t to_us, uint64_t to_them);
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,7 +33,8 @@ int main(int argc, char *argv[])
|
|||||||
struct signature sig;
|
struct signature sig;
|
||||||
struct privkey privkey;
|
struct privkey privkey;
|
||||||
bool testnet;
|
bool testnet;
|
||||||
struct pubkey pubkey1, pubkey2;
|
struct pubkey pubkey1, pubkey2, final1, final2;
|
||||||
|
struct sha256_double anchor_txid;
|
||||||
u8 *redeemscript;
|
u8 *redeemscript;
|
||||||
char *close_file = NULL;
|
char *close_file = NULL;
|
||||||
u64 close_fee = 10000;
|
u64 close_fee = 10000;
|
||||||
@ -87,12 +88,20 @@ int main(int argc, char *argv[])
|
|||||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
o2->commit_key, &pubkey2))
|
o2->commit_key, &pubkey2))
|
||||||
errx(1, "Invalid o2 commit pubkey");
|
errx(1, "Invalid o2 commit pubkey");
|
||||||
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
|
o1->final_key, &final1))
|
||||||
|
errx(1, "Invalid o1 final pubkey");
|
||||||
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
|
o2->final_key, &final2))
|
||||||
|
errx(1, "Invalid o2 final pubkey");
|
||||||
|
|
||||||
/* This is what the anchor pays to. */
|
/* This is what the anchor pays to. */
|
||||||
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||||
|
|
||||||
|
proto_to_sha256(a->txid, &anchor_txid.sha);
|
||||||
close_tx = create_close_tx(secp256k1_context_create(0),
|
close_tx = create_close_tx(secp256k1_context_create(0),
|
||||||
ctx, o1, o2, a,
|
ctx, &final1, &final2,
|
||||||
|
&anchor_txid, a->output_index, a->amount,
|
||||||
cstate->a.pay_msat / 1000,
|
cstate->a.pay_msat / 1000,
|
||||||
cstate->b.pay_msat / 1000);
|
cstate->b.pay_msat / 1000);
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ int main(int argc, char *argv[])
|
|||||||
OpenAnchor *a;
|
OpenAnchor *a;
|
||||||
struct bitcoin_tx *close_tx;
|
struct bitcoin_tx *close_tx;
|
||||||
struct bitcoin_signature sig1, sig2;
|
struct bitcoin_signature sig1, sig2;
|
||||||
struct pubkey pubkey1, pubkey2;
|
struct pubkey pubkey1, pubkey2, final1, final2;
|
||||||
|
struct sha256_double anchor_txid;
|
||||||
u8 *redeemscript;
|
u8 *redeemscript;
|
||||||
CloseChannel *close;
|
CloseChannel *close;
|
||||||
CloseChannelComplete *closecomplete;
|
CloseChannelComplete *closecomplete;
|
||||||
@ -59,6 +60,12 @@ int main(int argc, char *argv[])
|
|||||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
o2->commit_key, &pubkey2))
|
o2->commit_key, &pubkey2))
|
||||||
errx(1, "Invalid o2 commit_key");
|
errx(1, "Invalid o2 commit_key");
|
||||||
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
|
o1->final_key, &final1))
|
||||||
|
errx(1, "Invalid o1 final pubkey");
|
||||||
|
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||||
|
o2->final_key, &final2))
|
||||||
|
errx(1, "Invalid o2 final pubkey");
|
||||||
|
|
||||||
/* Get delta by accumulting all the updates. */
|
/* Get delta by accumulting all the updates. */
|
||||||
cstate = gather_updates(ctx, o1, o2, a, close->close_fee, argv + 6,
|
cstate = gather_updates(ctx, o1, o2, a, close->close_fee, argv + 6,
|
||||||
@ -68,8 +75,10 @@ int main(int argc, char *argv[])
|
|||||||
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||||
|
|
||||||
/* Now create the close tx to spend 2/2 output of anchor. */
|
/* Now create the close tx to spend 2/2 output of anchor. */
|
||||||
|
proto_to_sha256(a->txid, &anchor_txid.sha);
|
||||||
close_tx = create_close_tx(secp256k1_context_create(0),
|
close_tx = create_close_tx(secp256k1_context_create(0),
|
||||||
ctx, o1, o2, a,
|
ctx, &final1, &final2,
|
||||||
|
&anchor_txid, a->output_index, a->amount,
|
||||||
cstate->a.pay_msat / 1000,
|
cstate->a.pay_msat / 1000,
|
||||||
cstate->b.pay_msat / 1000);
|
cstate->b.pay_msat / 1000);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user