14
14
#include < util/spanparsing.h>
15
15
#include < util/system.h>
16
16
#include < util/strencodings.h>
17
+ #include < util/vector.h>
17
18
18
19
#include < memory>
19
20
#include < string>
@@ -501,22 +502,13 @@ class DescriptorImpl : public Descriptor
501
502
}
502
503
};
503
504
504
- /* * Construct a vector with one element, which is moved into it. */
505
- template <typename T>
506
- std::vector<T> Singleton (T elem)
507
- {
508
- std::vector<T> ret;
509
- ret.emplace_back (std::move (elem));
510
- return ret;
511
- }
512
-
513
505
/* * A parsed addr(A) descriptor. */
514
506
class AddressDescriptor final : public DescriptorImpl
515
507
{
516
508
const CTxDestination m_destination;
517
509
protected:
518
510
std::string ToStringExtra () const override { return EncodeDestination (m_destination); }
519
- std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Singleton (GetScriptForDestination (m_destination)); }
511
+ std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Vector (GetScriptForDestination (m_destination)); }
520
512
public:
521
513
AddressDescriptor (CTxDestination destination) : DescriptorImpl({}, {}, " addr" ), m_destination(std::move(destination)) {}
522
514
bool IsSolvable () const final { return false ; }
@@ -528,7 +520,7 @@ class RawDescriptor final : public DescriptorImpl
528
520
const CScript m_script;
529
521
protected:
530
522
std::string ToStringExtra () const override { return HexStr (m_script.begin (), m_script.end ()); }
531
- std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Singleton (m_script); }
523
+ std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript*, FlatSigningProvider&) const override { return Vector (m_script); }
532
524
public:
533
525
RawDescriptor (CScript script) : DescriptorImpl({}, {}, " raw" ), m_script(std::move(script)) {}
534
526
bool IsSolvable () const final { return false ; }
@@ -538,9 +530,9 @@ class RawDescriptor final : public DescriptorImpl
538
530
class PKDescriptor final : public DescriptorImpl
539
531
{
540
532
protected:
541
- std::vector<CScript> MakeScripts (const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton (GetScriptForRawPubKey (keys[0 ])); }
533
+ std::vector<CScript> MakeScripts (const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Vector (GetScriptForRawPubKey (keys[0 ])); }
542
534
public:
543
- PKDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton (std::move(prov)), {}, " pk" ) {}
535
+ PKDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector (std::move(prov)), {}, " pk" ) {}
544
536
};
545
537
546
538
/* * A parsed pkh(P) descriptor. */
@@ -551,10 +543,10 @@ class PKHDescriptor final : public DescriptorImpl
551
543
{
552
544
CKeyID id = keys[0 ].GetID ();
553
545
out.pubkeys .emplace (id, keys[0 ]);
554
- return Singleton (GetScriptForDestination (PKHash (id)));
546
+ return Vector (GetScriptForDestination (PKHash (id)));
555
547
}
556
548
public:
557
- PKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton (std::move(prov)), {}, " pkh" ) {}
549
+ PKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector (std::move(prov)), {}, " pkh" ) {}
558
550
};
559
551
560
552
/* * A parsed wpkh(P) descriptor. */
@@ -565,10 +557,10 @@ class WPKHDescriptor final : public DescriptorImpl
565
557
{
566
558
CKeyID id = keys[0 ].GetID ();
567
559
out.pubkeys .emplace (id, keys[0 ]);
568
- return Singleton (GetScriptForDestination (WitnessV0KeyHash (id)));
560
+ return Vector (GetScriptForDestination (WitnessV0KeyHash (id)));
569
561
}
570
562
public:
571
- WPKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton (std::move(prov)), {}, " wpkh" ) {}
563
+ WPKHDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector (std::move(prov)), {}, " wpkh" ) {}
572
564
};
573
565
574
566
/* * A parsed combo(P) descriptor. */
@@ -591,7 +583,7 @@ class ComboDescriptor final : public DescriptorImpl
591
583
return ret;
592
584
}
593
585
public:
594
- ComboDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton (std::move(prov)), {}, " combo" ) {}
586
+ ComboDescriptor (std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Vector (std::move(prov)), {}, " combo" ) {}
595
587
};
596
588
597
589
/* * A parsed multi(...) or sortedmulti(...) descriptor */
@@ -605,9 +597,9 @@ class MultisigDescriptor final : public DescriptorImpl
605
597
if (m_sorted) {
606
598
std::vector<CPubKey> sorted_keys (keys);
607
599
std::sort (sorted_keys.begin (), sorted_keys.end ());
608
- return Singleton (GetScriptForMultisig (m_threshold, sorted_keys));
600
+ return Vector (GetScriptForMultisig (m_threshold, sorted_keys));
609
601
}
610
- return Singleton (GetScriptForMultisig (m_threshold, keys));
602
+ return Vector (GetScriptForMultisig (m_threshold, keys));
611
603
}
612
604
public:
613
605
MultisigDescriptor (int threshold, std::vector<std::unique_ptr<PubkeyProvider>> providers, bool sorted = false ) : DescriptorImpl(std::move(providers), {}, sorted ? " sortedmulti" : " multi" ), m_threshold(threshold), m_sorted(sorted) {}
@@ -617,7 +609,7 @@ class MultisigDescriptor final : public DescriptorImpl
617
609
class SHDescriptor final : public DescriptorImpl
618
610
{
619
611
protected:
620
- std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Singleton (GetScriptForDestination (ScriptHash (*script))); }
612
+ std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector (GetScriptForDestination (ScriptHash (*script))); }
621
613
public:
622
614
SHDescriptor (std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), " sh" ) {}
623
615
};
@@ -626,7 +618,7 @@ class SHDescriptor final : public DescriptorImpl
626
618
class WSHDescriptor final : public DescriptorImpl
627
619
{
628
620
protected:
629
- std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Singleton (GetScriptForDestination (WitnessV0ScriptHash (*script))); }
621
+ std::vector<CScript> MakeScripts (const std::vector<CPubKey>&, const CScript* script, FlatSigningProvider&) const override { return Vector (GetScriptForDestination (WitnessV0ScriptHash (*script))); }
630
622
public:
631
623
WSHDescriptor (std::unique_ptr<DescriptorImpl> desc) : DescriptorImpl({}, std::move(desc), " wsh" ) {}
632
624
};
0 commit comments