Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #77 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R: merge code
  • Loading branch information
kaifei Hu authored Jun 24, 2021
2 parents b707ac5 + 5b029a1 commit bcf4394
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 5 deletions.
10 changes: 10 additions & 0 deletions block/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kaifei-bianjie/msg-parser/modules/bank"
"github.com/kaifei-bianjie/msg-parser/modules/coinswap"
"github.com/kaifei-bianjie/msg-parser/modules/distribution"
"github.com/kaifei-bianjie/msg-parser/modules/ibc"
"github.com/kaifei-bianjie/msg-parser/modules/staking"
"github.com/kaifei-bianjie/msg-parser/types"
)
Expand Down Expand Up @@ -121,6 +122,15 @@ func HandleTxMsg(v types.SdkMsg) CustomMsgDocInfo {
}
if ibcDocInfo, ok := msgparser.MsgClient.Ibc.HandleTxMsg(v); ok {
msgDoc.MsgDocInfo = ibcDocInfo
switch ibcDocInfo.DocTxMsg.Type {
case MsgTypeIBCTransfer:
doc := ibcDocInfo.DocTxMsg.Msg.(*ibc.DocMsgTransfer)
denoms = append(denoms, doc.Token.Denom)
case MsgTypeTimeout:
doc := ibcDocInfo.DocTxMsg.Msg.(*ibc.DocMsgTimeout)
denoms = append(denoms, doc.Packet.Data.Denom)
}
msgDoc.Denoms = removeDuplicatesFromSlice(denoms)
return msgDoc
}
return msgDoc
Expand Down
66 changes: 66 additions & 0 deletions block/parse_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/irisnet/rainbow-sync/model"
"github.com/irisnet/rainbow-sync/utils"
"github.com/kaifei-bianjie/msg-parser/codec"
. "github.com/kaifei-bianjie/msg-parser/modules"
"github.com/kaifei-bianjie/msg-parser/modules/ibc"
msgsdktypes "github.com/kaifei-bianjie/msg-parser/types"
aTypes "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -190,6 +192,29 @@ func ParseTx(txBytes types.Tx, block *types.Block, client *pool.Client) (model.T
continue
}

switch msgDocInfo.DocTxMsg.Type {
case MsgTypeIBCTransfer:
if ibcTranferMsg, ok := msgDocInfo.DocTxMsg.Msg.(*ibc.DocMsgTransfer); ok {
if val, exist := eventsIndexMap[i]; exist {
ibcTranferMsg.PacketId = buildPacketId(val.Events)
msgDocInfo.DocTxMsg.Msg = ibcTranferMsg
}

} else {
logger.Warn("ibc transfer handler packet_id failed", logger.String("errTag", "TxMsg"),
logger.String("txhash", txHash),
logger.Int("msg_index", i),
logger.Int64("height", height))
}
case MsgTypeRecvPacket:
if val, ok := eventsIndexMap[i]; ok {
denom := getIbcRecvPacketDenom(val.Events)
msgDocInfo.Denoms = append(msgDocInfo.Denoms, denom)
msgDocInfo.Denoms = removeDuplicatesFromSlice(msgDocInfo.Denoms)
}

}

docTx.Signers = append(docTx.Signers, removeDuplicatesFromSlice(msgDocInfo.Signers)...)
docTx.Addrs = append(docTx.Addrs, removeDuplicatesFromSlice(msgDocInfo.Addrs)...)
docTxMsgs = append(docTxMsgs, msgDocInfo.DocTxMsg)
Expand Down Expand Up @@ -254,6 +279,47 @@ func buildTxId(height int64, txIndex uint32) uint64 {
return uint64(height*10000) + uint64(txIndex)
}

func getIbcRecvPacketDenom(events []model.Event) string {
if len(events) > 0 {
for _, e := range events {
if len(e.Attributes) > 0 && e.Type == utils.IbcRecvPacketEventTypeDenomTrace {
for _, v := range e.Attributes {
if v.Key == utils.IbcRecvPacketEventAttrKeyDenomTrace {
return v.Value
}

}
}
}
}
return ""
}

func buildPacketId(events []model.Event) string {
if len(events) > 0 {
var mapKeyValue map[string]string
for _, e := range events {
if len(e.Attributes) > 0 && e.Type == utils.IbcTransferEventTypeSendPacket {
mapKeyValue = make(map[string]string, len(e.Attributes))
for _, v := range e.Attributes {
mapKeyValue[v.Key] = v.Value
}
break
}
}

if len(mapKeyValue) > 0 {
scPort := mapKeyValue[utils.IbcTransferEventAttriKeyPacketScPort]
scChannel := mapKeyValue[utils.IbcTransferEventAttriKeyPacketScChannel]
dcPort := mapKeyValue[utils.IbcTransferEventAttriKeyPacketDcPort]
dcChannel := mapKeyValue[utils.IbcTransferEventAttriKeyPacketDcChannels]
sequence := mapKeyValue[utils.IbcTransferEventAttriKeyPacketSequence]
return fmt.Sprintf("%v%v%v%v%v", scPort, scChannel, dcPort, dcChannel, sequence)
}
}
return ""
}

func parseEvents(events []aTypes.Event) []model.Event {
var eventDocs []model.Event
if len(events) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion block/parse_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestIris_Block_ParseIrisTx(t *testing.T) {
{
name: "test parse iris tx",
args: args{
b: 1758240,
b: 2282427,
client: client,
},
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/jolestar/go-commons-pool v2.0.0+incompatible
github.com/kaifei-bianjie/msg-parser v0.0.0-20210326132044-8f7f17bb3486
github.com/kaifei-bianjie/msg-parser v0.0.0-20210617063714-8e4372796b64
github.com/tendermint/tendermint v0.34.8
go.uber.org/zap v1.13.0
golang.org/x/net v0.0.0-20201021035429-f5854403a974
Expand Down
Loading

0 comments on commit bcf4394

Please sign in to comment.