@@ -2,8 +2,12 @@ package query
22
33import (
44 "context"
5+ "encoding/hex"
6+ "encoding/json"
57 "fmt"
8+ "regexp"
69 "strconv"
10+ "strings"
711
812 "github.com/bcdevtools/devd/v3/cmd/flags"
913
@@ -28,15 +32,71 @@ func GetQueryTxsInBlockCommand() *cobra.Command {
2832 resBlock , err := tendermintRpcHttpClient .Block (context .Background (), & blockNumber )
2933 utils .ExitOnErr (err , "failed to get block" )
3034
31- for _ , tx := range resBlock .Block .Txs {
32- fmt .Println (tx .Hash ())
33- }
34-
3535 resBlockResult , err := tendermintRpcHttpClient .BlockResults (context .Background (), & blockNumber )
3636 utils .ExitOnErr (err , "failed to get block results" )
3737
38- for _ , txResult := range resBlockResult .TxsResults {
39- fmt .Println (txResult .Log )
38+ orTextEmpty := func (input any ) any {
39+ if input == nil {
40+ return "(empty)"
41+ }
42+ if str , ok := input .(string ); ok && str == "" {
43+ return "(empty)"
44+ }
45+ return input
46+ }
47+
48+ tryExtractMsgTypeFromRawTx := func (input []byte ) []string {
49+ matches := regexp .MustCompile (`/[a-z\d]+(\.[a-z\d]+)+\.Msg[a-zA-Z\d]+` ).FindAll (input , - 1 )
50+ var result []string
51+ for _ , match := range matches {
52+ result = append (result , string (match ))
53+ }
54+ return result
55+ }
56+
57+ for i , tx := range resBlock .Block .Txs {
58+ if i > 0 {
59+ utils .PrintlnStdErr ("====================================" )
60+ }
61+ txResult := resBlockResult .TxsResults [i ]
62+ txResult .Events = utils .ResolveBase64Events (txResult .Events )
63+ fmt .Println ("Index:" , i )
64+ fmt .Println ("Hash:" , strings .ToUpper (hex .EncodeToString (tx .Hash ())))
65+ if strings .Contains (string (tx ), "/ethermint.evm.v1.MsgEthereumTx" ) {
66+ L1:
67+ for _ , event := range txResult .Events {
68+ if event .Type != "ethereum_tx" {
69+ continue
70+ }
71+
72+ for _ , attr := range event .Attributes {
73+ if string (attr .Key ) == "ethereumTxHash" {
74+ fmt .Println ("EvmHash:" , attr .Value )
75+ break L1
76+ }
77+ }
78+ }
79+ }
80+ fmt .Println ("Type:" , func () string {
81+ if msgsType := tryExtractMsgTypeFromRawTx (tx ); len (msgsType ) > 0 {
82+ return strings .Join (msgsType , ", " )
83+ }
84+ return "(failed to extract msg type)"
85+ }())
86+ fmt .Println ("Code:" , txResult .Code )
87+ fmt .Println ("Gas:" , txResult .GasUsed , "/" , txResult .GasWanted )
88+ fmt .Println ("Data:" , strings .ReplaceAll (string (txResult .Data ), "\n " , "" ))
89+ fmt .Println ("Log:" , orTextEmpty (txResult .Log ))
90+ fmt .Println ("Events:" , func () string {
91+ if len (txResult .Events ) == 0 {
92+ return orTextEmpty ("" ).(string )
93+ }
94+ bz , err := json .Marshal (txResult .Events )
95+ utils .ExitOnErr (err , "failed to marshal events" )
96+ return string (bz )
97+ }())
98+ fmt .Println ("Info:" , orTextEmpty (txResult .Info ))
99+ fmt .Println ("Code-space:" , orTextEmpty (txResult .Codespace ))
40100 }
41101 },
42102 }
0 commit comments