88#include <ctype.h>
99#include "mbedtls/sha256.h"
1010
11+ #define BIP110_SIGNAL_BIT 4
12+ #define BIP110_SIGNAL_EXPIRY_BLOCK 965664
13+
1114// Wrapper for SHA256 to match libbase58's expected signature
1215static bool my_sha256 (void * digest , const void * data , size_t datasz ) {
1316 mbedtls_sha256 (data , datasz , digest , 0 );
@@ -144,14 +147,14 @@ esp_err_t coinbase_process_notification(const mining_notify *notification,
144147 const char * extranonce1 ,
145148 int extranonce2_len ,
146149 const char * user_address ,
147- bool decode_outputs ,
150+ bool decode_coinbase_tx ,
148151 mining_notification_result_t * result ) {
149152 if (!notification || !extranonce1 || !result ) return ESP_ERR_INVALID_ARG ;
150153
151154 // Initialize result
152155 result -> total_value_satoshis = 0 ;
153156 result -> user_value_satoshis = 0 ;
154- result -> decoding_enabled = decode_outputs ;
157+ result -> decode_coinbase_tx = decode_coinbase_tx ;
155158
156159 // 1. Calculate difficulty
157160 result -> network_difficulty = networkDifficulty (notification -> target );
@@ -178,6 +181,9 @@ esp_err_t coinbase_process_notification(const mining_notify *notification,
178181 hex2bin (notification -> coinbase_1 + (coinbase_1_offset * 2 ), (uint8_t * )& result -> block_height , block_height_len );
179182 coinbase_1_offset += block_height_len ;
180183
184+ // Detect BIP-110 signaling: check if bit 4 (0x00000010) is set in version
185+ result -> bip110_signaling = decode_coinbase_tx && result -> block_height < BIP110_SIGNAL_EXPIRY_BLOCK && (notification -> version & (1U << BIP110_SIGNAL_BIT )) != 0 ;
186+
181187 // Calculate remaining scriptsig length (excluding block height part)
182188 int scriptsig_length = scriptsig_len - 1 - block_height_len ;
183189 size_t extranonce1_len = strlen (extranonce1 ) / 2 ;
@@ -281,7 +287,7 @@ esp_err_t coinbase_process_notification(const mining_notify *notification,
281287
282288 if (offset + script_len > coinbase_2_len ) break ;
283289
284- if (decode_outputs ) {
290+ if (decode_coinbase_tx ) {
285291 if (value_satoshis > 0 ) {
286292 char output_address [MAX_ADDRESS_STRING_LEN ];
287293 coinbase_decode_address_from_scriptpubkey (coinbase_2_bin + offset , script_len , output_address , MAX_ADDRESS_STRING_LEN );
0 commit comments