core: drop txHash from SpentCoinState

It's a key for it, makes no sense storing it as data.
This commit is contained in:
Roman Khimov 2020-03-09 16:31:05 +03:00
parent baeaa3dbe6
commit 0e2bda4f21
3 changed files with 2 additions and 8 deletions

View file

@ -219,7 +219,7 @@ func (dao *dao) GetSpentCoinsOrNew(hash util.Uint256, height uint32) (*SpentCoin
if err != storage.ErrKeyNotFound { if err != storage.ErrKeyNotFound {
return nil, err return nil, err
} }
spent = NewSpentCoinState(hash, height) spent = NewSpentCoinState(height)
} }
return spent, nil return spent, nil
} }

View file

@ -3,12 +3,10 @@ package core
import ( import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
) )
// SpentCoinState represents the state of a spent coin. // SpentCoinState represents the state of a spent coin.
type SpentCoinState struct { type SpentCoinState struct {
txHash util.Uint256
txHeight uint32 txHeight uint32
// A mapping between the index of the prevIndex and block height. // A mapping between the index of the prevIndex and block height.
@ -23,9 +21,8 @@ type spentCoin struct {
} }
// NewSpentCoinState returns a new SpentCoinState object. // NewSpentCoinState returns a new SpentCoinState object.
func NewSpentCoinState(hash util.Uint256, height uint32) *SpentCoinState { func NewSpentCoinState(height uint32) *SpentCoinState {
return &SpentCoinState{ return &SpentCoinState{
txHash: hash,
txHeight: height, txHeight: height,
items: make(map[uint16]uint32), items: make(map[uint16]uint32),
} }
@ -33,7 +30,6 @@ func NewSpentCoinState(hash util.Uint256, height uint32) *SpentCoinState {
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (s *SpentCoinState) DecodeBinary(br *io.BinReader) { func (s *SpentCoinState) DecodeBinary(br *io.BinReader) {
br.ReadBytes(s.txHash[:])
s.txHeight = br.ReadU32LE() s.txHeight = br.ReadU32LE()
s.items = make(map[uint16]uint32) s.items = make(map[uint16]uint32)
@ -51,7 +47,6 @@ func (s *SpentCoinState) DecodeBinary(br *io.BinReader) {
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (s *SpentCoinState) EncodeBinary(bw *io.BinWriter) { func (s *SpentCoinState) EncodeBinary(bw *io.BinWriter) {
bw.WriteBytes(s.txHash[:])
bw.WriteU32LE(s.txHeight) bw.WriteU32LE(s.txHeight)
bw.WriteVarUint(uint64(len(s.items))) bw.WriteVarUint(uint64(len(s.items)))
for k, v := range s.items { for k, v := range s.items {

View file

@ -10,7 +10,6 @@ import (
func TestEncodeDecodeSpentCoinState(t *testing.T) { func TestEncodeDecodeSpentCoinState(t *testing.T) {
spent := &SpentCoinState{ spent := &SpentCoinState{
txHash: random.Uint256(),
txHeight: 1001, txHeight: 1001,
items: map[uint16]uint32{ items: map[uint16]uint32{
1: 3, 1: 3,