Skip to content

Commit

Permalink
[Refactor] Migrate uint256.h/.cpp to blob_uint implementation
Browse files Browse the repository at this point in the history
- delete old uint256.h/uint256.cpp files
- delete old uint512.h
- rename files blob_uint256.h/blob_uint256.cpp --> uint256.h/uint256.cpp
- rename class blob_uint256 --> uint256
- add uint160/512 blob implementation inside uint256.* files
- move UintToArith/ArithToUint to arith_uint256.cpp
  • Loading branch information
random-zebra committed May 5, 2021
1 parent 957f529 commit 22213ff
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 445 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ set(UTIL_SOURCES
./src/rpc/protocol.cpp
./src/sync.cpp
./src/threadinterrupt.cpp
./src/blob_uint256.cpp
./src/arith_uint256.cpp
./src/uint256.cpp
./src/util/threadnames.cpp
Expand Down
4 changes: 0 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ BITCOIN_CORE_H = \
guiinterface.h \
guiinterfaceutil.h \
uint256.h \
uint512.h \
blob_uint256.h \
undo.h \
util/memory.h \
util.h \
Expand Down Expand Up @@ -547,7 +545,6 @@ libbitcoin_util_a_SOURCES = \
sync.cpp \
threadinterrupt.cpp \
uint256.cpp \
blob_uint256.cpp \
util.cpp \
utilmoneystr.cpp \
util/threadnames.cpp \
Expand Down Expand Up @@ -689,7 +686,6 @@ libbitcoinconsensus_la_SOURCES = \
script/interpreter.cpp \
script/bitcoinconsensus.cpp \
uint256.cpp \
blob_uint256.cpp \
utilstrencodings.cpp

if GLIBC_BACK_COMPAT
Expand Down
31 changes: 30 additions & 1 deletion src/arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "crypto/common.h"
#include "uint256.h"
#include "uint512.h"
#include "utilstrencodings.h"

#include <stdio.h>
Expand Down Expand Up @@ -325,3 +324,33 @@ uint256 arith_uint512::trim256() const
return uint256(vch);
}

uint256 ArithToUint256(const arith_uint256 &a)
{
uint256 b;
for(int x=0; x<a.WIDTH; ++x)
WriteLE32(b.begin() + x*4, a.pn[x]);
return b;
}
arith_uint256 UintToArith256(const uint256 &a)
{
arith_uint256 b;
for(int x=0; x<b.WIDTH; ++x)
b.pn[x] = ReadLE32(a.begin() + x*4);
return b;
}

uint512 ArithToUint512(const arith_uint512 &a)
{
uint512 b;
for(int x=0; x<a.WIDTH; ++x)
WriteLE32(b.begin() + x*4, a.pn[x]);
return b;
}
arith_uint512 UintToArith512(const uint512 &a)
{
arith_uint512 b;
for(int x=0; x<b.WIDTH; ++x)
b.pn[x] = ReadLE32(a.begin() + x*4);
return b;
}

18 changes: 9 additions & 9 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
#ifndef BITCOIN_ARITH_UINT256_H
#define BITCOIN_ARITH_UINT256_H

#include "blob_uint256.h"
#include "uint512.h"
#include <assert.h>
#include <cstring>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <vector>

class blob_uint512;
class blob_uint256;
class uint256;
class uint512;

Expand Down Expand Up @@ -363,6 +359,9 @@ class arith_uint256 : public base_uint<256> {
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
uint32_t GetCompact(bool fNegative = false) const;
uint32_t Get32(int n = 0) const { return pn[2 * n]; }

friend arith_uint256 UintToArith256(const uint256 &a);
friend uint256 ArithToUint256(const arith_uint256 &a);
};

/** 512-bit unsigned big integer. */
Expand All @@ -376,14 +375,15 @@ class arith_uint512 : public base_uint<512> {

uint256 trim256() const;

//friend arith_uint512 UintToArith512(const blob_uint512 &a);
//friend blob_uint512 ArithToUint512(const arith_uint512 &a);
friend arith_uint512 UintToArith512(const uint512 &a);
friend uint512 ArithToUint512(const arith_uint512 &a);

};

/** Old classes definitions */

/** End classes definitions */
uint256 ArithToUint256(const arith_uint256 &);
arith_uint256 UintToArith256(const uint256 &);
uint512 ArithToUint512(const arith_uint512 &);
arith_uint512 UintToArith512(const uint512 &);

const arith_uint256 ARITH_UINT256_ZERO = arith_uint256();
const arith_uint256 ARITH_UINT256_ONE = arith_uint256(1);
Expand Down
83 changes: 0 additions & 83 deletions src/blob_uint256.cpp

This file was deleted.

165 changes: 0 additions & 165 deletions src/blob_uint256.h

This file was deleted.

1 change: 1 addition & 0 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef PIVX_HASH_H
#define PIVX_HASH_H

#include "arith_uint256.h"
#include "crypto/ripemd160.h"
#include "crypto/sha256.h"
#include "prevector.h"
Expand Down
2 changes: 1 addition & 1 deletion src/sapling/proof.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ZC_PROOF_H_

#include "serialize.h"
#include "blob_uint256.h"
#include "uint256.h"

namespace libzcash {

Expand Down
2 changes: 1 addition & 1 deletion src/sapling/zip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef PIVX_ZIP32_H
#define PIVX_ZIP32_H

#include "blob_uint256.h"
#include "uint256.h"
#include "key.h"
#include "sapling/address.h"
#include "serialize.h"
Expand Down
Loading

0 comments on commit 22213ff

Please sign in to comment.