2018-04-16 20:15:30 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2018-04-16 20:15:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SpentCoinState represents the state of a spent coin.
|
|
|
|
type SpentCoinState struct {
|
|
|
|
txHeight uint32
|
|
|
|
|
|
|
|
// A mapping between the index of the prevIndex and block height.
|
|
|
|
items map[uint16]uint32
|
|
|
|
}
|
|
|
|
|
2020-02-27 12:45:52 +00:00
|
|
|
// spentCoin represents the state of a single spent coin output.
|
|
|
|
type spentCoin struct {
|
|
|
|
Output *transaction.Output
|
|
|
|
StartHeight uint32
|
|
|
|
EndHeight uint32
|
|
|
|
}
|
|
|
|
|
2018-04-16 20:15:30 +00:00
|
|
|
// NewSpentCoinState returns a new SpentCoinState object.
|
2020-03-09 13:31:05 +00:00
|
|
|
func NewSpentCoinState(height uint32) *SpentCoinState {
|
2018-04-16 20:15:30 +00:00
|
|
|
return &SpentCoinState{
|
|
|
|
txHeight: height,
|
|
|
|
items: make(map[uint16]uint32),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (s *SpentCoinState) DecodeBinary(br *io.BinReader) {
|
2019-12-12 15:52:23 +00:00
|
|
|
s.txHeight = br.ReadU32LE()
|
2018-04-16 20:15:30 +00:00
|
|
|
|
|
|
|
s.items = make(map[uint16]uint32)
|
2019-08-28 16:27:06 +00:00
|
|
|
lenItems := br.ReadVarUint()
|
2018-04-16 20:15:30 +00:00
|
|
|
for i := 0; i < int(lenItems); i++ {
|
|
|
|
var (
|
|
|
|
key uint16
|
|
|
|
value uint32
|
|
|
|
)
|
2019-12-12 15:52:23 +00:00
|
|
|
key = br.ReadU16LE()
|
|
|
|
value = br.ReadU32LE()
|
2018-04-16 20:15:30 +00:00
|
|
|
s.items[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (s *SpentCoinState) EncodeBinary(bw *io.BinWriter) {
|
2019-12-12 15:52:23 +00:00
|
|
|
bw.WriteU32LE(s.txHeight)
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteVarUint(uint64(len(s.items)))
|
2018-04-16 20:15:30 +00:00
|
|
|
for k, v := range s.items {
|
2019-12-12 15:52:23 +00:00
|
|
|
bw.WriteU16LE(k)
|
|
|
|
bw.WriteU32LE(v)
|
2018-04-16 20:15:30 +00:00
|
|
|
}
|
|
|
|
}
|