@@ -31,13 +31,6 @@ for default settings use -O0. -O may be a good tradeoff between both */
31
31
#define SEP_TOKEN " ,"
32
32
#define END_TOKEN " \n "
33
33
34
- /* For 8-bit microcontrollers we should use 16 bit variables since the
35
- difficulty is low, for all the other cases should be 32 bits. */
36
- #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
37
- typedef uint32_t uintDiff;
38
- #else
39
- typedef uint32_t uintDiff;
40
- #endif
41
34
// Arduino identifier library - https://github.com/ricaun
42
35
#include " uniqueID.h"
43
36
@@ -48,7 +41,7 @@ typedef uint32_t uintDiff;
48
41
49
42
bool digitDrawn = false ;
50
43
bool matrixEnabled = true ;
51
- int minedDigitCount = 0 ;
44
+ byte minedDigitCount = 0 ;
52
45
53
46
Adafruit_Microbit_Matrix microbit;
54
47
#endif
@@ -102,7 +95,7 @@ void lowercase_hex_to_bytes(char const * hexDigest, uint8_t * rawDigest) {
102
95
}
103
96
104
97
// DUCO-S1A hasher
105
- uintDiff ducos1a (char const * prevBlockHash, char const * targetBlockHash, uintDiff difficulty) {
98
+ uint32_t ducos1a (char const * prevBlockHash, char const * targetBlockHash, uint32_t difficulty) {
106
99
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
107
100
// If the difficulty is too high for AVR architecture then return 0
108
101
if (difficulty > 655 ) return 0 ;
@@ -111,16 +104,16 @@ uintDiff ducos1a(char const * prevBlockHash, char const * targetBlockHash, uintD
111
104
uint8_t target[SHA1_HASH_LEN];
112
105
lowercase_hex_to_bytes (targetBlockHash, target);
113
106
114
- uintDiff const maxNonce = difficulty * 100 + 1 ;
107
+ uint32_t const maxNonce = difficulty * 100 + 1 ;
115
108
return ducos1a_mine (prevBlockHash, target, maxNonce);
116
109
}
117
110
118
- uintDiff ducos1a_mine (char const * prevBlockHash, uint8_t const * target, uintDiff maxNonce) {
111
+ uint32_t ducos1a_mine (char const * prevBlockHash, uint8_t const * target, uint32_t maxNonce) {
119
112
static duco_hash_state_t hash;
120
113
duco_hash_init (&hash, prevBlockHash);
121
114
122
115
char nonceStr[10 + 1 ];
123
- for (uintDiff nonce = 0 ; nonce < maxNonce; nonce++) {
116
+ for (uint32_t nonce = 0 ; nonce < maxNonce; nonce++) {
124
117
ultoa (nonce, nonceStr, 10 );
125
118
126
119
uint8_t const * hash_bytes = duco_hash_try_nonce (&hash, nonceStr);
@@ -174,7 +167,7 @@ void loop() {
174
167
newBlockHash[40 ] = 0 ;
175
168
176
169
// Read difficulty
177
- uintDiff difficulty = strtoul (Serial.readStringUntil (' ,' ).c_str (), NULL , 10 );
170
+ uint32_t difficulty = strtoul (Serial.readStringUntil (' ,' ).c_str (), NULL , 10 );
178
171
// Clearing the receive buffer reading one job.
179
172
while (Serial.available ()) Serial.read ();
180
173
// Turn off the built-in led
@@ -188,7 +181,7 @@ void loop() {
188
181
uint32_t startTime = micros ();
189
182
190
183
// Call DUCO-S1A hasher
191
- uintDiff ducos1result = ducos1a (lastBlockHash, newBlockHash, difficulty);
184
+ uint32_t ducos1result = ducos1a (lastBlockHash, newBlockHash, difficulty);
192
185
193
186
// Calculate elapsed time
194
187
uint32_t elapsedTime = micros () - startTime;
0 commit comments