From 70e311e891c3f5b0b0b6b00562a2ced803263d07 Mon Sep 17 00:00:00 2001 From: Kirill Revenkov Date: Tue, 25 Sep 2018 23:17:50 +0300 Subject: [PATCH 1/4] first commit --- transactionCollector.js | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 transactionCollector.js diff --git a/transactionCollector.js b/transactionCollector.js new file mode 100644 index 0000000..a1626da --- /dev/null +++ b/transactionCollector.js @@ -0,0 +1,51 @@ +/** + 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.blockchain.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){ + broadcastFunction (this.createMessage(data), excludeSocket); + } +} + +//unify browser and node +if (this.window === undefined){ + module.exports = TransactionCollector; +} \ No newline at end of file From 4cf2ef2e0a4fb87719ff315102a37c04dfc1cd26 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 26 Sep 2018 10:02:02 +0300 Subject: [PATCH 2/4] added return --- transactionCollector.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transactionCollector.js b/transactionCollector.js index a1626da..2a4ee1d 100644 --- a/transactionCollector.js +++ b/transactionCollector.js @@ -41,7 +41,9 @@ class TransactionCollector { * @param excludeSocket */ sendTransactionToAllPeers(data, broadcastFunction, excludeSocket){ - broadcastFunction (this.createMessage(data), excludeSocket); + let message = this.createMessage(data); + broadcastFunction (message, excludeSocket); + return message; } } From ff5ec8e8c5464b6b072bef73e195da53124f7c7b Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 26 Sep 2018 10:09:18 +0300 Subject: [PATCH 3/4] add type --- candy.js | 3 ++- transactionCollector.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 index 2a4ee1d..f7dfcb7 100644 --- a/transactionCollector.js +++ b/transactionCollector.js @@ -28,7 +28,7 @@ class TransactionCollector { createMessage(data, index = ''){ let JSONdata = JSON.stringify(data); return { - type: this.blockchain.messageType.TRANS_COLL, + type: this.candy.MessageType.TRANS_COLL, data: JSONdata, index:index } From dcbedf4a2d61316a93c95caa6c3ac24a7d83eeb7 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 27 Sep 2018 08:03:14 +0300 Subject: [PATCH 4/4] gitigmore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 03a8da3..e83f5bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ demo — копия.html demo — копия — копия.html +node_modules