github.com/Finschia/finschia-sdk@v0.49.1/x/auth/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 gogotypes "github.com/gogo/protobuf/types" 8 9 "github.com/Finschia/finschia-sdk/codec" 10 "github.com/Finschia/finschia-sdk/types/kv" 11 "github.com/Finschia/finschia-sdk/x/auth/types" 12 ) 13 14 type AuthUnmarshaler interface { 15 UnmarshalAccount([]byte) (types.AccountI, error) 16 GetCodec() codec.BinaryCodec 17 } 18 19 // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 20 // Value to the corresponding auth type. 21 func NewDecodeStore(ak AuthUnmarshaler) func(kvA, kvB kv.Pair) string { 22 return func(kvA, kvB kv.Pair) string { 23 switch { 24 case bytes.Equal(kvA.Key[:1], types.AddressStoreKeyPrefix): 25 accA, err := ak.UnmarshalAccount(kvA.Value) 26 if err != nil { 27 panic(err) 28 } 29 30 accB, err := ak.UnmarshalAccount(kvB.Value) 31 if err != nil { 32 panic(err) 33 } 34 35 return fmt.Sprintf("%v\n%v", accA, accB) 36 37 case bytes.Equal(kvA.Key, types.GlobalAccountNumberKey): 38 var globalAccNumberA, globalAccNumberB gogotypes.UInt64Value 39 ak.GetCodec().MustUnmarshal(kvA.Value, &globalAccNumberA) 40 ak.GetCodec().MustUnmarshal(kvB.Value, &globalAccNumberB) 41 42 return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB) 43 44 default: 45 panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key)) 46 } 47 } 48 }