optimize redeemscript map generation
This commit is contained in:
parent
53e0371b7f
commit
326384cd4b
8 changed files with 48 additions and 35 deletions
|
|
@ -232,8 +232,6 @@ Insight.prototype._requestNode = function(options, callback) {
|
|||
return callback(e, ret);
|
||||
});
|
||||
response.on('error', function(e) {
|
||||
|
||||
console.log('[Insight.js.201]'); //TODO
|
||||
return callback(e, ret);
|
||||
});
|
||||
});
|
||||
|
|
@ -284,7 +282,6 @@ Insight.prototype._requestBrowser = function(options, callback) {
|
|||
} else {
|
||||
errTxt = 'Error code: ' + request.status + ' - Status: ' + request.statusText + ' - Description: ' + request.responseText;
|
||||
setTimeout(function() {
|
||||
console.log('### Retrying Insight Request....');
|
||||
return self._request(options, callback);
|
||||
}, self.retryDelay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,19 +233,17 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype._addScriptMap = function(map, index, isChange) {
|
||||
var script = this.getRedeemScript(index, isChange);
|
||||
PublicKeyRing.prototype._addScriptMap = function(map, path) {
|
||||
var p = Structure.indicesForPath(path);
|
||||
var script = this.getRedeemScript(p.index, p.isChange);
|
||||
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getRedeemScriptMap = function() {
|
||||
PublicKeyRing.prototype.getRedeemScriptMap = function(paths) {
|
||||
var ret = {};
|
||||
|
||||
for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
|
||||
this._addScriptMap(ret, i, true);
|
||||
}
|
||||
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
|
||||
this._addScriptMap(ret, i, false);
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var path = paths[i];
|
||||
this._addScriptMap(ret, path);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ var imports = require('soop').imports();
|
|||
|
||||
function Structure() {}
|
||||
|
||||
|
||||
/*
|
||||
* Based on https://github.com/maraoz/bips/blob/master/bip-NNNN.mediawiki
|
||||
* m / purpose' / cosigner_index / change / address_index
|
||||
|
|
@ -31,6 +30,15 @@ Structure.FullBranch = function(address_index, isChange, cosigner_index) {
|
|||
sub = sub.substring(2);
|
||||
return BIP45_PUBLIC_PREFIX + '/' + sub;
|
||||
};
|
||||
|
||||
Structure.indicesForPath = function(path) {
|
||||
var s = path.split('/');
|
||||
return {
|
||||
isChange: s[3] === '1',
|
||||
index: parseInt(s[4]),
|
||||
};
|
||||
};
|
||||
|
||||
Structure.IdFullBranch = Structure.FullBranch(0, 0, ID_INDEX);
|
||||
Structure.IdBranch = Structure.Branch(0, 0, ID_INDEX);
|
||||
Structure.PURPOSE = PURPOSE;
|
||||
|
|
|
|||
|
|
@ -709,7 +709,6 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
|
||||
var b = new Builder(opts)
|
||||
.setUnspent(utxos)
|
||||
.setHashToScriptMap(pkr.getRedeemScriptMap())
|
||||
.setOutputs([{
|
||||
address: toAddress,
|
||||
amountSat: amountSat
|
||||
|
|
@ -720,6 +719,8 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
|
|||
return pkr.pathForAddress(utxo.address);
|
||||
});
|
||||
|
||||
b = b.setHashToScriptMap(pkr.getRedeemScriptMap(inputChainPaths));
|
||||
|
||||
if (priv) {
|
||||
var keys = priv.getForPaths(inputChainPaths);
|
||||
var signed = b.sign(keys);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue