MCPcopy
hub / github.com/subquery/subql / BlockchainService

Class BlockchainService

packages/node/src/blockchain.service.ts:47–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46@Injectable()
47export class BlockchainService
48 implements
49 IBlockchainService<
50 SubstrateDatasource,
51 SubstrateCustomDatasource<
52 string,
53 SubstrateMapping<SubstrateCustomHandler>
54 >,
55 SubqueryProject,
56 ApiAt,
57 LightBlockContent,
58 BlockContent,
59 IIndexerWorker
60 >
61{
62 constructor(
63 @Inject('APIService') private apiService: ApiService,
64 @Inject('RuntimeService') private runtimeService: RuntimeService,
65 ) {}
66
67 isCustomDs = isCustomDs;
68 isRuntimeDs = isRuntimeDs;
69 blockHandlerKind = SubstrateHandlerKind.Block;
70 packageVersion = packageVersion;
71
72 @mainThreadOnly()
73 async fetchBlocks(
74 blockNums: number[],
75 ): Promise<IBlock<BlockContent>[] | IBlock<LightBlockContent>[]> {
76 const specChanged = await this.runtimeService.specChanged(
77 blockNums[blockNums.length - 1],
78 );
79
80 // If specVersion not changed, a known overallSpecVer will be pass in
81 // Otherwise use api to fetch runtimes
82 return this.apiService.fetchBlocks(
83 blockNums,
84 specChanged ? undefined : this.runtimeService.parentSpecVersion,
85 );
86 }
87
88 async fetchBlockWorker(
89 worker: IIndexerWorker,
90 height: number,
91 context: { workers: IIndexerWorker[] },
92 ): Promise<Header> {
93 // get SpecVersion from main runtime service
94 const { blockSpecVersion, syncedDictionary } =
95 await this.runtimeService.getSpecVersion(height);
96
97 // if main runtime specVersion has been updated, then sync with all workers specVersion map, and lastFinalizedBlock
98 if (syncedDictionary) {
99 context.workers.map((w) =>
100 w.syncRuntimeService(
101 this.runtimeService.specVersionMap,
102 this.runtimeService.latestFinalizedHeight,
103 ),
104 );

Callers

nothing calls this directly

Calls 1

mainThreadOnlyFunction · 0.90

Tested by

no test coverage detected