chainpoint / chainpoint-gateway

Chainpoint Gateway
https://chainpoint.org
Apache License 2.0
27 stars 12 forks source link

Fix `decodeCalendarTopBlockHeightValue` #24

Closed filoozom closed 6 years ago

filoozom commented 6 years ago

Maybe I'm missing something here, but an offset of 0 should work. As stated in #23:

$ docker run --rm -it node:alpine
> let buf = Buffer.from([0x00, 0x21, 0x6c, 0xa3])
> buf.readUInt32BE(buf)
TypeError [ERR_INVALID_ARG_TYPE]: The "offset" argument must be of type number. Received type object
    at checkNumberType (internal/buffer.js:42:11)
    at Buffer.readUInt32BE (internal/buffer.js:194:3)

$ docker run --rm -it node:8-alpine
> let buf = Buffer.from([0x00, 0x21, 0x6c, 0xa3]) 
undefined
> buf.readUInt32BE(buf)
2190499

A buffer obviously can't be an integer offset, right? I'm quite surprised that it worked on Node 8. In any case, it doesn't in Node 10 anymore.

filoozom commented 6 years ago

The definition of the function is buf.readUInt32BE(offset), not buf.readUInt32BE([offset]), which is why I decided to go with 0 instead of nothing at all. Who knows, maybe Node 11 or 12 will throw an error on undefined too 😛

grempe commented 6 years ago

Merged! Thanks for the find and the fix @filoozom !