forked from MettaChain/PropChain-BackEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockchain.service.ts
More file actions
32 lines (27 loc) · 887 Bytes
/
Copy pathblockchain.service.ts
File metadata and controls
32 lines (27 loc) · 887 Bytes
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
// blockchain.service.ts
import { Injectable, Logger } from '@nestjs/common';
import { ethers } from 'ethers';
import { ProviderFactory } from './providers/provider.factory';
import { SupportedChain } from './enums/supported-chain.enum';
@Injectable()
export class BlockchainService {
private readonly logger = new Logger(BlockchainService.name);
private providers = new Map<SupportedChain, ethers.JsonRpcProvider>();
constructor() {
Object.values(SupportedChain).forEach(chain => {
this.providers.set(chain, ProviderFactory.create(chain));
});
}
getProvider(chain: SupportedChain) {
return this.providers.get(chain);
}
async getNetworkStatus(chain: SupportedChain) {
const provider = this.getProvider(chain);
const block = await provider.getBlockNumber();
return {
chain,
latestBlock: block,
healthy: true,
};
}
}