|
1382 | 1382 | r.getInputValues = function() { |
1383 | 1383 | var self = this; |
1384 | 1384 | 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; |
1387 | 1385 | 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 | + } |
1407 | 1409 | } |
| 1410 | + } else { |
| 1411 | + alert('Can not retreive input values for Bitcoin Cash signatures.'); |
1408 | 1412 | } |
1409 | | - } else { |
1410 | | - alert('Can not retreive input values for Bitcoin Cash signatures.'); |
1411 | 1413 | } |
1412 | | - } |
1413 | | - }); |
| 1414 | + }); |
| 1415 | + } |
1414 | 1416 | } |
1415 | 1417 | } |
1416 | 1418 |
|
|
1482 | 1484 | if (coinjs.isBitcoinCash()) { |
1483 | 1485 | /* Add SIGHASH_FORKID by default for Bitcoin Cash */ |
1484 | 1486 | 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(); |
1490 | 1488 | } |
1491 | 1489 |
|
1492 | 1490 | var hash = txhash || Crypto.util.hexToBytes(this.transactionHash(index, shType)); |
|
0 commit comments