2018-04-16 20:15:30 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2020-02-27 12:45:52 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-04-16 20:15:30 +00:00
|
|
|
"github.com/CityOfZion/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.
|
|
|
|
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.
|
|
|
|
func NewSpentCoinState(hash util.Uint256, height uint32) *SpentCoinState {
|
|
|
|
return &SpentCoinState{
|
|
|
|
txHash: hash,
|
|
|
|
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-06 15:37:46 +00:00
|
|
|
br.ReadBytes(s.txHash[:])
|
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-06 15:22:21 +00:00
|
|
|
bw.WriteBytes(s.txHash[:])
|
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
|
|
|
}
|
|
|
|
}
|