Module: Solace::SquadsSmartAccounts::VaultIndex
- Extended by:
- VaultIndex
- Included in:
- VaultIndex
- Defined in:
- lib/solace/squads_smart_accounts/vault_index.rb
Overview
Reverse lookup from a smart-account (vault) address back to its index and settings address.
Vault addresses are derived one-way from an index (settings_seed), so the only way to invert the mapping is to precompute it. This builds a compact on-disk table — one 32-byte vault pubkey per record, where the record at 0-based offset ‘o` is the default vault (account_index 0) of `settings_seed = o + 1` — and queries it.
Caveats: the table is a snapshot covering indices ‘1..count`, so an address with a higher index (or created after the build) is not found — rebuild with a larger `count` to extend. Only the default vault (account_index 0) is indexed.
Constant Summary collapse
- RECORD_SIZE =
Bytes per record — a raw ed25519 public key.
32- DEFAULT_FILENAME =
'vault-index.bin'
Instance Method Summary collapse
-
#build(count: 500_000, path: default_path, progress: nil) ⇒ String
Derives the default vault for each seed in 1..count and writes the raw pubkeys to ‘path`.
-
#default_path ⇒ String
The default table path: DEFAULT_FILENAME in the current directory.
-
#lookup(vault_address, path: default_path) ⇒ Hash?
Resolves a vault address to its index and settings address.
Instance Method Details
#build(count: 500_000, path: default_path, progress: nil) ⇒ String
Derives the default vault for each seed in 1..count and writes the raw pubkeys to ‘path`. The write is atomic, so an interrupted build leaves no partial cache.
45 46 47 48 49 50 51 52 53 |
# File 'lib/solace/squads_smart_accounts/vault_index.rb', line 45 def build(count: 500_000, path: default_path, progress: nil) write_atomically(path) do |io| (1..count).each do |seed| io.write(default_vault_pubkey(seed)) progress&.call(seed, count) if (seed % 50_000).zero? end end path end |
#default_path ⇒ String
Returns The default table path: DEFAULT_FILENAME in the current directory.
34 35 36 |
# File 'lib/solace/squads_smart_accounts/vault_index.rb', line 34 def default_path File.join(Dir.pwd, DEFAULT_FILENAME) end |
#lookup(vault_address, path: default_path) ⇒ Hash?
Resolves a vault address to its index and settings address.
61 62 63 64 65 66 67 |
# File 'lib/solace/squads_smart_accounts/vault_index.rb', line 61 def lookup(vault_address, path: default_path) seed = table(path)[packed_pubkey(vault_address)] return unless seed settings_address, = settings_for(seed) { index: seed, settings_address: } end |