Browse Source

Use blockchain.info (temporary) to retrieve address & transactions infos

master
meriadec 7 years ago
parent
commit
98bfb1e31a
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 1
      package.json
  2. 29
      src/helpers/btc.js

1
package.json

@ -36,6 +36,7 @@
"@ledgerhq/hw-app-eth": "^1.1.2-beta.068e2a14",
"@ledgerhq/hw-transport": "^1.1.2-beta.068e2a14",
"@ledgerhq/hw-transport-node-hid": "^1.1.2-beta.068e2a14",
"blockchain.info": "^2.11.0",
"bcryptjs": "^2.4.3",
"color": "^2.0.1",
"downshift": "^1.25.0",

29
src/helpers/btc.js

@ -0,0 +1,29 @@
import blockexplorer from 'blockchain.info/blockexplorer'
const explorer = blockexplorer.usingNetwork(3)
function computeTransaction(address) {
return transaction => {
const outputVal = transaction.out
.filter(o => o.addr === address)
.reduce((acc, cur) => acc + cur.value, 0)
const inputVal = transaction.inputs
.filter(i => i.prev_out.addr === address)
.reduce((acc, cur) => acc + cur.prev_out.value, 0)
const balance = outputVal - inputVal
return {
...transaction,
balance,
}
}
}
export async function getAddressData(address) {
const addressData = await explorer.getAddress(address)
const unifiedData = {
address,
balance: addressData.final_balance,
transactions: addressData.txs.map(computeTransaction(address)),
}
return unifiedData
}
Loading…
Cancel
Save