2021-02-02 18:34:17 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2023-10-05 10:53:12 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/convert"
|
2021-03-12 12:16:36 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
2021-02-02 18:34:17 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetSerialized serializes data and puts it into contract storage.
|
2023-11-07 12:18:48 +00:00
|
|
|
func SetSerialized(ctx storage.Context, key any, value interface{}) {
|
2021-03-12 12:16:36 +00:00
|
|
|
data := std.Serialize(value)
|
2021-02-02 18:34:17 +00:00
|
|
|
storage.Put(ctx, key, data)
|
|
|
|
}
|
2023-10-05 10:53:12 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|