MCPcopy Create free account
hub / github.com/CPChain/chain / makeHeaderFetcher

Method makeHeaderFetcher

protocols/cpc/fetcher/fetcher_test.go:148–165  ·  view source on GitHub ↗

makeHeaderFetcher retrieves a block header fetcher associated with a simulated peer.

(peer string, blocks map[common.Hash]*types.Block, drift time.Duration)

Source from the content-addressed store, hash-verified

146
147// makeHeaderFetcher retrieves a block header fetcher associated with a simulated peer.
148func (f *fetcherTester) makeHeaderFetcher(peer string, blocks map[common.Hash]*types.Block, drift time.Duration) headerRequesterFn {
149 closure := make(map[common.Hash]*types.Block)
150 for hash, block := range blocks {
151 closure[hash] = block
152 }
153 // Create a function that return a header from the closure
154 return func(hash common.Hash) error {
155 // Gather the blocks to return
156 headers := make([]*types.Header, 0, 1)
157 if block, ok := closure[hash]; ok {
158 headers = append(headers, block.Header())
159 }
160 // Return on a new thread
161 go f.fetcher.FilterHeaders(peer, headers, time.Now().Add(drift))
162
163 return nil
164 }
165}
166
167// makeBodyFetcher retrieves a block body fetcher associated with a simulated peer.
168func (f *fetcherTester) makeBodyFetcher(peer string, blocks map[common.Hash]*types.Block, drift time.Duration) bodyRequesterFn {

Calls 4

HeaderMethod · 0.80
FilterHeadersMethod · 0.80
AddMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected