/
tx.go
58 lines (53 loc) · 1.41 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package utils
import (
berpctypes "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
"strings"
)
// NormalizeTransactionHash normalizes the transaction hash into '0xHASH' format.
// Contract: input hash is a valid transaction hash, with or without '0x' prefix.
func NormalizeTransactionHash(hash string, upper bool) string {
hash = strings.ToLower(hash)
if strings.HasPrefix(hash, "0x") {
if upper {
return "0x" + strings.ToUpper(hash[2:])
} else {
return strings.ToLower(hash)
}
} else {
if upper {
return "0x" + strings.ToUpper(hash)
} else {
return "0x" + hash
}
}
}
func ProtoMessageName(msg sdk.Msg) string {
return proto.MessageName(msg)
}
func IsEvmTx(tx *tx.Tx) bool {
for _, msg := range tx.Body.Messages {
if strings.HasSuffix(msg.TypeUrl, ".MsgEthereumTx") {
return true
}
}
return false
}
func GetEvmTransactionHashFromEvent(events []abci.Event) *common.Hash {
for _, event := range events {
if event.Type != berpctypes.EventTypeEthereumTx {
continue
}
for _, attr := range event.Attributes {
if string(attr.Key) == berpctypes.AttributeKeyEthereumTxHash {
hash := common.HexToHash(string(attr.Value))
return &hash
}
}
}
return nil
}