github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/ibctesting/event_utils.go (about) 1 package ibctesting 2 3 //import ( 4 // "strconv" 5 // "strings" 6 // 7 // clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" 8 // channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" 9 // abci "github.com/tendermint/tendermint/abci/types" 10 //) 11 // 12 //func getSendPackets(evts []abci.Event) []channeltypes.Packet { 13 // var res []channeltypes.Packet 14 // for _, evt := range evts { 15 // if evt.Type == "send_packet" { 16 // packet := parsePacketFromEvent(evt) 17 // res = append(res, packet) 18 // } 19 // } 20 // return res 21 //} 22 // 23 //func getAckPackets(evts []abci.Event) []PacketAck { 24 // var res []PacketAck 25 // for _, evt := range evts { 26 // if evt.Type == "write_acknowledgement" { 27 // packet := parsePacketFromEvent(evt) 28 // ack := PacketAck{ 29 // Packet: packet, 30 // Ack: []byte(getField(evt, "packet_ack")), 31 // } 32 // res = append(res, ack) 33 // } 34 // } 35 // return res 36 //} 37 // 38 //// Used for various debug statements above when needed... do not remove 39 //// func showEvent(evt abci.Event) { 40 //// fmt.Printf("evt.Type: %s\n", evt.Type) 41 //// for _, attr := range evt.Attributes { 42 //// fmt.Printf(" %s = %s\n", string(attr.Key), string(attr.Value)) 43 //// } 44 ////} 45 // 46 //func parsePacketFromEvent(evt abci.Event) channeltypes.Packet { 47 // return channeltypes.Packet{ 48 // Sequence: getUintField(evt, "packet_sequence"), 49 // SourcePort: getField(evt, "packet_src_port"), 50 // SourceChannel: getField(evt, "packet_src_channel"), 51 // DestinationPort: getField(evt, "packet_dst_port"), 52 // DestinationChannel: getField(evt, "packet_dst_channel"), 53 // Data: []byte(getField(evt, "packet_data")), 54 // TimeoutHeight: parseTimeoutHeight(getField(evt, "packet_timeout_height")), 55 // TimeoutTimestamp: getUintField(evt, "packet_timeout_timestamp"), 56 // } 57 //} 58 // 59 //// return the value for the attribute with the given name 60 //func getField(evt abci.Event, key string) string { 61 // for _, attr := range evt.Attributes { 62 // if string(attr.Key) == key { 63 // return string(attr.Value) 64 // } 65 // } 66 // return "" 67 //} 68 // 69 //func getUintField(evt abci.Event, key string) uint64 { 70 // raw := getField(evt, key) 71 // return toUint64(raw) 72 //} 73 // 74 //func toUint64(raw string) uint64 { 75 // if raw == "" { 76 // return 0 77 // } 78 // i, err := strconv.ParseUint(raw, 10, 64) 79 // if err != nil { 80 // panic(err) 81 // } 82 // return i 83 //} 84 // 85 //func parseTimeoutHeight(raw string) clienttypes.Height { 86 // chunks := strings.Split(raw, "-") 87 // return clienttypes.Height{ 88 // RevisionNumber: toUint64(chunks[0]), 89 // RevisionHeight: toUint64(chunks[1]), 90 // } 91 //}