From 9ba8bfa95b77a02fb24d93d4372bc8b0bd4c25b5 Mon Sep 17 00:00:00 2001 From: Luciano Bertenasco Date: Thu, 15 Aug 2019 16:13:04 -0300 Subject: [PATCH 1/3] Update subscription.js --- packages/web3-core-subscriptions/src/subscription.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index 330ee446904..848f5561e91 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -249,6 +249,7 @@ Subscription.prototype.subscribe = function() { this.options.requestManager.send(payload, function (err, result) { if(!err && result) { _this.id = result; + _this.emit('connected', result); // call callback on notifications _this.options.requestManager.addSubscription(_this.id, payload.params[0] , _this.options.type, function(err, result) { From c72a78ceb96d0ad7ac514e0608a94157598e99ce Mon Sep 17 00:00:00 2001 From: Luciano Bertenasco Date: Thu, 17 Oct 2019 14:11:41 +0900 Subject: [PATCH 2/3] Updates Changelog and Docs --- CHANGELOG.md | 8 +++++++- docs/web3-eth-subscribe.rst | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b997fa2ed..80af9bc925c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ Released with 1.0.0-beta.37 code base. ### Fixed - ``websocket`` dependency fixed (#2971, #2976) -- ``requestOptions`` added to ``WebsocketProvider`` (#2979) +- ``requestOptions`` added to ``WebsocketProvider`` (#2979) - Node >= v8.0.0 support (#2938) ## [Unreleased] @@ -74,3 +74,9 @@ Released with 1.0.0-beta.37 code base. - Gas check fixed (#2381) - Signing issues #1998, #2033, and #1074 fixed (#3125) - Fix hexToNumber and hexToNumberString prefix validation (#3086) + +## [1.2.2] + +### Added + +- Emit `connected` event on subscription creation (#3028) diff --git a/docs/web3-eth-subscribe.rst b/docs/web3-eth-subscribe.rst index 6a71a466126..5d6024ee58a 100644 --- a/docs/web3-eth-subscribe.rst +++ b/docs/web3-eth-subscribe.rst @@ -38,6 +38,7 @@ Returns - ``on("data")`` returns ``Object``: Fires on each incoming log with the log object as argument. - ``on("changed")`` returns ``Object``: Fires on each log which was removed from the blockchain. The log will have the additional property ``"removed: true"``. - ``on("error")`` returns ``Object``: Fires when an error in the subscription occurs. + - ``on("connected")`` returns ``Number``: Fires once after the subscription successfully connected. Returns the subscription id. ---------------- Notification returns @@ -189,6 +190,7 @@ Returns - ``"data"`` returns ``Object``: Fires on each incoming block header. - ``"error"`` returns ``Object``: Fires when an error in the subscription occurs. +- ``"connected"`` returns ``Number``: Fires once after the subscription successfully connected. Returns the subscription id. The structure of a returned block header is as follows: @@ -230,6 +232,9 @@ Example console.error(error); }) + .on("connected", function(subscriptionId){ + console.log(subscriptionId); + }) .on("data", function(blockHeader){ console.log(blockHeader); }) @@ -340,6 +345,7 @@ Returns - ``"data"`` returns ``Object``: Fires on each incoming log with the log object as argument. - ``"changed"`` returns ``Object``: Fires on each log which was removed from the blockchain. The log will have the additional property ``"removed: true"``. - ``"error"`` returns ``Object``: Fires when an error in the subscription occurs. +- ``"connected"`` returns ``Number``: Fires once after the subscription successfully connected. Returns the subscription id. For the structure of a returned event ``Object`` see :ref:`web3.eth.getPastEvents return values `. @@ -364,6 +370,9 @@ Example if (!error) console.log(result); }) + .on("connected", function(subscriptionId){ + console.log(subscriptionId); + }) .on("data", function(log){ console.log(log); }) From 387752ac365562b5e0744d1721be8e0ef990ecae Mon Sep 17 00:00:00 2001 From: nivida Date: Thu, 17 Oct 2019 17:40:05 +0200 Subject: [PATCH 3/3] documentation updated --- docs/web3-eth-contract.rst | 4 ++++ docs/web3-eth-subscribe.rst | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/web3-eth-contract.rst b/docs/web3-eth-contract.rst index 0f801f1ceab..7509b800257 100644 --- a/docs/web3-eth-contract.rst +++ b/docs/web3-eth-contract.rst @@ -953,6 +953,7 @@ Returns - ``"data"`` returns ``Object``: Fires on each incoming event with the event object as argument. - ``"changed"`` returns ``Object``: Fires on each event which was removed from the blockchain. The event will have the additional property ``"removed: true"``. - ``"error"`` returns ``Object``: Fires when an error in the subscription occours. +- ``"connected"`` returns ``String``: Fires once after the subscription successfully connected. Returns the subscription id. The structure of the returned event ``Object`` looks as follows: @@ -979,6 +980,9 @@ Example filter: {myIndexedParam: [20,23], myOtherIndexedParam: '0x123456789...'}, // Using an array means OR: e.g. 20 or 23 fromBlock: 0 }, function(error, event){ console.log(event); }) + .on("connected", function(subscriptionId){ + console.log(subscriptionId); + }) .on('data', function(event){ console.log(event); // same results as the optional callback above }) diff --git a/docs/web3-eth-subscribe.rst b/docs/web3-eth-subscribe.rst index 5d6024ee58a..88c1697e2f5 100644 --- a/docs/web3-eth-subscribe.rst +++ b/docs/web3-eth-subscribe.rst @@ -38,7 +38,7 @@ Returns - ``on("data")`` returns ``Object``: Fires on each incoming log with the log object as argument. - ``on("changed")`` returns ``Object``: Fires on each log which was removed from the blockchain. The log will have the additional property ``"removed: true"``. - ``on("error")`` returns ``Object``: Fires when an error in the subscription occurs. - - ``on("connected")`` returns ``Number``: Fires once after the subscription successfully connected. Returns the subscription id. + - ``on("connected")`` returns ``String``: Fires once after the subscription successfully connected. Returns the subscription id. ---------------- Notification returns