Skip to content

Commit 714cb2d

Browse files
committed
WIP: aliases by addr
1 parent b5c1134 commit 714cb2d

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

pkg/api/app_alias.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ func (a *App) AddrByAlias(alias proto.Alias) (proto.Address, error) {
1616
}
1717
return addr, nil
1818
}
19+
20+
func (a *App) AliasesOfAddr(addr proto.Address) ([]proto.Alias, error) {
21+
// TODO(nickeskov): implement me
22+
panic("AliasesOfAddr: NOT IMPLEMENTED")
23+
}

pkg/state/aliases.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,21 @@ type aliases struct {
7676

7777
disabled map[string]bool
7878

79+
hasher *stateHasher
80+
7981
calculateHashes bool
80-
hasher *stateHasher
82+
extendedAPI bool
8183
}
8284

83-
func newAliases(db keyvalue.IterableKeyVal, dbBatch keyvalue.Batch, hs *historyStorage, calcHashes bool) *aliases {
85+
func newAliases(db keyvalue.IterableKeyVal, dbBatch keyvalue.Batch, hs *historyStorage, calcHashes, extendedAPI bool) *aliases {
8486
return &aliases{
8587
db: db,
8688
dbBatch: dbBatch,
8789
hs: hs,
8890
disabled: make(map[string]bool),
89-
calculateHashes: calcHashes,
9091
hasher: newStateHasher(),
92+
calculateHashes: calcHashes,
93+
extendedAPI: extendedAPI,
9194
}
9295
}
9396

@@ -258,3 +261,13 @@ func (a *aliases) disabledAliases() (map[string]struct{}, error) {
258261
}
259262
return als, nil
260263
}
264+
265+
func (a *aliases) startProvidingAliasesByAddr() error {
266+
if a.extendedAPI {
267+
// Already provides.
268+
return nil
269+
}
270+
// TODO(nickeskov): need flush?
271+
a.extendedAPI = true
272+
return nil
273+
}

pkg/state/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type StateInfo interface {
7373

7474
// Aliases.
7575
AddrByAlias(alias proto.Alias) (proto.Address, error)
76+
//AliasesByAddr(alias proto.Alias) (proto.Address, error)
7677

7778
// Accounts data storage.
7879
RetrieveEntries(account proto.Recipient) ([]proto.DataEntry, error)

pkg/state/common_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ func createStorageObjects() (*testStorageObjects, []string, error) {
293293
if err != nil {
294294
return nil, res, err
295295
}
296-
entities, err := newBlockchainEntitiesStorage(hs, settings.MainNetSettings, rw, false)
296+
params := StateParams{
297+
BuildStateHashes: false,
298+
}
299+
entities, err := newBlockchainEntitiesStorage(hs, settings.MainNetSettings, rw, &params)
297300
if err != nil {
298301
return nil, res, err
299302
}

pkg/state/state.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ type blockchainEntitiesStorage struct {
6262
calculateHashes bool
6363
}
6464

65-
func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainSettings, rw *blockReadWriter, calcHashes bool) (*blockchainEntitiesStorage, error) {
65+
func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainSettings, rw *blockReadWriter, params *StateParams) (*blockchainEntitiesStorage, error) {
66+
calcHashes := params.BuildStateHashes
67+
extendedAPI := params.StoreExtendedApiData
68+
6669
balances, err := newBalances(hs.db, hs, calcHashes)
6770
if err != nil {
6871
return nil, err
@@ -74,7 +77,7 @@ func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainS
7477
features := newFeatures(rw, hs.db, hs, sets, settings.FeaturesInfo)
7578
return &blockchainEntitiesStorage{
7679
hs,
77-
newAliases(hs.db, hs.dbBatch, hs, calcHashes),
80+
newAliases(hs.db, hs.dbBatch, hs, calcHashes, extendedAPI),
7881
newAssets(hs.db, hs.dbBatch, hs),
7982
newLeases(hs, calcHashes),
8083
newScores(hs),
@@ -407,7 +410,7 @@ func newStateManager(dataDir string, params StateParams, settings *settings.Bloc
407410
if err != nil {
408411
return nil, wrapErr(Other, errors.Errorf("failed to create history storage: %v", err))
409412
}
410-
stor, err := newBlockchainEntitiesStorage(hs, settings, rw, params.BuildStateHashes)
413+
stor, err := newBlockchainEntitiesStorage(hs, settings, rw, &params)
411414
if err != nil {
412415
return nil, wrapErr(Other, errors.Errorf("failed to create blockchain entities storage: %v", err))
413416
}

0 commit comments

Comments
 (0)