mukan-ibc/modules/core/04-channel/simulation/decoder.go
Mukan Erkin Törük 88dd97a9f8
Some checks failed
CodeQL / Analyze (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:22 +03:00

49 lines
1.8 KiB
Go

package simulation
import (
"bytes"
"fmt"
"git.cw.tr/mukan-network/mukan-sdk/codec"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
"git.cw.tr/mukan-network/mukan-sdk/types/kv"
"git.cw.tr/mukan-network/mukan-ibc/modules/core/04-channel/types"
host "git.cw.tr/mukan-network/mukan-ibc/modules/core/24-host"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding channel type.
func NewDecodeStore(cdc codec.BinaryCodec, kvA, kvB kv.Pair) (string, bool) {
switch {
case bytes.HasPrefix(kvA.Key, []byte(host.KeyChannelEndPrefix)):
var channelA, channelB types.Channel
cdc.MustUnmarshal(kvA.Value, &channelA)
cdc.MustUnmarshal(kvB.Value, &channelB)
return fmt.Sprintf("Channel A: %v\nChannel B: %v", channelA, channelB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqSendPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqSend A: %d\nNextSeqSend B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqRecvPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqRecv A: %d\nNextSeqRecv B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyNextSeqAckPrefix)):
seqA := sdk.BigEndianToUint64(kvA.Value)
seqB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("NextSeqAck A: %d\nNextSeqAck B: %d", seqA, seqB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketCommitmentPrefix)):
return fmt.Sprintf("CommitmentHash A: %X\nCommitmentHash B: %X", kvA.Value, kvB.Value), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyPacketAckPrefix)):
return fmt.Sprintf("AckHash A: %X\nAckHash B: %X", kvA.Value, kvB.Value), true
default:
return "", false
}
}