Skip to content

Commit

Permalink
map storage by pallet name instead of prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Apr 8, 2024
1 parent f359138 commit d99c7ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions substrate/substrate-runtime/src/metadata/runtime-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,18 @@ class FromV14 {
return assertNotNull(def.type.params[idx].type)
}

private getStorageItem(prefix: string, name: string): StorageItem {
private getStorageItem(pallet: string, name: string): StorageItem {
let storage = this.storage()
let item = storage[prefix]?.[name]
return assertNotNull(item, `Can't find ${prefix}.${name} storage item`)
let item = storage[pallet]?.[name]
return assertNotNull(item, `Can't find ${pallet}.${name} storage item`)
}

@def
private storage(): Storage {
let storage: Storage = {}
this.metadata.pallets.forEach(pallet => {
if (pallet.storage == null) return
let items: Record<string, StorageItem> = storage[pallet.storage.prefix] = {}
let items: Record<string, StorageItem> = storage[pallet.name] = {}
pallet.storage.items.forEach(e => {
let hashers: StorageHasher[]
let keys: Ti[]
Expand Down Expand Up @@ -313,6 +313,9 @@ class FromV14 {
docs: e.docs
}
})
if (storage[pallet.storage.prefix] == null) {
storage[pallet.storage.prefix] = items
}
})
return storage
}
Expand Down Expand Up @@ -669,7 +672,7 @@ class FromOld {
let storage: Storage = {}
this.forEachPallet(null, mod => {
if (mod.storage == null) return
let items: Record<string, StorageItem> = storage[mod.storage.prefix] || {}
let items: Record<string, StorageItem> = storage[mod.name] = {}
mod.storage.items.forEach(e => {
let hashers: StorageHasher[]
let keys: Ti[]
Expand Down Expand Up @@ -708,7 +711,9 @@ class FromOld {
docs: e.docs
}
})
storage[mod.storage.prefix] = items
if (storage[mod.storage.prefix] == null) {
storage[mod.storage.prefix] = items
}
})
return storage
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/substrate-typegen/src/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class Typegen {
runtime => {
let storage = runtime.description.storage
return getStorageItems(runtime).map(({pallet, prefix, name}) => {
let def = assertNotNull(storage[prefix][name])
let def = assertNotNull(storage[pallet][name])
return {
runtime,
name: pallet + '.' + name,
Expand Down

0 comments on commit d99c7ef

Please sign in to comment.