diff --git a/pkg/api/app_alias.go b/pkg/api/app_alias.go index aa9424aef..b93f6cfef 100644 --- a/pkg/api/app_alias.go +++ b/pkg/api/app_alias.go @@ -16,3 +16,8 @@ func (a *App) AddrByAlias(alias proto.Alias) (proto.Address, error) { } return addr, nil } + +func (a *App) AliasesOfAddr(addr proto.Address) ([]proto.Alias, error) { + // TODO(nickeskov): implement me + panic("AliasesOfAddr: NOT IMPLEMENTED") +} diff --git a/pkg/state/aliases.go b/pkg/state/aliases.go index c8a45ba89..15ca31210 100644 --- a/pkg/state/aliases.go +++ b/pkg/state/aliases.go @@ -76,18 +76,21 @@ type aliases struct { disabled map[string]bool + hasher *stateHasher + calculateHashes bool - hasher *stateHasher + extendedAPI bool } -func newAliases(db keyvalue.IterableKeyVal, dbBatch keyvalue.Batch, hs *historyStorage, calcHashes bool) *aliases { +func newAliases(db keyvalue.IterableKeyVal, dbBatch keyvalue.Batch, hs *historyStorage, calcHashes, extendedAPI bool) *aliases { return &aliases{ db: db, dbBatch: dbBatch, hs: hs, disabled: make(map[string]bool), - calculateHashes: calcHashes, hasher: newStateHasher(), + calculateHashes: calcHashes, + extendedAPI: extendedAPI, } } @@ -258,3 +261,13 @@ func (a *aliases) disabledAliases() (map[string]struct{}, error) { } return als, nil } + +func (a *aliases) startProvidingAliasesByAddr() error { + if a.extendedAPI { + // Already provides. + return nil + } + // TODO(nickeskov): need flush? + a.extendedAPI = true + return nil +} diff --git a/pkg/state/api.go b/pkg/state/api.go index 27a96356e..7e14681a8 100644 --- a/pkg/state/api.go +++ b/pkg/state/api.go @@ -73,6 +73,7 @@ type StateInfo interface { // Aliases. AddrByAlias(alias proto.Alias) (proto.Address, error) + //AliasesByAddr(alias proto.Alias) (proto.Address, error) // Accounts data storage. RetrieveEntries(account proto.Recipient) ([]proto.DataEntry, error) diff --git a/pkg/state/common_test.go b/pkg/state/common_test.go index 88c1cf397..1a4f80410 100644 --- a/pkg/state/common_test.go +++ b/pkg/state/common_test.go @@ -293,7 +293,10 @@ func createStorageObjects() (*testStorageObjects, []string, error) { if err != nil { return nil, res, err } - entities, err := newBlockchainEntitiesStorage(hs, settings.MainNetSettings, rw, false) + params := StateParams{ + BuildStateHashes: false, + } + entities, err := newBlockchainEntitiesStorage(hs, settings.MainNetSettings, rw, ¶ms) if err != nil { return nil, res, err } diff --git a/pkg/state/state.go b/pkg/state/state.go index 56a856e3d..f20056505 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -62,7 +62,10 @@ type blockchainEntitiesStorage struct { calculateHashes bool } -func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainSettings, rw *blockReadWriter, calcHashes bool) (*blockchainEntitiesStorage, error) { +func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainSettings, rw *blockReadWriter, params *StateParams) (*blockchainEntitiesStorage, error) { + calcHashes := params.BuildStateHashes + extendedAPI := params.StoreExtendedApiData + balances, err := newBalances(hs.db, hs, calcHashes) if err != nil { return nil, err @@ -74,7 +77,7 @@ func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainS features := newFeatures(rw, hs.db, hs, sets, settings.FeaturesInfo) return &blockchainEntitiesStorage{ hs, - newAliases(hs.db, hs.dbBatch, hs, calcHashes), + newAliases(hs.db, hs.dbBatch, hs, calcHashes, extendedAPI), newAssets(hs.db, hs.dbBatch, hs), newLeases(hs, calcHashes), newScores(hs), @@ -407,7 +410,7 @@ func newStateManager(dataDir string, params StateParams, settings *settings.Bloc if err != nil { return nil, wrapErr(Other, errors.Errorf("failed to create history storage: %v", err)) } - stor, err := newBlockchainEntitiesStorage(hs, settings, rw, params.BuildStateHashes) + stor, err := newBlockchainEntitiesStorage(hs, settings, rw, ¶ms) if err != nil { return nil, wrapErr(Other, errors.Errorf("failed to create blockchain entities storage: %v", err)) }