Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
sighashtype.h
Go to the documentation of this file.
1// Copyright (c) 2017-2018 Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_SCRIPT_SIGHASHTYPE_H
6#define BITCOIN_SCRIPT_SIGHASHTYPE_H
7
8#include <serialize.h>
9
10#include <cstdint>
11#include <stdexcept>
12
14enum {
20};
21
35
38private:
40
41public:
43
45
49
51 return SigHashType((forkId << 8) | (sigHash & 0xff));
52 }
53
54 SigHashType withForkId(bool forkId = true) const {
56 (forkId ? SIGHASH_FORKID : 0));
57 }
58
63
65 return BaseSigHashType(sigHash & 0x1f);
66 }
67
68 uint32_t getForkValue() const { return sigHash >> 8; }
69
76
77 bool hasForkId() const { return (sigHash & SIGHASH_FORKID) != 0; }
78
79 bool hasAnyoneCanPay() const {
80 return (sigHash & SIGHASH_ANYONECANPAY) != 0;
81 }
82
84
85 template <typename Stream> void Serialize(Stream &s) const {
87 }
88
89 template <typename Stream> void Unserialize(Stream &s) {
91 }
92
96 friend constexpr bool operator==(const SigHashType &a,
97 const SigHashType &b) {
98 return a.sigHash == b.sigHash;
99 }
100
101 friend constexpr bool operator!=(const SigHashType &a,
102 const SigHashType &b) {
103 return !(a == b);
104 }
105};
106
107#endif // BITCOIN_SCRIPT_SIGHASHTYPE_H
Signature hash type wrapper class.
Definition sighashtype.h:37
uint32_t getRawSigHashType() const
Definition sighashtype.h:83
void Unserialize(Stream &s)
Definition sighashtype.h:89
BaseSigHashType getBaseType() const
Definition sighashtype.h:64
friend constexpr bool operator==(const SigHashType &a, const SigHashType &b)
Handy operators.
Definition sighashtype.h:96
SigHashType withForkId(bool forkId=true) const
Definition sighashtype.h:54
SigHashType withAnyoneCanPay(bool anyoneCanPay=true) const
Definition sighashtype.h:59
bool hasAnyoneCanPay() const
Definition sighashtype.h:79
bool isDefined() const
Definition sighashtype.h:70
SigHashType(uint32_t sigHashIn)
Definition sighashtype.h:44
void Serialize(Stream &s) const
Definition sighashtype.h:85
SigHashType withForkValue(uint32_t forkId) const
Definition sighashtype.h:50
bool hasForkId() const
Definition sighashtype.h:77
friend constexpr bool operator!=(const SigHashType &a, const SigHashType &b)
uint32_t sigHash
Definition sighashtype.h:39
SigHashType withBaseType(BaseSigHashType baseSigHashType) const
Definition sighashtype.h:46
uint32_t getForkValue() const
Definition sighashtype.h:68
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
@ SIGHASH_FORKID
Definition sighashtype.h:18
@ SIGHASH_ANYONECANPAY
Definition sighashtype.h:19
@ SIGHASH_ALL
Definition sighashtype.h:15
@ SIGHASH_NONE
Definition sighashtype.h:16
@ SIGHASH_SINGLE
Definition sighashtype.h:17
BaseSigHashType
Base signature hash types Base sig hash types not defined in this enum may be used,...
Definition sighashtype.h:29