neo-go/pkg/core/native/util.go

30 lines
722 B
Go
Raw Normal View History

2020-10-01 15:17:09 +00:00
package native
import (
"github.com/nspcc-dev/neo-go/pkg/core/dao"
2020-11-19 10:00:46 +00:00
"github.com/nspcc-dev/neo-go/pkg/core/state"
2020-10-01 15:17:09 +00:00
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/io"
)
func getSerializableFromDAO(id int32, d dao.DAO, key []byte, item io.Serializable) error {
si := d.GetStorageItem(id, key)
if si == nil {
return storage.ErrKeyNotFound
}
r := io.NewBinReaderFromBuf(si.Value)
item.DecodeBinary(r)
return r.Err
}
2020-11-19 10:00:46 +00:00
func putSerializableToDAO(id int32, d dao.DAO, key []byte, item io.Serializable) error {
w := io.NewBufBinWriter()
item.EncodeBinary(w.BinWriter)
if w.Err != nil {
return w.Err
}
return d.PutStorageItem(id, key, &state.StorageItem{
Value: w.Bytes(),
})
}