Add indexing of accounts and txs

This commit is contained in:
lash 2025-01-13 08:52:38 +00:00
parent d80648c7ae
commit f65abf625d
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -119,6 +119,7 @@ func (das *DevAccountService) loadAccount(ctx context.Context, pubKey string, v
if acc.Alias != "" {
das.accountsAlias[acc.Alias] = pubKey
}
logg.TraceCtxf(ctx, "add account", "address", acc.Address)
return nil
}
@ -131,6 +132,7 @@ func (das *DevAccountService) loadTx(ctx context.Context, hsh string, v []byte)
}
das.txs[hsh] = mytx
das.txsTrack[mytx.Track] = hsh
logg.TraceCtxf(ctx, "add tx", "hash", hsh)
return nil
}
@ -169,6 +171,21 @@ func (das *DevAccountService) loadAll(ctx context.Context) error {
return err
}
}
return das.indexAll(ctx)
}
func (das *DevAccountService) indexAll(ctx context.Context) error {
for k, v := range(das.txs) {
acc := das.accounts[v.From]
acc.Txs = append(acc.Txs, k)
logg.TraceCtxf(ctx, "add tx to sender index", "from", v.From, "tx", k)
if v.From == v.To {
continue
}
acc = das.accounts[v.To]
acc.Txs = append(acc.Txs, k)
logg.TraceCtxf(ctx, "add tx to recipient index", "from", v.To, "tx", k)
}
return nil
}