diff --git a/routes/api.js b/routes/api.js index 921a236..0c0b696 100644 --- a/routes/api.js +++ b/routes/api.js @@ -147,6 +147,7 @@ api = require('./api/native/idUpdate.js')(api); api = require('./api/native/idInformation.js')(api); api = require('./api/native/getCurrencies.js')(api); api = require('./api/native/getCurrency.js')(api); +api = require('./api/native/estimateSendcurrencyFee.js')(api); api = require('./api/native/estimateConversion.js')(api); api = require('./api/native/getConversionPaths.js')(api); api = require('./api/native/currencyGraylist.js')(api); diff --git a/routes/api/native/estimateSendcurrencyFee.js b/routes/api/native/estimateSendcurrencyFee.js new file mode 100644 index 0000000..4579892 --- /dev/null +++ b/routes/api/native/estimateSendcurrencyFee.js @@ -0,0 +1,53 @@ +module.exports = (api) => { + api.native.estimate_sendcurrency_fee = async (chain, _params, minconfs = 1, sendfee = 0.0001) => { + try { + let feecurrency; + + const vETH = await api.native.get_currency(chain, 'vETH'); + + // These are throwaway addresses, without any funds, to ensure this + // tx would fail if it were to be broadcasted, or at least not spend + // any user funds in the absolute worst case scenario. + const raddr = "RGM3raQ1McqQYZpFyuBrqUpLnmgK7h8k4A" + const address = _params.exportto === vETH.currencyid ? + "0xd62971620094e8244F1ed3B12a8D31bC969081fA" + : + raddr; + + const params = {..._params, amount: 0, address}; + + const res = await api.native.callDaemon(chain, 'sendcurrency', [raddr, [params], minconfs, sendfee, true]); + + if (params.feecurrency == null) { + const chainCurrency = await api.native.get_currency(chain, chain); + feecurrency = chainCurrency.currencyid; + } else feecurrency = params.feecurrency; + + return res.outputtotals[feecurrency]; + } catch(e) { + throw e + } + }; + + api.setPost('/native/estimate_sendcurrency_fee', async (req, res, next) => { + const { chainTicker, params, minconfs, sendfee } = req.body; + + try { + const retObj = { + msg: 'success', + result: await api.native.estimate_sendcurrency_fee(chainTicker, params, minconfs, sendfee), + }; + + res.send(JSON.stringify(retObj)); + } catch(e) { + const retObj = { + msg: 'error', + result: e.message, + }; + + res.send(JSON.stringify(retObj)); + } + }); + + return api; +}; \ No newline at end of file