github.com/Finschia/finschia-sdk@v0.49.1/x/feegrant/simulation/decoder.go (about)

     1  package simulation
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/Finschia/finschia-sdk/codec"
     8  	"github.com/Finschia/finschia-sdk/types/kv"
     9  	"github.com/Finschia/finschia-sdk/x/feegrant"
    10  )
    11  
    12  // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
    13  // Value to the corresponding feegrant type.
    14  func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
    15  	return func(kvA, kvB kv.Pair) string {
    16  		switch {
    17  		case bytes.Equal(kvA.Key[:1], feegrant.FeeAllowanceKeyPrefix):
    18  			var grantA, grantB feegrant.Grant
    19  			cdc.MustUnmarshal(kvA.Value, &grantA)
    20  			cdc.MustUnmarshal(kvB.Value, &grantB)
    21  			return fmt.Sprintf("%v\n%v", grantA, grantB)
    22  		default:
    23  			panic(fmt.Sprintf("invalid feegrant key %X", kvA.Key))
    24  		}
    25  	}
    26  }