@@ -319,9 +319,7 @@ impl TryFrom<StandardRequest> for Subscribe<'_> {
319
319
[ JString ( a) , Null , JString ( _) , Null ] => ( a. into ( ) , None ) ,
320
320
// bosminer subscribe message
321
321
[ JString ( a) , Null ] => ( a. into ( ) , None ) ,
322
- [ JString ( a) , JString ( b) ] => {
323
- ( a. into ( ) , Some ( Extranonce :: try_from ( hex:: decode ( b) ?) ?) )
324
- }
322
+ [ JString ( a) , JString ( b) ] => ( a. into ( ) , Some ( Extranonce :: try_from ( b. as_str ( ) ) ?) ) ,
325
323
[ JString ( a) ] => ( a. into ( ) , None ) ,
326
324
[ ] => ( "" . to_string ( ) , None ) ,
327
325
_ => return Err ( ParsingMethodError :: wrong_args_from_value ( msg. params ) ) ,
@@ -716,3 +714,36 @@ fn test_version_extension_with_no_bit_count() {
716
714
_ => panic ! ( ) ,
717
715
} ;
718
716
}
717
+
718
+ #[ test]
719
+ fn test_subscribe_with_odd_length_extranonce ( ) {
720
+ // Test that odd-length hex strings (with leading zeroes) are handled correctly
721
+ let client_message = r#"{"id":1,
722
+ "method": "mining.subscribe",
723
+ "params":["test-agent", "abc"]
724
+ }"# ;
725
+ let client_message: StandardRequest = serde_json:: from_str ( client_message) . unwrap ( ) ;
726
+ let subscribe = Subscribe :: try_from ( client_message) . unwrap ( ) ;
727
+
728
+ // Should successfully parse odd-length hex string by prepending "0"
729
+ assert_eq ! ( subscribe. agent_signature, "test-agent" ) ;
730
+ assert ! ( subscribe. extranonce1. is_some( ) ) ;
731
+ let extranonce = subscribe. extranonce1 . unwrap ( ) ;
732
+ assert_eq ! ( extranonce. 0 . inner_as_ref( ) , & [ 0x0a , 0xbc ] ) ; // "0abc" -> [10, 188]
733
+ }
734
+
735
+ #[ test]
736
+ fn test_subscribe_with_even_length_extranonce ( ) {
737
+ // Test that even-length hex strings work as before
738
+ let client_message = r#"{"id":1,
739
+ "method": "mining.subscribe",
740
+ "params":["test-agent", "abcd"]
741
+ }"# ;
742
+ let client_message: StandardRequest = serde_json:: from_str ( client_message) . unwrap ( ) ;
743
+ let subscribe = Subscribe :: try_from ( client_message) . unwrap ( ) ;
744
+
745
+ assert_eq ! ( subscribe. agent_signature, "test-agent" ) ;
746
+ assert ! ( subscribe. extranonce1. is_some( ) ) ;
747
+ let extranonce = subscribe. extranonce1 . unwrap ( ) ;
748
+ assert_eq ! ( extranonce. 0 . inner_as_ref( ) , & [ 0xab , 0xcd ] ) ; // "abcd" -> [171, 205]
749
+ }
0 commit comments