mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
package rpchelper
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/filters"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
)
|
|
|
|
type Pending struct {
|
|
sync.RWMutex
|
|
block *types.Block
|
|
logs types.Logs
|
|
}
|
|
|
|
func NewPending(filters *filters.Filters, quit <-chan struct{}) *Pending {
|
|
pending := &Pending{}
|
|
go func() {
|
|
logs := make(chan types.Logs)
|
|
defer close(logs)
|
|
logsId := filters.SubscribePendingLogs(logs)
|
|
defer filters.UnsubscribePendingLogs(logsId)
|
|
|
|
blocks := make(chan *types.Block)
|
|
defer close(blocks)
|
|
blocksId := filters.SubscribePendingBlock(blocks)
|
|
defer filters.UnsubscribePendingBlock(blocksId)
|
|
|
|
for {
|
|
select {
|
|
case l := <-logs:
|
|
pending.Lock()
|
|
pending.logs = l
|
|
pending.Unlock()
|
|
case block := <-blocks:
|
|
pending.Lock()
|
|
pending.block = block
|
|
pending.Unlock()
|
|
case <-quit:
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
return pending
|
|
}
|
|
|
|
func (p *Pending) Block() *types.Block {
|
|
p.RLock()
|
|
defer p.RUnlock()
|
|
return p.block
|
|
}
|
|
|
|
func (p *Pending) Logs() types.Logs {
|
|
p.RLock()
|
|
defer p.RUnlock()
|
|
return p.logs
|
|
}
|