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

Commit

Permalink
Added version number; improved shouldYouReplay and getAccountData
Browse files Browse the repository at this point in the history
  • Loading branch information
domschiener committed Apr 3, 2017
1 parent 1c7f46f commit 478fde5
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 74 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ var iota = new IOTA({
// now you can start using all of the functions
iota.api.getNodeInfo();
// you can also get the version
iota.version
```

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

You also have access to the `version` of the library
- **`version`**: Current version of the library

In the future new IOTA Core modules (such as Flash, MAM) and all IXI related functionality will be available.

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

### `getAccountData`

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`
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`

#### Input
```
Expand All @@ -507,9 +513,11 @@ iota.api.getAccountData(seed [, options], callback)
`Object` - returns an object of your account data in the following format:
```
{
'addresses': [],
'transfers': [],
'balance': 0
'latestAddress': '', // Latest, unused address which has no transactions in the tangle
'addresses': [], // List of all used addresses which have transactions associated with them
'transfers': [], // List of all transfers associated with the addresses
'inputs': [], // List of all inputs available for the seed. Follows the getInputs format of `address`, `balance`, `security` and `keyIndex`
'balance': 0 // latest confirmed balance
}
```

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

#### Input
```
iota.api.shouldYouReplay(inputAddress)
iota.api.shouldYouReplay(inputAddress, callback)
```

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

#### Returns
`Bool` - true / false
`Bool` - true / false

---

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iota.lib.js",
"version": "0.2.4",
"version": "0.2.5",
"description": "Javascript Library for IOTA",
"main": "./dist/iota.js",
"authors": [
Expand Down
145 changes: 114 additions & 31 deletions dist/iota.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ api.prototype.getNewAddress = function(seed, options, callback) {
// If total number of addresses to generate is supplied, simply generate
// and return the list of all addresses
if (total) {

// Increase index with each iteration
for (var i = 0; i < total; i++, index++) {

Expand Down Expand Up @@ -1601,19 +1600,23 @@ api.prototype.getAccountData = function(seed, options, callback) {
var security = options.security || 2;

// If start value bigger than end, return error
// or if difference between end and start is bigger than 500 keys
if (start > end || end > (start + 500)) {
// or if difference between end and start is bigger than 1000 keys
if (start > end || end > (start + 1000)) {
return callback(new Error("Invalid inputs provided"))
}

// These are the values that will be returned to the original caller
// @addresses all addresses associated with this seed
// @transfers all sent / received transfers
// @balance the confirmed balance
// @latestAddress: latest unused address
// @addresses: all addresses associated with this seed that have been used
// @transfers: all sent / received transfers
// @inputs: all inputs of the account
// @balance: the confirmed balance
var valuesToReturn = {
'addresses' : [],
'transfers' : [],
'balance' : 0
'latestAddress' : '',
'addresses' : [],
'transfers' : [],
'inputs' : [],
'balance' : 0
}

// first call findTransactions
Expand All @@ -1631,8 +1634,12 @@ api.prototype.getAccountData = function(seed, options, callback) {

if (error) return callback(error);

// assign the last address as the latest address
// since it has no transactions associated with it
valuesToReturn.latestAddress = addresses[addresses.length - 1];

// Add all returned addresses to the lsit of addresses
// remove the last element as that is the most recent
// remove the last element as that is the most recent address
valuesToReturn.addresses = addresses.slice(0, -1);

// get all bundles from a list of addresses
Expand All @@ -1646,8 +1653,24 @@ api.prototype.getAccountData = function(seed, options, callback) {
// Get the correct balance count of all addresses
self.getBalances(valuesToReturn.addresses, 100, function(error, balances) {

balances.balances.forEach(function(balance) {
valuesToReturn.balance += parseInt(balance);
balances.balances.forEach(function(balance, index) {

var balance = parseInt(balance);

valuesToReturn.balance += balance;

if (balance > 0) {

var newInput = {
'address': valuesToReturn.addresses[index],
'keyIndex': index,
'security': security,
'balance': balance
}

valuesToReturn.inputs.push(newInput);

}
})

return callback(null, valuesToReturn);
Expand All @@ -1664,39 +1687,45 @@ api.prototype.getAccountData = function(seed, options, callback) {
* @param {String} inputAddress Input address you want to have tested
* @returns {Bool}
**/
api.prototype.shouldYouReplay = function(inputAddress) {
api.prototype.shouldYouReplay = function(inputAddress, callback) {

var self = this;

var inputAddress = Utils.noChecksum(inputAddress);
if (!inputValidator.isAddress(inputAddress)) {

self.findTransactions( { 'address': inputAddress }, function( e, transactions ) {
return callback(errors.invalidInputs());

self.getTrytes(transactions, function(e, txTrytes) {
}

var valueTransactions = [];
var inputAddress = Utils.noChecksum(inputAddress);

txTrytes.forEach(function(trytes) {
var thisTransaction = Utils.transactionObject(txTrytes);
self.findTransactionObjects( { 'addresses': new Array(inputAddress) }, function( e, transactions ) {

if (thisTransaction.value < 0) {
if (e) return callback(e);

valueTransactions.push(thisTransaction.hash);
var valueTransactions = [];

}
})
transactions.forEach(function(thisTransaction) {

if ( valueTransactions.length > 0 ) {
if (thisTransaction.value < 0) {

self.getLatestInclusion( valueTransactions, function( e, inclusionStates ) {
valueTransactions.push(thisTransaction.hash);

return inclusionStates.indexOf(true) === -1;
})
} else {

return true;
}
})

if ( valueTransactions.length > 0 ) {

self.getLatestInclusion( valueTransactions, function( e, inclusionStates ) {

return callback(null, inclusionStates.indexOf( true ) === -1);

})

} else {

return callback(null, true);
}
})
}

Expand Down Expand Up @@ -2610,6 +2639,7 @@ function IOTA(settings) {

// IF NO SETTINGS, SET DEFAULT TO localhost:14265
settings = settings || {};
this.version = require('../package.json').version;
this.host = settings.host ? settings.host : "http://localhost";
this.port = settings.port ? settings.port : 14265;
this.provider = settings.provider || this.host.replace(/\/$/, '') + ":" + this.port;
Expand Down Expand Up @@ -2652,7 +2682,7 @@ IOTA.prototype.changeNode = function(settings) {

module.exports = IOTA;

},{"./api/api":2,"./multisig/multisig":11,"./utils/inputValidator":14,"./utils/makeRequest":15,"./utils/utils":16}],11:[function(require,module,exports){
},{"../package.json":55,"./api/api":2,"./multisig/multisig":11,"./utils/inputValidator":14,"./utils/makeRequest":15,"./utils/utils":16}],11:[function(require,module,exports){
var Signing = require('../crypto/signing');
var Converter = require('../crypto/converter');
var Curl = require('../crypto/curl');
Expand Down Expand Up @@ -17330,4 +17360,57 @@ function extend() {
return target
}

},{}],55:[function(require,module,exports){
module.exports={
"name": "iota.lib.js",
"version": "0.2.5",
"description": "Javascript Library for IOTA",
"main": "./lib/iota.js",
"scripts": {
"build": "gulp",
"test": "mocha"
},
"author": {
"name": "Dominik Schiener (IOTA Foundation)",
"website": "https://iota.org"
},
"keywords": [
"iota",
"tangle",
"library",
"browser",
"javascript",
"nodejs",
"API"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/iotaledger/iota.lib.js/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/iotaledger/iota.lib.js.git"
},
"dependencies": {
"async": "^2.1.2",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"bower": "^1.8.0",
"browserify": "^14.1.0",
"chai": "^3.5.0",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.2",
"gulp-nsp": "^2.4.2",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^2.1.2",
"jshint": "^2.9.4",
"mocha": "^3.2.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}

},{}]},{},[1]);
10 changes: 5 additions & 5 deletions dist/iota.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 478fde5

Please sign in to comment.