From b56823fb0ebe337b4a4e0abfda9a9bece4284233 Mon Sep 17 00:00:00 2001 From: Corey Phillips Date: Wed, 13 Jan 2021 22:16:23 -0500 Subject: [PATCH] Added broadcastTransaction to helpers/index.js --- helpers/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/helpers/index.js b/helpers/index.js index 189fda7..06835fd 100644 --- a/helpers/index.js +++ b/helpers/index.js @@ -417,6 +417,20 @@ const getTransactions = ({ txHashes = [], id = Math.random(), network = "", time }); }; +const broadcastTransaction = ({ rawTx = [], id = Math.random(), network = "", timeout = undefined } = {}) => { + const method = "broadcastTransaction"; + 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].blockchainTransaction_broadcast(rawTx)); + resolve({ id, error, method, data, network }); + } catch (e) { + resolve({ id, error: true, method, data: e, network }); + } + }); +}; + module.exports = { start, stop, @@ -430,5 +444,6 @@ module.exports = { getPeers, subscribeHeader, subscribeAddress, - getFeeEstimate + getFeeEstimate, + broadcastTransaction };