-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.go
36 lines (30 loc) · 1.03 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package async_geyser
import (
"context"
"github.com/pkg/errors"
"github.com/code-payments/code-server/pkg/cache"
"github.com/code-payments/code-server/pkg/code/common"
code_data "github.com/code-payments/code-server/pkg/code/data"
"github.com/code-payments/code-server/pkg/code/data/timelock"
)
var (
codeUserStatusCache = cache.NewCache(1_000_000)
)
// todo: use a bloom filter, but a caching strategy might be ok for now
func testForKnownCodeUserAccount(ctx context.Context, data code_data.Provider, vault *common.Account) (bool, error) {
status, ok := codeUserStatusCache.Retrieve(vault.PublicKey().ToBase58())
if ok {
return status.(bool), nil
}
_, err := data.GetTimelockByVault(ctx, vault.PublicKey().ToBase58())
switch err {
case timelock.ErrTimelockNotFound:
codeUserStatusCache.Insert(vault.PublicKey().ToBase58(), false, 1)
return false, nil
case nil:
codeUserStatusCache.Insert(vault.PublicKey().ToBase58(), true, 1)
return true, nil
default:
return false, errors.Wrap(err, "error getting timelock record")
}
}