paritytech / paritytech/polkadot-cli

feat: partial key filtering for map storage queries

Open
#73 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
10
Forks
2
Avg merge
12h 35m
Merged PRs (30d)
4

Description

Problem

Currently, querying storage maps requires providing all key fields or none. There's no way to query e.g. Hrmp.HrmpChannels filtered by just sender — you must know both sender and recipient, or fetch everything.

This makes exploratory queries painful when you only know part of the key.

Proposed Solution

For NMaps (multi-hasher storage items)

polkadot-api's getEntries() natively accepts partial key prefixes. If a storage item has keys (sender, recipient), passing just (sender) returns all entries for that sender.

  • Detect when fewer keys than expected are provided
  • Call getEntries(partialKey) instead of getValue(fullKey)
For single-hasher maps with struct keys

These don't support partial prefix queries at the protocol level.

  • Add a --filter key=value flag for client-side filtering after getEntries()
  • Example: polkadot query System.Account --filter balance.free>1000000
Implementation hints
// In query command handler:
if (providedKeys.length < expectedKeys.length) {
  // Partial key — use getEntries with prefix
  const entries = await storage.getEntries(...providedKeys)
} else {
  // Full key — use getValue
  const value = await storage.getValue(...providedKeys)
}

Priority

HIGH

Files

  • src/commands/query.ts
  • src/commands/query.test.ts

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/commands/query.ts and read the existing cases in src/commands/query.test.ts. Trace how provided keys are counted and how getValue() and getEntries() are currently used. Done means partial NMap keys query by prefix and single-hasher struct keys support the specified --filter key=value behavior, with tests covering both paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.