ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

rlp decode example does not work

Open shafu0x opened this issue 3 years ago • 2 comments

Running rlp decode 0xc88363617483646f67 returns ["636174","646f67"] for me not ["cat","dog"].

What is this format and how do I return the actual string?

shafu0x avatar Apr 03 '22 20:04 shafu0x

Ok, so this seems to be a simple hex encoding. But shouldn't the function return the actual string as described in the example?

shafu0x avatar Apr 03 '22 20:04 shafu0x

hey @SharifElfouly thanks for reporting, you are indeed right we are just returning the hex strings in the cli interface.

to return the string representation, I replaced this line:

https://github.com/ethereumjs/ethereumjs-monorepo/blob/7a3549aed58836adfaf03bcb64bac4384096afc0/packages/rlp/bin/rlp#L50

with

return new TextDecoder().decode(ba)

Which works:

❯ bin/rlp decode 0xc88363617483646f67
["cat","dog"]

However then we can't decode simple numbers, like this:

"mediumint1": {
    "in": 128,
    "out": "0x8180"
  },
❯ bin/rlp encode 128
0x8180
❯ bin/rlp decode 0x8180
"�"

so I'm not sure what's the best approach here. @paulmillr do you have any thoughts?

ryanio avatar Apr 03 '22 23:04 ryanio

Outdated, will close.

holgerd77 avatar Jul 31 '23 18:07 holgerd77