main.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "encoding/hex"
  19. "flag"
  20. "fmt"
  21. "os"
  22. "strings"
  23. "github.com/ethereum/go-ethereum/signer/core"
  24. "github.com/ethereum/go-ethereum/signer/fourbyte"
  25. )
  26. func init() {
  27. flag.Usage = func() {
  28. fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "<hexdata>")
  29. flag.PrintDefaults()
  30. fmt.Fprintln(os.Stderr, `
  31. Parses the given ABI data and tries to interpret it from the fourbyte database.`)
  32. }
  33. }
  34. func parse(data []byte) {
  35. db, err := fourbyte.New()
  36. if err != nil {
  37. die(err)
  38. }
  39. messages := core.ValidationMessages{}
  40. db.ValidateCallData(nil, data, &messages)
  41. for _, m := range messages.Messages {
  42. fmt.Printf("%v: %v\n", m.Typ, m.Message)
  43. }
  44. }
  45. // Example
  46. // ./abidump a9059cbb000000000000000000000000ea0e2dc7d65a50e77fc7e84bff3fd2a9e781ff5c0000000000000000000000000000000000000000000000015af1d78b58c40000
  47. func main() {
  48. flag.Parse()
  49. switch {
  50. case flag.NArg() == 1:
  51. hexdata := flag.Arg(0)
  52. data, err := hex.DecodeString(strings.TrimPrefix(hexdata, "0x"))
  53. if err != nil {
  54. die(err)
  55. }
  56. parse(data)
  57. default:
  58. fmt.Fprintln(os.Stderr, "Error: one argument needed")
  59. flag.Usage()
  60. os.Exit(2)
  61. }
  62. }
  63. func die(args ...interface{}) {
  64. fmt.Fprintln(os.Stderr, args...)
  65. os.Exit(1)
  66. }