{"action":"created","comment":{"url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/comments/66058206","id":66058206,"diff_hunk":"@@ -0,0 +1,142 @@\n+import co from 'co/';\n+\n+import reconnectCore from 'reconnect-core/';\n+import EventEmitter2 from 'eventemitter2/';\n+import SimpleWebsocket from 'simple-websocket/';\n+\n+import request from '../../utils/request';\n+\n+class BigchainDBLedger extends EventEmitter2 {\n+\n+    constructor(options) {\n+        super();\n+\n+        this.id = null;\n+        this.credentials = options.auth;\n+        this.config = options.config;\n+\n+        this.connection = null;\n+        this.connected = false;\n+    }\n+\n+    connect() {\n+        return co(this._connect.bind(this));\n+    }\n+\n+    * _connect() {\n+        const accountUri = this.credentials.account.uri;\n+\n+        if (this.connection) {\n+            console.warn('already connected, ignoring connection request');\n+            return Promise.resolve(null);\n+        }\n+\n+        const streamUri = accountUri + '/changes';\n+        console.log('subscribing to ' + streamUri);\n+\n+        const reconnect = reconnectCore(() => {\n+            return new SimpleWebsocket(streamUri);\n+        });\n+\n+        return new Promise((resolve, reject) => {\n+            this.connection = reconnect({immediate: true}, (ws) => {\n+                ws.on('open', () => {\n+                    console.log('ws connected to ' + streamUri);\n+                })\n+                ws.on('data', (msg) => {\n+                    const notification = JSON.parse(msg);\n+                    co.wrap(this._handleNotification)\n+                        .call(this, notification)\n+                        .catch((err) => {\n+                            console.warn('failure while processing notification: ' +\n+                            (err && err.stack) ? err.stack : err)\n+                        });\n+                });\n+                ws.on('close', () => {\n+                    console.log('ws disconnected from ' + streamUri);\n+                });\n+            })\n+                .once('connect', () => resolve(null))\n+                .on('connect', () => {\n+                    this.connected = true;\n+                    this.emit('connect');\n+                })\n+                .on('disconnect', () => {\n+                    this.connected = false;\n+                    this.emit('disconnect');\n+                })\n+                .on('error', (err) => {\n+                    console.warn('ws error on ' + streamUri + ': ' + err);\n+                    reject(err);\n+                })\n+                .connect();\n+        });\n+    }\n+\n+    disconnect() {\n+        if (this.connection) {\n+            this.connection.disconnect();\n+            this.connection = null;\n+        }\n+    }\n+\n+    isConnected() {\n+        return this.connected;\n+    }\n+\n+    validateTransfer(transfer) {\n+        // validator.validate('TransferTemplate', transfer)\n+    }\n+\n+    getInfo() {\n+    }\n+\n+    getAccount() {\n+        return this.credentials.account;\n+    }\n+\n+    getBalance() {\n+        return co.wrap(this._getBalance).call(this);\n+    }\n+\n+    * _getBalance() {\n+        const creds = this.credentials;\n+        let res;\n+        try {\n+            res = yield request('assets_for_account', {\n+                urlTemplateSpec: {\n+                    accountId: creds.account.id\n+                }\n+            });\n+        } catch (e) {\n+            throw new Error('Unable to determine current balance');\n+        }\n+        res = res.assets.bigchain.length;\n+        console.log('balance: ', res);\n+        return res;\n+    }\n+\n+\n+    getConnectors() {\n+    }\n+\n+    send(transfer) {\n+        return co.wrap(this._send).call(this, transfer);\n+    }\n+\n+    * _send(transfer) {\n+        \n+    }\n+\n+    fulfillCondition() {","path":"client/lib/js/react/components/ledgerplugin.js","position":131,"original_position":131,"commit_id":"1134168a7d34af0ce6f596e9b86b94d77399f879","original_commit_id":"1134168a7d34af0ce6f596e9b86b94d77399f879","user":{"login":"diminator","id":6178597,"avatar_url":"https://avatars.githubusercontent.com/u/6178597?v=3","gravatar_id":"","url":"https://api.github.com/users/diminator","html_url":"https://github.com/diminator","followers_url":"https://api.github.com/users/diminator/followers","following_url":"https://api.github.com/users/diminator/following{/other_user}","gists_url":"https://api.github.com/users/diminator/gists{/gist_id}","starred_url":"https://api.github.com/users/diminator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diminator/subscriptions","organizations_url":"https://api.github.com/users/diminator/orgs","repos_url":"https://api.github.com/users/diminator/repos","events_url":"https://api.github.com/users/diminator/events{/privacy}","received_events_url":"https://api.github.com/users/diminator/received_events","type":"User","site_admin":false},"body":"it's a bootstrap for the next PR, where I will create the actual interledger example","created_at":"2016-06-07T12:09:39Z","updated_at":"2016-06-07T12:09:40Z","html_url":"https://github.com/bigchaindb/bigchaindb-examples/pull/16#discussion_r66058206","pull_request_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/comments/66058206"},"html":{"href":"https://github.com/bigchaindb/bigchaindb-examples/pull/16#discussion_r66058206"},"pull_request":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16","id":72840119,"html_url":"https://github.com/bigchaindb/bigchaindb-examples/pull/16","diff_url":"https://github.com/bigchaindb/bigchaindb-examples/pull/16.diff","patch_url":"https://github.com/bigchaindb/bigchaindb-examples/pull/16.patch","issue_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/16","number":16,"state":"open","locked":false,"title":"LedgerPlugin with websocket changefeed","user":{"login":"diminator","id":6178597,"avatar_url":"https://avatars.githubusercontent.com/u/6178597?v=3","gravatar_id":"","url":"https://api.github.com/users/diminator","html_url":"https://github.com/diminator","followers_url":"https://api.github.com/users/diminator/followers","following_url":"https://api.github.com/users/diminator/following{/other_user}","gists_url":"https://api.github.com/users/diminator/gists{/gist_id}","starred_url":"https://api.github.com/users/diminator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diminator/subscriptions","organizations_url":"https://api.github.com/users/diminator/orgs","repos_url":"https://api.github.com/users/diminator/repos","events_url":"https://api.github.com/users/diminator/events{/privacy}","received_events_url":"https://api.github.com/users/diminator/received_events","type":"User","site_admin":false},"body":"- Ledgerplugin wraps bigchaindb websocket connection\r\n- Ledgerplugin connects on activeAccount\r\n- Apps listen to changes on Ledgerplugin\r\n\r\n... no more polling\r\n\r\nrefs:\r\n\r\n- [ILP spec for plugins](https://github.com/interledger/rfcs/blob/master/0004-ledger-plugin-interface/0004-ledger-plugin-interface.md#send)\r\n- [ILP reference implementation of plugin](https://github.com/interledger/js-ilp-plugin-bells/blob/master/src/lib/plugin.js)","created_at":"2016-06-07T09:11:32Z","updated_at":"2016-06-07T12:09:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8c3a0c5c5e4e6f36a716513e84e89b54fd0c97bd","assignee":{"login":"TimDaub","id":2758453,"avatar_url":"https://avatars.githubusercontent.com/u/2758453?v=3","gravatar_id":"","url":"https://api.github.com/users/TimDaub","html_url":"https://github.com/TimDaub","followers_url":"https://api.github.com/users/TimDaub/followers","following_url":"https://api.github.com/users/TimDaub/following{/other_user}","gists_url":"https://api.github.com/users/TimDaub/gists{/gist_id}","starred_url":"https://api.github.com/users/TimDaub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimDaub/subscriptions","organizations_url":"https://api.github.com/users/TimDaub/orgs","repos_url":"https://api.github.com/users/TimDaub/repos","events_url":"https://api.github.com/users/TimDaub/events{/privacy}","received_events_url":"https://api.github.com/users/TimDaub/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16/commits","review_comments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16/comments","review_comment_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/16/comments","statuses_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/statuses/1134168a7d34af0ce6f596e9b86b94d77399f879","head":{"label":"bigchaindb:feat/interledger","ref":"feat/interledger","sha":"1134168a7d34af0ce6f596e9b86b94d77399f879","user":{"login":"bigchaindb","id":17097586,"avatar_url":"https://avatars.githubusercontent.com/u/17097586?v=3","gravatar_id":"","url":"https://api.github.com/users/bigchaindb","html_url":"https://github.com/bigchaindb","followers_url":"https://api.github.com/users/bigchaindb/followers","following_url":"https://api.github.com/users/bigchaindb/following{/other_user}","gists_url":"https://api.github.com/users/bigchaindb/gists{/gist_id}","starred_url":"https://api.github.com/users/bigchaindb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigchaindb/subscriptions","organizations_url":"https://api.github.com/users/bigchaindb/orgs","repos_url":"https://api.github.com/users/bigchaindb/repos","events_url":"https://api.github.com/users/bigchaindb/events{/privacy}","received_events_url":"https://api.github.com/users/bigchaindb/received_events","type":"Organization","site_admin":false},"repo":{"id":57370173,"name":"bigchaindb-examples","full_name":"bigchaindb/bigchaindb-examples","owner":{"login":"bigchaindb","id":17097586,"avatar_url":"https://avatars.githubusercontent.com/u/17097586?v=3","gravatar_id":"","url":"https://api.github.com/users/bigchaindb","html_url":"https://github.com/bigchaindb","followers_url":"https://api.github.com/users/bigchaindb/followers","following_url":"https://api.github.com/users/bigchaindb/following{/other_user}","gists_url":"https://api.github.com/users/bigchaindb/gists{/gist_id}","starred_url":"https://api.github.com/users/bigchaindb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigchaindb/subscriptions","organizations_url":"https://api.github.com/users/bigchaindb/orgs","repos_url":"https://api.github.com/users/bigchaindb/repos","events_url":"https://api.github.com/users/bigchaindb/events{/privacy}","received_events_url":"https://api.github.com/users/bigchaindb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bigchaindb/bigchaindb-examples","description":"Examples and tutorials for BigchainDB use cases.","fork":false,"url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples","forks_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/forks","keys_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/teams","hooks_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/hooks","issue_events_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/events{/number}","events_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/events","assignees_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/assignees{/user}","branches_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/branches{/branch}","tags_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/tags","blobs_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/refs{/sha}","trees_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/statuses/{sha}","languages_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/languages","stargazers_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/stargazers","contributors_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/contributors","subscribers_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/subscribers","subscription_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/subscription","commits_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/commits{/sha}","git_commits_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/commits{/sha}","comments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/comments{/number}","issue_comment_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/comments{/number}","contents_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/contents/{+path}","compare_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/merges","archive_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/downloads","issues_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues{/number}","pulls_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls{/number}","milestones_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/milestones{/number}","notifications_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/labels{/name}","releases_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/releases{/id}","deployments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/deployments","created_at":"2016-04-29T08:45:28Z","updated_at":"2016-06-01T20:47:28Z","pushed_at":"2016-06-07T09:11:32Z","git_url":"git://github.com/bigchaindb/bigchaindb-examples.git","ssh_url":"git@github.com:bigchaindb/bigchaindb-examples.git","clone_url":"https://github.com/bigchaindb/bigchaindb-examples.git","svn_url":"https://github.com/bigchaindb/bigchaindb-examples","homepage":null,"size":759,"stargazers_count":10,"watchers_count":10,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":10,"default_branch":"master"}},"base":{"label":"bigchaindb:master","ref":"master","sha":"e63d5545fb685783b51c8e3e4884eec0ae1eb801","user":{"login":"bigchaindb","id":17097586,"avatar_url":"https://avatars.githubusercontent.com/u/17097586?v=3","gravatar_id":"","url":"https://api.github.com/users/bigchaindb","html_url":"https://github.com/bigchaindb","followers_url":"https://api.github.com/users/bigchaindb/followers","following_url":"https://api.github.com/users/bigchaindb/following{/other_user}","gists_url":"https://api.github.com/users/bigchaindb/gists{/gist_id}","starred_url":"https://api.github.com/users/bigchaindb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigchaindb/subscriptions","organizations_url":"https://api.github.com/users/bigchaindb/orgs","repos_url":"https://api.github.com/users/bigchaindb/repos","events_url":"https://api.github.com/users/bigchaindb/events{/privacy}","received_events_url":"https://api.github.com/users/bigchaindb/received_events","type":"Organization","site_admin":false},"repo":{"id":57370173,"name":"bigchaindb-examples","full_name":"bigchaindb/bigchaindb-examples","owner":{"login":"bigchaindb","id":17097586,"avatar_url":"https://avatars.githubusercontent.com/u/17097586?v=3","gravatar_id":"","url":"https://api.github.com/users/bigchaindb","html_url":"https://github.com/bigchaindb","followers_url":"https://api.github.com/users/bigchaindb/followers","following_url":"https://api.github.com/users/bigchaindb/following{/other_user}","gists_url":"https://api.github.com/users/bigchaindb/gists{/gist_id}","starred_url":"https://api.github.com/users/bigchaindb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigchaindb/subscriptions","organizations_url":"https://api.github.com/users/bigchaindb/orgs","repos_url":"https://api.github.com/users/bigchaindb/repos","events_url":"https://api.github.com/users/bigchaindb/events{/privacy}","received_events_url":"https://api.github.com/users/bigchaindb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bigchaindb/bigchaindb-examples","description":"Examples and tutorials for BigchainDB use cases.","fork":false,"url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples","forks_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/forks","keys_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/teams","hooks_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/hooks","issue_events_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/events{/number}","events_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/events","assignees_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/assignees{/user}","branches_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/branches{/branch}","tags_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/tags","blobs_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/refs{/sha}","trees_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/statuses/{sha}","languages_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/languages","stargazers_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/stargazers","contributors_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/contributors","subscribers_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/subscribers","subscription_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/subscription","commits_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/commits{/sha}","git_commits_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/git/commits{/sha}","comments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/comments{/number}","issue_comment_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/comments{/number}","contents_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/contents/{+path}","compare_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/merges","archive_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/downloads","issues_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues{/number}","pulls_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls{/number}","milestones_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/milestones{/number}","notifications_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/labels{/name}","releases_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/releases{/id}","deployments_url":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/deployments","created_at":"2016-04-29T08:45:28Z","updated_at":"2016-06-01T20:47:28Z","pushed_at":"2016-06-07T09:11:32Z","git_url":"git://github.com/bigchaindb/bigchaindb-examples.git","ssh_url":"git@github.com:bigchaindb/bigchaindb-examples.git","clone_url":"https://github.com/bigchaindb/bigchaindb-examples.git","svn_url":"https://github.com/bigchaindb/bigchaindb-examples","homepage":null,"size":759,"stargazers_count":10,"watchers_count":10,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16"},"html":{"href":"https://github.com/bigchaindb/bigchaindb-examples/pull/16"},"issue":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/16"},"comments":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/bigchaindb/bigchaindb-examples/statuses/1134168a7d34af0ce6f596e9b86b94d77399f879"}}}}
{"actor":{"display_login":"diminator"}}