data api: added block hashes to pool/blocks
This commit is contained in:
@@ -148,6 +148,9 @@ struct hash
|
||||
const uint64_t* a = reinterpret_cast<const uint64_t*>(h);
|
||||
return (a[0] == 0) && (a[1] == 0) && (a[2] == 0) && (a[3] == 0);
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& s, const hash& d);
|
||||
friend std::istream& operator>>(std::istream& s, hash& d);
|
||||
};
|
||||
|
||||
static_assert(sizeof(hash) == HASH_SIZE, "struct hash has invalid size, check your compiler options");
|
||||
|
||||
@@ -35,7 +35,7 @@ struct Stream
|
||||
enum params : int { BUF_SIZE = 1024 - 1 };
|
||||
|
||||
explicit FORCEINLINE Stream(char* buf) : m_pos(0), m_numberWidth(1), m_buf(buf), m_bufSize(BUF_SIZE) {}
|
||||
FORCEINLINE Stream(char* buf, size_t size) : m_pos(0), m_numberWidth(1), m_buf(buf), m_bufSize(static_cast<int>(size)) {}
|
||||
FORCEINLINE Stream(char* buf, size_t size) : m_pos(0), m_numberWidth(1), m_buf(buf), m_bufSize(static_cast<int>(size) - 1) {}
|
||||
|
||||
template<typename T>
|
||||
struct Entry
|
||||
|
||||
+8
-3
@@ -585,6 +585,10 @@ void p2pool::get_info()
|
||||
f >> height;
|
||||
if (f.eof()) break;
|
||||
|
||||
hash id;
|
||||
f >> id;
|
||||
if (f.eof()) break;
|
||||
|
||||
difficulty_type block_difficulty;
|
||||
f >> block_difficulty;
|
||||
if (f.eof()) break;
|
||||
@@ -592,7 +596,7 @@ void p2pool::get_info()
|
||||
difficulty_type cumulative_difficulty;
|
||||
f >> cumulative_difficulty;
|
||||
|
||||
m_foundBlocks.emplace_back(timestamp, height, block_difficulty, cumulative_difficulty);
|
||||
m_foundBlocks.emplace_back(timestamp, height, id, block_difficulty, cumulative_difficulty);
|
||||
}
|
||||
api_update_block_found(nullptr);
|
||||
}
|
||||
@@ -884,9 +888,9 @@ void p2pool::api_update_block_found(const ChainMain* data)
|
||||
{
|
||||
MutexLock lock(m_foundBlocksLock);
|
||||
if (data) {
|
||||
m_foundBlocks.emplace_back(cur_time, data->height, diff, total_hashes);
|
||||
m_foundBlocks.emplace_back(cur_time, data->height, data->id, diff, total_hashes);
|
||||
}
|
||||
found_blocks.assign(m_foundBlocks.end() - std::min<size_t>(m_foundBlocks.size(), 100), m_foundBlocks.end());
|
||||
found_blocks.assign(m_foundBlocks.end() - std::min<size_t>(m_foundBlocks.size(), 50), m_foundBlocks.end());
|
||||
}
|
||||
|
||||
m_api->set(p2pool_api::Category::POOL, "blocks",
|
||||
@@ -899,6 +903,7 @@ void p2pool::api_update_block_found(const ChainMain* data)
|
||||
s << ',';
|
||||
}
|
||||
s << "{\"height\":" << i->height << ','
|
||||
<< "\"hash\":\"" << i->id << "\","
|
||||
<< "\"difficulty\":" << i->block_diff << ','
|
||||
<< "\"totalHashes\":" << i->total_hashes << ','
|
||||
<< "\"ts\":" << i->timestamp << '}';
|
||||
|
||||
+3
-1
@@ -119,15 +119,17 @@ private:
|
||||
|
||||
struct FoundBlock
|
||||
{
|
||||
FORCEINLINE FoundBlock(time_t _t, uint64_t _h, const difficulty_type& _block_diff, const difficulty_type& _total_hashes)
|
||||
FORCEINLINE FoundBlock(time_t _t, uint64_t _h, const hash& _id, const difficulty_type& _block_diff, const difficulty_type& _total_hashes)
|
||||
: timestamp(_t)
|
||||
, height(_h)
|
||||
, id(_id)
|
||||
, block_diff(_block_diff)
|
||||
, total_hashes(_total_hashes)
|
||||
{}
|
||||
|
||||
time_t timestamp;
|
||||
uint64_t height;
|
||||
hash id;
|
||||
difficulty_type block_diff;
|
||||
difficulty_type total_hashes;
|
||||
};
|
||||
|
||||
@@ -155,6 +155,40 @@ std::istream& operator>>(std::istream& s, difficulty_type& diff)
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& s, const hash& h)
|
||||
{
|
||||
char buf[log::Stream::BUF_SIZE + 1];
|
||||
log::Stream s1(buf);
|
||||
s1 << h << '\0';
|
||||
s << buf;
|
||||
return s;
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& s, hash& h)
|
||||
{
|
||||
memset(h.h, 0, HASH_SIZE);
|
||||
|
||||
bool found_number = false;
|
||||
uint32_t index = 0;
|
||||
char c;
|
||||
while (s.good() && !s.eof()) {
|
||||
s.read(&c, 1);
|
||||
if (!s.good() || s.eof()) {
|
||||
break;
|
||||
}
|
||||
uint8_t digit;
|
||||
if (from_hex(c, digit)) {
|
||||
found_number = true;
|
||||
h.h[index >> 1] = (h.h[index >> 1] << 4) | digit;
|
||||
++index;
|
||||
}
|
||||
else if (found_number) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void uv_mutex_init_checked(uv_mutex_t* mutex)
|
||||
{
|
||||
const int result = uv_mutex_init(mutex);
|
||||
|
||||
Reference in New Issue
Block a user