Bitcoin ABC  0.26.3
P2P Digital Currency
outputtype.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <outputtype.h>
7 
8 #include <pubkey.h>
9 #include <script/script.h>
10 #include <script/sign.h>
11 #include <util/vector.h>
12 
13 #include <cassert>
14 
15 static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
16 
17 const std::array<OutputType, 1> OUTPUT_TYPES = {{OutputType::LEGACY}};
18 
19 bool ParseOutputType(const std::string &type, OutputType &output_type) {
20  if (type == OUTPUT_TYPE_STRING_LEGACY) {
21  output_type = OutputType::LEGACY;
22  return true;
23  }
24  return false;
25 }
26 
27 const std::string &FormatOutputType(OutputType type) {
28  switch (type) {
29  case OutputType::LEGACY:
31  } // no default case, so the compiler can warn about missing cases
32  assert(false);
33 }
34 
36  switch (type) {
37  case OutputType::LEGACY:
38  return PKHash(key);
39  } // no default case, so the compiler can warn about missing cases
40  assert(false);
41 }
42 
43 std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey &key) {
44  PKHash keyid(key);
45  CTxDestination p2pkh{keyid};
46  return Vector(std::move(p2pkh));
47 }
48 
50  const CScript &script,
51  OutputType type) {
52  // Add script to keystore
53  keystore.AddCScript(script);
54  // Note that scripts over 520 bytes are not yet supported.
55  switch (type) {
56  case OutputType::LEGACY:
57  return ScriptHash(script);
58  } // no default case, so the compiler can warn about missing cases
59  assert(false);
60 }
An encapsulated public key.
Definition: pubkey.h:31
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:27
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
Definition: outputtype.cpp:35
bool ParseOutputType(const std::string &type, OutputType &output_type)
Definition: outputtype.cpp:19
CTxDestination AddAndGetDestinationForScript(FillableSigningProvider &keystore, const CScript &script, OutputType type)
Get a destination of the requested type (if possible) to the specified script.
Definition: outputtype.cpp:49
static const std::string OUTPUT_TYPE_STRING_LEGACY
Definition: outputtype.cpp:15
std::vector< CTxDestination > GetAllDestinationsForKey(const CPubKey &key)
Get all destinations (potentially) supported by the wallet for the given key.
Definition: outputtype.cpp:43
const std::array< OutputType, 1 > OUTPUT_TYPES
Definition: outputtype.cpp:17
OutputType
Definition: outputtype.h:16
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
assert(!tx.IsCoinBase())
std::vector< typename std::common_type< Args... >::type > Vector(Args &&...args)
Construct a vector with the specified elements.
Definition: vector.h:21