@@ -211,13 +211,13 @@ func mustConvertHeader(in btHeader) *types.Header {
211211 UncleHash : mustConvertHash (in .UncleHash ),
212212 ParentHash : mustConvertHash (in .ParentHash ),
213213 Extra : mustConvertBytes (in .ExtraData ),
214- GasUsed : mustConvertBigInt (in .GasUsed ),
215- GasLimit : mustConvertBigInt (in .GasLimit ),
216- Difficulty : mustConvertBigInt (in .Difficulty ),
217- Time : mustConvertUint (in .Timestamp ),
214+ GasUsed : mustConvertBigInt (in .GasUsed , 10 ),
215+ GasLimit : mustConvertBigInt (in .GasLimit , 10 ),
216+ Difficulty : mustConvertBigInt (in .Difficulty , 10 ),
217+ Time : mustConvertUint (in .Timestamp , 10 ),
218218 }
219219 // XXX cheats? :-)
220- header .SetNonce (common . BytesToHash ( mustConvertBytes ( in .Nonce )). Big (). Uint64 ( ))
220+ header .SetNonce (mustConvertUint ( in .Nonce , 16 ))
221221 return header
222222}
223223
@@ -238,7 +238,7 @@ func mustConvertBytes(in string) []byte {
238238 if in == "0x" {
239239 return []byte {}
240240 }
241- h := strings .TrimPrefix (unfuckCPPHexInts ( in ) , "0x" )
241+ h := nibbleFix ( strings .TrimPrefix (in , "0x" ) )
242242 out , err := hex .DecodeString (h )
243243 if err != nil {
244244 panic (fmt .Errorf ("invalid hex: %q" , h ))
@@ -255,7 +255,7 @@ func mustConvertHash(in string) common.Hash {
255255}
256256
257257func mustConvertAddress (in string ) common.Address {
258- out , err := hex .DecodeString (strings .TrimPrefix (in , "0x" ))
258+ out , err := hex .DecodeString (nibbleFix ( strings .TrimPrefix (in , "0x" ) ))
259259 if err != nil {
260260 panic (fmt .Errorf ("invalid hex: %q" , in ))
261261 }
@@ -270,16 +270,18 @@ func mustConvertBloom(in string) types.Bloom {
270270 return types .BytesToBloom (out )
271271}
272272
273- func mustConvertBigInt (in string ) * big.Int {
274- out , ok := new (big.Int ).SetString (unfuckCPPHexInts (in ), 0 )
273+ func mustConvertBigInt (in string , base int ) * big.Int {
274+ in = prepInt (base , in )
275+ out , ok := new (big.Int ).SetString (in , base )
275276 if ! ok {
276277 panic (fmt .Errorf ("invalid integer: %q" , in ))
277278 }
278279 return out
279280}
280281
281- func mustConvertUint (in string ) uint64 {
282- out , err := strconv .ParseUint (unfuckCPPHexInts (in ), 0 , 64 )
282+ func mustConvertUint (in string , base int ) uint64 {
283+ in = prepInt (base , in )
284+ out , err := strconv .ParseUint (in , base , 64 )
283285 if err != nil {
284286 panic (fmt .Errorf ("invalid integer: %q" , in ))
285287 }
@@ -316,19 +318,22 @@ func findLine(data []byte, offset int64) (line int) {
316318 return
317319}
318320
319- func unfuckCPPHexInts (s string ) string {
320- switch {
321- case s == "0x" :
322- // no respect for the empty value :(
323- return "0x00"
324- case len (s ) == 0 :
325- return "0x00"
326- case len (s ) == 1 :
327- return "0x0" + s [:1 ]
328- case len (s )% 2 != 0 :
329- // motherfucking nibbles
330- return "0x0" + s [2 :]
331- default :
332- return s
321+ func prepInt (base int , s string ) string {
322+ if base == 16 {
323+ if strings .HasPrefix (s , "0x" ) {
324+ s = s [2 :]
325+ }
326+ if len (s ) == 0 {
327+ s = "00"
328+ }
329+ s = nibbleFix (s )
330+ }
331+ return s
332+ }
333+
334+ func nibbleFix (s string ) string {
335+ if len (s )% 2 != 0 {
336+ s = "0" + s
333337 }
338+ return s
334339}
0 commit comments