Skip to content

Commit

Permalink
Merge pull request #6 from bcdevtools/imp/include-wasm-tx-sig-for-ind…
Browse files Browse the repository at this point in the history
…exer

imp(rpc): `be_getTransactionsInBlockRange` response include some wasm tx information
  • Loading branch information
0xbcdev authored Apr 13, 2024
2 parents d32393d + 94c86df commit 126040e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Templates for Unreleased:

## Unreleased

## v1.1.1 - 2024-04-14

### Improvements

- (rpc) [#6](https://github.com/bcdevtools/block-explorer-rpc-cosmos/pull/6) `be_getTransactionsInBlockRange` response include some wasm tx information

## v1.1.0 - 2024-04-14

### Improvements
Expand Down
47 changes: 43 additions & 4 deletions be_rpc/backend/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
ibctypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -80,6 +79,7 @@ func (m *Backend) GetTransactionsInBlockRange(fromHeightIncluded, toHeightInclud

const txTypeCosmos = "cosmos"
const txTypeEvm = "evm"
const txTypeWasm = "wasm"

var txsInfo []map[string]any
for txIdx := 0; txIdx < len(resBlock.Block.Data.Txs); txIdx++ {
Expand All @@ -91,12 +91,14 @@ func (m *Backend) GetTransactionsInBlockRange(fromHeightIncluded, toHeightInclud
evmTxAction := constants.EvmActionNone
var evmTxSignature string

var optionalTxResult *coretypes.ResultTx
wasmTxAction := constants.WasmActionNone
var wasmTxSignature string

if berpcutils.IsEvmTx(tx) {
var errTxResult error
optionalTxResult, errTxResult = m.clientCtx.Client.Tx(m.ctx, tmTx.Hash(), false)
optionalTxResult, errTxResult := m.clientCtx.Client.Tx(m.ctx, tmTx.Hash(), false)
if errTxResult != nil {
m.GetLogger().Error("failed to query tx", "error", errTxResult)
// TODO BE: find another way to handle properly when error
} else if optionalTxResult == nil {
// ignore
} else if evmTxHash := berpcutils.GetEvmTransactionHashFromEvent(optionalTxResult.TxResult.Events); evmTxHash != nil {
Expand Down Expand Up @@ -160,6 +162,34 @@ func (m *Backend) GetTransactionsInBlockRange(fromHeightIncluded, toHeightInclud
break
}

if wasmTxAction == constants.WasmActionNone {
switch msg.TypeUrl {
case "/cosmwasm.wasm.v1.MsgInstantiateContract":
txType = txTypeWasm
wasmTxAction = constants.WasmActionCreate
wasmTxSignature = ""
case "/cosmwasm.wasm.v1.MsgExecuteContract":
txType = txTypeWasm
wasmTxAction = constants.WasmActionCall
msgContent, err := berpcutils.FromAnyToJsonMap(msg, m.clientCtx.Codec)
if err == nil {
if execMsgRaw, found := msgContent["msg"]; found {
bz, err := json.Marshal(execMsgRaw)
if err == nil {
var execMsg map[string]any
err = json.Unmarshal(bz, &execMsg)
if err == nil && len(execMsg) > 0 {
for k := range execMsg {
wasmTxSignature = k
break
}
}
}
}
}
}
}

var messageInvolversExtractor berpctypes.MessageInvolversExtractor
if extractor, found := m.messageInvolversExtractors[berpcutils.ProtoMessageName(cosmosMsg)]; found {
messageInvolversExtractor = extractor
Expand Down Expand Up @@ -203,6 +233,15 @@ func (m *Backend) GetTransactionsInBlockRange(fromHeightIncluded, toHeightInclud
if len(evmTxSignature) > 0 {
evmTxInfo["sig"] = evmTxSignature
}
} else if txType == txTypeWasm {
wasmTxInfo := make(map[string]any)
txInfo["wasmTx"] = wasmTxInfo
if len(wasmTxAction) > 0 {
wasmTxInfo["action"] = wasmTxAction
}
if len(wasmTxSignature) > 0 {
wasmTxInfo["sig"] = wasmTxSignature
}
}
txsInfo = append(txsInfo, txInfo)
}
Expand Down
10 changes: 10 additions & 0 deletions be_rpc/constants/wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package constants

type WasmAction string

const (
WasmActionNone WasmAction = ""
WasmActionTransfer WasmAction = "transfer"
WasmActionCall WasmAction = "call"
WasmActionCreate WasmAction = "create"
)

0 comments on commit 126040e

Please sign in to comment.