core: do not write new dao elements into DB

It's useless work being done before it's actually needed. These (updated with
new values) are going to be written with some kind of Put anyway, so writing
them here is just a waste of time.
This commit is contained in:
Roman Khimov 2019-12-13 18:47:45 +03:00
parent 6896b40dee
commit a9401e2ec7
2 changed files with 0 additions and 24 deletions

View file

@ -55,9 +55,6 @@ func (dao *dao) GetAccountStateOrNew(hash util.Uint160) (*state.Account, error)
return nil, err return nil, err
} }
account = state.NewAccount(hash) account = state.NewAccount(hash)
if err = dao.PutAccountState(account); err != nil {
return nil, err
}
} }
return account, nil return account, nil
} }
@ -151,9 +148,6 @@ func (dao *dao) GetUnspentCoinStateOrNew(hash util.Uint256) (*UnspentCoinState,
unspent = &UnspentCoinState{ unspent = &UnspentCoinState{
states: []state.Coin{}, states: []state.Coin{},
} }
if err = dao.PutUnspentCoinState(hash, unspent); err != nil {
return nil, err
}
} }
return unspent, nil return unspent, nil
} }
@ -189,9 +183,6 @@ func (dao *dao) GetSpentCoinsOrNew(hash util.Uint256) (*SpentCoinState, error) {
spent = &SpentCoinState{ spent = &SpentCoinState{
items: make(map[uint16]uint32), items: make(map[uint16]uint32),
} }
if err = dao.PutSpentCoinState(hash, spent); err != nil {
return nil, err
}
} }
return spent, nil return spent, nil
} }
@ -231,9 +222,6 @@ func (dao *dao) GetValidatorStateOrNew(publicKey *keys.PublicKey) (*state.Valida
return nil, err return nil, err
} }
validatorState = &state.Validator{PublicKey: publicKey} validatorState = &state.Validator{PublicKey: publicKey}
if err = dao.PutValidatorState(validatorState); err != nil {
return nil, err
}
} }
return validatorState, nil return validatorState, nil

View file

@ -45,9 +45,6 @@ func TestGetAccountStateOrNew_New(t *testing.T) {
createdAccount, err := dao.GetAccountStateOrNew(hash) createdAccount, err := dao.GetAccountStateOrNew(hash)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, createdAccount) require.NotNil(t, createdAccount)
gotAccount, err := dao.GetAccountState(hash)
require.NoError(t, err)
require.Equal(t, createdAccount, gotAccount)
} }
func TestPutAndGetAccountStateOrNew(t *testing.T) { func TestPutAndGetAccountStateOrNew(t *testing.T) {
@ -102,9 +99,6 @@ func TestGetUnspentCoinStateOrNew_New(t *testing.T) {
unspentCoinState, err := dao.GetUnspentCoinStateOrNew(hash) unspentCoinState, err := dao.GetUnspentCoinStateOrNew(hash)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, unspentCoinState) require.NotNil(t, unspentCoinState)
gotUnspentCoinState, err := dao.GetUnspentCoinState(hash)
require.NoError(t, err)
require.Equal(t, unspentCoinState, gotUnspentCoinState)
} }
func TestGetUnspentCoinState_Err(t *testing.T) { func TestGetUnspentCoinState_Err(t *testing.T) {
@ -132,9 +126,6 @@ func TestGetSpentCoinStateOrNew_New(t *testing.T) {
spentCoinState, err := dao.GetSpentCoinsOrNew(hash) spentCoinState, err := dao.GetSpentCoinsOrNew(hash)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, spentCoinState) require.NotNil(t, spentCoinState)
gotSpentCoinState, err := dao.GetSpentCoinState(hash)
require.NoError(t, err)
require.Equal(t, spentCoinState, gotSpentCoinState)
} }
func TestPutAndGetSpentCoinState(t *testing.T) { func TestPutAndGetSpentCoinState(t *testing.T) {
@ -175,9 +166,6 @@ func TestGetValidatorStateOrNew_New(t *testing.T) {
validatorState, err := dao.GetValidatorStateOrNew(publicKey) validatorState, err := dao.GetValidatorStateOrNew(publicKey)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, validatorState) require.NotNil(t, validatorState)
gotValidatorState, err := dao.GetValidatorState(publicKey)
require.NoError(t, err)
require.Equal(t, validatorState, gotValidatorState)
} }
func TestPutGetValidatorState(t *testing.T) { func TestPutGetValidatorState(t *testing.T) {