Skip to content

Commit bbaa0d6

Browse files
fixup! wip: opening control notify the tx to master
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent e2de541 commit bbaa0d6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

bitcoin/test/run-tx-encode.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <common/setup.h>
1010
#include <common/utils.h>
1111
#include <stdio.h>
12+
#include <string.h>
1213

1314
/* AUTOGENERATED MOCKS START */
1415
/* Generated stub for amount_asset_is_main */
@@ -125,6 +126,7 @@ int main(int argc, const char *argv[])
125126
chainparams = chainparams_for_network("bitcoin");
126127

127128
struct bitcoin_tx *tx;
129+
char *hex_tx;
128130

129131
tx = bitcoin_tx_from_hex(NULL, extended_tx, strlen(extended_tx));
130132
assert(tx);
@@ -161,6 +163,10 @@ int main(int argc, const char *argv[])
161163
"0204096eb817f7efb414ef4d3d8be39dd04374256d3b054a322d4a6ee22736d0"
162164
"3b");
163165

166+
hex_tx = "0200000001fd9915bf664e2b4888b4770101d92d9086144124646b3df49bd6e3156c9d194a000000000086450b80024a010000000000002200207b6d27992d8294099919c1beea2397dbb6d934f8b62c25130a070a608f0e58a2f4d98dff4d000000220020aa8bd5637587bebb499a4f52b13864bc03d7664985da1ba4fc34005d591e55680effaa20";
167+
tx = bitcoin_tx_from_hex(NULL, hex_tx, strlen(hex_tx));
168+
assert(strcmp(hex_tx, fmt_bitcoin_tx(NULL, tx)) == 0);
169+
164170
tal_free(tx);
165171
common_shutdown();
166172
return 0;

common/json_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ bool json_to_txid(const char *buffer, const jsmntok_t *tok,
584584
bool json_to_tx(const char *buffer, const jsmntok_t *tok,
585585
struct bitcoin_tx *tx)
586586
{
587-
tx = bitcoin_tx_from_hex(buffer, buffer + tok->start, tok->size);
588-
return true;
587+
tx = bitcoin_tx_from_hex(buffer, buffer + tok->start, tok->end - tok->start);
588+
return tx != NULL;
589589
}
590590

591591

lightningd/opening_control.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ struct onfunding_channel_tx_hook_payload {
869869
static void onfunding_channel_tx_hook_final(struct onfunding_channel_tx_hook_payload *payload STEALS)
870870
{
871871
struct subd *openingd = payload->openingd;
872+
log_info(openingd->log, "from hook sending the tx %s", fmt_bitcoin_tx(tmpctx, payload->tx));
872873
// FIXME(bitfinix): manage the errors!
873874
subd_send_msg(openingd,
874875
take(towire_openingd_on_funding_tx_reply(NULL, payload->tx)));
@@ -894,25 +895,26 @@ static bool onfunding_channel_tx_hook_deserialize(struct onfunding_channel_tx_ho
894895
{
895896
const jsmntok_t *result_tok, *error_tok, *tx_tok;
896897

898+
log_info(payload->openingd->log, "buffer %s", buffer);
897899
if ((error_tok = json_get_member(buffer, toks, "error")) != NULL)
898900
fatal("Plugin returned an error inside the response to the"
899901
" onfunding_channel_tx hook: %.*s",
900902
toks[0].end - toks[0].start, buffer + toks[0].start);
901903

902-
if ((result_tok = json_get_member(buffer, toks, "result")) == NULL)
903-
fatal("Plugin returned an invalid response to the"
904+
if ((result_tok = json_get_member(buffer, toks, "result")) == NULL)
905+
fatal("Plugin returned an invalid response (missing result) to the"
904906
" onfunding_channel_tx hook: %.*s",
905907
toks[0].end - toks[0].start, buffer + toks[0].start);
906908

907909
if ((tx_tok = json_get_member(buffer, result_tok, "tx")) == NULL)
908-
fatal("Plugin returned an invalid response to the"
910+
fatal("Plugin returned an invalid response (missing tx) to the"
909911
" onfunding_channel_tx hook: %.*s",
910912
toks[0].end - toks[0].start, buffer + toks[0].start);
911913

912914
if (!json_to_tx(buffer, tx_tok, payload->tx))
913-
fatal("Plugin returned an invalid response to the"
915+
fatal("Plugin returned an invalid (json to tx) response to the"
914916
" onfunding_channel_tx hook: %.*s",
915-
toks[0].end - toks[0].start, buffer + toks[0].start);
917+
tx_tok[0].end - tx_tok[0].start, buffer + tx_tok[0].start);
916918
return true;
917919
}
918920

0 commit comments

Comments
 (0)