{"action":"created","comment":{"url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/comments/208062364","pull_request_review_id":143798944,"id":208062364,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODA2MjM2NA==","diff_hunk":"@@ -1136,6 +1136,238 @@ class Wallet extends EventEmitter {\n     assert(mtx.getFee() <= MTX.Selector.MAX_FEE, 'TX exceeds MAX_FEE.');\n   }\n \n+  /**\n+   * Fill a transaction with as many of passed coins\n+   * as possible\n+   * @see MTX#selectCoins\n+   * @see MTX#fill\n+   * @param {MTX} mtx - _Must_ be a mutable transaction.\n+   * @param {Object?} options\n+   * @param {(String|Number)?} options.account - If no account is\n+   * specified, coins from the entire wallet will be filled.\n+   * @param {Boolean} options.round - Whether to round to the nearest\n+   * kilobyte for fee calculation.\n+   * See {@link TX#getMinFee} vs. {@link TX#getRoundFee}.\n+   * @param {Rate} options.rate - Rate used for fee calculation.\n+   * @param {Boolean} options.confirmed - Select only confirmed coins.\n+   * @param {Boolean} options.free - Do not apply a fee if the\n+   * transaction priority is high enough to be considered free.\n+   * @param {Amount?} options.hardFee - Use a hard fee rather than\n+   * calculating one.\n+   * @param {Number|Boolean} options.subtractFee - Whether to subtract the\n+   * fee from existing outputs rather than adding more inputs.\n+   */\n+\n+  async fill(mtx, coins, options, force) {\n+    const unlock = await this.fundLock.lock(force);\n+    try {\n+      return await this._fill(mtx, coins, options);\n+    } finally {\n+      unlock();\n+    }\n+  }\n+\n+  /**\n+   * Fill a transaction with as many of passed coins\n+   * as possible\n+   * @private\n+   * @see MTX#selectCoins\n+   * @see MTX#fill\n+   * @param {MTX} mtx - _Must_ be a mutable transaction.\n+   * @param {Object?} options\n+   * @param {(String|Number)?} options.account - If no account is\n+   * specified, coins from the default account will be used to fill.\n+   * Pass -1 to fill from the entire wallet.\n+   * @param {String?} options.selection - Coin selection priority. Can\n+   * be `age`, `random`, or `all`. (default=age).\n+   * @param {Boolean} options.round - Whether to round to the nearest\n+   * kilobyte for fee calculation.\n+   * See {@link TX#getMinFee} vs. {@link TX#getRoundFee}.\n+   * @param {Rate} options.rate - Rate used for fee calculation.\n+   * @param {Boolean} options.confirmed - Select only confirmed coins.\n+   * @param {Boolean} options.free - Do not apply a fee if the\n+   * transaction priority is high enough to be considered free.\n+   * @param {Amount?} options.hardFee - Use a hard fee rather than\n+   * calculating one.\n+   * @param {Number|Boolean} options.subtractFee - Whether to subtract the\n+   * fee from existing outputs rather than adding more inputs.\n+   */\n+\n+  async _fill(mtx, coins, options) {\n+    let accountIndex = 0;\n+    if (options.account) {\n+      assert(\n+        typeof options.account === 'number',\n+        'Account option should be a number corresponding to index of account'\n+      );\n+      accountIndex = options.account;\n+    }\n+\n+    // pick random address from options.addresses or generate new one\n+    const addressCount = options.addresses ? options.addresses.length : 0;\n+    let address;\n+    if (addressCount) {\n+      const index =\n+        Math.floor(Math.random() * (addressCount + 1));","path":"lib/wallet/wallet.js","position":null,"original_position":98,"commit_id":"f6bb974427979a33869263a6aa8c88595e720737","original_commit_id":"8a4a216fb91a3ad2e9bd84327bb16b8748976888","user":{"login":"bucko13","id":4344978,"node_id":"MDQ6VXNlcjQzNDQ5Nzg=","avatar_url":"https://avatars2.githubusercontent.com/u/4344978?v=4","gravatar_id":"","url":"https://api.github.com/users/bucko13","html_url":"https://github.com/bucko13","followers_url":"https://api.github.com/users/bucko13/followers","following_url":"https://api.github.com/users/bucko13/following{/other_user}","gists_url":"https://api.github.com/users/bucko13/gists{/gist_id}","starred_url":"https://api.github.com/users/bucko13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bucko13/subscriptions","organizations_url":"https://api.github.com/users/bucko13/orgs","repos_url":"https://api.github.com/users/bucko13/repos","events_url":"https://api.github.com/users/bucko13/events{/privacy}","received_events_url":"https://api.github.com/users/bucko13/received_events","type":"User","site_admin":false},"body":"Good catch. Careless bug. Would also have problems if the random selector picked something at the end of the list. Should be fixed and am testing with a single address in the array in the rpc test now too. ","created_at":"2018-08-06T23:57:54Z","updated_at":"2018-08-06T23:57:54Z","html_url":"https://github.com/bcoin-org/bcoin/pull/482#discussion_r208062364","pull_request_url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/comments/208062364"},"html":{"href":"https://github.com/bcoin-org/bcoin/pull/482#discussion_r208062364"},"pull_request":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482"}},"in_reply_to_id":206654155},"pull_request":{"url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482","id":193202660,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzMjAyNjYw","html_url":"https://github.com/bcoin-org/bcoin/pull/482","diff_url":"https://github.com/bcoin-org/bcoin/pull/482.diff","patch_url":"https://github.com/bcoin-org/bcoin/pull/482.patch","issue_url":"https://api.github.com/repos/bcoin-org/bcoin/issues/482","number":482,"state":"open","locked":false,"title":"Adding methods for sweeping wallet funds","user":{"login":"bucko13","id":4344978,"node_id":"MDQ6VXNlcjQzNDQ5Nzg=","avatar_url":"https://avatars2.githubusercontent.com/u/4344978?v=4","gravatar_id":"","url":"https://api.github.com/users/bucko13","html_url":"https://github.com/bucko13","followers_url":"https://api.github.com/users/bucko13/followers","following_url":"https://api.github.com/users/bucko13/following{/other_user}","gists_url":"https://api.github.com/users/bucko13/gists{/gist_id}","starred_url":"https://api.github.com/users/bucko13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bucko13/subscriptions","organizations_url":"https://api.github.com/users/bucko13/orgs","repos_url":"https://api.github.com/users/bucko13/repos","events_url":"https://api.github.com/users/bucko13/events{/privacy}","received_events_url":"https://api.github.com/users/bucko13/received_events","type":"User","site_admin":false},"body":"- [x] mtx fill method\r\n- [x] mtx coin selector for fill coins\r\n- [x] sweep method in the wallet for sweeping all UTXOS\r\n\r\n`MTX.fill` works mostly like `fund` and takes the same options except that instead of filling with coins to reach the total output level (plus fee), it keeps adding coins until there are no more coins, the coin with the lowest value is higher than the threshold (optional), or the tx size has reached `policy.MAX_TX_WEIGHT`. \r\n\r\nFor the naive implementation, we are only expecting one output for `fill` and will increase it by the value of each new coin added to it (and then subtract the fee based on the new size). `Wallet.sweep` will have the option of passing it an array of addresses that can be used to sweep to (similar to a normal `send`). As a default one will be generated from the wallet. Possible later to support more than one output and split the value and fee evenly.\r\n\r\nMTX `fill` and the `CoinSelector` both support a threshold option where you can indicate what the maximum coin value you want to fill with (could help with privacy if you don't want to sweep _all_ coins).","created_at":"2018-06-07T04:46:45Z","updated_at":"2018-08-06T23:57:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a7069ab14539b9877856fea741aded4ae2de4c6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482/commits","review_comments_url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482/comments","review_comment_url":"https://api.github.com/repos/bcoin-org/bcoin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bcoin-org/bcoin/issues/482/comments","statuses_url":"https://api.github.com/repos/bcoin-org/bcoin/statuses/f6bb974427979a33869263a6aa8c88595e720737","head":{"label":"bucko13:sweep","ref":"sweep","sha":"f6bb974427979a33869263a6aa8c88595e720737","user":{"login":"bucko13","id":4344978,"node_id":"MDQ6VXNlcjQzNDQ5Nzg=","avatar_url":"https://avatars2.githubusercontent.com/u/4344978?v=4","gravatar_id":"","url":"https://api.github.com/users/bucko13","html_url":"https://github.com/bucko13","followers_url":"https://api.github.com/users/bucko13/followers","following_url":"https://api.github.com/users/bucko13/following{/other_user}","gists_url":"https://api.github.com/users/bucko13/gists{/gist_id}","starred_url":"https://api.github.com/users/bucko13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bucko13/subscriptions","organizations_url":"https://api.github.com/users/bucko13/orgs","repos_url":"https://api.github.com/users/bucko13/repos","events_url":"https://api.github.com/users/bucko13/events{/privacy}","received_events_url":"https://api.github.com/users/bucko13/received_events","type":"User","site_admin":false},"repo":{"id":98933149,"node_id":"MDEwOlJlcG9zaXRvcnk5ODkzMzE0OQ==","name":"bcoin","full_name":"bucko13/bcoin","owner":{"login":"bucko13","id":4344978,"node_id":"MDQ6VXNlcjQzNDQ5Nzg=","avatar_url":"https://avatars2.githubusercontent.com/u/4344978?v=4","gravatar_id":"","url":"https://api.github.com/users/bucko13","html_url":"https://github.com/bucko13","followers_url":"https://api.github.com/users/bucko13/followers","following_url":"https://api.github.com/users/bucko13/following{/other_user}","gists_url":"https://api.github.com/users/bucko13/gists{/gist_id}","starred_url":"https://api.github.com/users/bucko13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bucko13/subscriptions","organizations_url":"https://api.github.com/users/bucko13/orgs","repos_url":"https://api.github.com/users/bucko13/repos","events_url":"https://api.github.com/users/bucko13/events{/privacy}","received_events_url":"https://api.github.com/users/bucko13/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bucko13/bcoin","description":"Javascript bitcoin library for node.js and browsers","fork":true,"url":"https://api.github.com/repos/bucko13/bcoin","forks_url":"https://api.github.com/repos/bucko13/bcoin/forks","keys_url":"https://api.github.com/repos/bucko13/bcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bucko13/bcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bucko13/bcoin/teams","hooks_url":"https://api.github.com/repos/bucko13/bcoin/hooks","issue_events_url":"https://api.github.com/repos/bucko13/bcoin/issues/events{/number}","events_url":"https://api.github.com/repos/bucko13/bcoin/events","assignees_url":"https://api.github.com/repos/bucko13/bcoin/assignees{/user}","branches_url":"https://api.github.com/repos/bucko13/bcoin/branches{/branch}","tags_url":"https://api.github.com/repos/bucko13/bcoin/tags","blobs_url":"https://api.github.com/repos/bucko13/bcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bucko13/bcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bucko13/bcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bucko13/bcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bucko13/bcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/bucko13/bcoin/languages","stargazers_url":"https://api.github.com/repos/bucko13/bcoin/stargazers","contributors_url":"https://api.github.com/repos/bucko13/bcoin/contributors","subscribers_url":"https://api.github.com/repos/bucko13/bcoin/subscribers","subscription_url":"https://api.github.com/repos/bucko13/bcoin/subscription","commits_url":"https://api.github.com/repos/bucko13/bcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bucko13/bcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bucko13/bcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bucko13/bcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bucko13/bcoin/contents/{+path}","compare_url":"https://api.github.com/repos/bucko13/bcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bucko13/bcoin/merges","archive_url":"https://api.github.com/repos/bucko13/bcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bucko13/bcoin/downloads","issues_url":"https://api.github.com/repos/bucko13/bcoin/issues{/number}","pulls_url":"https://api.github.com/repos/bucko13/bcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/bucko13/bcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/bucko13/bcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bucko13/bcoin/labels{/name}","releases_url":"https://api.github.com/repos/bucko13/bcoin/releases{/id}","deployments_url":"https://api.github.com/repos/bucko13/bcoin/deployments","created_at":"2017-07-31T21:54:05Z","updated_at":"2018-07-13T18:50:53Z","pushed_at":"2018-08-06T23:56:57Z","git_url":"git://github.com/bucko13/bcoin.git","ssh_url":"git@github.com:bucko13/bcoin.git","clone_url":"https://github.com/bucko13/bcoin.git","svn_url":"https://github.com/bucko13/bcoin","homepage":"http://bcoin.io","size":22395,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bcoin-org:master","ref":"master","sha":"f24a9b674fbf73c7ae475aa526a851aeedd510d7","user":{"login":"bcoin-org","id":17676391,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3Njc2Mzkx","avatar_url":"https://avatars0.githubusercontent.com/u/17676391?v=4","gravatar_id":"","url":"https://api.github.com/users/bcoin-org","html_url":"https://github.com/bcoin-org","followers_url":"https://api.github.com/users/bcoin-org/followers","following_url":"https://api.github.com/users/bcoin-org/following{/other_user}","gists_url":"https://api.github.com/users/bcoin-org/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoin-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoin-org/subscriptions","organizations_url":"https://api.github.com/users/bcoin-org/orgs","repos_url":"https://api.github.com/users/bcoin-org/repos","events_url":"https://api.github.com/users/bcoin-org/events{/privacy}","received_events_url":"https://api.github.com/users/bcoin-org/received_events","type":"Organization","site_admin":false},"repo":{"id":19239509,"node_id":"MDEwOlJlcG9zaXRvcnkxOTIzOTUwOQ==","name":"bcoin","full_name":"bcoin-org/bcoin","owner":{"login":"bcoin-org","id":17676391,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3Njc2Mzkx","avatar_url":"https://avatars0.githubusercontent.com/u/17676391?v=4","gravatar_id":"","url":"https://api.github.com/users/bcoin-org","html_url":"https://github.com/bcoin-org","followers_url":"https://api.github.com/users/bcoin-org/followers","following_url":"https://api.github.com/users/bcoin-org/following{/other_user}","gists_url":"https://api.github.com/users/bcoin-org/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoin-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoin-org/subscriptions","organizations_url":"https://api.github.com/users/bcoin-org/orgs","repos_url":"https://api.github.com/users/bcoin-org/repos","events_url":"https://api.github.com/users/bcoin-org/events{/privacy}","received_events_url":"https://api.github.com/users/bcoin-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bcoin-org/bcoin","description":"Javascript bitcoin library for node.js and browsers","fork":false,"url":"https://api.github.com/repos/bcoin-org/bcoin","forks_url":"https://api.github.com/repos/bcoin-org/bcoin/forks","keys_url":"https://api.github.com/repos/bcoin-org/bcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bcoin-org/bcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bcoin-org/bcoin/teams","hooks_url":"https://api.github.com/repos/bcoin-org/bcoin/hooks","issue_events_url":"https://api.github.com/repos/bcoin-org/bcoin/issues/events{/number}","events_url":"https://api.github.com/repos/bcoin-org/bcoin/events","assignees_url":"https://api.github.com/repos/bcoin-org/bcoin/assignees{/user}","branches_url":"https://api.github.com/repos/bcoin-org/bcoin/branches{/branch}","tags_url":"https://api.github.com/repos/bcoin-org/bcoin/tags","blobs_url":"https://api.github.com/repos/bcoin-org/bcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bcoin-org/bcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bcoin-org/bcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bcoin-org/bcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bcoin-org/bcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/bcoin-org/bcoin/languages","stargazers_url":"https://api.github.com/repos/bcoin-org/bcoin/stargazers","contributors_url":"https://api.github.com/repos/bcoin-org/bcoin/contributors","subscribers_url":"https://api.github.com/repos/bcoin-org/bcoin/subscribers","subscription_url":"https://api.github.com/repos/bcoin-org/bcoin/subscription","commits_url":"https://api.github.com/repos/bcoin-org/bcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bcoin-org/bcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bcoin-org/bcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bcoin-org/bcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bcoin-org/bcoin/contents/{+path}","compare_url":"https://api.github.com/repos/bcoin-org/bcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bcoin-org/bcoin/merges","archive_url":"https://api.github.com/repos/bcoin-org/bcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bcoin-org/bcoin/downloads","issues_url":"https://api.github.com/repos/bcoin-org/bcoin/issues{/number}","pulls_url":"https://api.github.com/repos/bcoin-org/bcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/bcoin-org/bcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/bcoin-org/bcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bcoin-org/bcoin/labels{/name}","releases_url":"https://api.github.com/repos/bcoin-org/bcoin/releases{/id}","deployments_url":"https://api.github.com/repos/bcoin-org/bcoin/deployments","created_at":"2014-04-28T13:28:18Z","updated_at":"2018-08-06T17:24:16Z","pushed_at":"2018-08-06T23:56:58Z","git_url":"git://github.com/bcoin-org/bcoin.git","ssh_url":"git@github.com:bcoin-org/bcoin.git","clone_url":"https://github.com/bcoin-org/bcoin.git","svn_url":"https://github.com/bcoin-org/bcoin","homepage":"http://bcoin.io","size":22874,"stargazers_count":1792,"watchers_count":1792,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":475,"mirror_url":null,"archived":false,"open_issues_count":107,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":475,"open_issues":107,"watchers":1792,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482"},"html":{"href":"https://github.com/bcoin-org/bcoin/pull/482"},"issue":{"href":"https://api.github.com/repos/bcoin-org/bcoin/issues/482"},"comments":{"href":"https://api.github.com/repos/bcoin-org/bcoin/issues/482/comments"},"review_comments":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482/comments"},"review_comment":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bcoin-org/bcoin/pulls/482/commits"},"statuses":{"href":"https://api.github.com/repos/bcoin-org/bcoin/statuses/f6bb974427979a33869263a6aa8c88595e720737"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"bucko13"}}