diff --git a/.gitignore b/.gitignore index 03a8da3..e83f5bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ demo — копия.html demo — копия — копия.html +node_modules diff --git a/candy.js b/candy.js index 455eed9..c55e0c0 100644 --- a/candy.js +++ b/candy.js @@ -21,7 +21,8 @@ const MessageType = { MY_PEERS: 3, BROADCAST: 4, META: 5, - SW_BROADCAST: 6 + SW_BROADCAST: 6, + TRANS_COLL:7, }; const BlockchainRequestors = { diff --git a/transactionCollector.js b/transactionCollector.js new file mode 100644 index 0000000..f7dfcb7 --- /dev/null +++ b/transactionCollector.js @@ -0,0 +1,53 @@ +/** + Module which made transactions collections + */ + +'use strict'; +//unify browser and node +if (typeof _this ==='undefined') { + var _this = this; +} +if (_this.window === undefined){ + +} + +class TransactionCollector { + + constructor (candy) { + this.candy = candy; + this.lastAddedTransaction = {}; + } + + + /** + * create alert about new transaction + * @param data + * @param index + * @returns {{type: number, data: *, index: string}} + */ + createMessage(data, index = ''){ + let JSONdata = JSON.stringify(data); + return { + type: this.candy.MessageType.TRANS_COLL, + data: JSONdata, + index:index + } + } + + /** + * broadcasting message to all peers about new element of collection, excluding excludeSocket + * @param data + * @param broadcastFunction + * @param excludeSocket + */ + sendTransactionToAllPeers(data, broadcastFunction, excludeSocket){ + let message = this.createMessage(data); + broadcastFunction (message, excludeSocket); + return message; + } +} + +//unify browser and node +if (this.window === undefined){ + module.exports = TransactionCollector; +} \ No newline at end of file