Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lumerin/wallet-core",
"version": "1.1.0",
"version": "1.1.1",
"author": {
"name": "Lumerin",
"email": "developer@lumerin.io",
Expand Down
15 changes: 12 additions & 3 deletions src/plugins/rates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -53,11 +53,20 @@ function createPlugin() {
})
})

networkDifficultyStream = createStream(getNetworkDifficulty, ratesUpdateMs)
const streamFn = async () => {
return {
difficulty: await getNetworkDifficulty(),
reward: await getBlockReward(),
Comment thread
alex-sandrk marked this conversation as resolved.
}
}

networkDifficultyStream = createStream(streamFn, ratesUpdateMs)
Comment thread
alex-sandrk marked this conversation as resolved.

networkDifficultyStream.on('data', function (difficulty) {
networkDifficultyStream.on('data', function (data) {
const { difficulty, reward } = data;
eventBus.emit('network-difficulty-updated', {
difficulty,
reward,
})
})

Expand Down
12 changes: 11 additions & 1 deletion src/plugins/rates/network-difficulty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Comment thread
alex-sandrk marked this conversation as resolved.
Comment thread
alex-sandrk marked this conversation as resolved.
}

module.exports = { getNetworkDifficulty, getBlockReward }