-
Notifications
You must be signed in to change notification settings - Fork 272
Add method for stripping leading hex zeroes #79
Comments
How about something along the lines of |
Correct handling of quantities and unformatted data is already implemented by ganache-core. I think it is more correct to have those features there because ganache-core is specifically about handling RPC communications. Maybe those features could be more useful into ethrpc, though reading the project's description it seems they are already there. I didn't find them but notice the output of rpc.eth.blockNumber(). |
This is not about correct handling quantities and data but just about providing a helper function which would transform data into a specific format (which could be e.g. used for correct data transmission in the problem case described above). Don't see why this shouldn't fit into the scope of this library. I actually prefer the |
My reasoning is this.
|
@Neurone Hmm, this is not specifically for |
@holgerd77 Sorry, but I currently cannot see the usefulness of this in other contexts. The stripZero() function should be enough for anyone that wants only to remove leading zeros. |
There is prior art for having a strip/trim function that accepts a direction (defaulting to some direction, probably trailing) e.g. Erlang[1], Matlab[2], and R[3]. We could introduce a Edit: Looks like there's already precedent for that kind of API here in Lines 97 to 122 in ff7bb86
|
I am actually getting lost here a bit what trim/strip cases we are talking about and what cases are not covered by actual functionality like Could you give 4-5 practical in-out examples together with the flag you are suggesting? |
This is offered by addHexPrefix(unpad('0x00060a24181e4000')) === '0x60a24181e4000'
// => true |
Will close in favor of ethereumjs/ethereumjs-monorepo#1302 |
Opening for comment.
Geth recently became more strict and now rejects many hex values that have leading zeroes (ie
0x02
instead of0x2
).The official RPC spec dictates that quantities should have no leading zero, and unformatted data should.
For this reason, it would probably make sense to include some new methods here for creating un-prefixed hex numbers.
I'm curious what kind of API surface people would like for that. Maybe something as simple as a
stripZeroPrefix()
method? I could submit that PR in minutes. We could also have a few new methods, for converting different things to this new type of hex, but that might get more confusing.Thoughts? Would a
stripZeroPrefix()
method get merged?The text was updated successfully, but these errors were encountered: