@@ -676,7 +676,7 @@ static void openchannel_hook_serialize(struct openchannel_hook_payload *payload,
676676
677677/* openingd dies? Remove openingd ptr from payload */
678678static void openchannel_payload_remove_openingd (struct subd * openingd ,
679- struct openchannel_hook_payload * payload )
679+ struct openchannel_hook_payload * payload )
680680{
681681 assert (payload -> openingd == openingd );
682682 payload -> openingd = NULL ;
@@ -860,6 +860,74 @@ static void opening_got_offer(struct subd *openingd,
860860 plugin_hook_call_openchannel (openingd -> ld , NULL , payload );
861861}
862862
863+ struct onfunding_channel_tx_hook_payload {
864+ struct subd * openingd ;
865+ struct bitcoin_tx * tx ;
866+ };
867+
868+ static void onfunding_channel_tx_hook_final (struct onfunding_channel_tx_hook_payload * payload STEALS )
869+ {
870+ struct subd * openingd = payload -> openingd ;
871+ // FIXME(bitfinix): manage the errors!
872+ subd_send_msg (openingd ,
873+ take (towire_openingd_on_funding_tx_reply (NULL , payload -> tx )));
874+ }
875+
876+ static void onfunding_channel_tx_hook_serialize (struct onfunding_channel_tx_hook_payload * payload ,
877+ struct json_stream * stream ,
878+ struct plugin * plugin )
879+ {
880+ json_object_start (stream , "onfunding_channel_tx" );
881+ json_add_tx (stream , "tx" , payload -> tx );
882+ json_object_end (stream );
883+ }
884+
885+ static bool onfunding_channel_tx_hook_deserialize (struct onfunding_channel_tx_hook_payload * payload ,
886+ const char * buffer ,
887+ const jsmntok_t * toks )
888+ {
889+ const jsmntok_t * result_tok , * error_tok , * tx_tok ;
890+
891+ if ((error_tok = json_get_member (buffer , toks , "error" )) != NULL )
892+ /*FIXME(bitfinix): please return an error to openingd*/
893+ return false;
894+
895+ if ((result_tok = json_get_member (buffer , toks , "result" )) == NULL )
896+ fatal ("Plugin returned an invalid response to the"
897+ " onfunding_channel_tx hook: %.*s" ,
898+ toks [0 ].end - toks [0 ].start , buffer + toks [0 ].start );
899+
900+ if ((tx_tok = json_get_member (buffer , result_tok , "tx" )) == NULL )
901+ fatal ("Plugin returned an invalid response to the"
902+ " onfunding_channel_tx hook: %.*s" ,
903+ toks [0 ].end - toks [0 ].start , buffer + toks [0 ].start );
904+
905+ if (!json_to_tx (buffer , tx_tok , payload -> tx ))
906+ return false;
907+ return true;
908+ }
909+
910+ REGISTER_PLUGIN_HOOK (onfunding_channel_tx ,
911+ onfunding_channel_tx_hook_deserialize ,
912+ onfunding_channel_tx_hook_final ,
913+ onfunding_channel_tx_hook_serialize ,
914+ struct onfunding_channel_tx_hook_payload * );
915+
916+
917+ static char * opening_on_funding_tx (struct subd * openingd , const u8 * msg )
918+ {
919+ struct onfunding_channel_tx_hook_payload * payload ;
920+ payload = tal (openingd , struct onfunding_channel_tx_hook_payload );
921+ payload -> openingd = openingd ;
922+
923+ if (!fromwire_openingd_on_funding_tx (msg , msg , & payload -> tx ))
924+ return tal_fmt (tmpctx , "Unexpected encoding of openingd_on_funding_tx msg: %s" ,
925+ tal_hex (tmpctx , msg ));
926+ assert (plugin_hook_call_onfunding_channel_tx (openingd -> ld , NULL , payload ));
927+ // FIXME(bitfinix): return an error
928+ return NULL ;
929+ }
930+
863931static unsigned int openingd_msg (struct subd * openingd ,
864932 const u8 * msg , const int * fds )
865933{
@@ -900,13 +968,20 @@ static unsigned int openingd_msg(struct subd *openingd,
900968 case WIRE_OPENINGD_GOT_OFFER :
901969 opening_got_offer (openingd , msg , uc );
902970 return 0 ;
903-
971+ case WIRE_OPENINGD_ON_FUNDING_TX :
972+ const char * err ;
973+ if ((err = opening_on_funding_tx (openingd , msg )) != NULL ) {
974+ log_debug (openingd -> log , "Unexpected error while handling on funding tx: %s" , err );
975+ return 1 ;
976+ }
977+ return 0 ;
904978 /* We send these! */
905979 case WIRE_OPENINGD_INIT :
906980 case WIRE_OPENINGD_FUNDER_START :
907981 case WIRE_OPENINGD_FUNDER_COMPLETE :
908982 case WIRE_OPENINGD_FUNDER_CANCEL :
909983 case WIRE_OPENINGD_GOT_OFFER_REPLY :
984+ case WIRE_OPENINGD_ON_FUNDING_TX_REPLY :
910985 case WIRE_OPENINGD_DEV_MEMLEAK :
911986 /* Replies never get here */
912987 case WIRE_OPENINGD_DEV_MEMLEAK_REPLY :
0 commit comments