@@ -187,9 +187,9 @@ func mustConvertHeader(in btHeader) *types.Header {
187187 UncleHash : mustConvertHash (in .UncleHash ),
188188 ParentHash : mustConvertHash (in .ParentHash ),
189189 Extra : mustConvertBytes (in .ExtraData ),
190- GasUsed : mustConvertBigInt10 (in .GasUsed ),
191- GasLimit : mustConvertBigInt10 (in .GasLimit ),
192- Difficulty : mustConvertBigInt10 (in .Difficulty ),
190+ GasUsed : mustConvertBigInt (in .GasUsed ),
191+ GasLimit : mustConvertBigInt (in .GasLimit ),
192+ Difficulty : mustConvertBigInt (in .Difficulty ),
193193 Time : mustConvertUint (in .Timestamp ),
194194 }
195195 // XXX cheats? :-)
@@ -211,9 +211,13 @@ func mustConvertBlocks(testBlocks []btBlock) []*types.Block {
211211}
212212
213213func mustConvertBytes (in string ) []byte {
214- out , err := hex .DecodeString (strings .TrimPrefix (in , "0x" ))
214+ if in == "0x" {
215+ return []byte {}
216+ }
217+ h := strings .TrimPrefix (unfuckCPPHexInts (in ), "0x" )
218+ out , err := hex .DecodeString (h )
215219 if err != nil {
216- panic (fmt .Errorf ("invalid hex: %q" , in ))
220+ panic (fmt .Errorf ("invalid hex: %q" , h ))
217221 }
218222 return out
219223}
@@ -242,32 +246,16 @@ func mustConvertBloom(in string) types.Bloom {
242246 return types .BytesToBloom (out )
243247}
244248
245- func mustConvertBigInt10 (in string ) * big.Int {
246- out , ok := new (big.Int ).SetString (in , 10 )
247- if ! ok {
248- panic (fmt .Errorf ("invalid integer: %q" , in ))
249- }
250- return out
251- }
252-
253- func mustConvertBigIntHex (in string ) * big.Int {
254- out , ok := new (big.Int ).SetString (in , 16 )
249+ func mustConvertBigInt (in string ) * big.Int {
250+ out , ok := new (big.Int ).SetString (unfuckCPPHexInts (in ), 0 )
255251 if ! ok {
256252 panic (fmt .Errorf ("invalid integer: %q" , in ))
257253 }
258254 return out
259255}
260256
261257func mustConvertUint (in string ) uint64 {
262- out , err := strconv .ParseUint (in , 0 , 64 )
263- if err != nil {
264- panic (fmt .Errorf ("invalid integer: %q" , in ))
265- }
266- return out
267- }
268-
269- func mustConvertUintHex (in string ) uint64 {
270- out , err := strconv .ParseUint (in , 16 , 64 )
258+ out , err := strconv .ParseUint (unfuckCPPHexInts (in ), 0 , 64 )
271259 if err != nil {
272260 panic (fmt .Errorf ("invalid integer: %q" , in ))
273261 }
@@ -303,3 +291,13 @@ func findLine(data []byte, offset int64) (line int) {
303291 }
304292 return
305293}
294+
295+ func unfuckCPPHexInts (s string ) string {
296+ if s == "0x" { // no respect for the empty value :(
297+ return "0x00"
298+ }
299+ if (len (s ) % 2 ) != 0 { // motherfucking nibbles
300+ return "0x0" + s [2 :]
301+ }
302+ return s
303+ }
0 commit comments