@@ -543,3 +543,44 @@ struct command_result *param_outpoint_arr(struct command *cmd,
543543 }
544544 return NULL ;
545545}
546+
547+ struct command_result * param_extra_tlvs (struct command * cmd , const char * name ,
548+ const char * buffer ,
549+ const jsmntok_t * tok ,
550+ struct tlv_field * * fields )
551+ {
552+ size_t i ;
553+ const jsmntok_t * curr ;
554+ struct tlv_field * f , * temp ;
555+
556+ if (tok -> type != JSMN_OBJECT ) {
557+ return command_fail (
558+ cmd , JSONRPC2_INVALID_PARAMS ,
559+ "Could not decode the TLV object from %s: "
560+ "\"%s\" is not a valid JSON object." ,
561+ name , json_strdup (tmpctx , buffer , tok ));
562+ }
563+
564+ temp = tal_arr (cmd , struct tlv_field , tok -> size );
565+ json_for_each_obj (i , curr , tok ) {
566+ f = & temp [i ];
567+ if (!json_to_u64 (buffer , curr , & f -> numtype )) {
568+ return command_fail (
569+ cmd , JSONRPC2_INVALID_PARAMS ,
570+ "\"%s\" is not a valid numeric TLV type." ,
571+ json_strdup (tmpctx , buffer , curr ));
572+ }
573+ f -> value = json_tok_bin_from_hex (temp , buffer , curr + 1 );
574+
575+ if (f -> value == NULL ) {
576+ return command_fail (
577+ cmd , JSONRPC2_INVALID_PARAMS ,
578+ "\"%s\" is not a valid hex encoded TLV value." ,
579+ json_strdup (tmpctx , buffer , curr ));
580+ }
581+ f -> length = tal_bytelen (f -> value );
582+ f -> meta = NULL ;
583+ }
584+ * fields = temp ;
585+ return NULL ;
586+ }
0 commit comments