Bitcoin ABC  0.24.7
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 }
OutputType
OutputType
Definition: outputtype.h:17
FormatOutputType
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:27
OutputType::LEGACY
@ LEGACY
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:76
AddAndGetDestinationForScript
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
outputtype.h
OUTPUT_TYPE_STRING_LEGACY
static const std::string OUTPUT_TYPE_STRING_LEGACY
Definition: outputtype.cpp:15
GetDestinationForKey
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
Definition: outputtype.cpp:35
pubkey.h
OUTPUT_TYPES
const std::array< OutputType, 1 > OUTPUT_TYPES
Definition: outputtype.cpp:17
ParseOutputType
bool ParseOutputType(const std::string &type, OutputType &output_type)
Definition: outputtype.cpp:19
sign.h
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
PKHash
Definition: standard.h:106
CPubKey
An encapsulated public key.
Definition: pubkey.h:31
Vector
std::vector< typename std::common_type< Args... >::type > Vector(Args &&... args)
Construct a vector with the specified elements.
Definition: vector.h:21
vector.h
FillableSigningProvider::AddCScript
virtual bool AddCScript(const CScript &redeemScript)
Definition: signingprovider.cpp:125
script.h
GetAllDestinationsForKey
std::vector< CTxDestination > GetAllDestinationsForKey(const CPubKey &key)
Get all destinations (potentially) supported by the wallet for the given key.
Definition: outputtype.cpp:43
CTxDestination
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:132
ScriptHash
Definition: standard.h:114