Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit 478fde5

Browse files
author
domschiener
committed
Added version number; improved shouldYouReplay and getAccountData
1 parent 1c7f46f commit 478fde5

File tree

7 files changed

+196
-74
lines changed

7 files changed

+196
-74
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ var iota = new IOTA({
6060
6161
// now you can start using all of the functions
6262
iota.api.getNodeInfo();
63+
64+
// you can also get the version
65+
iota.version
6366
```
6467

6568
Overall, there are currently four subclasses that are accessible from the IOTA object:
@@ -68,6 +71,9 @@ Overall, there are currently four subclasses that are accessible from the IOTA o
6871
- **`multisig`**: Functions for creating and signing multi-signature addresses and transactions.
6972
- **`valid`**: Validator functions that can help with determining whether the inputs or results that you get are valid.
7073

74+
You also have access to the `version` of the library
75+
- **`version`**: Current version of the library
76+
7177
In the future new IOTA Core modules (such as Flash, MAM) and all IXI related functionality will be available.
7278

7379
## How to use the Library
@@ -489,7 +495,7 @@ iota.api.getTransfers(seed [, options], callback)
489495

490496
### `getAccountData`
491497

492-
Similar to `getTransfers`, just a bit more comprehensive in the sense that it also returns the `balance` and `addresses` that are associated with your account (seed). This function is useful in getting all the relevant information of your account. If you want to have your transfers split into received / sent, you can use the utility function `categorizeTransfers`
498+
Similar to `getTransfers`, just a bit more comprehensive in the sense that it also returns the `addresses`, `transfers`, `inputs` and `balance` that are associated and have been used with your account (seed). This function is useful in getting all the relevant information of your account. If you want to have your transfers split into received / sent, you can use the utility function `categorizeTransfers`
493499

494500
#### Input
495501
```
@@ -507,9 +513,11 @@ iota.api.getAccountData(seed [, options], callback)
507513
`Object` - returns an object of your account data in the following format:
508514
```
509515
{
510-
'addresses': [],
511-
'transfers': [],
512-
'balance': 0
516+
'latestAddress': '', // Latest, unused address which has no transactions in the tangle
517+
'addresses': [], // List of all used addresses which have transactions associated with them
518+
'transfers': [], // List of all transfers associated with the addresses
519+
'inputs': [], // List of all inputs available for the seed. Follows the getInputs format of `address`, `balance`, `security` and `keyIndex`
520+
'balance': 0 // latest confirmed balance
513521
}
514522
```
515523

@@ -521,13 +529,14 @@ This API function helps you to determine whether you should replay a transaction
521529

522530
#### Input
523531
```
524-
iota.api.shouldYouReplay(inputAddress)
532+
iota.api.shouldYouReplay(inputAddress, callback)
525533
```
526534

527535
1. **`inputAddress`**: `String` address used as input in a transaction
536+
2. **`callback`**: `Function` callback function
528537

529538
#### Returns
530-
`Bool` - true / false
539+
`Bool` - true / false
531540

532541
---
533542

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iota.lib.js",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Javascript Library for IOTA",
55
"main": "./dist/iota.js",
66
"authors": [

dist/iota.js

Lines changed: 114 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

26532683
module.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){
26562686
var Signing = require('../crypto/signing');
26572687
var Converter = require('../crypto/converter');
26582688
var 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]);

dist/iota.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)