forked from bnb-chain/bnc-cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool.go
43 lines (36 loc) · 936 Bytes
/
pool.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
package types
import (
"sync"
)
// block level pool to avoid frequently call ctx.With harms performance according to our test
//
// NOTE: states keep in this pool should be cleared per-block,
// an appropriate place should be in the end of Commit() with
// deliver state
type Pool struct {
accounts sync.Map // save tx/gov related addresses (string wrapped bytes) to be published
txs sync.Map
}
func (p *Pool) AddTx(tx Tx, txHash string) {
p.txs.Store(txHash, tx)
}
func (p Pool) GetTxs() sync.Map{
return p.txs
}
func (p *Pool) AddAddrs(addrs []AccAddress) {
for _, addr := range addrs {
p.accounts.Store(string(addr.Bytes()), struct{}{})
}
}
func (p Pool) TxRelatedAddrs() []string {
addrs := make([]string, 0, 0)
p.accounts.Range(func(key, value interface{}) bool {
addrs = append(addrs, key.(string))
return true
})
return addrs
}
func (p *Pool) Clear() {
p.accounts = sync.Map{}
p.txs = sync.Map{}
}