MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_signpsbt

Function json_signpsbt

wallet/walletrpc.c:739–799  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737}
738
739static struct command_result *json_signpsbt(struct command *cmd,
740 const char *buffer,
741 const jsmntok_t *obj UNNEEDED,
742 const jsmntok_t *params)
743{
744 struct command_result *res;
745 struct json_stream *response;
746 struct wally_psbt *psbt, *signed_psbt;
747 struct utxo **utxos;
748 u32 *input_nums;
749
750 if (!param(cmd, buffer, params,
751 p_req("psbt", param_psbt, &psbt),
752 p_opt("signonly", param_input_numbers, &input_nums),
753 NULL))
754 return command_param_failed();
755
756 /* Sanity check! */
757 for (size_t i = 0; i < tal_count(input_nums); i++) {
758 if (input_nums[i] >= psbt->num_inputs)
759 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
760 "signonly[%zu]: %u out of range",
761 i, input_nums[i]);
762 }
763
764 /* We have to find/locate the utxos that are ours on this PSBT,
765 * so that the HSM knows how/what to sign for (it's possible some of
766 * our utxos require more complicated data to sign for e.g.
767 * closeinfo outputs */
768 res = match_psbt_inputs_to_utxos(cmd, psbt, input_nums, &utxos);
769 if (res)
770 return res;
771
772 if (tal_count(utxos) == 0)
773 return command_fail(cmd, LIGHTNINGD,
774 "No wallet inputs to sign");
775
776 /* Update the keypaths on any outputs that are in our wallet (change addresses). */
777 match_psbt_outputs_to_wallet(psbt, cmd->ld->wallet);
778
779 /* FIXME: hsm will sign almost anything, but it should really
780 * fail cleanly (not abort!) and let us report the error here. */
781 u8 *msg = towire_hsmd_sign_withdrawal(cmd,
782 cast_const2(const struct utxo **, utxos),
783 psbt);
784
785 if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
786 fatal("Could not write sign_withdrawal to HSM: %s",
787 strerror(errno));
788
789 msg = wire_sync_read(cmd, cmd->ld->hsm_fd);
790
791 if (!fromwire_hsmd_sign_withdrawal_reply(cmd, msg, &signed_psbt))
792 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
793 "HSM gave bad sign_withdrawal_reply %s",
794 tal_hex(tmpctx, msg));
795
796 response = json_stream_success(cmd);

Callers

nothing calls this directly

Calls 12

tal_hexFunction · 0.85
json_add_psbtFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
command_failFunction · 0.50
wire_sync_writeFunction · 0.50
fatalFunction · 0.50
wire_sync_readFunction · 0.50
json_stream_successFunction · 0.50
command_successFunction · 0.50

Tested by

no test coverage detected