bitcore-lib-doge
Advanced tools
Comparing version 8.25.1 to 8.25.2
@@ -564,2 +564,62 @@ 'use strict'; | ||
/** | ||
* associateInputs - Update inputs with utxos, allowing you to specify value, and pubkey. | ||
* Populating these inputs allows for them to be signed with .sign(privKeys) | ||
* | ||
* @param {Array<Object>} utxos | ||
* @param {Array<string | PublicKey>} pubkeys | ||
* @param {number} threshold | ||
* @param {Object} opts | ||
* @returns {Array<number>} | ||
*/ | ||
Transaction.prototype.associateInputs = function(utxos, pubkeys, threshold, opts) { | ||
let indexes = []; | ||
for(let utxo of utxos) { | ||
const index = this.inputs.findIndex(i => i.prevTxId.toString('hex') === utxo.txId && i.outputIndex === utxo.outputIndex); | ||
indexes.push(index); | ||
if(index >= 0) { | ||
this.inputs[index] = this._getInputFrom(utxo, pubkeys, threshold, opts); | ||
} | ||
} | ||
return indexes; | ||
} | ||
Transaction.prototype._selectInputType = function(utxo, pubkeys, threshold) { | ||
var clazz; | ||
utxo = new UnspentOutput(utxo); | ||
if(pubkeys && threshold) { | ||
if (utxo.script.isMultisigOut()) { | ||
clazz = MultiSigInput; | ||
} else if (utxo.script.isScriptHashOut() || utxo.script.isWitnessScriptHashOut()) { | ||
clazz = MultiSigScriptHashInput; | ||
} | ||
} else if (utxo.script.isPublicKeyHashOut() || utxo.script.isWitnessPublicKeyHashOut() || utxo.script.isScriptHashOut()) { | ||
clazz = PublicKeyHashInput; | ||
} else if (utxo.script.isPublicKeyOut()) { | ||
clazz = PublicKeyInput; | ||
} else { | ||
clazz = Input; | ||
} | ||
return clazz; | ||
} | ||
Transaction.prototype._getInputFrom = function(utxo, pubkeys, threshold, opts) { | ||
utxo = new UnspentOutput(utxo); | ||
const InputClass = this._selectInputType(utxo, pubkeys, threshold); | ||
const input = { | ||
output: new Output({ | ||
script: utxo.script, | ||
satoshis: utxo.satoshis | ||
}), | ||
prevTxId: utxo.txId, | ||
outputIndex: utxo.outputIndex, | ||
sequenceNumber: utxo.sequenceNumber, | ||
script: Script.empty() | ||
}; | ||
let args = pubkeys && threshold ? [pubkeys, threshold, false, opts] : [] | ||
return new InputClass(input, ...args); | ||
} | ||
Transaction.prototype._fromNonP2SH = function(utxo) { | ||
@@ -566,0 +626,0 @@ var clazz; |
{ | ||
"name": "bitcore-lib-doge", | ||
"version": "8.25.1", | ||
"version": "8.25.2", | ||
"description": "A pure and powerful JavaScript Dogecoin library.", | ||
@@ -48,3 +48,3 @@ "author": "BitPay <dev@bitpay.com>", | ||
"devDependencies": { | ||
"bitcore-build": "^8.25.1", | ||
"bitcore-build": "^8.25.2", | ||
"brfs": "^2.0.1", | ||
@@ -51,0 +51,0 @@ "chai": "^4.2.0", |
Sorry, the diff of this file is too big to display
3282573
75019