• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway-nest / 4872567943

03 May 2023 01:40PM UTC coverage: 90.107%. First build
4872567943

Pull #305

github

GitHub
Merge 188a78406 into fc078e9a7
Pull Request #305: Refactor cache directions to partition by chain

728 of 858 branches covered (84.85%)

Branch coverage included in aggregate %.

23 of 34 new or added lines in 9 files covered. (67.65%)

3662 of 4014 relevant lines covered (91.23%)

39.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.08
/src/datasources/cache/cache.router.ts
1
import { CacheDir } from './entities/cache-dir.entity';
26✔
2

3
export class CacheRouter {
26✔
4
  private static readonly ALL_TRANSACTIONS_KEY = 'all_transactions';
26✔
5
  private static readonly BACKBONE_KEY = 'backbone';
26✔
6
  private static readonly BALANCES_KEY = 'balances';
26✔
7
  private static readonly CHAIN_KEY = 'chain';
26✔
8
  private static readonly CHAINS_KEY = 'chains';
26✔
9
  private static readonly COLLECTIBLES_KEY = 'collectibles';
26✔
10
  private static readonly CONTRACT_KEY = 'contract';
26✔
11
  private static readonly CREATION_TRANSACTION_KEY = 'creation_transaction';
26✔
12
  private static readonly DELEGATES_KEY = 'delegates';
26✔
13
  private static readonly INCOMING_TRANSFERS_KEY = 'incoming_transfers';
26✔
14
  private static readonly MASTER_COPIES_KEY = 'master_copies';
26✔
15
  private static readonly MESSAGE_KEY = 'message';
26✔
16
  private static readonly MESSAGES_KEY = 'messages';
26✔
17
  private static readonly MODULE_TRANSACTIONS_KEY = 'module_transactions';
26✔
18
  private static readonly MULTISIG_TRANSACTION_KEY = 'multisig_transaction';
26✔
19
  private static readonly MULTISIG_TRANSACTIONS_KEY = 'multisig_transactions';
26✔
20
  private static readonly OWNERS_SAFE_KEY = 'owner_safes';
26✔
21
  private static readonly SAFE_APPS_KEY = 'safe_apps';
26✔
22
  private static readonly SAFE_KEY = 'safe';
26✔
23
  private static readonly TOKEN_KEY = 'token';
26✔
24
  private static readonly TOKENS_KEY = 'tokens';
26✔
25
  private static readonly TRANSFERS_KEY = 'transfers';
26✔
26

27
  static getBalanceCacheDir(
28
    chainId: string,
29
    safeAddress: string,
30
    trusted?: boolean,
31
    excludeSpam?: boolean,
32
  ): CacheDir {
33
    return new CacheDir(
13✔
34
      `${chainId}_${CacheRouter.BALANCES_KEY}_${safeAddress}`,
35
      `${trusted}_${excludeSpam}`,
36
    );
37
  }
38

39
  static getSafeCacheDir(chainId: string, safeAddress: string): CacheDir {
40
    return new CacheDir(
53✔
41
      `${chainId}_${CacheRouter.SAFE_KEY}_${safeAddress}`,
42
      '',
43
    );
44
  }
45

46
  static getContractCacheDir(
47
    chainId: string,
48
    contractAddress: string,
49
  ): CacheDir {
50
    return new CacheDir(
200✔
51
      `${chainId}_${CacheRouter.CONTRACT_KEY}_${contractAddress}`,
52
      '',
53
    );
54
  }
55

56
  static getContractsCachePattern(): string {
57
    return `*_${CacheRouter.CONTRACT_KEY}_*`;
1✔
58
  }
59

60
  static getBackboneCacheDir(chainId: string): CacheDir {
61
    return new CacheDir(`${chainId}_${CacheRouter.BACKBONE_KEY}`, '');
4✔
62
  }
63

64
  static getMasterCopiesCacheDir(chainId: string): CacheDir {
65
    return new CacheDir(`${chainId}_${CacheRouter.MASTER_COPIES_KEY}`, '');
14✔
66
  }
67

68
  static getCollectiblesCacheDir(
69
    chainId: string,
70
    safeAddress: string,
71
    limit?: number,
72
    offset?: number,
73
    trusted?: boolean,
74
    excludeSpam?: boolean,
75
  ): CacheDir {
76
    return new CacheDir(
5✔
77
      `${chainId}_${CacheRouter.COLLECTIBLES_KEY}_${safeAddress}`,
78
      `${limit}_${offset}_${trusted}_${excludeSpam}`,
79
    );
80
  }
81

82
  static getDelegatesCacheDir(
83
    chainId: string,
84
    safeAddress?: string,
85
    delegate?: string,
86
    delegator?: string,
87
    label?: string,
88
    limit?: number,
89
    offset?: number,
90
  ): CacheDir {
91
    return new CacheDir(
3✔
92
      `${chainId}_${CacheRouter.DELEGATES_KEY}_${safeAddress}`,
93
      `${delegate}_${delegator}_${label}_${limit}_${offset}`,
94
    );
95
  }
96

97
  static getTransfersCacheDir(
98
    chainId: string,
99
    safeAddress: string,
100
    onlyErc20: boolean,
101
    onlyErc721: boolean,
102
    limit?: number,
103
    offset?: number,
104
  ): CacheDir {
105
    return new CacheDir(
11✔
106
      `${chainId}_${CacheRouter.TRANSFERS_KEY}_${safeAddress}`,
107
      `${onlyErc20}_${onlyErc721}_${limit}_${offset}`,
108
    );
109
  }
110

111
  static getModuleTransactionsCacheDir(
112
    chainId: string,
113
    safeAddress: string,
114
    to?: string,
115
    module?: string,
116
    limit?: number,
117
    offset?: number,
118
  ): CacheDir {
119
    return new CacheDir(
4✔
120
      `${chainId}_${CacheRouter.MODULE_TRANSACTIONS_KEY}_${safeAddress}`,
121
      `${to}_${module}_${limit}_${offset}`,
122
    );
123
  }
124

125
  static getIncomingTransfersCacheDir(
126
    chainId: string,
127
    safeAddress: string,
128
    executionDateGte?: string,
129
    executionDateLte?: string,
130
    to?: string,
131
    value?: string,
132
    tokenAddress?: string,
133
    limit?: number,
134
    offset?: number,
135
  ): CacheDir {
136
    return new CacheDir(
8✔
137
      `${chainId}_${CacheRouter.INCOMING_TRANSFERS_KEY}_${safeAddress}`,
138
      `${executionDateGte}_${executionDateLte}_${to}_${value}_${tokenAddress}_${limit}_${offset}`,
139
    );
140
  }
141

142
  static getMultisigTransactionsCacheDir(
143
    chainId: string,
144
    safeAddress: string,
145
    ordering?: string,
146
    executed?: boolean,
147
    trusted?: boolean,
148
    executionDateGte?: string,
149
    executionDateLte?: string,
150
    to?: string,
151
    value?: string,
152
    nonce?: string,
153
    limit?: number,
154
    offset?: number,
155
  ): CacheDir {
156
    return new CacheDir(
25✔
157
      `${chainId}_${CacheRouter.MULTISIG_TRANSACTIONS_KEY}_${safeAddress}`,
158
      `${ordering}_${executed}_${trusted}_${executionDateGte}_${executionDateLte}_${to}_${value}_${nonce}_${limit}_${offset}`,
159
    );
160
  }
161

162
  static getMultisigTransactionCacheDir(
163
    chainId: string,
164
    safeTransactionHash: string,
165
  ): CacheDir {
166
    return new CacheDir(
×
167
      `${chainId}_${CacheRouter.MULTISIG_TRANSACTION_KEY}_${safeTransactionHash}`,
168
      '',
169
    );
170
  }
171

172
  static getCreationTransactionCacheDir(
173
    chainId: string,
174
    safeAddress: string,
175
  ): CacheDir {
176
    return new CacheDir(
2✔
177
      `${chainId}_${CacheRouter.CREATION_TRANSACTION_KEY}_${safeAddress}`,
178
      '',
179
    );
180
  }
181

182
  static getAllTransactionsCacheDir(
183
    chainId: string,
184
    safeAddress: string,
185
    ordering?: string,
186
    executed?: boolean,
187
    queued?: boolean,
188
    limit?: number,
189
    offset?: number,
190
  ): CacheDir {
191
    return new CacheDir(
18✔
192
      `${chainId}_${CacheRouter.ALL_TRANSACTIONS_KEY}_${safeAddress}`,
193
      `${ordering}_${executed}_${queued}_${limit}_${offset}`,
194
    );
195
  }
196

197
  static getTokensCacheKey(chainId: string): string {
198
    return `${chainId}_${CacheRouter.TOKENS_KEY}`;
1✔
199
  }
200

201
  static getTokensCacheDir(
202
    chainId: string,
203
    limit?: number,
204
    offset?: number,
205
  ): CacheDir {
NEW
206
    return new CacheDir(
×
207
      CacheRouter.getTokensCacheKey(chainId),
208
      `${limit}_${offset}`,
209
    );
210
  }
211

212
  static getTokenCacheDir(chainId: string, address: string): CacheDir {
213
    return new CacheDir(`${chainId}_${CacheRouter.TOKEN_KEY}_${address}`, '');
16✔
214
  }
215

216
  static getTokensCachePattern(chainId: string): string {
217
    return `${chainId}_${CacheRouter.TOKEN_KEY}_*`;
1✔
218
  }
219

220
  static getSafesByOwnerCacheDir(
221
    chainId: string,
222
    ownerAddress: string,
223
  ): CacheDir {
224
    return new CacheDir(
4✔
225
      `${chainId}_${CacheRouter.OWNERS_SAFE_KEY}_${ownerAddress}`,
226
      '',
227
    );
228
  }
229

230
  static getMessageByHashCacheDir(
231
    chainId: string,
232
    messageHash: string,
233
  ): CacheDir {
234
    return new CacheDir(
6✔
235
      `${chainId}_${CacheRouter.MESSAGE_KEY}_${messageHash}`,
236
      '',
237
    );
238
  }
239

240
  static getMessagesBySafeCacheDir(
241
    chainId: string,
242
    safeAddress: string,
243
    limit?: number,
244
    offset?: number,
245
  ): CacheDir {
246
    return new CacheDir(
3✔
247
      `${chainId}_${CacheRouter.MESSAGES_KEY}_${safeAddress}`,
248
      `${limit}_${offset}`,
249
    );
250
  }
251

252
  static getChainsCacheKey(): string {
253
    return CacheRouter.CHAINS_KEY;
7✔
254
  }
255

256
  static getChainsCacheDir(limit?: number, offset?: number): CacheDir {
257
    return new CacheDir(CacheRouter.getChainsCacheKey(), `${limit}_${offset}`);
6✔
258
  }
259

260
  static getChainCacheDir(chainId: string): CacheDir {
261
    return new CacheDir(`${chainId}_${CacheRouter.CHAIN_KEY}`, '');
153✔
262
  }
263

264
  static getChainsCachePattern(): string {
265
    return `*_${CacheRouter.CHAIN_KEY}`;
1✔
266
  }
267

268
  static getSafeAppsCacheDir(
269
    chainId?: string,
270
    clientUrl?: string,
271
    url?: string,
272
  ): CacheDir {
273
    return new CacheDir(
30✔
274
      `${chainId}_${CacheRouter.SAFE_APPS_KEY}`,
275
      `${clientUrl}_${url}`,
276
    );
277
  }
278
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc