Skip to content

Commit a3780d3

Browse files
committed
rebase onto bitcoin core 24.0.1
1 parent d919e9a commit a3780d3

File tree

142 files changed

+32319
-4508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+32319
-4508
lines changed

Makefile.am

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ LIBBITCOIN_DEB_H = \
3636
# bitcoin core #
3737
BITCOIN_CORE_H = \
3838
$(LIBBITCOIN_DEB_H) \
39-
amount.h \
4039
arith_uint256.h \
4140
attributes.h \
4241
base58.h \
@@ -45,14 +44,15 @@ BITCOIN_CORE_H = \
4544
compat/byteswap.h \
4645
compat/cpuid.h \
4746
compat/endian.h \
47+
consensus/amount.h \
48+
consensus/merkle.h \
4849
crypto/common.h \
4950
crypto/hmac_sha512.h \
5051
crypto/ripemd160.h \
5152
crypto/sha1.h \
5253
crypto/sha256.h \
5354
crypto/sha512.h \
5455
hash.h \
55-
merkle.h \
5656
policy/policy.h \
5757
prevector.h \
5858
primitives/transaction.h \
@@ -69,6 +69,7 @@ BITCOIN_CORE_H = \
6969
support/lockedpool.h \
7070
tinyformat.h \
7171
uint256.h \
72+
util/overflow.h \
7273
util/spanparsing.h \
7374
util/strencodings.h \
7475
util/vector.h \
@@ -86,20 +87,20 @@ libbitcoin_deb_a_SOURCES = \
8687
$(BITCOIN_CORE_H)
8788

8889
# bitcoin: shared between all the tools
89-
libbitcoin_a_LIBADD = $(LIBSECP256K1)
90+
# libbitcoin_a_LIBADD = $(LIBSECP256K1)
9091
libbitcoin_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
9192
libbitcoin_a_CXXFLAGS = $(AM_CXXFLAGS)
9293
libbitcoin_a_SOURCES = \
9394
arith_uint256.cpp \
9495
base58.cpp \
9596
bech32.cpp \
97+
consensus/merkle.cpp \
9698
crypto/hmac_sha512.cpp \
9799
crypto/ripemd160.cpp \
98100
crypto/sha1.cpp \
99101
crypto/sha256.cpp \
100102
crypto/sha512.cpp \
101103
hash.cpp \
102-
merkle.cpp \
103104
primitives/transaction.cpp \
104105
pubkey.cpp \
105106
script/interpreter.cpp \

arith_uint256.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ base_uint<BITS>& base_uint<BITS>::operator/=(const base_uint& b)
9696
while (shift >= 0) {
9797
if (num >= div) {
9898
num -= div;
99-
pn[shift / 32] |= (1 << (shift & 31)); // set a bit of the result.
99+
pn[shift / 32] |= (1U << (shift & 31)); // set a bit of the result.
100100
}
101101
div >>= 1; // shift back.
102102
shift--;
@@ -146,13 +146,21 @@ double base_uint<BITS>::getdouble() const
146146
template <unsigned int BITS>
147147
std::string base_uint<BITS>::GetHex() const
148148
{
149-
return ArithToUint256(*this).GetHex();
149+
base_blob<BITS> b;
150+
for (int x = 0; x < this->WIDTH; ++x) {
151+
WriteLE32(b.begin() + x*4, this->pn[x]);
152+
}
153+
return b.GetHex();
150154
}
151155

152156
template <unsigned int BITS>
153157
void base_uint<BITS>::SetHex(const char* psz)
154158
{
155-
*this = UintToArith256(uint256S(psz));
159+
base_blob<BITS> b;
160+
b.SetHex(psz);
161+
for (int x = 0; x < this->WIDTH; ++x) {
162+
this->pn[x] = ReadLE32(b.begin() + x*4);
163+
}
156164
}
157165

158166
template <unsigned int BITS>
@@ -164,7 +172,7 @@ void base_uint<BITS>::SetHex(const std::string& str)
164172
template <unsigned int BITS>
165173
std::string base_uint<BITS>::ToString() const
166174
{
167-
return (GetHex());
175+
return GetHex();
168176
}
169177

170178
template <unsigned int BITS>
@@ -183,20 +191,7 @@ unsigned int base_uint<BITS>::bits() const
183191
}
184192

185193
// Explicit instantiations for base_uint<256>
186-
template base_uint<256>::base_uint(const std::string&);
187-
template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
188-
template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
189-
template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);
190-
template base_uint<256>& base_uint<256>::operator*=(const base_uint<256>& b);
191-
template base_uint<256>& base_uint<256>::operator/=(const base_uint<256>& b);
192-
template int base_uint<256>::CompareTo(const base_uint<256>&) const;
193-
template bool base_uint<256>::EqualTo(uint64_t) const;
194-
template double base_uint<256>::getdouble() const;
195-
template std::string base_uint<256>::GetHex() const;
196-
template std::string base_uint<256>::ToString() const;
197-
template void base_uint<256>::SetHex(const char*);
198-
template void base_uint<256>::SetHex(const std::string&);
199-
template unsigned int base_uint<256>::bits() const;
194+
template class base_uint<256>;
200195

201196
// This implementation directly uses shifts instead of going
202197
// through an intermediate MPI representation.
@@ -236,7 +231,7 @@ uint32_t arith_uint256::GetCompact(bool fNegative) const
236231
nCompact >>= 8;
237232
nSize++;
238233
}
239-
assert((nCompact & ~0x007fffff) == 0);
234+
assert((nCompact & ~0x007fffffU) == 0);
240235
assert(nSize < 256);
241236
nCompact |= nSize << 24;
242237
nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);

arith_uint256.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,19 @@ template<unsigned int BITS>
2424
class base_uint
2525
{
2626
protected:
27+
static_assert(BITS / 32 > 0 && BITS % 32 == 0, "Template parameter BITS must be a positive multiple of 32.");
2728
static constexpr int WIDTH = BITS / 32;
2829
uint32_t pn[WIDTH];
2930
public:
3031

3132
base_uint()
3233
{
33-
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
34-
3534
for (int i = 0; i < WIDTH; i++)
3635
pn[i] = 0;
3736
}
3837

3938
base_uint(const base_uint& b)
4039
{
41-
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
42-
4340
for (int i = 0; i < WIDTH; i++)
4441
pn[i] = b.pn[i];
4542
}
@@ -53,8 +50,6 @@ class base_uint
5350

5451
base_uint(uint64_t b)
5552
{
56-
static_assert(BITS/32 > 0 && BITS%32 == 0, "Template parameter BITS must be a positive multiple of 32.");
57-
5853
pn[0] = (unsigned int)b;
5954
pn[1] = (unsigned int)(b >> 32);
6055
for (int i = 2; i < WIDTH; i++)
@@ -288,4 +283,6 @@ class arith_uint256 : public base_uint<256> {
288283
uint256 ArithToUint256(const arith_uint256 &);
289284
arith_uint256 UintToArith256(const uint256 &);
290285

286+
extern template class base_uint<256>;
287+
291288
#endif // BITCOIN_ARITH_UINT256_H

base58.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2020 The Bitcoin Core developers
1+
// Copyright (c) 2014-2021 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -7,6 +7,7 @@
77
#include <hash.h>
88
#include <uint256.h>
99
#include <util/strencodings.h>
10+
#include <util/string.h>
1011

1112
#include <assert.h>
1213
#include <string.h>
@@ -125,7 +126,7 @@ std::string EncodeBase58(Span<const unsigned char> input)
125126

126127
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len)
127128
{
128-
if (!ValidAsCString(str)) {
129+
if (!ContainsNoNUL(str)) {
129130
return false;
130131
}
131132
return DecodeBase58(str.c_str(), vchRet, max_ret_len);
@@ -148,7 +149,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)
148149
return false;
149150
}
150151
// re-calculate the checksum, ensure it matches the included 4-byte checksum
151-
uint256 hash = Hash(MakeSpan(vchRet).first(vchRet.size() - 4));
152+
uint256 hash = Hash(Span{vchRet}.first(vchRet.size() - 4));
152153
if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
153154
vchRet.clear();
154155
return false;
@@ -159,7 +160,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)
159160

160161
bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret)
161162
{
162-
if (!ValidAsCString(str)) {
163+
if (!ContainsNoNUL(str)) {
163164
return false;
164165
}
165166
return DecodeBase58Check(str.c_str(), vchRet, max_ret);

base58.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef BITCOIN_BASE58_H
1515
#define BITCOIN_BASE58_H
1616

17-
#include <attributes.h>
1817
#include <span.h>
1918

2019
#include <string>

0 commit comments

Comments
 (0)