2018-04-16 20:15:30 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&s.txHeight)
|
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-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&key)
|
|
|
|
br.ReadLE(&value)
|
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-08-28 16:27:06 +00:00
|
|
|
bw.WriteLE(s.txHeight)
|
|
|
|
bw.WriteVarUint(uint64(len(s.items)))
|
2018-04-16 20:15:30 +00:00
|
|
|
for k, v := range s.items {
|
2019-08-28 16:27:06 +00:00
|
|
|
bw.WriteLE(k)
|
|
|
|
bw.WriteLE(v)
|
2018-04-16 20:15:30 +00:00
|
|
|
}
|
|
|
|
}
|