Coverage Summary for Class: BlockTxSignatureCache (org.ethereum.core)
Class |
Class, %
|
Method, %
|
Line, %
|
BlockTxSignatureCache |
100%
(1/1)
|
100%
(3/3)
|
66.7%
(14/21)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.core;
21
22 import co.rsk.core.RskAddress;
23 import co.rsk.remasc.RemascTransaction;
24 import co.rsk.util.MaxSizeHashMap;
25
26
27 public class BlockTxSignatureCache extends SignatureCache {
28
29 private static final int MAX_CACHE_SIZE = 900;
30
31 private SignatureCache internalCache;
32
33 public BlockTxSignatureCache(SignatureCache internalCache) {
34 this.internalCache = internalCache;
35 addressesCache = new MaxSizeHashMap<>(MAX_CACHE_SIZE,false);
36 }
37
38 @Override
39 public RskAddress getSender(Transaction transaction) {
40
41 if (transaction instanceof RemascTransaction) {
42 return RemascTransaction.REMASC_ADDRESS;
43 }
44
45 RskAddress address = addressesCache.get(transaction);
46 if (address != null) {
47 return address;
48 }
49
50 if (internalCache.containsTx(transaction)) {
51 RskAddress sender = internalCache.getSender(transaction);
52 addressesCache.put(transaction, sender);
53 return sender;
54 }
55
56 return transaction.getSender();
57 }
58
59 @Override
60 public void storeSender(Transaction transaction) {
61
62 if (!hasToComputeSender(transaction)) {
63 return;
64 }
65
66 if (internalCache.containsTx(transaction)) {
67 RskAddress sender = internalCache.getSender(transaction);
68 addressesCache.put(transaction, sender);
69 }
70
71 addressesCache.put(transaction, transaction.getSender());
72 }
73 }