[bitcoin/bitcoin] Add scantxoutset RPC method (#12196)

sipa commented on this pull request.

> @@ -19,6 +23,41 @@ bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
return GetCoin(outpoint, coin);
}

+bool CCoinsView::FindScriptPubKey(std::atomic& scan_progress, std::atomic& should_abort, int64_t& count, CCoinsViewCursor& cursor, const std::set& needles, std::map& out_results) {

In commit «Add CCoinsView::FindScriptPubKey to search the UTXO set».

There is no need for this function to burden the CCoinsView interface I think, as it only uses publicly available data from that class. The implementation can just move to where scantxoutset is defined.

> — if (cursor.GetKey(key) && cursor.GetValue(coin)) {
— if (++count % 8192 == 0) {
— boost::this_thread::interruption_point();
— if (should_abort) {
— // allow to abort the scan via the abort reference
— return false;
— }
— }
— if (count % 256 == 0) {
— // update progress reference every 256 item
— uint32_t high = 0x100 * *key.hash.begin() + *(key.hash.begin() + 1);
— scan_progress = (int)(high * 100.0 / 65536.0 + 0.5);
— }
— if (needles.count(coin.out.scriptPubKey)) {
— out_results.emplace(key, coin);
+ if (!cursor.GetKey(key) || !cursor.GetValue(coin)) return false;

In commit «Blockchain/RPC: Add scantxoutset method to scan UTXO set».

The implementation of «CCoinsView::FindScriptPubKey» is being changed significantly in this commit. Can you move the changes to the previous commit that introduces the function?

> +
+UniValue scantxoutset(const JSONRPCRequest& request)
+{
+ if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
+ throw std::runtime_error(
+ «scantxoutset ( )n»
+ «nScans the unspent transaction output set for possible entries that matches common scripts of given public keys.n»
+ «nArguments:n»
+ «1. «action» (string, required) The action to executen»
+ » «start» for starting a scann»
+ » «abort» for aborting the current scan (returns true when abort was successful)n»
+ » «status» for progress report (in %) of the current scann»
+ «2. «scanobjects» (array, required) Array of scan objects (only one object type per scan object allowed)n»
+ » [n»
+ » { «address» : «

» }, (string, optional) Bitcoin addressn»
+ » { «pubkey» : (object, optional) Public keyn»

I would leave this out as well, as it’ll be handled equally by the descriptor based approach. It’s a lot of complexity to maintain which will be handled more generically later.

Also, I don’t think it’s very useful and add — if you know the pubkey and derivation type you generally also know the address already.

> @@ -2012,6 +2032,12 @@ UniValue scantxoutset(const JSONRPCRequest& request)
» }n»
» },n»
» ]n»
+ «3. «options» (object, optional)n»
+ » «rawsweep»: { (object, optional) Optionally creates a raw sweep transactionn»

In commit «scantxoutset: Add optional raw sweep transaction».

Is this the best place to implement this? As a separate wallet RPC it could work much more correctly (as it would know the actual scripts involved and be able to give a vsize estimate that’s more than a dumb guess), and be more useful too by being combinable with whatever way to find inputs.

I feel this makes the RPC look like a kitchen sink.

Добавить комментарий