MCPcopy Create free account
hub / github.com/ElementsProject/elements / SignTransaction

Method SignTransaction

src/external_signer.cpp:72–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error)
73{
74 // Serialize the PSBT
75 CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
76 ssTx << psbtx;
77
78 // Check if signer fingerprint matches any input master key fingerprint
79 auto matches_signer_fingerprint = [&](const PSBTInput& input) {
80 for (const auto& entry : input.hd_keypaths) {
81 if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) return true;
82 }
83 return false;
84 };
85
86 if (!std::any_of(psbtx.inputs.begin(), psbtx.inputs.end(), matches_signer_fingerprint)) {
87 error = "Signer fingerprint " + m_fingerprint + " does not match any of the inputs:\n" + EncodeBase64(ssTx.str());
88 return false;
89 }
90
91 const std::string command = m_command + " --stdin --fingerprint \"" + m_fingerprint + "\"" + NetworkArg();
92 const std::string stdinStr = "signtx \"" + EncodeBase64(ssTx.str()) + "\"";
93
94 const UniValue signer_result = RunCommandParseJSON(command, stdinStr);
95
96 if (find_value(signer_result, "error").isStr()) {
97 error = find_value(signer_result, "error").get_str();
98 return false;
99 }
100
101 if (!find_value(signer_result, "psbt").isStr()) {
102 error = "Unexpected result from signer";
103 return false;
104 }
105
106 PartiallySignedTransaction signer_psbtx;
107 std::string signer_psbt_error;
108 if (!DecodeBase64PSBT(signer_psbtx, find_value(signer_result, "psbt").get_str(), signer_psbt_error)) {
109 error = strprintf("TX decode failed %s", signer_psbt_error);
110 return false;
111 }
112
113 psbtx = signer_psbtx;
114
115 return true;
116}

Callers

nothing calls this directly

Calls 8

RunCommandParseJSONFunction · 0.85
DecodeBase64PSBTFunction · 0.85
strMethod · 0.80
isStrMethod · 0.80
ReadBE32Function · 0.50
EncodeBase64Function · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected