Hello i've opened a thread lately about converting a function in xmrig to a python version of it.
I rewrote a thread with better presentation including all the needed c++ code to understand how the function works and the actual python version of it i've coded.
The code just basically get a job from a monero pool and then try to extract tx count of the block from the "blob" an hexadecimal string.
Here the c++ code :
Cvt::fromHex is just sodium_hex2bin function in c++ i tought the equivalent in python is bytesarray.fromhex(self.blob)
Here the python version i've coded :
It sometimes return the right tx count with 1 more tx and sometimes a completly wrong number ! something should went wrong with type casting or hexadecimal to bytes conversion.
Looking for some help to get the exact tx count from the actual height job !
Regards ✌
I rewrote a thread with better presentation including all the needed c++ code to understand how the function works and the actual python version of it i've coded.
The code just basically get a job from a monero pool and then try to extract tx count of the block from the "blob" an hexadecimal string.
Here the c++ code :
Code
uint32_t xmrig::Job::getNumTransactions() const
{
uint32_t num_transactions = 0;
// Monero (and some other coins) has the number of transactions encoded as varint in the end of hashing blob
const size_t expected_tx_offset = 75;
if ((m_size > expected_tx_offset) && (m_size <= expected_tx_offset + 4)) {
for (size_t i = expected_tx_offset, k = 0; i < m_size; ++i, k += 7) {
const uint8_t b = m_blob[i];
num_transactions |= static_cast<uint32_t>(b & 0x7F) << k;
if ((b & 0x80) == 0) {
break;
}
}
}
return num_transactions;
}Code
bool xmrig::Job::setBlob(const char *blob)
{
if (!blob) {
return false;
}
m_size = strlen(blob);
if (m_size % 2 != 0) {
return false;
}
m_size /= 2;
const size_t minSize = nonceOffset() + nonceSize();
if (m_size < minSize || m_size >= sizeof(m_blob)) {
return false;
}
if (!Cvt::fromHex(m_blob, sizeof(m_blob), blob, m_size * 2)) {
return false;
}
if (readUnaligned(nonce()) != 0 && !m_nicehash) {
m_nicehash = true;
}
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawBlob, 0, sizeof(m_rawBlob));
memcpy(m_rawBlob, blob, m_size * 2);
# endif
return true;
}Cvt::fromHex is just sodium_hex2bin function in c++ i tought the equivalent in python is bytesarray.fromhex(self.blob)
Here the python version i've coded :
Code
def _getNumTransactions(self):
txCount = 0
print(self.blob)
blob = bytearray.fromhex(self.blob)
txOffset = 75
k = 0
if txOffset < len(blob) <= txOffset + 4:
for bit in blob[txOffset:]:
bit = bit % 2**8
txCount |= (((bit & 0x7F) % 2**32) << k) % 2**32
if (bit & 0x80) == 0: break
k += 7
return txCountIt sometimes return the right tx count with 1 more tx and sometimes a completly wrong number ! something should went wrong with type casting or hexadecimal to bytes conversion.
Looking for some help to get the exact tx count from the actual height job !
Regards ✌
