Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 1,720 Lines • ▼ Show 20 Lines | static UniValue finalizepsbt(const Config &config, | ||||
// Unserialize the transactions | // Unserialize the transactions | ||||
PartiallySignedTransaction psbtx; | PartiallySignedTransaction psbtx; | ||||
std::string error; | std::string error; | ||||
if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | if (!DecodePSBT(psbtx, request.params[0].get_str(), error)) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
strprintf("TX decode failed %s", error)); | strprintf("TX decode failed %s", error)); | ||||
} | } | ||||
// Get all of the previous transactions | // Finalize input signatures -- in case we have partial signatures that add | ||||
// up to a complete | |||||
// signature, but have not combined them yet (e.g. because the combiner | |||||
// that created this PartiallySignedTransaction did not understand them), | |||||
// this will combine them into a final script. | |||||
bool complete = true; | bool complete = true; | ||||
for (size_t i = 0; i < psbtx.tx->vin.size(); ++i) { | for (size_t i = 0; i < psbtx.tx->vin.size(); ++i) { | ||||
PSBTInput &input = psbtx.inputs.at(i); | complete &= | ||||
SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, SigHashType()); | |||||
complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, *psbtx.tx, input, i, | |||||
SigHashType()); | |||||
} | } | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); | ||||
bool extract = request.params[1].isNull() || (!request.params[1].isNull() && | bool extract = request.params[1].isNull() || (!request.params[1].isNull() && | ||||
request.params[1].get_bool()); | request.params[1].get_bool()); | ||||
if (complete && extract) { | if (complete && extract) { | ||||
CMutableTransaction mtx(*psbtx.tx); | CMutableTransaction mtx(*psbtx.tx); | ||||
for (size_t i = 0; i < mtx.vin.size(); ++i) { | for (size_t i = 0; i < mtx.vin.size(); ++i) { | ||||
mtx.vin[i].scriptSig = psbtx.inputs[i].final_script_sig; | mtx.vin[i].scriptSig = psbtx.inputs[i].final_script_sig; | ||||
} | } | ||||
ssTx << mtx; | ssTx << mtx; | ||||
result.pushKV("hex", HexStr(ssTx.begin(), ssTx.end())); | result.pushKV("hex", HexStr(ssTx.str())); | ||||
} else { | } else { | ||||
ssTx << psbtx; | ssTx << psbtx; | ||||
result.pushKV("psbt", | result.pushKV("psbt", EncodeBase64(ssTx.str())); | ||||
EncodeBase64((uint8_t *)ssTx.data(), ssTx.size())); | |||||
} | } | ||||
result.pushKV("complete", complete); | result.pushKV("complete", complete); | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue createpsbt(const Config &config, | static UniValue createpsbt(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |