neoneo-go/pkg/core/transaction/not_valid_before.go
Anna Shaleva 31aa66a4a4 core: check the length of NotValidBefore attr while decoding
DecodeBinary throws panic otherwise.
2020-11-25 18:37:29 +03:00

37 lines
868 B
Go

package transaction
import (
"encoding/binary"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/io"
)
// NotValidBefore represents attribute with the height transaction is not valid before.
type NotValidBefore struct {
Height uint32 `json:"height"`
}
// DecodeBinary implements io.Serializable interface.
func (n *NotValidBefore) DecodeBinary(br *io.BinReader) {
bytes := br.ReadVarBytes(4)
if br.Err != nil {
return
}
if len(bytes) != 4 {
br.Err = fmt.Errorf("expected 4 bytes, got %d", len(bytes))
return
}
n.Height = binary.LittleEndian.Uint32(bytes)
}
// EncodeBinary implements io.Serializable interface.
func (n *NotValidBefore) EncodeBinary(w *io.BinWriter) {
bytes := make([]byte, 4)
binary.LittleEndian.PutUint32(bytes, n.Height)
w.WriteVarBytes(bytes)
}
func (n *NotValidBefore) toJSONMap(m map[string]interface{}) {
m["height"] = n.Height
}