You can achieve this by creating a Geyser plugin.
First, you must run your own Solana validator. Into this validator, you can insert a Geyser plugin by using the --geyser-plugin-config
argument when you start it up. That argument takes a path to a valid configuration file.
The function you want to implement in your Geyser plugin is this one:
fn update_account(
&mut self,
account: ReplicaAccountInfoVersions,
slot: u64,
is_startup: bool,
) -> Result<()>
Every time an account changes, that function will be called. Among the changes in ReplicaAccountInfo
you will find the account balance. Use this to build up your database of accounts with a non-zero balance.
For an example Geyser plugin that you can use as a basis, see the solana-accountsdb-plugin-postgres
.