{"action":"created","comment":{"url":"https://api.github.com/repos/interledgerjs/ilp/pulls/comments/178555472","pull_request_review_id":108629129,"id":178555472,"diff_hunk":"@@ -0,0 +1,64 @@\n+const crypto = require('crypto')\n+const IlpPacket = require('ilp-packet')\n+const IlDcp = require('ilp-protocol-ildcp')\n+\n+function sha256 (preimage) {\n+  return crypto.createHash('sha256').update(preimage).digest()\n+}\n+\n+class Loop {\n+  constructor (plugin1, plugin2, destination) {\n+    this.pending = {}\n+    this.destination = destination\n+    this.plugin1 = plugin1\n+    this.plugin2 = plugin2\n+    this.plugin2.registerDataHandler(this._loopbackPrepareHandler.bind(this))\n+  }\n+\n+  async _loopbackPrepareHandler (packet) {\n+    const { amount, executionCondition } = IlpPacket.deserializeIlpPrepare(packet)\n+    if (this.pending[executionCondition]) {\n+      const shouldFulfill = await this.pending[executionCondition].loopbackHandler(amount)\n+      if (shouldFulfill) {\n+        const fulfillment = this.pending[executionCondition].fulfillment\n+        return IlpPacket.serializeIlpFulfill({ fulfillment, data: Buffer.from([]) })\n+      }\n+    }\n+    return IlpPacket.serializeIlpReject({\n+      code: 'F04',\n+      triggeredBy: this.destination,\n+      message: 'Insufficient destination amount',\n+      data: Buffer.from([])\n+    })\n+  }\n+\n+  async pay ({ sourceAmount, expiresAt, loopbackHandler }) {\n+    const fulfillment = crypto.randomBytes(32)\n+    const executionCondition = sha256(fulfillment)\n+    const packet = IlpPacket.serializeIlpPrepare({\n+      amount: sourceAmount,\n+      expiresAt,\n+      executionCondition,\n+      destination: this.destination,\n+      data: Buffer.from([])","path":"src/lib/lt.js","position":43,"original_position":43,"commit_id":"86b381a86e563d3cfc9d97629e3bec0e4ec34d9b","original_commit_id":"86b381a86e563d3cfc9d97629e3bec0e4ec34d9b","user":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars2.githubusercontent.com/u/408412?v=4","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"body":"Yeah, I had that at first, but then realized that the condition is already a unique identifier (and is also used actually used as such in the code, as the index to the `pending` hashmap).","created_at":"2018-04-02T14:31:58Z","updated_at":"2018-04-02T14:31:58Z","html_url":"https://github.com/interledgerjs/ilp/pull/134#discussion_r178555472","pull_request_url":"https://api.github.com/repos/interledgerjs/ilp/pulls/134","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/comments/178555472"},"html":{"href":"https://github.com/interledgerjs/ilp/pull/134#discussion_r178555472"},"pull_request":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/134"}},"in_reply_to_id":178468055},"pull_request":{"url":"https://api.github.com/repos/interledgerjs/ilp/pulls/134","id":178013817,"html_url":"https://github.com/interledgerjs/ilp/pull/134","diff_url":"https://github.com/interledgerjs/ilp/pull/134.diff","patch_url":"https://github.com/interledgerjs/ilp/pull/134.patch","issue_url":"https://api.github.com/repos/interledgerjs/ilp/issues/134","number":134,"state":"open","locked":false,"title":"Add support for Loopback Transport","user":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars2.githubusercontent.com/u/408412?v=4","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"body":"work in progress...","created_at":"2018-03-28T11:52:45Z","updated_at":"2018-04-02T14:31:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7cc1235b5ac10e72d61c69618297de5dbb2a059a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/interledgerjs/ilp/pulls/134/commits","review_comments_url":"https://api.github.com/repos/interledgerjs/ilp/pulls/134/comments","review_comment_url":"https://api.github.com/repos/interledgerjs/ilp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/interledgerjs/ilp/issues/134/comments","statuses_url":"https://api.github.com/repos/interledgerjs/ilp/statuses/86b381a86e563d3cfc9d97629e3bec0e4ec34d9b","head":{"label":"interledgerjs:mj-lt","ref":"mj-lt","sha":"86b381a86e563d3cfc9d97629e3bec0e4ec34d9b","user":{"login":"interledgerjs","id":22465593,"avatar_url":"https://avatars1.githubusercontent.com/u/22465593?v=4","gravatar_id":"","url":"https://api.github.com/users/interledgerjs","html_url":"https://github.com/interledgerjs","followers_url":"https://api.github.com/users/interledgerjs/followers","following_url":"https://api.github.com/users/interledgerjs/following{/other_user}","gists_url":"https://api.github.com/users/interledgerjs/gists{/gist_id}","starred_url":"https://api.github.com/users/interledgerjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interledgerjs/subscriptions","organizations_url":"https://api.github.com/users/interledgerjs/orgs","repos_url":"https://api.github.com/users/interledgerjs/repos","events_url":"https://api.github.com/users/interledgerjs/events{/privacy}","received_events_url":"https://api.github.com/users/interledgerjs/received_events","type":"Organization","site_admin":false},"repo":{"id":59520462,"name":"ilp","full_name":"interledgerjs/ilp","owner":{"login":"interledgerjs","id":22465593,"avatar_url":"https://avatars1.githubusercontent.com/u/22465593?v=4","gravatar_id":"","url":"https://api.github.com/users/interledgerjs","html_url":"https://github.com/interledgerjs","followers_url":"https://api.github.com/users/interledgerjs/followers","following_url":"https://api.github.com/users/interledgerjs/following{/other_user}","gists_url":"https://api.github.com/users/interledgerjs/gists{/gist_id}","starred_url":"https://api.github.com/users/interledgerjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interledgerjs/subscriptions","organizations_url":"https://api.github.com/users/interledgerjs/orgs","repos_url":"https://api.github.com/users/interledgerjs/repos","events_url":"https://api.github.com/users/interledgerjs/events{/privacy}","received_events_url":"https://api.github.com/users/interledgerjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/interledgerjs/ilp","description":"ILP client for browsers/Node.js","fork":false,"url":"https://api.github.com/repos/interledgerjs/ilp","forks_url":"https://api.github.com/repos/interledgerjs/ilp/forks","keys_url":"https://api.github.com/repos/interledgerjs/ilp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/interledgerjs/ilp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/interledgerjs/ilp/teams","hooks_url":"https://api.github.com/repos/interledgerjs/ilp/hooks","issue_events_url":"https://api.github.com/repos/interledgerjs/ilp/issues/events{/number}","events_url":"https://api.github.com/repos/interledgerjs/ilp/events","assignees_url":"https://api.github.com/repos/interledgerjs/ilp/assignees{/user}","branches_url":"https://api.github.com/repos/interledgerjs/ilp/branches{/branch}","tags_url":"https://api.github.com/repos/interledgerjs/ilp/tags","blobs_url":"https://api.github.com/repos/interledgerjs/ilp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/interledgerjs/ilp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/interledgerjs/ilp/git/refs{/sha}","trees_url":"https://api.github.com/repos/interledgerjs/ilp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/interledgerjs/ilp/statuses/{sha}","languages_url":"https://api.github.com/repos/interledgerjs/ilp/languages","stargazers_url":"https://api.github.com/repos/interledgerjs/ilp/stargazers","contributors_url":"https://api.github.com/repos/interledgerjs/ilp/contributors","subscribers_url":"https://api.github.com/repos/interledgerjs/ilp/subscribers","subscription_url":"https://api.github.com/repos/interledgerjs/ilp/subscription","commits_url":"https://api.github.com/repos/interledgerjs/ilp/commits{/sha}","git_commits_url":"https://api.github.com/repos/interledgerjs/ilp/git/commits{/sha}","comments_url":"https://api.github.com/repos/interledgerjs/ilp/comments{/number}","issue_comment_url":"https://api.github.com/repos/interledgerjs/ilp/issues/comments{/number}","contents_url":"https://api.github.com/repos/interledgerjs/ilp/contents/{+path}","compare_url":"https://api.github.com/repos/interledgerjs/ilp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/interledgerjs/ilp/merges","archive_url":"https://api.github.com/repos/interledgerjs/ilp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/interledgerjs/ilp/downloads","issues_url":"https://api.github.com/repos/interledgerjs/ilp/issues{/number}","pulls_url":"https://api.github.com/repos/interledgerjs/ilp/pulls{/number}","milestones_url":"https://api.github.com/repos/interledgerjs/ilp/milestones{/number}","notifications_url":"https://api.github.com/repos/interledgerjs/ilp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/interledgerjs/ilp/labels{/name}","releases_url":"https://api.github.com/repos/interledgerjs/ilp/releases{/id}","deployments_url":"https://api.github.com/repos/interledgerjs/ilp/deployments","created_at":"2016-05-23T21:44:52Z","updated_at":"2018-03-23T10:03:03Z","pushed_at":"2018-03-30T11:37:14Z","git_url":"git://github.com/interledgerjs/ilp.git","ssh_url":"git@github.com:interledgerjs/ilp.git","clone_url":"https://github.com/interledgerjs/ilp.git","svn_url":"https://github.com/interledgerjs/ilp","homepage":null,"size":658,"stargazers_count":116,"watchers_count":116,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"archived":false,"open_issues_count":13,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":22,"open_issues":13,"watchers":116,"default_branch":"master"}},"base":{"label":"interledgerjs:master","ref":"master","sha":"a9bc6d61d99041609207067af2927ccc1c4c30b9","user":{"login":"interledgerjs","id":22465593,"avatar_url":"https://avatars1.githubusercontent.com/u/22465593?v=4","gravatar_id":"","url":"https://api.github.com/users/interledgerjs","html_url":"https://github.com/interledgerjs","followers_url":"https://api.github.com/users/interledgerjs/followers","following_url":"https://api.github.com/users/interledgerjs/following{/other_user}","gists_url":"https://api.github.com/users/interledgerjs/gists{/gist_id}","starred_url":"https://api.github.com/users/interledgerjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interledgerjs/subscriptions","organizations_url":"https://api.github.com/users/interledgerjs/orgs","repos_url":"https://api.github.com/users/interledgerjs/repos","events_url":"https://api.github.com/users/interledgerjs/events{/privacy}","received_events_url":"https://api.github.com/users/interledgerjs/received_events","type":"Organization","site_admin":false},"repo":{"id":59520462,"name":"ilp","full_name":"interledgerjs/ilp","owner":{"login":"interledgerjs","id":22465593,"avatar_url":"https://avatars1.githubusercontent.com/u/22465593?v=4","gravatar_id":"","url":"https://api.github.com/users/interledgerjs","html_url":"https://github.com/interledgerjs","followers_url":"https://api.github.com/users/interledgerjs/followers","following_url":"https://api.github.com/users/interledgerjs/following{/other_user}","gists_url":"https://api.github.com/users/interledgerjs/gists{/gist_id}","starred_url":"https://api.github.com/users/interledgerjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interledgerjs/subscriptions","organizations_url":"https://api.github.com/users/interledgerjs/orgs","repos_url":"https://api.github.com/users/interledgerjs/repos","events_url":"https://api.github.com/users/interledgerjs/events{/privacy}","received_events_url":"https://api.github.com/users/interledgerjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/interledgerjs/ilp","description":"ILP client for browsers/Node.js","fork":false,"url":"https://api.github.com/repos/interledgerjs/ilp","forks_url":"https://api.github.com/repos/interledgerjs/ilp/forks","keys_url":"https://api.github.com/repos/interledgerjs/ilp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/interledgerjs/ilp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/interledgerjs/ilp/teams","hooks_url":"https://api.github.com/repos/interledgerjs/ilp/hooks","issue_events_url":"https://api.github.com/repos/interledgerjs/ilp/issues/events{/number}","events_url":"https://api.github.com/repos/interledgerjs/ilp/events","assignees_url":"https://api.github.com/repos/interledgerjs/ilp/assignees{/user}","branches_url":"https://api.github.com/repos/interledgerjs/ilp/branches{/branch}","tags_url":"https://api.github.com/repos/interledgerjs/ilp/tags","blobs_url":"https://api.github.com/repos/interledgerjs/ilp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/interledgerjs/ilp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/interledgerjs/ilp/git/refs{/sha}","trees_url":"https://api.github.com/repos/interledgerjs/ilp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/interledgerjs/ilp/statuses/{sha}","languages_url":"https://api.github.com/repos/interledgerjs/ilp/languages","stargazers_url":"https://api.github.com/repos/interledgerjs/ilp/stargazers","contributors_url":"https://api.github.com/repos/interledgerjs/ilp/contributors","subscribers_url":"https://api.github.com/repos/interledgerjs/ilp/subscribers","subscription_url":"https://api.github.com/repos/interledgerjs/ilp/subscription","commits_url":"https://api.github.com/repos/interledgerjs/ilp/commits{/sha}","git_commits_url":"https://api.github.com/repos/interledgerjs/ilp/git/commits{/sha}","comments_url":"https://api.github.com/repos/interledgerjs/ilp/comments{/number}","issue_comment_url":"https://api.github.com/repos/interledgerjs/ilp/issues/comments{/number}","contents_url":"https://api.github.com/repos/interledgerjs/ilp/contents/{+path}","compare_url":"https://api.github.com/repos/interledgerjs/ilp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/interledgerjs/ilp/merges","archive_url":"https://api.github.com/repos/interledgerjs/ilp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/interledgerjs/ilp/downloads","issues_url":"https://api.github.com/repos/interledgerjs/ilp/issues{/number}","pulls_url":"https://api.github.com/repos/interledgerjs/ilp/pulls{/number}","milestones_url":"https://api.github.com/repos/interledgerjs/ilp/milestones{/number}","notifications_url":"https://api.github.com/repos/interledgerjs/ilp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/interledgerjs/ilp/labels{/name}","releases_url":"https://api.github.com/repos/interledgerjs/ilp/releases{/id}","deployments_url":"https://api.github.com/repos/interledgerjs/ilp/deployments","created_at":"2016-05-23T21:44:52Z","updated_at":"2018-03-23T10:03:03Z","pushed_at":"2018-03-30T11:37:14Z","git_url":"git://github.com/interledgerjs/ilp.git","ssh_url":"git@github.com:interledgerjs/ilp.git","clone_url":"https://github.com/interledgerjs/ilp.git","svn_url":"https://github.com/interledgerjs/ilp","homepage":null,"size":658,"stargazers_count":116,"watchers_count":116,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"archived":false,"open_issues_count":13,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":22,"open_issues":13,"watchers":116,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/134"},"html":{"href":"https://github.com/interledgerjs/ilp/pull/134"},"issue":{"href":"https://api.github.com/repos/interledgerjs/ilp/issues/134"},"comments":{"href":"https://api.github.com/repos/interledgerjs/ilp/issues/134/comments"},"review_comments":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/134/comments"},"review_comment":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/interledgerjs/ilp/pulls/134/commits"},"statuses":{"href":"https://api.github.com/repos/interledgerjs/ilp/statuses/86b381a86e563d3cfc9d97629e3bec0e4ec34d9b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"michielbdejong"}}