@catalist-nestjs/consensus
v1.0.0
Published
NestJS Consensus Layer API Module for Catalist Finance projects. Part of [Catalist NestJS Modules](https://github.com/blockarchivelabs/catalist-nestjs-modules/#readme)
Downloads
14
Maintainers
Readme
Consensus Layer API Module
NestJS Consensus Layer API Module for Catalist Finance projects. Part of Catalist NestJS Modules
Install
yarn add @catalist-nestjs/consensus
Update types
The types used in the API methods are based on Eth2Spec. To update them use the script:
./generate.sh
Usage
This module depends on FetchModule
from @catalist-nestjs/fetch
, so you need to provide it as a global module or import it into ConsensusModule
.
// Import
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-nestjs/fetch';
import { MyService } from './my.service';
@Module({
imports: [ConsensusModule.forFeature({ imports: [FetchModule] })],
providers: [MyService],
exports: [MyService],
})
export class MyModule {}
// Usage
import { ConsensusService } from '@catalist-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {}
async myMethod() {
return await this.consensusService.getGenesis();
}
}
Global usage
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-nestjs/fetch';
@Module({
imports: [FetchModule.forRoot(), ConsensusModule.forRoot()],
})
export class MyModule {}
Async usage
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-nestjs/fetch';
import { ConfigModule, ConfigService } from './my.service';
@Module({
imports: [
ConfigModule.forRoot(),
FetchModule.forRoot(),
ConsensusModule.forRootAsync({
async useFactory(configService: ConfigService) {
return { pollingInterval: configService.pollingInterval };
},
inject: [ConfigService],
}),
],
})
export class MyModule {}
Fetch options
Methods support fetch options
:
// Usage
import { ConsensusService } from '@catalist-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {}
async myMethod() {
return await this.consensusService.getGenesis({
options: { headers: { 'x-header-foo': 'bar' } },
});
}
}
Subscription
Subscribe to head blocks:
import { ConsensusService } from '@catalist-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {
this.consensusService.subscribe((error, data) => {
console.log(error, data);
});
}
}
Subscribe to finalized blocks:
import { ConsensusService } from '@catalist-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {
this.consensusService.subscribe(
(error, data) => {
console.log(error, data);
},
{ blockId: 'finalized' },
);
}
}
Methods
Beacon
- getGenesis
- getStateRoot
- getStateFork
- getStateFinalityCheckpoints
- getStateValidators
- getStateValidator
- getStateValidatorBalances
- getEpochCommittees
- getEpochSyncCommittees
- getBlockHeaders
- getBlockHeader
- publishBlock
- getBlock
- getBlockV2
- getBlockRoot
- getBlockAttestations
- getPoolAttestations
- submitPoolAttestations
- getPoolAttesterSlashings
- submitPoolAttesterSlashings
- getPoolProposerSlashings
- submitPoolProposerSlashings
- submitPoolSyncCommitteeSignatures
- getPoolVoluntaryExits
- submitPoolVoluntaryExit