Created
January 27, 2017 15:54
-
-
Save acastellana/320c2e0fa722d9526e98f021d2e5a3b2 to your computer and use it in GitHub Desktop.
getTransactionMessagesWithString(address, str, start)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* getTransactionMessagesWithString(address, str, start) Obtains every transaction message that contains a certain string (starting from position start) | |
* | |
* @param {string} address - NEM Address to explore | |
* @param {string} str - String to find on addresses txs | |
* @param {integer} start - Starting position in the transaction message to search | |
* | |
* @return {promise} - A promise of the NetworkRequests service that returns an Array with the filtered messages | |
*/ | |
getTransactionMessagesWithString(address, str, start){ | |
var deferred = this._q.defer(); | |
var promise = deferred.promise; | |
// Obtain all transactions to/from the address | |
this._NetworkRequests.getAllTransactions(helpers.getHostname(this._Wallet.node), address).then((result)=>{ | |
if(result.data.length) { | |
var messages = []; | |
for (let i = 0; i < result.data.length; ++i) { | |
let transaction = result.data[i].transaction; | |
if(transaction.type==257){ | |
// On this version we are only using decoded messages! | |
let msg = this._filter('fmtHexMessage')(transaction.message); | |
if(msg.includes(str,start)){ | |
messages[messages.length]=msg; | |
} | |
} | |
} | |
} | |
deferred.resolve(messages); | |
}); | |
return deferred.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment