Skip to content

Commit f6ccf67

Browse files
committed
Fix duplicate API calls
1 parent 9d87b40 commit f6ccf67

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

js/coin.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,35 +1382,37 @@
13821382
r.getInputValues = function() {
13831383
var self = this;
13841384
for (var k = 0; k < self.ins.length; k++) {
1385-
var utxo_txid = self.ins[k].outpoint.hash;
1386-
var utxo_index = self.ins[k].outpoint.index;
13871385
var utxo_address = self.extractAddress(k);
1388-
$.ajax ({
1389-
type: "GET",
1390-
cache: false,
1391-
async: false,
1392-
url: "https://bitcoincash.blockexplorer.com/api/addr/"+utxo_address+"/utxo",
1393-
dataType: "json",
1394-
error: function(data) {
1395-
alert('Couldn\'t get values for inputs. Bitcoin Cash will not sign correctly.');
1396-
},
1397-
success: function(data) {
1398-
if(data[0] == undefined)
1399-
{
1400-
alert('Can not retreive input values for Bitcoin Cash signatures.');
1401-
}
1402-
if((data[0].address && data[0].txid) && data[0].address==utxo_address){
1403-
for(var i in data){
1404-
if (utxo_txid == data[i].txid
1405-
&& utxo_index == data[i].vout) {
1406-
self.ins[k].value = new BigInteger('' + Math.round((data[i].amount*1) * 1e8), 10);
1386+
if (!self.ins[k].value) {
1387+
$.ajax ({
1388+
type: "GET",
1389+
cache: false,
1390+
async: false,
1391+
url: "https://bitcoincash.blockexplorer.com/api/addr/"+utxo_address+"/utxo",
1392+
dataType: "json",
1393+
error: function(data) {
1394+
alert('Couldn\'t get values for inputs. Bitcoin Cash will not sign correctly.');
1395+
},
1396+
success: function(data) {
1397+
if(data[0] == undefined)
1398+
{
1399+
alert('Can not retreive input values for Bitcoin Cash signatures.');
1400+
}
1401+
if((data[0].address && data[0].txid) && data[0].address === utxo_address){
1402+
for(var i in data){
1403+
for(var j in self.ins){
1404+
if (self.ins[j].outpoint.hash === data[i].txid
1405+
&& self.ins[j].outpoint.index === data[i].vout) {
1406+
self.ins[j].value = new BigInteger('' + Math.round((data[i].amount*1) * 1e8), 10);
1407+
}
1408+
}
14071409
}
1410+
} else {
1411+
alert('Can not retreive input values for Bitcoin Cash signatures.');
14081412
}
1409-
} else {
1410-
alert('Can not retreive input values for Bitcoin Cash signatures.');
14111413
}
1412-
}
1413-
});
1414+
});
1415+
}
14141416
}
14151417
}
14161418

@@ -1482,11 +1484,7 @@
14821484
if (coinjs.isBitcoinCash()) {
14831485
/* Add SIGHASH_FORKID by default for Bitcoin Cash */
14841486
shType = shType | 0x40;
1485-
for (var i = 0; i < this.ins.length; i++) {
1486-
if (this.ins[i].value == undefined) {
1487-
this.getInputValues()
1488-
}
1489-
}
1487+
this.getInputValues();
14901488
}
14911489

14921490
var hash = txhash || Crypto.util.hexToBytes(this.transactionHash(index, shType));

0 commit comments

Comments
 (0)