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 {
return nil, err
}
spent = NewSpentCoinState(hash, height)
spent = NewSpentCoinState(height)
}
return spent, nil
}

View file

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

View file

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