implement txparse tool and add make target for txparse
This commit is contained in:
parent
1cd4a3fd54
commit
dcd1225724
4
Makefile
4
Makefile
|
@ -260,6 +260,10 @@ evmstate: | build deps
|
|||
evmstate_test: | build deps evmstate
|
||||
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) "tools/evmstate/$@.nim"
|
||||
|
||||
# builds txparse tool
|
||||
txparse: | build deps
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) "tools/txparse/$@.nim"
|
||||
|
||||
# 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}
|
||||
|
|
|
@ -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
|
||||
```
|
|
@ -0,0 +1,9 @@
|
|||
test
|
||||
monkey
|
||||
0x1
|
||||
0x112391201239129312392139123 123 12 312 312 3
|
||||
0xdead
|
||||
0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9
|
||||
02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904
|
||||
0x02f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904
|
||||
deadest
|
|
@ -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://www.apache.org/licenses/LICENSE-2.0)
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
||||
# http://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()
|
Loading…
Reference in New Issue