Skip to content

Commit de8fbaf

Browse files
committed
chore: alternative for 4905
Signed-off-by: moul <[email protected]>
1 parent cd3b309 commit de8fbaf

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

gno.land/pkg/gnoland/mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (m *mockParamsKeeper) GetString(ctx sdk.Context, key string, ptr *string)
171171
func (m *mockParamsKeeper) GetInt64(ctx sdk.Context, key string, ptr *int64) {}
172172
func (m *mockParamsKeeper) GetUint64(ctx sdk.Context, key string, ptr *uint64) {}
173173
func (m *mockParamsKeeper) GetBool(ctx sdk.Context, key string, ptr *bool) {}
174-
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte { return nil }
174+
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {}
175175
func (m *mockParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {}
176176

177177
func (m *mockParamsKeeper) SetString(ctx sdk.Context, key string, value string) {}

tm2/pkg/sdk/params/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func (bh paramsHandler) Query(ctx sdk.Context, req abci.RequestQuery) (res abci.
5353
std.ErrUnknownRequest(fmt.Sprintf("module not registered: %q", module)))
5454
return
5555
}
56-
val := bh.params.GetBytes(ctx, rest)
56+
var val []byte
57+
bh.params.GetBytes(ctx, rest, &val)
5758
res.Data = val
5859
return
5960

tm2/pkg/sdk/params/keeper.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ParamsKeeperI interface {
3838
SetStrings(ctx sdk.Context, key string, value []string)
3939

4040
Has(ctx sdk.Context, key string) bool
41-
GetBytes(ctx sdk.Context, key string) []byte
41+
GetBytes(ctx sdk.Context, key string, ptr *[]byte)
4242
SetBytes(ctx sdk.Context, key string, value []byte)
4343

4444
GetStruct(ctx sdk.Context, key string, strctPtr any)
@@ -124,8 +124,12 @@ func (pk ParamsKeeper) GetUint64(ctx sdk.Context, key string, ptr *uint64) {
124124
pk.getIfExists(ctx, key, ptr)
125125
}
126126

127-
func (pk ParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte {
128-
return ctx.Store(pk.key).Get(storeKey(key))
127+
func (pk ParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {
128+
stor := ctx.Store(pk.key)
129+
bz := stor.Get(storeKey(key))
130+
if bz != nil {
131+
*ptr = bz
132+
}
129133
}
130134

131135
func (pk ParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {
@@ -287,8 +291,8 @@ func (ppk prefixParamsKeeper) GetBool(ctx sdk.Context, key string, ptr *bool) {
287291
ppk.pk.GetBool(ctx, ppk.prefixed(key), ptr)
288292
}
289293

290-
func (ppk prefixParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte {
291-
return ppk.pk.GetBytes(ctx, ppk.prefixed(key))
294+
func (ppk prefixParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {
295+
ppk.pk.GetBytes(ctx, ppk.prefixed(key), ptr)
292296
}
293297

294298
func (ppk prefixParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {

tm2/pkg/sdk/params/keeper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestKeeper(t *testing.T) {
4545
require.NotPanics(t, func() { keeper.GetBool(ctx, "param2", &param2) })
4646
require.NotPanics(t, func() { keeper.GetUint64(ctx, "param3", &param3) })
4747
require.NotPanics(t, func() { keeper.GetInt64(ctx, "param4", &param4) })
48-
require.NotPanics(t, func() { param5 = keeper.GetBytes(ctx, "param5") })
48+
require.NotPanics(t, func() { keeper.GetBytes(ctx, "param5", &param5) })
4949

5050
require.Equal(t, param1, "foo")
5151
require.Equal(t, param2, true)
@@ -70,7 +70,7 @@ func TestKeeper(t *testing.T) {
7070
require.NotPanics(t, func() { keeper.GetBool(ctx, "param2", &param2) })
7171
require.NotPanics(t, func() { keeper.GetUint64(ctx, "param3", &param3) })
7272
require.NotPanics(t, func() { keeper.GetInt64(ctx, "param4", &param4) })
73-
require.NotPanics(t, func() { param5 = keeper.GetBytes(ctx, "param5") })
73+
require.NotPanics(t, func() { keeper.GetBytes(ctx, "param5", &param5) })
7474

7575
require.Equal(t, param1, "bar")
7676
require.Equal(t, param2, false)

0 commit comments

Comments
 (0)