Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tx parse #1362

Merged
merged 2 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
implement txparse tool and add make target for txparse
  • Loading branch information
jangko committed Dec 10, 2022
commit dcd122572474b6d00e65cf1849bb7d1892a52aa9
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ evmstate: | build deps
evmstate_test: | build deps evmstate
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) "tools/evmstate/[email protected]"

# builds txparse tool
txparse: | build deps
$(ENV_SCRIPT) nim c $(NIM_PARAMS) "tools/txparse/[email protected]"

# usual cleaning
clean: | clean-common
rm -rf build/{nimbus,fluffy,nimbus_verified_proxy,$(TOOLS_CSV),all_tests,test_kvstore_rocksdb,test_rpc,all_fluffy_tests,all_fluffy_portal_spec_tests,test_portal_testnet,portalcli,blockwalk,eth_data_exporter,utp_test_app,utp_test,*.dSYM}
Expand Down
43 changes: 43 additions & 0 deletions tools/txparse/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Tx parser (`txparse`)

This is a very simple utility, which reads line by line from standard input.
For each line, it tries to interpret it as hexadecimal data, and the data as
an Ethereum transaction.

If all goes well, it outputs a line containing the `address` of the sender.
Otherwise, it outputs `err: ` and a suitable error message.

### Build instructions

There are few options to build `txparse` tool like any other nimbus tools.

1. Use nimble to install dependencies and your system Nim compiler(version <= 1.6.0).
```
$> nimble install -y --depsOnly
$> nim c -d:release tools/txparse/txparse
```
2. Use nimbus shipped Nim compiler and dependencies.
```
$> make update
$> ./env.sh nim c tools/txparse/txparse
```
3. Use nimbus makefile.
```
$> make update
$> make txparse
```

Example:

```
$ cat ./sample.input | ./txparse
err: t is not a hexadecimal character
err: m is not a hexadecimal character
err: hex string must have even length
err: is not a hexadecimal character
err: Read past the end of the RLP stream
err: The RLP contains a larger than expected Int value
0xd02d72e067e77158444ef2020ff2d325f929b363
0xd02d72e067e77158444ef2020ff2d325f929b363
err: hex string must have even length
```
9 changes: 9 additions & 0 deletions tools/txparse/sample.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test
monkey
0x1
0x112391201239129312392139123 123 12 312 312 3
0xdead
0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9
02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904
0x02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904
deadest
37 changes: 37 additions & 0 deletions tools/txparse/txparse.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Nimbus
# Copyright (c) 2022 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http:https://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http:https://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.

import
eth/[common, rlp],
stew/byteutils,
../../nimbus/transaction

proc parseTx(hexLine: string) =
try:
let
bytes = hexToSeqByte(hexLine)
tx = rlp.decode(bytes, Transaction)
address = tx.getSender()

# everything ok
echo "0x", address.toHex

except RlpError as ex:
echo "err: ", ex.msg
except ValueError as ex:
echo "err: ", ex.msg
except ValidationError as ex:
echo "err: ", ex.msg

proc main() =
for hexLine in stdin.lines:
parseTx(hexLine)

main()