Bitcoin ABC  0.22.13
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  default:
32  assert(false);
33  }
34 }
35 
37  switch (type) {
38  case OutputType::LEGACY:
39  return PKHash(key);
40  default:
41  assert(false);
42  }
43 }
44 
45 std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey &key) {
46  PKHash keyid(key);
47  CTxDestination p2pkh{keyid};
48  return Vector(std::move(p2pkh));
49 }
50 
52  const CScript &script,
53  OutputType type) {
54  // Add script to keystore
55  keystore.AddCScript(script);
56  ScriptHash sh(script);
57  // Note that scripts over 520 bytes are not yet supported.
58  switch (type) {
59  case OutputType::LEGACY:
60  keystore.AddCScript(GetScriptForDestination(sh));
61  return sh;
62  default:
63  assert(false);
64  }
65 }
virtual bool AddCScript(const CScript &redeemScript)
OutputType
Definition: outputtype.h:17
std::vector< CTxDestination > GetAllDestinationsForKey(const CPubKey &key)
Get all destinations (potentially) supported by the wallet for the given key.
Definition: outputtype.cpp:45
std::vector< typename std::common_type< Args... >::type > Vector(Args &&... args)
Construct a vector with the specified elements.
Definition: vector.h:21
An encapsulated public key.
Definition: pubkey.h:31
Fillable signing provider that keeps keys in an address->secret map.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:246
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:51
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:27
static const std::string OUTPUT_TYPE_STRING_LEGACY
Definition: outputtype.cpp:15
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
Definition: outputtype.cpp:36
const std::array< OutputType, 1 > OUTPUT_TYPES
Definition: outputtype.cpp:17
bool ParseOutputType(const std::string &type, OutputType &output_type)
Definition: outputtype.cpp:19
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:87