Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
partial key support in storage rune size
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Feb 27, 2023
1 parent 4915833 commit cf47fa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions fluent/StorageRune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export class StorageRune<in out K extends unknown[], out V, out U> extends Rune<
this.$value = this.pallet.metadata.codec(this.into(ValueRune).access("value"))
}

size<X>(...[blockHash]: RunicArgs<X, [HexHash?]>) {
size<X>(...[partialKey, blockHash]: RunicArgs<X, [partialKey?: unknown[], blockHash?: HexHash]>) {
return this.pallet.metadata.chain.connection
.call("state_getStorageSize", this.$key.encoded([]).map(hex.encode), blockHash)
.call(
"state_getStorageSize",
this.$key.encoded(Rune.resolve(partialKey).map((x) => x ?? [])).map(hex.encode),
blockHash,
)
.unhandle(null)
.rehandle(null, () => Rune.constant(undefined))
}
Expand Down
4 changes: 2 additions & 2 deletions patterns/sizeTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Chain, ChainRune, HexHash, MetaRune, Rune, RunicArgs, ValueRune } from

export function sizeTree<U, C extends Chain, X>(
chain: ChainRune<U, C>,
...[blockHash]: RunicArgs<X, [HexHash?]>
...[blockHash]: RunicArgs<X, [blockHash?: HexHash]>
) {
const metadata = chain.metadata(blockHash)
return metadata
Expand All @@ -13,7 +13,7 @@ export function sizeTree<U, C extends Chain, X>(
Rune.rec(Object.fromEntries(
pallet.storage?.entries.map((entry) => [
entry.name,
metadata.pallet(pallet.name).storage(entry.name).size(blockHash),
metadata.pallet(pallet.name).storage(entry.name).size([], blockHash),
]) || [],
)),
])))
Expand Down

0 comments on commit cf47fa9

Please sign in to comment.