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