Browse Source

Added getHeader method to helpers/index.js.

Removed deprecated methods from electrum_client.js.
get-transaction-merkle
Corey Phillips 2 years ago
parent
commit
5cd7535db0
No known key found for this signature in database GPG Key ID: 80C0975F55D3A07B
  1. 25
      helpers/index.js
  2. 14
      lib/electrum_client.js

25
helpers/index.js

@ -440,6 +440,28 @@ const broadcastTransaction = ({ rawTx = [], id = Math.random(), network = "", ti
}); });
}; };
/**
* Returns header hex of the provided height and network.
* @param {Number} [height]
* @param {Number} [id]
* @param {"bitcoin" | "bitcoinTestnet"} network
* @param {Number | undefined} [timeout]
* @return {Promise<{id: Number, error: boolean, method: "getHeader", data: string, network: "bitcoin" | "bitcoinTestnet"}>}
*/
const getHeader = ({ height = 0, id = Math.random(), network = "", timeout = undefined } = {}) => {
const method = "getHeader";
return new Promise(async (resolve) => {
try {
if (clients.mainClient[network] === false) await connectToRandomPeer(network, clients.peers[network]);
if (!timeout) timeout = _getTimeout();
const { error, data } = await promiseTimeout(timeout, clients.mainClient[network].blockchainBlock_getBlockHeader(height));
resolve({ id, error, method, data, network });
} catch (e) {
resolve({ id, error: true, method, data: e, network });
}
});
}
module.exports = { module.exports = {
start, start,
stop, stop,
@ -455,5 +477,6 @@ module.exports = {
subscribeAddress, subscribeAddress,
getFeeEstimate, getFeeEstimate,
broadcastTransaction, broadcastTransaction,
getConnectedPeer getConnectedPeer,
getHeader,
}; };

14
lib/electrum_client.js

@ -125,13 +125,6 @@ class ElectrumClient extends Client{
} catch (e) { } catch (e) {
return { error: true, data: e }; return { error: true, data: e };
} }
}
blockchainBlock_getHeader(height){
try {
return this.request('blockchain.block.get_header', [height]);
} catch (e) {
return { error: true, data: e };
}
} }
blockchainBlock_getBlockHeader(height){ blockchainBlock_getBlockHeader(height){
try { try {
@ -140,13 +133,6 @@ class ElectrumClient extends Client{
return { error: true, data: e }; return { error: true, data: e };
} }
} }
blockchainBlock_getChunk(index){
try {
return this.request('blockchain.block.get_chunk', [index]);
} catch (e) {
return { error: true, data: e };
}
}
blockchainEstimatefee(number){ blockchainEstimatefee(number){
try { try {
return this.request('blockchain.estimatefee', [number]); return this.request('blockchain.estimatefee', [number]);

Loading…
Cancel
Save