@@ -739,7 +739,6 @@ api.prototype.getNewAddress = function(seed, options, callback) {
739739 // If total number of addresses to generate is supplied, simply generate
740740 // and return the list of all addresses
741741 if (total) {
742-
743742 // Increase index with each iteration
744743 for (var i = 0; i < total; i++, index++) {
745744
@@ -1601,19 +1600,23 @@ api.prototype.getAccountData = function(seed, options, callback) {
16011600 var security = options.security || 2;
16021601
16031602 // If start value bigger than end, return error
1604- // or if difference between end and start is bigger than 500 keys
1605- if (start > end || end > (start + 500 )) {
1603+ // or if difference between end and start is bigger than 1000 keys
1604+ if (start > end || end > (start + 1000 )) {
16061605 return callback(new Error("Invalid inputs provided"))
16071606 }
16081607
16091608 // These are the values that will be returned to the original caller
1610- // @addresses all addresses associated with this seed
1611- // @transfers all sent / received transfers
1612- // @balance the confirmed balance
1609+ // @latestAddress: latest unused address
1610+ // @addresses: all addresses associated with this seed that have been used
1611+ // @transfers: all sent / received transfers
1612+ // @inputs: all inputs of the account
1613+ // @balance: the confirmed balance
16131614 var valuesToReturn = {
1614- 'addresses' : [],
1615- 'transfers' : [],
1616- 'balance' : 0
1615+ 'latestAddress' : '',
1616+ 'addresses' : [],
1617+ 'transfers' : [],
1618+ 'inputs' : [],
1619+ 'balance' : 0
16171620 }
16181621
16191622 // first call findTransactions
@@ -1631,8 +1634,12 @@ api.prototype.getAccountData = function(seed, options, callback) {
16311634
16321635 if (error) return callback(error);
16331636
1637+ // assign the last address as the latest address
1638+ // since it has no transactions associated with it
1639+ valuesToReturn.latestAddress = addresses[addresses.length - 1];
1640+
16341641 // Add all returned addresses to the lsit of addresses
1635- // remove the last element as that is the most recent
1642+ // remove the last element as that is the most recent address
16361643 valuesToReturn.addresses = addresses.slice(0, -1);
16371644
16381645 // get all bundles from a list of addresses
@@ -1646,8 +1653,24 @@ api.prototype.getAccountData = function(seed, options, callback) {
16461653 // Get the correct balance count of all addresses
16471654 self.getBalances(valuesToReturn.addresses, 100, function(error, balances) {
16481655
1649- balances.balances.forEach(function(balance) {
1650- valuesToReturn.balance += parseInt(balance);
1656+ balances.balances.forEach(function(balance, index) {
1657+
1658+ var balance = parseInt(balance);
1659+
1660+ valuesToReturn.balance += balance;
1661+
1662+ if (balance > 0) {
1663+
1664+ var newInput = {
1665+ 'address': valuesToReturn.addresses[index],
1666+ 'keyIndex': index,
1667+ 'security': security,
1668+ 'balance': balance
1669+ }
1670+
1671+ valuesToReturn.inputs.push(newInput);
1672+
1673+ }
16511674 })
16521675
16531676 return callback(null, valuesToReturn);
@@ -1664,39 +1687,45 @@ api.prototype.getAccountData = function(seed, options, callback) {
16641687* @param {String} inputAddress Input address you want to have tested
16651688* @returns {Bool}
16661689**/
1667- api.prototype.shouldYouReplay = function(inputAddress) {
1690+ api.prototype.shouldYouReplay = function(inputAddress, callback ) {
16681691
16691692 var self = this;
16701693
1671- var inputAddress = Utils.noChecksum (inputAddress);
1694+ if (!inputValidator.isAddress (inputAddress)) {
16721695
1673- self.findTransactions( { 'address': inputAddress }, function( e, transactions ) {
1696+ return callback(errors.invalidInputs());
16741697
1675- self.getTrytes(transactions, function(e, txTrytes) {
1698+ }
16761699
1677- var valueTransactions = [] ;
1700+ var inputAddress = Utils.noChecksum(inputAddress) ;
16781701
1679- txTrytes.forEach(function(trytes) {
1680- var thisTransaction = Utils.transactionObject(txTrytes);
1702+ self.findTransactionObjects( { 'addresses': new Array(inputAddress) }, function( e, transactions ) {
16811703
1682- if (thisTransaction.value < 0) {
1704+ if (e) return callback(e);
16831705
1684- valueTransactions.push(thisTransaction.hash) ;
1706+ var valueTransactions = [] ;
16851707
1686- }
1687- })
1708+ transactions.forEach(function(thisTransaction) {
16881709
1689- if ( valueTransactions.length > 0 ) {
1710+ if (thisTransaction.value < 0 ) {
16901711
1691- self.getLatestInclusion( valueTransactions, function( e, inclusionStates ) {
1712+ valueTransactions.push(thisTransaction.hash);
16921713
1693- return inclusionStates.indexOf(true) === -1;
1694- })
1695- } else {
1696-
1697- return true;
16981714 }
16991715 })
1716+
1717+ if ( valueTransactions.length > 0 ) {
1718+
1719+ self.getLatestInclusion( valueTransactions, function( e, inclusionStates ) {
1720+
1721+ return callback(null, inclusionStates.indexOf( true ) === -1);
1722+
1723+ })
1724+
1725+ } else {
1726+
1727+ return callback(null, true);
1728+ }
17001729 })
17011730}
17021731
@@ -2610,6 +2639,7 @@ function IOTA(settings) {
26102639
26112640 // IF NO SETTINGS, SET DEFAULT TO localhost:14265
26122641 settings = settings || {};
2642+ this.version = require('../package.json').version;
26132643 this.host = settings.host ? settings.host : "http://localhost";
26142644 this.port = settings.port ? settings.port : 14265;
26152645 this.provider = settings.provider || this.host.replace(/\/$/, '') + ":" + this.port;
@@ -2652,7 +2682,7 @@ IOTA.prototype.changeNode = function(settings) {
26522682
26532683module.exports = IOTA;
26542684
2655- },{"./api/api":2,"./multisig/multisig":11,"./utils/inputValidator":14,"./utils/makeRequest":15,"./utils/utils":16}],11:[function(require,module,exports){
2685+ },{"../package.json":55,". /api/api":2,"./multisig/multisig":11,"./utils/inputValidator":14,"./utils/makeRequest":15,"./utils/utils":16}],11:[function(require,module,exports){
26562686var Signing = require('../crypto/signing');
26572687var Converter = require('../crypto/converter');
26582688var Curl = require('../crypto/curl');
@@ -17330,4 +17360,57 @@ function extend() {
1733017360 return target
1733117361}
1733217362
17363+ },{}],55:[function(require,module,exports){
17364+ module.exports={
17365+ "name": "iota.lib.js",
17366+ "version": "0.2.5",
17367+ "description": "Javascript Library for IOTA",
17368+ "main": "./lib/iota.js",
17369+ "scripts": {
17370+ "build": "gulp",
17371+ "test": "mocha"
17372+ },
17373+ "author": {
17374+ "name": "Dominik Schiener (IOTA Foundation)",
17375+ "website": "https://iota.org"
17376+ },
17377+ "keywords": [
17378+ "iota",
17379+ "tangle",
17380+ "library",
17381+ "browser",
17382+ "javascript",
17383+ "nodejs",
17384+ "API"
17385+ ],
17386+ "license": "MIT",
17387+ "bugs": {
17388+ "url": "https://github.com/iotaledger/iota.lib.js/issues"
17389+ },
17390+ "repository": {
17391+ "type": "git",
17392+ "url": "https://github.com/iotaledger/iota.lib.js.git"
17393+ },
17394+ "dependencies": {
17395+ "async": "^2.1.2",
17396+ "xmlhttprequest": "^1.8.0"
17397+ },
17398+ "devDependencies": {
17399+ "bower": "^1.8.0",
17400+ "browserify": "^14.1.0",
17401+ "chai": "^3.5.0",
17402+ "del": "^2.2.2",
17403+ "gulp": "^3.9.1",
17404+ "gulp-jshint": "^2.0.2",
17405+ "gulp-nsp": "^2.4.2",
17406+ "gulp-rename": "^1.2.2",
17407+ "gulp-replace": "^0.5.4",
17408+ "gulp-uglify": "^2.1.2",
17409+ "jshint": "^2.9.4",
17410+ "mocha": "^3.2.0",
17411+ "vinyl-buffer": "^1.0.0",
17412+ "vinyl-source-stream": "^1.1.0"
17413+ }
17414+ }
17415+
1733317416},{}]},{},[1]);
0 commit comments