core: renames entities-> state and removed State prefix

This commit is contained in:
Vsevolod Brekelov 2019-11-28 19:06:09 +03:00
parent 8809fe437d
commit 2d42b14a1d
31 changed files with 221 additions and 222 deletions

View file

@ -11,7 +11,7 @@ import (
"time" "time"
"github.com/CityOfZion/neo-go/config" "github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -378,7 +378,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
if err != nil { if err != nil {
return err return err
} }
unspent.states[input.PrevIndex] = entities.CoinStateSpent unspent.states[input.PrevIndex] = state.CoinSpent
if err = cache.PutUnspentCoinState(input.PrevHash, unspent); err != nil { if err = cache.PutUnspentCoinState(input.PrevHash, unspent); err != nil {
return err return err
} }
@ -439,7 +439,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
// Process the underlying type of the TX. // Process the underlying type of the TX.
switch t := tx.Data.(type) { switch t := tx.Data.(type) {
case *transaction.RegisterTX: case *transaction.RegisterTX:
err := cache.PutAssetState(&entities.AssetState{ err := cache.PutAssetState(&state.Asset{
ID: tx.Hash(), ID: tx.Hash(),
AssetType: t.AssetType, AssetType: t.AssetType,
Name: t.Name, Name: t.Name,
@ -499,7 +499,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
if t.NeedStorage { if t.NeedStorage {
properties |= smartcontract.HasStorage properties |= smartcontract.HasStorage
} }
contract := &entities.ContractState{ contract := &state.Contract{
Script: t.Script, Script: t.Script,
ParamList: t.ParamList, ParamList: t.ParamList,
ReturnType: t.ReturnType, ReturnType: t.ReturnType,
@ -555,7 +555,7 @@ func (bc *Blockchain) storeBlock(block *Block) error {
"err": err, "err": err,
}).Warn("contract invocation failed") }).Warn("contract invocation failed")
} }
aer := &entities.AppExecResult{ aer := &state.AppExecResult{
TxHash: tx.Hash(), TxHash: tx.Hash(),
Trigger: trigger.Application, Trigger: trigger.Application,
VMState: v.State(), VMState: v.State(),
@ -588,7 +588,7 @@ func processOutputs(tx *transaction.Transaction, dao *dao) error {
if err != nil { if err != nil {
return err return err
} }
account.Balances[output.AssetID] = append(account.Balances[output.AssetID], entities.UnspentBalance{ account.Balances[output.AssetID] = append(account.Balances[output.AssetID], state.UnspentBalance{
Tx: tx.Hash(), Tx: tx.Hash(),
Index: uint16(index), Index: uint16(index),
Value: output.Amount, Value: output.Amount,
@ -739,12 +739,12 @@ func (bc *Blockchain) GetTransaction(hash util.Uint256) (*transaction.Transactio
} }
// GetStorageItem returns an item from storage. // GetStorageItem returns an item from storage.
func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *entities.StorageItem { func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem {
return bc.dao.GetStorageItem(scripthash, key) return bc.dao.GetStorageItem(scripthash, key)
} }
// GetStorageItems returns all storage items for a given scripthash. // GetStorageItems returns all storage items for a given scripthash.
func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*entities.StorageItem, error) { func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) {
return bc.dao.GetStorageItems(hash) return bc.dao.GetStorageItems(hash)
} }
@ -830,7 +830,7 @@ func (bc *Blockchain) HeaderHeight() uint32 {
} }
// GetAssetState returns asset state from its assetID. // GetAssetState returns asset state from its assetID.
func (bc *Blockchain) GetAssetState(assetID util.Uint256) *entities.AssetState { func (bc *Blockchain) GetAssetState(assetID util.Uint256) *state.Asset {
asset, err := bc.dao.GetAssetState(assetID) asset, err := bc.dao.GetAssetState(assetID)
if asset == nil && err != storage.ErrKeyNotFound { if asset == nil && err != storage.ErrKeyNotFound {
log.Warnf("failed to get asset state %s : %s", assetID, err) log.Warnf("failed to get asset state %s : %s", assetID, err)
@ -839,7 +839,7 @@ func (bc *Blockchain) GetAssetState(assetID util.Uint256) *entities.AssetState {
} }
// GetContractState returns contract by its script hash. // GetContractState returns contract by its script hash.
func (bc *Blockchain) GetContractState(hash util.Uint160) *entities.ContractState { func (bc *Blockchain) GetContractState(hash util.Uint160) *state.Contract {
contract, err := bc.dao.GetContractState(hash) contract, err := bc.dao.GetContractState(hash)
if contract == nil && err != storage.ErrKeyNotFound { if contract == nil && err != storage.ErrKeyNotFound {
log.Warnf("failed to get contract state: %s", err) log.Warnf("failed to get contract state: %s", err)
@ -848,7 +848,7 @@ func (bc *Blockchain) GetContractState(hash util.Uint160) *entities.ContractStat
} }
// GetAccountState returns the account state from its script hash. // GetAccountState returns the account state from its script hash.
func (bc *Blockchain) GetAccountState(scriptHash util.Uint160) *entities.AccountState { func (bc *Blockchain) GetAccountState(scriptHash util.Uint160) *state.Account {
as, err := bc.dao.GetAccountState(scriptHash) as, err := bc.dao.GetAccountState(scriptHash)
if as == nil && err != storage.ErrKeyNotFound { if as == nil && err != storage.ErrKeyNotFound {
log.Warnf("failed to get account state: %s", err) log.Warnf("failed to get account state: %s", err)
@ -1166,7 +1166,7 @@ func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.P
if err != nil { if err != nil {
return nil, err return nil, err
} }
accountState.Balances[output.AssetID] = append(accountState.Balances[output.AssetID], entities.UnspentBalance{ accountState.Balances[output.AssetID] = append(accountState.Balances[output.AssetID], state.UnspentBalance{
Tx: tx.Hash(), Tx: tx.Hash(),
Index: uint16(index), Index: uint16(index),
Value: output.Amount, Value: output.Amount,
@ -1250,7 +1250,7 @@ func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.P
validators := cache.GetValidators() validators := cache.GetValidators()
count := entities.GetValidatorsWeightedAverage(validators) count := state.GetValidatorsWeightedAverage(validators)
standByValidators, err := bc.GetStandByValidators() standByValidators, err := bc.GetStandByValidators()
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -2,7 +2,7 @@ package core
import ( import (
"github.com/CityOfZion/neo-go/config" "github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -20,19 +20,19 @@ type Blockchainer interface {
Close() Close()
HeaderHeight() uint32 HeaderHeight() uint32
GetBlock(hash util.Uint256) (*Block, error) GetBlock(hash util.Uint256) (*Block, error)
GetContractState(hash util.Uint160) *entities.ContractState GetContractState(hash util.Uint160) *state.Contract
GetHeaderHash(int) util.Uint256 GetHeaderHash(int) util.Uint256
GetHeader(hash util.Uint256) (*Header, error) GetHeader(hash util.Uint256) (*Header, error)
CurrentHeaderHash() util.Uint256 CurrentHeaderHash() util.Uint256
CurrentBlockHash() util.Uint256 CurrentBlockHash() util.Uint256
HasBlock(util.Uint256) bool HasBlock(util.Uint256) bool
HasTransaction(util.Uint256) bool HasTransaction(util.Uint256) bool
GetAssetState(util.Uint256) *entities.AssetState GetAssetState(util.Uint256) *state.Asset
GetAccountState(util.Uint160) *entities.AccountState GetAccountState(util.Uint160) *state.Account
GetValidators(txes... *transaction.Transaction) ([]*keys.PublicKey, error) GetValidators(txes... *transaction.Transaction) ([]*keys.PublicKey, error)
GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error)
GetStorageItem(scripthash util.Uint160, key []byte) *entities.StorageItem GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem
GetStorageItems(hash util.Uint160) (map[string]*entities.StorageItem, error) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error)
GetTestVM() (*vm.VM, storage.Store) GetTestVM() (*vm.VM, storage.Store)
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
GetUnspentCoinState(util.Uint256) *UnspentCoinState GetUnspentCoinState(util.Uint256) *UnspentCoinState

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"sort" "sort"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -42,15 +42,15 @@ func (dao *dao) Put(entity io.Serializable, key []byte) error {
// -- start accounts. // -- start accounts.
// GetAccountStateOrNew retrieves AccountState from temporary or persistent Store // GetAccountStateOrNew retrieves Account from temporary or persistent Store
// or creates a new one if it doesn't exist and persists it. // or creates a new one if it doesn't exist and persists it.
func (dao *dao) GetAccountStateOrNew(hash util.Uint160) (*entities.AccountState, error) { func (dao *dao) GetAccountStateOrNew(hash util.Uint160) (*state.Account, error) {
account, err := dao.GetAccountState(hash) account, err := dao.GetAccountState(hash)
if err != nil { if err != nil {
if err != storage.ErrKeyNotFound { if err != storage.ErrKeyNotFound {
return nil, err return nil, err
} }
account = entities.NewAccountState(hash) account = state.NewAccount(hash)
if err = dao.PutAccountState(account); err != nil { if err = dao.PutAccountState(account); err != nil {
return nil, err return nil, err
} }
@ -58,10 +58,10 @@ func (dao *dao) GetAccountStateOrNew(hash util.Uint160) (*entities.AccountState,
return account, nil return account, nil
} }
// GetAccountState returns AccountState from the given Store if it's // GetAccountState returns Account from the given Store if it's
// present there. Returns nil otherwise. // present there. Returns nil otherwise.
func (dao *dao) GetAccountState(hash util.Uint160) (*entities.AccountState, error) { func (dao *dao) GetAccountState(hash util.Uint160) (*state.Account, error) {
account := &entities.AccountState{} account := &state.Account{}
key := storage.AppendPrefix(storage.STAccount, hash.BytesBE()) key := storage.AppendPrefix(storage.STAccount, hash.BytesBE())
err := dao.GetAndDecode(account, key) err := dao.GetAndDecode(account, key)
if err != nil { if err != nil {
@ -70,8 +70,7 @@ func (dao *dao) GetAccountState(hash util.Uint160) (*entities.AccountState, erro
return account, err return account, err
} }
// PutAccountState puts given AccountState into the given store. func (dao *dao) PutAccountState(as *state.Account) error {
func (dao *dao) PutAccountState(as *entities.AccountState) error {
key := storage.AppendPrefix(storage.STAccount, as.ScriptHash.BytesBE()) key := storage.AppendPrefix(storage.STAccount, as.ScriptHash.BytesBE())
return dao.Put(as, key) return dao.Put(as, key)
} }
@ -81,8 +80,8 @@ func (dao *dao) PutAccountState(as *entities.AccountState) error {
// -- start assets. // -- start assets.
// GetAssetState returns given asset state as recorded in the given store. // GetAssetState returns given asset state as recorded in the given store.
func (dao *dao) GetAssetState(assetID util.Uint256) (*entities.AssetState, error) { func (dao *dao) GetAssetState(assetID util.Uint256) (*state.Asset, error) {
asset := &entities.AssetState{} asset := &state.Asset{}
key := storage.AppendPrefix(storage.STAsset, assetID.BytesBE()) key := storage.AppendPrefix(storage.STAsset, assetID.BytesBE())
err := dao.GetAndDecode(asset, key) err := dao.GetAndDecode(asset, key)
if err != nil { if err != nil {
@ -95,7 +94,7 @@ func (dao *dao) GetAssetState(assetID util.Uint256) (*entities.AssetState, error
} }
// PutAssetState puts given asset state into the given store. // PutAssetState puts given asset state into the given store.
func (dao *dao) PutAssetState(as *entities.AssetState) error { func (dao *dao) PutAssetState(as *state.Asset) error {
key := storage.AppendPrefix(storage.STAsset, as.ID.BytesBE()) key := storage.AppendPrefix(storage.STAsset, as.ID.BytesBE())
return dao.Put(as, key) return dao.Put(as, key)
} }
@ -106,8 +105,8 @@ func (dao *dao) PutAssetState(as *entities.AssetState) error {
// GetContractState returns contract state as recorded in the given // GetContractState returns contract state as recorded in the given
// store by the given script hash. // store by the given script hash.
func (dao *dao) GetContractState(hash util.Uint160) (*entities.ContractState, error) { func (dao *dao) GetContractState(hash util.Uint160) (*state.Contract, error) {
contract := &entities.ContractState{} contract := &state.Contract{}
key := storage.AppendPrefix(storage.STContract, hash.BytesBE()) key := storage.AppendPrefix(storage.STContract, hash.BytesBE())
err := dao.GetAndDecode(contract, key) err := dao.GetAndDecode(contract, key)
if err != nil { if err != nil {
@ -121,7 +120,7 @@ func (dao *dao) GetContractState(hash util.Uint160) (*entities.ContractState, er
} }
// PutContractState puts given contract state into the given store. // PutContractState puts given contract state into the given store.
func (dao *dao) PutContractState(cs *entities.ContractState) error { func (dao *dao) PutContractState(cs *state.Contract) error {
key := storage.AppendPrefix(storage.STContract, cs.ScriptHash().BytesBE()) key := storage.AppendPrefix(storage.STContract, cs.ScriptHash().BytesBE())
return dao.Put(cs, key) return dao.Put(cs, key)
} }
@ -146,7 +145,7 @@ func (dao *dao) GetUnspentCoinStateOrNew(hash util.Uint256) (*UnspentCoinState,
return nil, err return nil, err
} }
unspent = &UnspentCoinState{ unspent = &UnspentCoinState{
states: []entities.CoinState{}, states: []state.Coin{},
} }
if err = dao.PutUnspentCoinState(hash, unspent); err != nil { if err = dao.PutUnspentCoinState(hash, unspent); err != nil {
return nil, err return nil, err
@ -221,13 +220,13 @@ func (dao *dao) DeleteSpentCoinState(hash util.Uint256) error {
// -- start validator. // -- start validator.
// GetValidatorStateOrNew gets validator from store or created new one in case of error. // GetValidatorStateOrNew gets validator from store or created new one in case of error.
func (dao *dao) GetValidatorStateOrNew(publicKey *keys.PublicKey) (*entities.ValidatorState, error) { func (dao *dao) GetValidatorStateOrNew(publicKey *keys.PublicKey) (*state.Validator, error) {
validatorState, err := dao.GetValidatorState(publicKey) validatorState, err := dao.GetValidatorState(publicKey)
if err != nil { if err != nil {
if err != storage.ErrKeyNotFound { if err != storage.ErrKeyNotFound {
return nil, err return nil, err
} }
validatorState = &entities.ValidatorState{PublicKey: publicKey} validatorState = &state.Validator{PublicKey: publicKey}
if err = dao.PutValidatorState(validatorState); err != nil { if err = dao.PutValidatorState(validatorState); err != nil {
return nil, err return nil, err
} }
@ -237,11 +236,11 @@ func (dao *dao) GetValidatorStateOrNew(publicKey *keys.PublicKey) (*entities.Val
} }
// GetValidators returns all validators from store. // GetValidators returns all validators from store.
func (dao *dao) GetValidators() []*entities.ValidatorState { func (dao *dao) GetValidators() []*state.Validator {
var validators []*entities.ValidatorState var validators []*state.Validator
dao.store.Seek(storage.STValidator.Bytes(), func(k, v []byte) { dao.store.Seek(storage.STValidator.Bytes(), func(k, v []byte) {
r := io.NewBinReaderFromBuf(v) r := io.NewBinReaderFromBuf(v)
validator := &entities.ValidatorState{} validator := &state.Validator{}
validator.DecodeBinary(r) validator.DecodeBinary(r)
if r.Err != nil { if r.Err != nil {
return return
@ -252,8 +251,8 @@ func (dao *dao) GetValidators() []*entities.ValidatorState {
} }
// GetValidatorState returns validator by publicKey. // GetValidatorState returns validator by publicKey.
func (dao *dao) GetValidatorState(publicKey *keys.PublicKey) (*entities.ValidatorState, error) { func (dao *dao) GetValidatorState(publicKey *keys.PublicKey) (*state.Validator, error) {
validatorState := &entities.ValidatorState{} validatorState := &state.Validator{}
key := storage.AppendPrefix(storage.STValidator, publicKey.Bytes()) key := storage.AppendPrefix(storage.STValidator, publicKey.Bytes())
err := dao.GetAndDecode(validatorState, key) err := dao.GetAndDecode(validatorState, key)
if err != nil { if err != nil {
@ -262,14 +261,14 @@ func (dao *dao) GetValidatorState(publicKey *keys.PublicKey) (*entities.Validato
return validatorState, nil return validatorState, nil
} }
// PutValidatorState puts given ValidatorState into the given store. // PutValidatorState puts given Validator into the given store.
func (dao *dao) PutValidatorState(vs *entities.ValidatorState) error { func (dao *dao) PutValidatorState(vs *state.Validator) error {
key := storage.AppendPrefix(storage.STValidator, vs.PublicKey.Bytes()) key := storage.AppendPrefix(storage.STValidator, vs.PublicKey.Bytes())
return dao.Put(vs, key) return dao.Put(vs, key)
} }
// DeleteValidatorState deletes given ValidatorState into the given store. // DeleteValidatorState deletes given Validator into the given store.
func (dao *dao) DeleteValidatorState(vs *entities.ValidatorState) error { func (dao *dao) DeleteValidatorState(vs *state.Validator) error {
key := storage.AppendPrefix(storage.STValidator, vs.PublicKey.Bytes()) key := storage.AppendPrefix(storage.STValidator, vs.PublicKey.Bytes())
return dao.store.Delete(key) return dao.store.Delete(key)
} }
@ -280,8 +279,8 @@ func (dao *dao) DeleteValidatorState(vs *entities.ValidatorState) error {
// GetAppExecResult gets application execution result from the // GetAppExecResult gets application execution result from the
// given store. // given store.
func (dao *dao) GetAppExecResult(hash util.Uint256) (*entities.AppExecResult, error) { func (dao *dao) GetAppExecResult(hash util.Uint256) (*state.AppExecResult, error) {
aer := &entities.AppExecResult{} aer := &state.AppExecResult{}
key := storage.AppendPrefix(storage.STNotification, hash.BytesBE()) key := storage.AppendPrefix(storage.STNotification, hash.BytesBE())
err := dao.GetAndDecode(aer, key) err := dao.GetAndDecode(aer, key)
if err != nil { if err != nil {
@ -292,7 +291,7 @@ func (dao *dao) GetAppExecResult(hash util.Uint256) (*entities.AppExecResult, er
// PutAppExecResult puts given application execution result into the // PutAppExecResult puts given application execution result into the
// given store. // given store.
func (dao *dao) PutAppExecResult(aer *entities.AppExecResult) error { func (dao *dao) PutAppExecResult(aer *state.AppExecResult) error {
key := storage.AppendPrefix(storage.STNotification, aer.TxHash.BytesBE()) key := storage.AppendPrefix(storage.STNotification, aer.TxHash.BytesBE())
return dao.Put(aer, key) return dao.Put(aer, key)
} }
@ -302,14 +301,14 @@ func (dao *dao) PutAppExecResult(aer *entities.AppExecResult) error {
// -- start storage item. // -- start storage item.
// GetStorageItem returns StorageItem if it exists in the given Store. // GetStorageItem returns StorageItem if it exists in the given Store.
func (dao *dao) GetStorageItem(scripthash util.Uint160, key []byte) *entities.StorageItem { func (dao *dao) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem {
b, err := dao.store.Get(makeStorageItemKey(scripthash, key)) b, err := dao.store.Get(makeStorageItemKey(scripthash, key))
if err != nil { if err != nil {
return nil return nil
} }
r := io.NewBinReaderFromBuf(b) r := io.NewBinReaderFromBuf(b)
si := &entities.StorageItem{} si := &state.StorageItem{}
si.DecodeBinary(r) si.DecodeBinary(r)
if r.Err != nil { if r.Err != nil {
return nil return nil
@ -320,7 +319,7 @@ func (dao *dao) GetStorageItem(scripthash util.Uint160, key []byte) *entities.St
// PutStorageItem puts given StorageItem for given script with given // PutStorageItem puts given StorageItem for given script with given
// key into the given Store. // key into the given Store.
func (dao *dao) PutStorageItem(scripthash util.Uint160, key []byte, si *entities.StorageItem) error { func (dao *dao) PutStorageItem(scripthash util.Uint160, key []byte, si *state.StorageItem) error {
return dao.Put(si, makeStorageItemKey(scripthash, key)) return dao.Put(si, makeStorageItemKey(scripthash, key))
} }
@ -331,8 +330,8 @@ func (dao *dao) DeleteStorageItem(scripthash util.Uint160, key []byte) error {
} }
// GetStorageItems returns all storage items for a given scripthash. // GetStorageItems returns all storage items for a given scripthash.
func (dao *dao) GetStorageItems(hash util.Uint160) (map[string]*entities.StorageItem, error) { func (dao *dao) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) {
var siMap = make(map[string]*entities.StorageItem) var siMap = make(map[string]*state.StorageItem)
var err error var err error
saveToMap := func(k, v []byte) { saveToMap := func(k, v []byte) {
@ -340,7 +339,7 @@ func (dao *dao) GetStorageItems(hash util.Uint160) (map[string]*entities.Storage
return return
} }
r := io.NewBinReaderFromBuf(v) r := io.NewBinReaderFromBuf(v)
si := &entities.StorageItem{} si := &state.StorageItem{}
si.DecodeBinary(r) si.DecodeBinary(r)
if r.Err != nil { if r.Err != nil {
err = r.Err err = r.Err
@ -546,7 +545,7 @@ func (dao *dao) IsDoubleSpend(tx *transaction.Transaction) bool {
return false return false
} }
for _, input := range inputs { for _, input := range inputs {
if int(input.PrevIndex) >= len(unspent.states) || unspent.states[input.PrevIndex] == entities.CoinStateSpent { if int(input.PrevIndex) >= len(unspent.states) || unspent.states[input.PrevIndex] == state.CoinSpent {
return true return true
} }
} }

View file

@ -3,7 +3,7 @@ package core
import ( import (
"testing" "testing"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/testutil" "github.com/CityOfZion/neo-go/pkg/core/testutil"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
@ -53,7 +53,7 @@ func TestGetAccountStateOrNew_New(t *testing.T) {
func TestPutAndGetAccountStateOrNew(t *testing.T) { func TestPutAndGetAccountStateOrNew(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
hash := testutil.RandomUint160() hash := testutil.RandomUint160()
accountState := &entities.AccountState{ScriptHash: hash} accountState := &state.Account{ScriptHash: hash}
err := dao.PutAccountState(accountState) err := dao.PutAccountState(accountState)
require.NoError(t, err) require.NoError(t, err)
gotAccount, err := dao.GetAccountStateOrNew(hash) gotAccount, err := dao.GetAccountStateOrNew(hash)
@ -64,7 +64,7 @@ func TestPutAndGetAccountStateOrNew(t *testing.T) {
func TestPutAndGetAssetState(t *testing.T) { func TestPutAndGetAssetState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
id := testutil.RandomUint256() id := testutil.RandomUint256()
assetState := &entities.AssetState{ID: id, Owner: keys.PublicKey{}} assetState := &state.Asset{ID: id, Owner: keys.PublicKey{}}
err := dao.PutAssetState(assetState) err := dao.PutAssetState(assetState)
require.NoError(t, err) require.NoError(t, err)
gotAssetState, err := dao.GetAssetState(id) gotAssetState, err := dao.GetAssetState(id)
@ -74,7 +74,7 @@ func TestPutAndGetAssetState(t *testing.T) {
func TestPutAndGetContractState(t *testing.T) { func TestPutAndGetContractState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
contractState := &entities.ContractState{Script: []byte{}, ParamList:[]smartcontract.ParamType{}} contractState := &state.Contract{Script: []byte{}, ParamList:[]smartcontract.ParamType{}}
hash := contractState.ScriptHash() hash := contractState.ScriptHash()
err := dao.PutContractState(contractState) err := dao.PutContractState(contractState)
require.NoError(t, err) require.NoError(t, err)
@ -85,7 +85,7 @@ func TestPutAndGetContractState(t *testing.T) {
func TestDeleteContractState(t *testing.T) { func TestDeleteContractState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
contractState := &entities.ContractState{Script: []byte{}, ParamList:[]smartcontract.ParamType{}} contractState := &state.Contract{Script: []byte{}, ParamList:[]smartcontract.ParamType{}}
hash := contractState.ScriptHash() hash := contractState.ScriptHash()
err := dao.PutContractState(contractState) err := dao.PutContractState(contractState)
require.NoError(t, err) require.NoError(t, err)
@ -118,7 +118,7 @@ func TestGetUnspentCoinState_Err(t *testing.T) {
func TestPutGetUnspentCoinState(t *testing.T) { func TestPutGetUnspentCoinState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
hash := testutil.RandomUint256() hash := testutil.RandomUint256()
unspentCoinState := &UnspentCoinState{states:[]entities.CoinState{}} unspentCoinState := &UnspentCoinState{states:[]state.Coin{}}
err := dao.PutUnspentCoinState(hash, unspentCoinState) err := dao.PutUnspentCoinState(hash, unspentCoinState)
require.NoError(t, err) require.NoError(t, err)
gotUnspentCoinState, err := dao.GetUnspentCoinState(hash) gotUnspentCoinState, err := dao.GetUnspentCoinState(hash)
@ -183,7 +183,7 @@ func TestGetValidatorStateOrNew_New(t *testing.T) {
func TestPutGetValidatorState(t *testing.T) { func TestPutGetValidatorState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
publicKey := &keys.PublicKey{} publicKey := &keys.PublicKey{}
validatorState := &entities.ValidatorState{ validatorState := &state.Validator{
PublicKey: publicKey, PublicKey: publicKey,
Registered: false, Registered: false,
Votes: 0, Votes: 0,
@ -198,7 +198,7 @@ func TestPutGetValidatorState(t *testing.T) {
func TestDeleteValidatorState(t *testing.T) { func TestDeleteValidatorState(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
publicKey := &keys.PublicKey{} publicKey := &keys.PublicKey{}
validatorState := &entities.ValidatorState{ validatorState := &state.Validator{
PublicKey: publicKey, PublicKey: publicKey,
Registered: false, Registered: false,
Votes: 0, Votes: 0,
@ -215,7 +215,7 @@ func TestDeleteValidatorState(t *testing.T) {
func TestGetValidators(t *testing.T) { func TestGetValidators(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
publicKey := &keys.PublicKey{} publicKey := &keys.PublicKey{}
validatorState := &entities.ValidatorState{ validatorState := &state.Validator{
PublicKey: publicKey, PublicKey: publicKey,
Registered: false, Registered: false,
Votes: 0, Votes: 0,
@ -230,7 +230,7 @@ func TestGetValidators(t *testing.T) {
func TestPutGetAppExecResult(t *testing.T) { func TestPutGetAppExecResult(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
hash := testutil.RandomUint256() hash := testutil.RandomUint256()
appExecResult := &entities.AppExecResult{TxHash: hash, Events:[]entities.NotificationEvent{}} appExecResult := &state.AppExecResult{TxHash: hash, Events:[]state.NotificationEvent{}}
err := dao.PutAppExecResult(appExecResult) err := dao.PutAppExecResult(appExecResult)
require.NoError(t, err) require.NoError(t, err)
gotAppExecResult, err := dao.GetAppExecResult(hash) gotAppExecResult, err := dao.GetAppExecResult(hash)
@ -242,7 +242,7 @@ func TestPutGetStorageItem(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
hash := testutil.RandomUint160() hash := testutil.RandomUint160()
key := []byte{0} key := []byte{0}
storageItem := &entities.StorageItem{Value:[]uint8{}} storageItem := &state.StorageItem{Value: []uint8{}}
err := dao.PutStorageItem(hash, key, storageItem) err := dao.PutStorageItem(hash, key, storageItem)
require.NoError(t, err) require.NoError(t, err)
gotStorageItem := dao.GetStorageItem(hash, key) gotStorageItem := dao.GetStorageItem(hash, key)
@ -253,7 +253,7 @@ func TestDeleteStorageItem(t *testing.T) {
dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())} dao := &dao{store: storage.NewMemCachedStore(storage.NewMemoryStore())}
hash := testutil.RandomUint160() hash := testutil.RandomUint160()
key := []byte{0} key := []byte{0}
storageItem := &entities.StorageItem{Value:[]uint8{}} storageItem := &state.StorageItem{Value: []uint8{}}
err := dao.PutStorageItem(hash, key, storageItem) err := dao.PutStorageItem(hash, key, storageItem)
require.NoError(t, err) require.NoError(t, err)
err = dao.DeleteStorageItem(hash, key) err = dao.DeleteStorageItem(hash, key)

View file

@ -1,12 +0,0 @@
package entities
// CoinState represents the state of a coin.
type CoinState uint8
// Viable CoinState constants.
const (
CoinStateConfirmed CoinState = 0
CoinStateSpent CoinState = 1 << 1
CoinStateClaimed CoinState = 1 << 2
CoinStateFrozen CoinState = 1 << 5
)

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"math" "math"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/smartcontract" "github.com/CityOfZion/neo-go/pkg/smartcontract"
@ -317,7 +317,7 @@ func (ic *interopContext) bcGetAccount(v *vm.VM) error {
} }
acc := ic.bc.GetAccountState(acchash) acc := ic.bc.GetAccountState(acchash)
if acc == nil { if acc == nil {
acc = entities.NewAccountState(acchash) acc = state.NewAccount(acchash)
} }
v.Estack().PushVal(vm.NewInteropItem(acc)) v.Estack().PushVal(vm.NewInteropItem(acc))
return nil return nil
@ -341,7 +341,7 @@ func (ic *interopContext) bcGetAsset(v *vm.VM) error {
// accountGetBalance returns balance for a given account. // accountGetBalance returns balance for a given account.
func (ic *interopContext) accountGetBalance(v *vm.VM) error { func (ic *interopContext) accountGetBalance(v *vm.VM) error {
accInterface := v.Estack().Pop().Value() accInterface := v.Estack().Pop().Value()
acc, ok := accInterface.(*entities.AccountState) acc, ok := accInterface.(*state.Account)
if !ok { if !ok {
return fmt.Errorf("%T is not an account state", acc) return fmt.Errorf("%T is not an account state", acc)
} }
@ -361,7 +361,7 @@ func (ic *interopContext) accountGetBalance(v *vm.VM) error {
// accountGetScriptHash returns script hash of a given account. // accountGetScriptHash returns script hash of a given account.
func (ic *interopContext) accountGetScriptHash(v *vm.VM) error { func (ic *interopContext) accountGetScriptHash(v *vm.VM) error {
accInterface := v.Estack().Pop().Value() accInterface := v.Estack().Pop().Value()
acc, ok := accInterface.(*entities.AccountState) acc, ok := accInterface.(*state.Account)
if !ok { if !ok {
return fmt.Errorf("%T is not an account state", acc) return fmt.Errorf("%T is not an account state", acc)
} }
@ -372,7 +372,7 @@ func (ic *interopContext) accountGetScriptHash(v *vm.VM) error {
// accountGetVotes returns votes of a given account. // accountGetVotes returns votes of a given account.
func (ic *interopContext) accountGetVotes(v *vm.VM) error { func (ic *interopContext) accountGetVotes(v *vm.VM) error {
accInterface := v.Estack().Pop().Value() accInterface := v.Estack().Pop().Value()
acc, ok := accInterface.(*entities.AccountState) acc, ok := accInterface.(*state.Account)
if !ok { if !ok {
return fmt.Errorf("%T is not an account state", acc) return fmt.Errorf("%T is not an account state", acc)
} }
@ -428,9 +428,9 @@ func (ic *interopContext) storageFind(v *vm.VM) error {
} }
*/ */
// createContractStateFromVM pops all contract state elements from the VM // createContractStateFromVM pops all contract state elements from the VM
// evaluation stack, does a lot of checks and returns ContractState if it // evaluation stack, does a lot of checks and returns Contract if it
// succeeds. // succeeds.
func (ic *interopContext) createContractStateFromVM(v *vm.VM) (*entities.ContractState, error) { func (ic *interopContext) createContractStateFromVM(v *vm.VM) (*state.Contract, error) {
if ic.trigger != trigger.Application { if ic.trigger != trigger.Application {
return nil, errors.New("can't create contract when not triggered by an application") return nil, errors.New("can't create contract when not triggered by an application")
} }
@ -468,7 +468,7 @@ func (ic *interopContext) createContractStateFromVM(v *vm.VM) (*entities.Contrac
if len(desc) > MaxContractStringLen { if len(desc) > MaxContractStringLen {
return nil, errors.New("too big description") return nil, errors.New("too big description")
} }
contract := &entities.ContractState{ contract := &state.Contract{
Script: script, Script: script,
ParamList: paramList, ParamList: paramList,
ReturnType: retType, ReturnType: retType,
@ -503,7 +503,7 @@ func (ic *interopContext) contractCreate(v *vm.VM) error {
// contractGetScript returns a script associated with a contract. // contractGetScript returns a script associated with a contract.
func (ic *interopContext) contractGetScript(v *vm.VM) error { func (ic *interopContext) contractGetScript(v *vm.VM) error {
csInterface := v.Estack().Pop().Value() csInterface := v.Estack().Pop().Value()
cs, ok := csInterface.(*entities.ContractState) cs, ok := csInterface.(*state.Contract)
if !ok { if !ok {
return fmt.Errorf("%T is not a contract state", cs) return fmt.Errorf("%T is not a contract state", cs)
} }
@ -514,7 +514,7 @@ func (ic *interopContext) contractGetScript(v *vm.VM) error {
// contractIsPayable returns whether contract is payable. // contractIsPayable returns whether contract is payable.
func (ic *interopContext) contractIsPayable(v *vm.VM) error { func (ic *interopContext) contractIsPayable(v *vm.VM) error {
csInterface := v.Estack().Pop().Value() csInterface := v.Estack().Pop().Value()
cs, ok := csInterface.(*entities.ContractState) cs, ok := csInterface.(*state.Contract)
if !ok { if !ok {
return fmt.Errorf("%T is not a contract state", cs) return fmt.Errorf("%T is not a contract state", cs)
} }
@ -610,7 +610,7 @@ func (ic *interopContext) assetCreate(v *vm.VM) error {
if err != nil { if err != nil {
return gherr.Wrap(err, "failed to get issuer") return gherr.Wrap(err, "failed to get issuer")
} }
asset := &entities.AssetState{ asset := &state.Asset{
ID: ic.tx.Hash(), ID: ic.tx.Hash(),
AssetType: atype, AssetType: atype,
Name: name, Name: name,
@ -632,7 +632,7 @@ func (ic *interopContext) assetCreate(v *vm.VM) error {
// assetGetAdmin returns asset admin. // assetGetAdmin returns asset admin.
func (ic *interopContext) assetGetAdmin(v *vm.VM) error { func (ic *interopContext) assetGetAdmin(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -643,7 +643,7 @@ func (ic *interopContext) assetGetAdmin(v *vm.VM) error {
// assetGetAmount returns the overall amount of asset available. // assetGetAmount returns the overall amount of asset available.
func (ic *interopContext) assetGetAmount(v *vm.VM) error { func (ic *interopContext) assetGetAmount(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -654,7 +654,7 @@ func (ic *interopContext) assetGetAmount(v *vm.VM) error {
// assetGetAssetId returns the id of an asset. // assetGetAssetId returns the id of an asset.
func (ic *interopContext) assetGetAssetID(v *vm.VM) error { func (ic *interopContext) assetGetAssetID(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -665,7 +665,7 @@ func (ic *interopContext) assetGetAssetID(v *vm.VM) error {
// assetGetAssetType returns type of an asset. // assetGetAssetType returns type of an asset.
func (ic *interopContext) assetGetAssetType(v *vm.VM) error { func (ic *interopContext) assetGetAssetType(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -676,7 +676,7 @@ func (ic *interopContext) assetGetAssetType(v *vm.VM) error {
// assetGetAvailable returns available (not yet issued) amount of asset. // assetGetAvailable returns available (not yet issued) amount of asset.
func (ic *interopContext) assetGetAvailable(v *vm.VM) error { func (ic *interopContext) assetGetAvailable(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -687,7 +687,7 @@ func (ic *interopContext) assetGetAvailable(v *vm.VM) error {
// assetGetIssuer returns issuer of an asset. // assetGetIssuer returns issuer of an asset.
func (ic *interopContext) assetGetIssuer(v *vm.VM) error { func (ic *interopContext) assetGetIssuer(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -698,7 +698,7 @@ func (ic *interopContext) assetGetIssuer(v *vm.VM) error {
// assetGetOwner returns owner of an asset. // assetGetOwner returns owner of an asset.
func (ic *interopContext) assetGetOwner(v *vm.VM) error { func (ic *interopContext) assetGetOwner(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -709,7 +709,7 @@ func (ic *interopContext) assetGetOwner(v *vm.VM) error {
// assetGetPrecision returns precision used to measure this asset. // assetGetPrecision returns precision used to measure this asset.
func (ic *interopContext) assetGetPrecision(v *vm.VM) error { func (ic *interopContext) assetGetPrecision(v *vm.VM) error {
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }
@ -723,7 +723,7 @@ func (ic *interopContext) assetRenew(v *vm.VM) error {
return errors.New("can't create asset when not triggered by an application") return errors.New("can't create asset when not triggered by an application")
} }
asInterface := v.Estack().Pop().Value() asInterface := v.Estack().Pop().Value()
as, ok := asInterface.(*entities.AssetState) as, ok := asInterface.(*state.Asset)
if !ok { if !ok {
return fmt.Errorf("%T is not an asset state", as) return fmt.Errorf("%T is not an asset state", as)
} }

View file

@ -4,7 +4,7 @@ import (
"math/big" "math/big"
"testing" "testing"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/testutil" "github.com/CityOfZion/neo-go/pkg/core/testutil"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
@ -323,7 +323,7 @@ func TestAssetGetPrecision(t *testing.T) {
require.Equal(t, big.NewInt(int64(assetState.Precision)), precision) require.Equal(t, big.NewInt(int64(assetState.Precision)), precision)
} }
// Helper functions to create VM, InteropContext, TX, AccountState, ContractState, AssetState. // Helper functions to create VM, InteropContext, TX, Account, Contract, Asset.
func createVMAndPushBlock(t *testing.T) (*vm.VM, *Block, *interopContext) { func createVMAndPushBlock(t *testing.T) (*vm.VM, *Block, *interopContext) {
v := vm.New() v := vm.New()
@ -339,9 +339,9 @@ func createVMAndPushTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interop
return v, tx, context return v, tx, context
} }
func createVMAndAssetState(t *testing.T) (*vm.VM, *entities.AssetState, *interopContext) { func createVMAndAssetState(t *testing.T) (*vm.VM, *state.Asset, *interopContext) {
v := vm.New() v := vm.New()
assetState := &entities.AssetState{ assetState := &state.Asset{
ID: util.Uint256{}, ID: util.Uint256{},
AssetType: transaction.GoverningToken, AssetType: transaction.GoverningToken,
Name: "TestAsset", Name: "TestAsset",
@ -361,9 +361,9 @@ func createVMAndAssetState(t *testing.T) (*vm.VM, *entities.AssetState, *interop
return v, assetState, context return v, assetState, context
} }
func createVMAndContractState(t *testing.T) (*vm.VM, *entities.ContractState, *interopContext) { func createVMAndContractState(t *testing.T) (*vm.VM, *state.Contract, *interopContext) {
v := vm.New() v := vm.New()
contractState := &entities.ContractState{ contractState := &state.Contract{
Script: []byte("testscript"), Script: []byte("testscript"),
ParamList: []smartcontract.ParamType{smartcontract.StringType, smartcontract.IntegerType, smartcontract.Hash160Type}, ParamList: []smartcontract.ParamType{smartcontract.StringType, smartcontract.IntegerType, smartcontract.Hash160Type},
ReturnType: smartcontract.ArrayType, ReturnType: smartcontract.ArrayType,
@ -379,11 +379,11 @@ func createVMAndContractState(t *testing.T) (*vm.VM, *entities.ContractState, *i
return v, contractState, context return v, contractState, context
} }
func createVMAndAccState(t *testing.T) (*vm.VM, *entities.AccountState, *interopContext) { func createVMAndAccState(t *testing.T) (*vm.VM, *state.Account, *interopContext) {
v := vm.New() v := vm.New()
rawHash := "4d3b96ae1bcc5a585e075e3b81920210dec16302" rawHash := "4d3b96ae1bcc5a585e075e3b81920210dec16302"
hash, err := util.Uint160DecodeStringBE(rawHash) hash, err := util.Uint160DecodeStringBE(rawHash)
accountState := entities.NewAccountState(hash) accountState := state.NewAccount(hash)
key := &keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)} key := &keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)}
accountState.Votes = []*keys.PublicKey{key} accountState.Votes = []*keys.PublicKey{key}

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"math" "math"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -342,7 +342,7 @@ func (ic *interopContext) runtimeCheckWitness(v *vm.VM) error {
func (ic *interopContext) runtimeNotify(v *vm.VM) error { func (ic *interopContext) runtimeNotify(v *vm.VM) error {
// It can be just about anything. // It can be just about anything.
e := v.Estack().Pop() e := v.Estack().Pop()
ne := entities.NotificationEvent{ScriptHash:getContextScriptHash(v, 0), Item:e.Item()} ne := state.NotificationEvent{ScriptHash: getContextScriptHash(v, 0), Item: e.Item()}
ic.notifications = append(ic.notifications, ne) ic.notifications = append(ic.notifications, ne)
return nil return nil
} }
@ -475,7 +475,7 @@ func (ic *interopContext) putWithContextAndFlags(stc *StorageContext, key []byte
} }
si := ic.dao.GetStorageItem(stc.ScriptHash, key) si := ic.dao.GetStorageItem(stc.ScriptHash, key)
if si == nil { if si == nil {
si = &entities.StorageItem{} si = &state.StorageItem{}
} }
if si.IsConst { if si.IsConst {
return errors.New("storage item exists and is read-only") return errors.New("storage item exists and is read-only")
@ -558,7 +558,7 @@ func (ic *interopContext) contractDestroy(v *vm.VM) error {
// contractGetStorageContext retrieves StorageContext of a contract. // contractGetStorageContext retrieves StorageContext of a contract.
func (ic *interopContext) contractGetStorageContext(v *vm.VM) error { func (ic *interopContext) contractGetStorageContext(v *vm.VM) error {
csInterface := v.Estack().Pop().Value() csInterface := v.Estack().Pop().Value()
cs, ok := csInterface.(*entities.ContractState) cs, ok := csInterface.(*state.Contract)
if !ok { if !ok {
return fmt.Errorf("%T is not a contract state", cs) return fmt.Errorf("%T is not a contract state", cs)
} }

View file

@ -8,7 +8,7 @@ package core
*/ */
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/vm" "github.com/CityOfZion/neo-go/pkg/vm"
@ -20,12 +20,12 @@ type interopContext struct {
block *Block block *Block
tx *transaction.Transaction tx *transaction.Transaction
dao *dao dao *dao
notifications []entities.NotificationEvent notifications []state.NotificationEvent
} }
func newInteropContext(trigger byte, bc Blockchainer, s storage.Store, block *Block, tx *transaction.Transaction) *interopContext { func newInteropContext(trigger byte, bc Blockchainer, s storage.Store, block *Block, tx *transaction.Transaction) *interopContext {
dao := &dao{store: storage.NewMemCachedStore(s)} dao := &dao{store: storage.NewMemCachedStore(s)}
nes := make([]entities.NotificationEvent, 0) nes := make([]state.NotificationEvent, 0)
return &interopContext{bc, trigger, block, tx, dao, nes} return &interopContext{bc, trigger, block, tx, dao, nes}
} }

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -17,8 +17,8 @@ type UnspentBalance struct {
// UnspentBalances is a slice of UnspentBalance (mostly needed to sort them). // UnspentBalances is a slice of UnspentBalance (mostly needed to sort them).
type UnspentBalances []UnspentBalance type UnspentBalances []UnspentBalance
// AccountState represents the state of a NEO account. // Account represents the state of a NEO account.
type AccountState struct { type Account struct {
Version uint8 Version uint8
ScriptHash util.Uint160 ScriptHash util.Uint160
IsFrozen bool IsFrozen bool
@ -26,9 +26,9 @@ type AccountState struct {
Balances map[util.Uint256][]UnspentBalance Balances map[util.Uint256][]UnspentBalance
} }
// NewAccountState returns a new AccountState object. // NewAccount returns a new Account object.
func NewAccountState(scriptHash util.Uint160) *AccountState { func NewAccount(scriptHash util.Uint160) *Account {
return &AccountState{ return &Account{
Version: 0, Version: 0,
ScriptHash: scriptHash, ScriptHash: scriptHash,
IsFrozen: false, IsFrozen: false,
@ -37,8 +37,8 @@ func NewAccountState(scriptHash util.Uint160) *AccountState {
} }
} }
// DecodeBinary decodes AccountState from the given BinReader. // DecodeBinary decodes Account from the given BinReader.
func (s *AccountState) DecodeBinary(br *io.BinReader) { func (s *Account) DecodeBinary(br *io.BinReader) {
br.ReadLE(&s.Version) br.ReadLE(&s.Version)
br.ReadBytes(s.ScriptHash[:]) br.ReadBytes(s.ScriptHash[:])
br.ReadLE(&s.IsFrozen) br.ReadLE(&s.IsFrozen)
@ -55,8 +55,8 @@ func (s *AccountState) DecodeBinary(br *io.BinReader) {
} }
} }
// EncodeBinary encodes AccountState to the given BinWriter. // EncodeBinary encodes Account to the given BinWriter.
func (s *AccountState) EncodeBinary(bw *io.BinWriter) { func (s *Account) EncodeBinary(bw *io.BinWriter) {
bw.WriteLE(s.Version) bw.WriteLE(s.Version)
bw.WriteBytes(s.ScriptHash[:]) bw.WriteBytes(s.ScriptHash[:])
bw.WriteLE(s.IsFrozen) bw.WriteLE(s.IsFrozen)
@ -85,7 +85,7 @@ func (u *UnspentBalance) EncodeBinary(w *io.BinWriter) {
// GetBalanceValues sums all unspent outputs and returns a map of asset IDs to // GetBalanceValues sums all unspent outputs and returns a map of asset IDs to
// overall balances. // overall balances.
func (s *AccountState) GetBalanceValues() map[util.Uint256]util.Fixed8 { func (s *Account) GetBalanceValues() map[util.Uint256]util.Fixed8 {
res := make(map[util.Uint256]util.Fixed8) res := make(map[util.Uint256]util.Fixed8)
for k, v := range s.Balances { for k, v := range s.Balances {
balance := util.Fixed8(0) balance := util.Fixed8(0)

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"testing" "testing"
@ -30,7 +30,7 @@ func TestDecodeEncodeAccountState(t *testing.T) {
votes[i] = k.PublicKey() votes[i] = k.PublicKey()
} }
a := &AccountState{ a := &Account{
Version: 0, Version: 0,
ScriptHash: testutil.RandomUint160(), ScriptHash: testutil.RandomUint160(),
IsFrozen: true, IsFrozen: true,
@ -42,7 +42,7 @@ func TestDecodeEncodeAccountState(t *testing.T) {
a.EncodeBinary(buf.BinWriter) a.EncodeBinary(buf.BinWriter)
assert.Nil(t, buf.Err) assert.Nil(t, buf.Err)
aDecode := &AccountState{} aDecode := &Account{}
r := io.NewBinReaderFromBuf(buf.Bytes()) r := io.NewBinReaderFromBuf(buf.Bytes())
aDecode.DecodeBinary(r) aDecode.DecodeBinary(r)
assert.Nil(t, r.Err) assert.Nil(t, r.Err)
@ -60,7 +60,7 @@ func TestDecodeEncodeAccountState(t *testing.T) {
func TestAccountStateBalanceValues(t *testing.T) { func TestAccountStateBalanceValues(t *testing.T) {
asset1 := testutil.RandomUint256() asset1 := testutil.RandomUint256()
asset2 := testutil.RandomUint256() asset2 := testutil.RandomUint256()
as := AccountState{Balances: make(map[util.Uint256][]UnspentBalance)} as := Account{Balances: make(map[util.Uint256][]UnspentBalance)}
ref := 0 ref := 0
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
ref += i ref += i

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
@ -9,8 +9,8 @@ import (
const feeMode = 0x0 const feeMode = 0x0
// AssetState represents the state of an NEO registered Asset. // Asset represents the state of an NEO registered Asset.
type AssetState struct { type Asset struct {
ID util.Uint256 ID util.Uint256
AssetType transaction.AssetType AssetType transaction.AssetType
Name string Name string
@ -27,7 +27,7 @@ type AssetState struct {
} }
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (a *AssetState) DecodeBinary(br *io.BinReader) { func (a *Asset) DecodeBinary(br *io.BinReader) {
br.ReadBytes(a.ID[:]) br.ReadBytes(a.ID[:])
br.ReadLE(&a.AssetType) br.ReadLE(&a.AssetType)
@ -47,7 +47,7 @@ func (a *AssetState) DecodeBinary(br *io.BinReader) {
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (a *AssetState) EncodeBinary(bw *io.BinWriter) { func (a *Asset) EncodeBinary(bw *io.BinWriter) {
bw.WriteBytes(a.ID[:]) bw.WriteBytes(a.ID[:])
bw.WriteLE(a.AssetType) bw.WriteLE(a.AssetType)
bw.WriteString(a.Name) bw.WriteString(a.Name)
@ -66,7 +66,7 @@ func (a *AssetState) EncodeBinary(bw *io.BinWriter) {
} }
// GetName returns the asset name based on its type. // GetName returns the asset name based on its type.
func (a *AssetState) GetName() string { func (a *Asset) GetName() string {
if a.AssetType == transaction.GoverningToken { if a.AssetType == transaction.GoverningToken {
return "NEO" return "NEO"

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"testing" "testing"
@ -12,7 +12,7 @@ import (
) )
func TestEncodeDecodeAssetState(t *testing.T) { func TestEncodeDecodeAssetState(t *testing.T) {
asset := &AssetState{ asset := &Asset{
ID: testutil.RandomUint256(), ID: testutil.RandomUint256(),
AssetType: transaction.Token, AssetType: transaction.Token,
Name: "super cool token", Name: "super cool token",
@ -30,7 +30,7 @@ func TestEncodeDecodeAssetState(t *testing.T) {
buf := io.NewBufBinWriter() buf := io.NewBufBinWriter()
asset.EncodeBinary(buf.BinWriter) asset.EncodeBinary(buf.BinWriter)
assert.Nil(t, buf.Err) assert.Nil(t, buf.Err)
assetDecode := &AssetState{} assetDecode := &Asset{}
r := io.NewBinReaderFromBuf(buf.Bytes()) r := io.NewBinReaderFromBuf(buf.Bytes())
assetDecode.DecodeBinary(r) assetDecode.DecodeBinary(r)
assert.Nil(t, r.Err) assert.Nil(t, r.Err)
@ -38,11 +38,11 @@ func TestEncodeDecodeAssetState(t *testing.T) {
} }
func TestAssetState_GetName_NEO(t *testing.T) { func TestAssetState_GetName_NEO(t *testing.T) {
asset := &AssetState{AssetType: transaction.GoverningToken} asset := &Asset{AssetType: transaction.GoverningToken}
assert.Equal(t, "NEO", asset.GetName()) assert.Equal(t, "NEO", asset.GetName())
} }
func TestAssetState_GetName_NEOGas(t *testing.T) { func TestAssetState_GetName_NEOGas(t *testing.T) {
asset := &AssetState{AssetType: transaction.UtilityToken} asset := &Asset{AssetType: transaction.UtilityToken}
assert.Equal(t, "NEOGas", asset.GetName()) assert.Equal(t, "NEOGas", asset.GetName())
} }

12
pkg/core/state/coin.go Normal file
View file

@ -0,0 +1,12 @@
package state
// Coin represents the state of a coin.
type Coin uint8
// Viable Coin constants.
const (
CoinConfirmed Coin = 0
CoinSpent Coin = 1 << 1
CoinClaimed Coin = 1 << 2
CoinFrozen Coin = 1 << 5
)

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
@ -7,8 +7,8 @@ import (
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
// ContractState holds information about a smart contract in the NEO blockchain. // Contract holds information about a smart contract in the NEO blockchain.
type ContractState struct { type Contract struct {
Script []byte Script []byte
ParamList []smartcontract.ParamType ParamList []smartcontract.ParamType
ReturnType smartcontract.ParamType ReturnType smartcontract.ParamType
@ -23,7 +23,7 @@ type ContractState struct {
} }
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (cs *ContractState) DecodeBinary(br *io.BinReader) { func (cs *Contract) DecodeBinary(br *io.BinReader) {
cs.Script = br.ReadVarBytes() cs.Script = br.ReadVarBytes()
br.ReadArray(&cs.ParamList) br.ReadArray(&cs.ParamList)
br.ReadLE(&cs.ReturnType) br.ReadLE(&cs.ReturnType)
@ -37,7 +37,7 @@ func (cs *ContractState) DecodeBinary(br *io.BinReader) {
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (cs *ContractState) EncodeBinary(bw *io.BinWriter) { func (cs *Contract) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarBytes(cs.Script) bw.WriteVarBytes(cs.Script)
bw.WriteArray(cs.ParamList) bw.WriteArray(cs.ParamList)
bw.WriteLE(cs.ReturnType) bw.WriteLE(cs.ReturnType)
@ -50,7 +50,7 @@ func (cs *ContractState) EncodeBinary(bw *io.BinWriter) {
} }
// ScriptHash returns a contract script hash. // ScriptHash returns a contract script hash.
func (cs *ContractState) ScriptHash() util.Uint160 { func (cs *Contract) ScriptHash() util.Uint160 {
if cs.scriptHash.Equals(util.Uint160{}) { if cs.scriptHash.Equals(util.Uint160{}) {
cs.createHash() cs.createHash()
} }
@ -58,21 +58,21 @@ func (cs *ContractState) ScriptHash() util.Uint160 {
} }
// createHash creates contract script hash. // createHash creates contract script hash.
func (cs *ContractState) createHash() { func (cs *Contract) createHash() {
cs.scriptHash = hash.Hash160(cs.Script) cs.scriptHash = hash.Hash160(cs.Script)
} }
// HasStorage checks whether the contract has storage property set. // HasStorage checks whether the contract has storage property set.
func (cs *ContractState) HasStorage() bool { func (cs *Contract) HasStorage() bool {
return (cs.Properties & smartcontract.HasStorage) != 0 return (cs.Properties & smartcontract.HasStorage) != 0
} }
// HasDynamicInvoke checks whether the contract has dynamic invoke property set. // HasDynamicInvoke checks whether the contract has dynamic invoke property set.
func (cs *ContractState) HasDynamicInvoke() bool { func (cs *Contract) HasDynamicInvoke() bool {
return (cs.Properties & smartcontract.HasDynamicInvoke) != 0 return (cs.Properties & smartcontract.HasDynamicInvoke) != 0
} }
// IsPayable checks whether the contract has payable property set. // IsPayable checks whether the contract has payable property set.
func (cs *ContractState) IsPayable() bool { func (cs *Contract) IsPayable() bool {
return (cs.Properties & smartcontract.IsPayable) != 0 return (cs.Properties & smartcontract.IsPayable) != 0
} }

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"testing" "testing"
@ -12,7 +12,7 @@ import (
func TestEncodeDecodeContractState(t *testing.T) { func TestEncodeDecodeContractState(t *testing.T) {
script := []byte("testscript") script := []byte("testscript")
contract := &ContractState{ contract := &Contract{
Script: script, Script: script,
ParamList: []smartcontract.ParamType{smartcontract.StringType, smartcontract.IntegerType, smartcontract.Hash160Type}, ParamList: []smartcontract.ParamType{smartcontract.StringType, smartcontract.IntegerType, smartcontract.Hash160Type},
ReturnType: smartcontract.BoolType, ReturnType: smartcontract.BoolType,
@ -28,7 +28,7 @@ func TestEncodeDecodeContractState(t *testing.T) {
buf := io.NewBufBinWriter() buf := io.NewBufBinWriter()
contract.EncodeBinary(buf.BinWriter) contract.EncodeBinary(buf.BinWriter)
assert.Nil(t, buf.Err) assert.Nil(t, buf.Err)
contractDecoded := &ContractState{} contractDecoded := &Contract{}
r := io.NewBinReaderFromBuf(buf.Bytes()) r := io.NewBinReaderFromBuf(buf.Bytes())
contractDecoded.DecodeBinary(r) contractDecoded.DecodeBinary(r)
assert.Nil(t, r.Err) assert.Nil(t, r.Err)
@ -37,10 +37,10 @@ func TestEncodeDecodeContractState(t *testing.T) {
} }
func TestContractStateProperties(t *testing.T) { func TestContractStateProperties(t *testing.T) {
flaggedContract := ContractState{ flaggedContract := Contract{
Properties: smartcontract.HasStorage | smartcontract.HasDynamicInvoke | smartcontract.IsPayable, Properties: smartcontract.HasStorage | smartcontract.HasDynamicInvoke | smartcontract.IsPayable,
} }
nonFlaggedContract := ContractState{ nonFlaggedContract := Contract{
ReturnType: smartcontract.BoolType, ReturnType: smartcontract.BoolType,
} }
assert.Equal(t, true, flaggedContract.HasStorage()) assert.Equal(t, true, flaggedContract.HasStorage())

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"testing" "testing"

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"testing" "testing"

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -6,27 +6,27 @@ import (
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
// ValidatorState holds the state of a validator. // Validator holds the state of a validator.
type ValidatorState struct { type Validator struct {
PublicKey *keys.PublicKey PublicKey *keys.PublicKey
Registered bool Registered bool
Votes util.Fixed8 Votes util.Fixed8
} }
// RegisteredAndHasVotes returns true or false whether Validator is registered and has votes. // RegisteredAndHasVotes returns true or false whether Validator is registered and has votes.
func (vs *ValidatorState) RegisteredAndHasVotes() bool { func (vs *Validator) RegisteredAndHasVotes() bool {
return vs.Registered && vs.Votes > util.Fixed8(0) return vs.Registered && vs.Votes > util.Fixed8(0)
} }
// EncodeBinary encodes ValidatorState to the given BinWriter. // EncodeBinary encodes Validator to the given BinWriter.
func (vs *ValidatorState) EncodeBinary(bw *io.BinWriter) { func (vs *Validator) EncodeBinary(bw *io.BinWriter) {
vs.PublicKey.EncodeBinary(bw) vs.PublicKey.EncodeBinary(bw)
bw.WriteLE(vs.Registered) bw.WriteLE(vs.Registered)
bw.WriteLE(vs.Votes) bw.WriteLE(vs.Votes)
} }
// DecodeBinary decodes ValidatorState from the given BinReader. // DecodeBinary decodes Validator from the given BinReader.
func (vs *ValidatorState) DecodeBinary(reader *io.BinReader) { func (vs *Validator) DecodeBinary(reader *io.BinReader) {
vs.PublicKey = &keys.PublicKey{} vs.PublicKey = &keys.PublicKey{}
vs.PublicKey.DecodeBinary(reader) vs.PublicKey.DecodeBinary(reader)
reader.ReadLE(&vs.Registered) reader.ReadLE(&vs.Registered)
@ -35,17 +35,17 @@ func (vs *ValidatorState) DecodeBinary(reader *io.BinReader) {
// GetValidatorsWeightedAverage applies weighted filter based on votes for validator and returns number of validators. // GetValidatorsWeightedAverage applies weighted filter based on votes for validator and returns number of validators.
// Get back to it with further investigation in https://github.com/nspcc-dev/neo-go/issues/512. // Get back to it with further investigation in https://github.com/nspcc-dev/neo-go/issues/512.
func GetValidatorsWeightedAverage(validators []*ValidatorState) int { func GetValidatorsWeightedAverage(validators []*Validator) int {
return int(weightedAverage(applyWeightedFilter(validators))) return int(weightedAverage(applyWeightedFilter(validators)))
} }
// applyWeightedFilter is an implementation of the filter for validators votes. // applyWeightedFilter is an implementation of the filter for validators votes.
// C# reference https://github.com/neo-project/neo/blob/41caff115c28d6c7665b2a7ac72967e7ce82e921/neo/Helper.cs#L273 // C# reference https://github.com/neo-project/neo/blob/41caff115c28d6c7665b2a7ac72967e7ce82e921/neo/Helper.cs#L273
func applyWeightedFilter(validators []*ValidatorState) map[*ValidatorState]float64 { func applyWeightedFilter(validators []*Validator) map[*Validator]float64 {
var validatorsWithVotes []*ValidatorState var validatorsWithVotes []*Validator
var amount float64 var amount float64
weightedVotes := make(map[*ValidatorState]float64) weightedVotes := make(map[*Validator]float64)
start := 0.25 start := 0.25
end := 0.75 end := 0.75
sum := float64(0) sum := float64(0)
@ -85,7 +85,7 @@ func applyWeightedFilter(validators []*ValidatorState) map[*ValidatorState]float
return weightedVotes return weightedVotes
} }
func weightedAverage(weightedVotes map[*ValidatorState]float64) float64 { func weightedAverage(weightedVotes map[*Validator]float64) float64 {
sumWeight := float64(0) sumWeight := float64(0)
sumValue := float64(0) sumValue := float64(0)
for vState, weight := range weightedVotes { for vState, weight := range weightedVotes {

View file

@ -1,4 +1,4 @@
package entities package state
import ( import (
"math/big" "math/big"
@ -11,7 +11,7 @@ import (
) )
func TestValidatorState_DecodeEncodeBinary(t *testing.T) { func TestValidatorState_DecodeEncodeBinary(t *testing.T) {
state := &ValidatorState{ state := &Validator{
PublicKey: &keys.PublicKey{}, PublicKey: &keys.PublicKey{},
Registered: false, Registered: false,
Votes: util.Fixed8(10), Votes: util.Fixed8(10),
@ -20,7 +20,7 @@ func TestValidatorState_DecodeEncodeBinary(t *testing.T) {
state.EncodeBinary(buf.BinWriter) state.EncodeBinary(buf.BinWriter)
require.NoError(t, buf.Err) require.NoError(t, buf.Err)
decodedState := &ValidatorState{} decodedState := &Validator{}
reader := io.NewBinReaderFromBuf(buf.Bytes()) reader := io.NewBinReaderFromBuf(buf.Bytes())
decodedState.DecodeBinary(reader) decodedState.DecodeBinary(reader)
require.NoError(t, reader.Err) require.NoError(t, reader.Err)
@ -28,7 +28,7 @@ func TestValidatorState_DecodeEncodeBinary(t *testing.T) {
} }
func TestRegisteredAndHasVotes_Registered(t *testing.T) { func TestRegisteredAndHasVotes_Registered(t *testing.T) {
state := &ValidatorState{ state := &Validator{
PublicKey: &keys.PublicKey{ PublicKey: &keys.PublicKey{
X: big.NewInt(1), X: big.NewInt(1),
Y: big.NewInt(1), Y: big.NewInt(1),
@ -40,7 +40,7 @@ func TestRegisteredAndHasVotes_Registered(t *testing.T) {
} }
func TestRegisteredAndHasVotes_RegisteredWithVotes(t *testing.T) { func TestRegisteredAndHasVotes_RegisteredWithVotes(t *testing.T) {
state := &ValidatorState{ state := &Validator{
PublicKey: &keys.PublicKey{ PublicKey: &keys.PublicKey{
X: big.NewInt(1), X: big.NewInt(1),
Y: big.NewInt(1), Y: big.NewInt(1),
@ -52,7 +52,7 @@ func TestRegisteredAndHasVotes_RegisteredWithVotes(t *testing.T) {
} }
func TestRegisteredAndHasVotes_NotRegisteredWithVotes(t *testing.T) { func TestRegisteredAndHasVotes_NotRegisteredWithVotes(t *testing.T) {
state := &ValidatorState{ state := &Validator{
PublicKey: &keys.PublicKey{ PublicKey: &keys.PublicKey{
X: big.NewInt(1), X: big.NewInt(1),
Y: big.NewInt(1), Y: big.NewInt(1),

View file

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

View file

@ -3,19 +3,19 @@ package core
import ( import (
"testing" "testing"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestDecodeEncodeUnspentCoinState(t *testing.T) { func TestDecodeEncodeUnspentCoinState(t *testing.T) {
unspent := &UnspentCoinState{ unspent := &UnspentCoinState{
states: []entities.CoinState{ states: []state.Coin{
entities.CoinStateConfirmed, state.CoinConfirmed,
entities.CoinStateSpent, state.CoinSpent,
entities.CoinStateSpent, state.CoinSpent,
entities.CoinStateSpent, state.CoinSpent,
entities.CoinStateConfirmed, state.CoinConfirmed,
}, },
} }

View file

@ -9,7 +9,7 @@ import (
"github.com/CityOfZion/neo-go/config" "github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/storage"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -63,7 +63,7 @@ func (chain testChain) HeaderHeight() uint32 {
func (chain testChain) GetBlock(hash util.Uint256) (*core.Block, error) { func (chain testChain) GetBlock(hash util.Uint256) (*core.Block, error) {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetContractState(hash util.Uint160) *entities.ContractState { func (chain testChain) GetContractState(hash util.Uint160) *state.Contract {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetHeaderHash(int) util.Uint256 { func (chain testChain) GetHeaderHash(int) util.Uint256 {
@ -73,10 +73,10 @@ func (chain testChain) GetHeader(hash util.Uint256) (*core.Header, error) {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetAssetState(util.Uint256) *entities.AssetState { func (chain testChain) GetAssetState(util.Uint256) *state.Asset {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetAccountState(util.Uint160) *entities.AccountState { func (chain testChain) GetAccountState(util.Uint160) *state.Account {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetValidators(...*transaction.Transaction) ([]*keys.PublicKey, error) { func (chain testChain) GetValidators(...*transaction.Transaction) ([]*keys.PublicKey, error) {
@ -85,13 +85,13 @@ func (chain testChain) GetValidators(...*transaction.Transaction) ([]*keys.Publi
func (chain testChain) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) { func (chain testChain) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetStorageItem(scripthash util.Uint160, key []byte) *entities.StorageItem { func (chain testChain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetTestVM() (*vm.VM, storage.Store) { func (chain testChain) GetTestVM() (*vm.VM, storage.Store) {
panic("TODO") panic("TODO")
} }
func (chain testChain) GetStorageItems(hash util.Uint160) (map[string]*entities.StorageItem, error) { func (chain testChain) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) {
panic("TODO") panic("TODO")
} }
func (chain testChain) CurrentHeaderHash() util.Uint256 { func (chain testChain) CurrentHeaderHash() util.Uint256 {

View file

@ -11,7 +11,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
@ -158,7 +158,7 @@ func (c *Client) SetClient(cli *http.Client) {
// asset belonging to specified address. This implementation uses GetUnspents // asset belonging to specified address. This implementation uses GetUnspents
// JSON-RPC call internally, so make sure your RPC server suppors that. // JSON-RPC call internally, so make sure your RPC server suppors that.
func (c *Client) CalculateInputs(address string, asset util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error) { func (c *Client) CalculateInputs(address string, asset util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error) {
var utxos entities.UnspentBalances var utxos state.UnspentBalances
resp, err := c.GetUnspents(address) resp, err := c.GetUnspents(address)
if err != nil || resp.Error != nil { if err != nil || resp.Error != nil {

View file

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers" "github.com/CityOfZion/neo-go/pkg/rpc/wrappers"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
@ -68,7 +68,7 @@ func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256,
// unspentsToInputs uses UnspentBalances to create a slice of inputs for a new // unspentsToInputs uses UnspentBalances to create a slice of inputs for a new
// transcation containing the required amount of asset. // transcation containing the required amount of asset.
func unspentsToInputs(utxos entities.UnspentBalances, required util.Fixed8) ([]transaction.Input, util.Fixed8, error) { func unspentsToInputs(utxos state.UnspentBalances, required util.Fixed8) ([]transaction.Input, util.Fixed8, error) {
var ( var (
num, i uint16 num, i uint16
selected = util.Fixed8(0) selected = util.Fixed8(0)

View file

@ -1,7 +1,7 @@
package rpc package rpc
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
@ -20,7 +20,7 @@ type (
// Unspent stores Unspents per asset // Unspent stores Unspents per asset
Unspent struct { Unspent struct {
Unspent entities.UnspentBalances Unspent state.UnspentBalances
Asset string // "NEO" / "GAS" Asset string // "NEO" / "GAS"
Amount util.Fixed8 // total unspent of this asset Amount util.Fixed8 // total unspent of this asset
} }

View file

@ -2,7 +2,7 @@ package wrappers
import ( import (
"bytes" "bytes"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"sort" "sort"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
@ -10,7 +10,7 @@ import (
) )
// AccountState wrapper used for the representation of // AccountState wrapper used for the representation of
// core.AccountState on the RPC Server. // state.Account on the RPC Server.
type AccountState struct { type AccountState struct {
Version uint8 `json:"version"` Version uint8 `json:"version"`
ScriptHash util.Uint160 `json:"script_hash"` ScriptHash util.Uint160 `json:"script_hash"`
@ -32,8 +32,8 @@ type Balance struct {
Value util.Fixed8 `json:"value"` Value util.Fixed8 `json:"value"`
} }
// NewAccountState creates a new AccountState wrapper. // NewAccountState creates a new Account wrapper.
func NewAccountState(a *entities.AccountState) AccountState { func NewAccountState(a *state.Account) AccountState {
balances := make(Balances, 0, len(a.Balances)) balances := make(Balances, 0, len(a.Balances))
for k, v := range a.GetBalanceValues() { for k, v := range a.GetBalanceValues() {
balances = append(balances, Balance{ balances = append(balances, Balance{

View file

@ -1,14 +1,14 @@
package wrappers package wrappers
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto" "github.com/CityOfZion/neo-go/pkg/crypto"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
// AssetState wrapper used for the representation of // AssetState wrapper used for the representation of
// core.AssetState on the RPC Server. // state.Asset on the RPC Server.
type AssetState struct { type AssetState struct {
ID util.Uint256 `json:"assetID"` ID util.Uint256 `json:"assetID"`
AssetType transaction.AssetType `json:"assetType"` AssetType transaction.AssetType `json:"assetType"`
@ -25,8 +25,8 @@ type AssetState struct {
IsFrozen bool `json:"is_frozen"` IsFrozen bool `json:"is_frozen"`
} }
// NewAssetState creates a new AssetState wrapper. // NewAssetState creates a new Asset wrapper.
func NewAssetState(a *entities.AssetState) AssetState { func NewAssetState(a *state.Asset) AssetState {
return AssetState{ return AssetState{
ID: a.ID, ID: a.ID,
AssetType: a.AssetType, AssetType: a.AssetType,

View file

@ -2,18 +2,18 @@ package wrappers
import ( import (
"github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/entities" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
// UnspentBalanceInfo wrapper is used to represent single unspent asset entry // UnspentBalanceInfo wrapper is used to represent single unspent asset entry
// in `getunspents` output. // in `getunspents` output.
type UnspentBalanceInfo struct { type UnspentBalanceInfo struct {
Unspents []entities.UnspentBalance `json:"unspent"` Unspents []state.UnspentBalance `json:"unspent"`
AssetHash util.Uint256 `json:"asset_hash"` AssetHash util.Uint256 `json:"asset_hash"`
Asset string `json:"asset"` Asset string `json:"asset"`
AssetSymbol string `json:"asset_symbol"` AssetSymbol string `json:"asset_symbol"`
Amount util.Fixed8 `json:"amount"` Amount util.Fixed8 `json:"amount"`
} }
// Unspents wrapper is used to represent getunspents return result. // Unspents wrapper is used to represent getunspents return result.
@ -28,8 +28,8 @@ var GlobalAssets = map[string]string{
"602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS", "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS",
} }
// NewUnspents creates a new AccountState wrapper using given Blockchainer. // NewUnspents creates a new Account wrapper using given Blockchainer.
func NewUnspents(a *entities.AccountState, chain core.Blockchainer, addr string) Unspents { func NewUnspents(a *state.Account, chain core.Blockchainer, addr string) Unspents {
res := Unspents{ res := Unspents{
Address: addr, Address: addr,
Balance: make([]UnspentBalanceInfo, 0, len(a.Balances)), Balance: make([]UnspentBalanceInfo, 0, len(a.Balances)),