frostfs-contract/common/storage.go
Evgenii Stratonikov d890a7eba4
All checks were successful
DCO action / DCO (pull_request) Successful in 1m6s
Tests / Tests (1.19) (pull_request) Successful in 1m17s
Tests / Tests (1.20) (pull_request) Successful in 1m12s
[#50] Replace interface{} with any
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-11-07 15:18:48 +03:00

28 lines
782 B
Go

package common
import (
"github.com/nspcc-dev/neo-go/pkg/interop/convert"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
// SetSerialized serializes data and puts it into contract storage.
func SetSerialized(ctx storage.Context, key any, value interface{}) {
data := std.Serialize(value)
storage.Put(ctx, key, data)
}
// ToFixedWidth64 converts x to bytes such that numbers <= math.MaxUint64
// have constant with of 9.
func ToFixedWidth64(x int) []byte {
data := convert.ToBytes(x)
if x < 0 || len(data) >= 9 {
return data
}
return append(data, make([]byte, 9-len(data))...)
}
// FromFixedWidth64 is a reverse function for ToFixedWidth64.
func FromFixedWidth64(x []byte) int {
return convert.ToInteger(x)
}