mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #15427: Add support for descriptors to utxoupdatepsbt
26fe9b9909Add support for descriptors to utxoupdatepsbt (Pieter Wuille)3135c1a2d2Abstract out UpdatePSBTOutput from FillPSBT (Pieter Wuille)fb90ec3c33Abstract out EvalDescriptorStringOrObject from scantxoutset (Pieter Wuille)eaf4f88734Abstract out IsSegWitOutput from utxoupdatepsbt (Pieter Wuille) Pull request description: This adds a descriptors argument to the `utxoupdatepsbt` RPC. This means: * Input and output scripts and keys will be filled in when known. * P2SH-witness inputs will be filled in from the UTXO set when a descriptor is provided that shows they're spending segwit outputs. This also moves some (newly) shared code to separate functions: `UpdatePSBTOutput` (an analogue to `SignPSBTInput`), `IsSegWitOutput`, and `EvalDescriptorStringOrObject` (implementing the string or object notation parsing used in `scantxoutset`). ACKs for top commit: jnewbery: utACK26fe9b9909laanwj: utACK26fe9b9909(will hold merging until response to promag's comments) promag: ACK26fe9b9, checked refactors and tests look comprehensive. Still missing a release note but can be added later. Tree-SHA512: 1d833b7351b59d6c5ded6da399ff371a8a2a6ad04c0a8f90e6e46105dc737fa6f2740b1e5340280d59e01f42896c40b720c042f44417e38dfbee6477b894b245
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <keystore.h>
|
||||
#include <outputtype.h>
|
||||
#include <rpc/util.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
@@ -697,3 +698,40 @@ std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value)
|
||||
}
|
||||
return {low, high};
|
||||
}
|
||||
|
||||
std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, FlatSigningProvider& provider)
|
||||
{
|
||||
std::string desc_str;
|
||||
std::pair<int64_t, int64_t> range = {0, 1000};
|
||||
if (scanobject.isStr()) {
|
||||
desc_str = scanobject.get_str();
|
||||
} else if (scanobject.isObject()) {
|
||||
UniValue desc_uni = find_value(scanobject, "desc");
|
||||
if (desc_uni.isNull()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Descriptor needs to be provided in scan object");
|
||||
desc_str = desc_uni.get_str();
|
||||
UniValue range_uni = find_value(scanobject, "range");
|
||||
if (!range_uni.isNull()) {
|
||||
range = ParseDescriptorRange(range_uni);
|
||||
}
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan object needs to be either a string or an object");
|
||||
}
|
||||
|
||||
auto desc = Parse(desc_str, provider);
|
||||
if (!desc) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor '%s'", desc_str));
|
||||
}
|
||||
if (!desc->IsRange()) {
|
||||
range.first = 0;
|
||||
range.second = 0;
|
||||
}
|
||||
std::vector<CScript> ret;
|
||||
for (int i = range.first; i <= range.second; ++i) {
|
||||
std::vector<CScript> scripts;
|
||||
if (!desc->Expand(i, provider, scripts, provider)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Cannot derive script without private keys: '%s'", desc_str));
|
||||
}
|
||||
std::move(scripts.begin(), scripts.end(), std::back_inserter(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user