Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
15static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
16
17const std::array<OutputType, 1> OUTPUT_TYPES = {{OutputType::LEGACY}};
18
19bool ParseOutputType(const std::string &type, OutputType &output_type) {
20 if (type == OUTPUT_TYPE_STRING_LEGACY) {
22 return true;
23 }
24 return false;
25}
26
27const std::string &FormatOutputType(OutputType type) {
28 switch (type) {
31 } // no default case, so the compiler can warn about missing cases
32 assert(false);
33}
34
36 switch (type) {
38 return PKHash(key);
39 } // no default case, so the compiler can warn about missing cases
40 assert(false);
41}
42
43std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey &key) {
44 PKHash keyid(key);
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) {
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:424
Fillable signing provider that keeps keys in an address->secret map.
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
bool ParseOutputType(const std::string &type, OutputType &output_type)
CTxDestination AddAndGetDestinationForScript(FillableSigningProvider &keystore, const CScript &script, OutputType type)
Get a destination of the requested type (if possible) to the specified script.
static const std::string OUTPUT_TYPE_STRING_LEGACY
std::vector< CTxDestination > GetAllDestinationsForKey(const CPubKey &key)
Get all destinations (potentially) supported by the wallet for the given key.
const std::string & FormatOutputType(OutputType type)
const std::array< OutputType, 1 > OUTPUT_TYPES
OutputType
Definition outputtype.h:16
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
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