diff --git a/package.json b/package.json index a5b17af..a29ad7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lumerin/wallet-core", - "version": "1.1.0", + "version": "1.1.1", "author": { "name": "Lumerin", "email": "developer@lumerin.io", diff --git a/src/plugins/rates/index.js b/src/plugins/rates/index.js index bdf4432..69cf6f8 100644 --- a/src/plugins/rates/index.js +++ b/src/plugins/rates/index.js @@ -2,7 +2,7 @@ const logger = require('../../logger'); -const { getNetworkDifficulty } = require('./network-difficulty') +const { getNetworkDifficulty, getBlockReward } = require('./network-difficulty') const { getRate } = require('./rate') const createStream = require('./stream') @@ -53,11 +53,20 @@ function createPlugin() { }) }) - networkDifficultyStream = createStream(getNetworkDifficulty, ratesUpdateMs) + const streamFn = async () => { + return { + difficulty: await getNetworkDifficulty(), + reward: await getBlockReward(), + } + } + + networkDifficultyStream = createStream(streamFn, ratesUpdateMs) - networkDifficultyStream.on('data', function (difficulty) { + networkDifficultyStream.on('data', function (data) { + const { difficulty, reward } = data; eventBus.emit('network-difficulty-updated', { difficulty, + reward, }) }) diff --git a/src/plugins/rates/network-difficulty.js b/src/plugins/rates/network-difficulty.js index d235b3f..77713e8 100644 --- a/src/plugins/rates/network-difficulty.js +++ b/src/plugins/rates/network-difficulty.js @@ -16,4 +16,14 @@ const getNetworkDifficulty = async () => { } } -module.exports = { getNetworkDifficulty } +const getBlockReward = async () => { + try { + const baseUrl = 'https://blockchain.info' + const res = await axios.get(`${baseUrl}/q/bcperblock`) + return res?.data + } catch (err) { + logger.error('Failed to get block reward:', err) + } +} + +module.exports = { getNetworkDifficulty, getBlockReward }