]> Git Repo - VerusCoin.git/blame - src/uint252.h
Merge branch 'dev' into jl777
[VerusCoin.git] / src / uint252.h
CommitLineData
defe37a6
SB
1#ifndef UINT252_H
2#define UINT252_H
3
4#include <vector>
5#include "uint256.h"
6#include "serialize.h"
7
8// Wrapper of uint256 with guarantee that first
9// four bits are zero.
10class uint252 {
11private:
12 uint256 contents;
13
14public:
15 ADD_SERIALIZE_METHODS;
16
17 template <typename Stream, typename Operation>
18 inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
19 READWRITE(contents);
20
21 if ((*contents.begin()) & 0xF0) {
22 throw std::ios_base::failure("spending key has invalid leading bits");
23 }
24 }
25
26 const unsigned char* begin() const
27 {
28 return contents.begin();
29 }
30
31 const unsigned char* end() const
32 {
33 return contents.end();
34 }
35
36 uint252() : contents() {};
37 explicit uint252(const uint256& in) : contents(in) {
38 if (*contents.begin() & 0xF0) {
39 throw std::domain_error("leading bits are set in argument given to uint252 constructor");
40 }
41 }
42
43 uint256 inner() const {
44 return contents;
45 }
7c929cf5
JG
46
47 friend inline bool operator==(const uint252& a, const uint252& b) { return a.contents == b.contents; }
defe37a6
SB
48};
49
50#endif
This page took 0.15318 seconds and 4 git commands to generate.