-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_msg_cache.go
58 lines (44 loc) · 1.42 KB
/
sign_msg_cache.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package walletutils
import (
"sync"
"github.com/ethereum/go-ethereum/common"
lotustypes "github.com/filecoin-project/lotus/chain/types"
)
// maps ethereum tx hashes to filecoin signed messages
type SignedMessageCache struct {
signedMessages map[common.Hash]*lotustypes.SignedMessage
txHashLookup map[common.Hash]common.Hash
mutex sync.Mutex
}
func (smc *SignedMessageCache) Add(txHash common.Hash, signedMsg *lotustypes.SignedMessage) {
smc.mutex.Lock()
defer smc.mutex.Unlock()
smc.signedMessages[txHash] = signedMsg
}
func (smc *SignedMessageCache) Get(txHash common.Hash) *lotustypes.SignedMessage {
smc.mutex.Lock()
defer smc.mutex.Unlock()
return smc.signedMessages[txHash]
}
func (smc *SignedMessageCache) Delete(txHash common.Hash) {
smc.mutex.Lock()
defer smc.mutex.Unlock()
delete(smc.signedMessages, txHash)
}
func (smc *SignedMessageCache) MapHash(innerHash, outerHash common.Hash) {
smc.mutex.Lock()
defer smc.mutex.Unlock()
smc.txHashLookup[innerHash] = outerHash
}
func (smc *SignedMessageCache) GetOuterHash(innerHash common.Hash) common.Hash {
smc.mutex.Lock()
defer smc.mutex.Unlock()
return smc.txHashLookup[innerHash]
}
func NewSignedMsgCache() *SignedMessageCache {
return &SignedMessageCache{
signedMessages: make(map[common.Hash]*lotustypes.SignedMessage),
// maps the outer filecoin tx hash to the inner filecoin tx hash
txHashLookup: make(map[common.Hash]common.Hash),
}
}