neo-go/pkg/core/unspent_coin_state.go
Vsevolod Brekelov ec17654986 core: refactoring blockchain state and storage
add dao which takes care about all CRUD operations on storage
remove blockchain state since everything is stored on change
remove storage operations from structs(entities)
move structs to entities package
2019-12-11 13:05:31 +03:00

41 lines
1.1 KiB
Go

package core
import (
"github.com/CityOfZion/neo-go/pkg/core/entities"
"github.com/CityOfZion/neo-go/pkg/io"
)
// UnspentCoinState hold the state of a unspent coin.
type UnspentCoinState struct {
states []entities.CoinState
}
// NewUnspentCoinState returns a new unspent coin state with N confirmed states.
func NewUnspentCoinState(n int) *UnspentCoinState {
u := &UnspentCoinState{
states: make([]entities.CoinState, n),
}
for i := 0; i < n; i++ {
u.states[i] = entities.CoinStateConfirmed
}
return u
}
// EncodeBinary encodes UnspentCoinState to the given BinWriter.
func (s *UnspentCoinState) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarUint(uint64(len(s.states)))
for _, state := range s.states {
bw.WriteBytes([]byte{byte(state)})
}
}
// DecodeBinary decodes UnspentCoinState from the given BinReader.
func (s *UnspentCoinState) DecodeBinary(br *io.BinReader) {
lenStates := br.ReadVarUint()
s.states = make([]entities.CoinState, lenStates)
for i := 0; i < int(lenStates); i++ {
var state uint8
br.ReadLE(&state)
s.states[i] = entities.CoinState(state)
}
}