|
| 1 | +import ethonDictionary from './EthonDictionary.js'; |
| 2 | +import BlockUtils from './BlockUtils.js'; |
| 3 | + |
1 | 4 | export default class DsDataLoader { |
2 | 5 | constructor(diContainer) { |
3 | 6 | this.appConfig = diContainer.appConfig; |
@@ -121,8 +124,20 @@ export default class DsDataLoader { |
121 | 124 | return this.result.setupNodeData(nodeData, true); |
122 | 125 | } |
123 | 126 |
|
124 | | - return this.models.Blocks.getBlock({number: nodeData.lastConfirmations[0].blockNumber, hash: nodeData.lastConfirmations[0].blockHash}).then(lastBlock => { |
| 127 | + return this.models.Blocks.getBlock({number: nodeData.lastConfirmations[0].blockNumber, hash: nodeData.lastConfirmations[0].blockHash}).then(async lastBlock => { |
125 | 128 | nodeData.lastBlock = lastBlock; |
| 129 | + |
| 130 | + if (nodeData.lastBlock) { |
| 131 | + if (this.appConfig.NETWORK_ALGO === 'ibft2' && nodeData.lastBlock.extraData) { |
| 132 | + nodeData.lastBlock.validators = BlockUtils.getIBFT2Validators(nodeData.lastBlock.extraData); |
| 133 | + } |
| 134 | + |
| 135 | + if (this.appConfig.NETWORK_ALGO === 'clique') { |
| 136 | + let validators = await this.models.Validators.get({blockNumber: nodeData.lastBlock.number, blockHash: nodeData.lastBlock.hash}); |
| 137 | + nodeData.lastBlock.validators = (validators && validators.rowLength > 0) ? JSON.parse(validators.rows[0].validators) : []; |
| 138 | + } |
| 139 | + } |
| 140 | + |
126 | 141 | return this.result.setupNodeData(nodeData, true); |
127 | 142 | }); |
128 | 143 | }); |
@@ -203,4 +218,22 @@ export default class DsDataLoader { |
203 | 218 | this.log.debug(`Deepstream record '${recordId}' delete`); |
204 | 219 | }); |
205 | 220 | } |
| 221 | + |
| 222 | + sendValidatorsToDeepstream(validators) { |
| 223 | + this.log.debug(`Deepstream update 'validators': ${JSON.stringify(validators)}`); |
| 224 | + |
| 225 | + let nodesList = this.deepstream.record.getList(`${this.appConfig.DEEPSTREAM_NAMESPACE}/nodes`); |
| 226 | + nodesList.whenReady(list => { |
| 227 | + list.getEntries().forEach(dsNodeId => { |
| 228 | + this.getRecord(`${dsNodeId}/nodeData`).whenReady(node => { |
| 229 | + let nodeData = node.get()[ethonDictionary.nodeData]; |
| 230 | + if (nodeData) { |
| 231 | + if (validators.includes(nodeData[ethonDictionary.coinbase])) { |
| 232 | + this.setRecord(`${dsNodeId}/nodeData`, 'nodeData.isValidator', true); |
| 233 | + } |
| 234 | + } |
| 235 | + }); |
| 236 | + }); |
| 237 | + }); |
| 238 | + } |
206 | 239 | } |
0 commit comments