laconicd-deprecated/x/evm/simulation/decoder.go

32 lines
895 B
Go
Raw Permalink Normal View History

2022-04-28 07:43:39 +00:00
package simulation
import (
"bytes"
"fmt"
"github.com/cerc-io/laconicd/x/evm/types"
2022-04-28 07:43:39 +00:00
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/ethereum/go-ethereum/common"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
2022-10-10 10:38:33 +00:00
// value to the corresponding EVM type.
2022-04-28 07:43:39 +00:00
func NewDecodeStore() func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.KeyPrefixStorage):
2022-10-10 10:38:33 +00:00
storageA := common.BytesToHash(kvA.Value).Hex()
storageB := common.BytesToHash(kvB.Value).Hex()
2022-04-28 07:43:39 +00:00
2022-10-10 10:38:33 +00:00
return fmt.Sprintf("%v\n%v", storageA, storageB)
2022-04-28 07:43:39 +00:00
case bytes.Equal(kvA.Key[:1], types.KeyPrefixCode):
2022-10-10 10:38:33 +00:00
codeHashA := common.Bytes2Hex(kvA.Value)
codeHashB := common.Bytes2Hex(kvB.Value)
2022-04-28 07:43:39 +00:00
return fmt.Sprintf("%v\n%v", codeHashA, codeHashB)
default:
panic(fmt.Sprintf("invalid evm key prefix %X", kvA.Key[:1]))
}
}
}