Skip to content

Commit

Permalink
WIP: aliases by addr
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Jul 5, 2021
1 parent 33257df commit 1aff29e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/api/app_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
19 changes: 16 additions & 3 deletions pkg/state/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/state/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/state/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
if err != nil {
return nil, res, err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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, &params)
if err != nil {
return nil, wrapErr(Other, errors.Errorf("failed to create blockchain entities storage: %v", err))
}
Expand Down

0 comments on commit 1aff29e

Please sign in to comment.