Comparing version 1.3.4 to 1.3.5
@@ -28,9 +28,10 @@ (function (exports) { | ||
/** @typedef {import('./').GetUtxos} GetUtxos */ | ||
/** @typedef {import('./').ToCoreUtxos} ToCoreUtxos */ | ||
/** | ||
* @param {Object} opts | ||
* @param {String} opts.baseUrl - for the Insight API | ||
* @param {String} [opts.insightBaseUrl] - for regular Insight features, includes prefix | ||
* @param {String} [opts.dashsightBaseUrl] - for Dash-specific features, such as instant send | ||
* @param {String} [opts.dashsocketBaseUrl] - for WebSocket notifications | ||
* @param {String} [opts.baseUrl] - for the Insight API | ||
* @param {String} opts.insightBaseUrl - for regular Insight features, includes prefix | ||
* @param {String} opts.dashsightBaseUrl - for Dash-specific features, such as instant send | ||
* @param {String} opts.dashsocketBaseUrl - for WebSocket notifications | ||
* @returns {DashSightInstance} | ||
@@ -47,3 +48,3 @@ */ | ||
if (!dashsightBaseUrl) { | ||
dashsightBaseUrl = `${baseUrl}/insight-api`; | ||
dashsightBaseUrl = insightBaseUrl || `${baseUrl}/insight-api`; | ||
} | ||
@@ -119,3 +120,3 @@ if (dashsightBaseUrl.endsWith("/")) { | ||
let utxos = await insight.getUtxos(address); | ||
return await getCoreUtxos(utxos); | ||
return insight.toCoreUtxos(utxos); | ||
} | ||
@@ -190,42 +191,16 @@ | ||
/** | ||
* @param {Array<InsightUtxo>} body | ||
*/ | ||
async function getCoreUtxos(body) { | ||
// TODO import type from (new) dash lib | ||
/** @type Array<CoreUtxo> */ | ||
let utxos = []; | ||
await body.reduce(async function (promise, utxo) { | ||
await promise; | ||
// TODO [performance] we could get the first page of TXs of the address | ||
let tx = await insight.getTx(utxo.txid); | ||
let utxoIndex = -1; | ||
tx.vout.some(function (vout, index) { | ||
if (!vout.scriptPubKey?.addresses?.includes(utxo.address)) { | ||
return false; | ||
} | ||
let satoshis = Math.round(parseFloat(vout.value) * DUFFS); | ||
if (utxo.satoshis !== satoshis) { | ||
return false; | ||
} | ||
utxoIndex = index; | ||
return true; | ||
}); | ||
utxos.push({ | ||
/** @type {ToCoreUtxos} */ | ||
insight.toCoreUtxos = function (insightUtxos) { | ||
let coreUtxos = insightUtxos.map(function (utxo) { | ||
return { | ||
txId: utxo.txid, | ||
outputIndex: utxoIndex, | ||
outputIndex: utxo.vout, | ||
address: utxo.address, | ||
script: utxo.scriptPubKey, | ||
satoshis: utxo.satoshis, | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
}); | ||
return utxos; | ||
} | ||
return coreUtxos; | ||
}; | ||
@@ -232,0 +207,0 @@ /** |
22
index.js
@@ -13,2 +13,4 @@ "use strict"; | ||
* @prop {GetUtxos} getUtxos | ||
* @prop {InstantSend} instantSend | ||
* @prop {ToCoreUtxos} toCoreUtxos | ||
*/ | ||
@@ -63,9 +65,15 @@ | ||
/** | ||
* @callback ToCoreUtxos | ||
* @param {Array<InsightUtxo>} insightUtxos | ||
* @returns {Array<CoreUtxo>} | ||
*/ | ||
/** | ||
* @typedef {Object} InsightUtxo | ||
* @property {String} address | ||
* @property {String} txid | ||
* @property {Number} vout | ||
* @property {String} address - pay addr (base58check pubkey hash) | ||
* @property {String} txid - hex tx id | ||
* @property {Number} vout - output index | ||
* @property {String} scriptPubKey | ||
* @property {Number} amount | ||
* @property {Number} satoshis | ||
* @property {Number} amount - DASH | ||
* @property {Number} satoshis - duffs | ||
* @property {Number} height | ||
@@ -145,4 +153,4 @@ * @property {Number} confirmations | ||
* @property {Number} confirmations | ||
* @property {Number} time | ||
* @property {Boolean} txlock | ||
* @property {Number} time - ?? | ||
* @property {Boolean} txlock - instant send | ||
* @property {Number} version | ||
@@ -149,0 +157,0 @@ * @property {Array<InsightTxVin>} vin |
{ | ||
"name": "dashsight", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "SDK for Dash's flavor of the Insight API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66188
1957