{"action":"created","comment":{"url":"https://api.github.com/repos/btcsuite/btcdb/pulls/comments/23142838","id":23142838,"diff_hunk":"@@ -290,3 +290,43 @@ func (db *LevelDb) NewestSha() (rsha *btcwire.ShaHash, rblkid int64, err error)\n \n \treturn &sha, db.lastBlkIdx, nil\n }\n+\n+// fetchAddrIndexTip returns the last block height and block sha to be indexed.\n+// Meta-data about the address tip is currently cached in memory, and will be\n+// updated accordingly by functions that modify the state. This function is\n+// used on start up to load the info into memory. Callers will use the public\n+// version of this function below, which returns our cached copy.\n+func (db *LevelDb) fetchAddrIndexTip() (*btcwire.ShaHash, int64, error) {\n+\tdb.dbLock.Lock()\n+\tdefer db.dbLock.Unlock()\n+\n+\tkey := addrIndexMetaDataKey","path":"ldb/block.go","position":14,"original_position":14,"commit_id":"b89f62d4265a2b1e5a7e65ce8cba61e08f61674c","original_commit_id":"b89f62d4265a2b1e5a7e65ce8cba61e08f61674c","user":{"login":"davecgh","id":2115102,"avatar_url":"https://avatars.githubusercontent.com/u/2115102?v=3","gravatar_id":"","url":"https://api.github.com/users/davecgh","html_url":"https://github.com/davecgh","followers_url":"https://api.github.com/users/davecgh/followers","following_url":"https://api.github.com/users/davecgh/following{/other_user}","gists_url":"https://api.github.com/users/davecgh/gists{/gist_id}","starred_url":"https://api.github.com/users/davecgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davecgh/subscriptions","organizations_url":"https://api.github.com/users/davecgh/orgs","repos_url":"https://api.github.com/users/davecgh/repos","events_url":"https://api.github.com/users/davecgh/events{/privacy}","received_events_url":"https://api.github.com/users/davecgh/received_events","type":"User","site_admin":false},"body":"This is only used in the call to `Get` below and it's not a function.  Any reason `addrIndexMetaDataKey` is just not passed directly?","created_at":"2015-01-19T05:00:31Z","updated_at":"2015-01-19T05:00:31Z","html_url":"https://github.com/btcsuite/btcdb/pull/11#discussion_r23142838","pull_request_url":"https://api.github.com/repos/btcsuite/btcdb/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/comments/23142838"},"html":{"href":"https://github.com/btcsuite/btcdb/pull/11#discussion_r23142838"},"pull_request":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/btcsuite/btcdb/pulls/11","id":26570759,"html_url":"https://github.com/btcsuite/btcdb/pull/11","diff_url":"https://github.com/btcsuite/btcdb/pull/11.diff","patch_url":"https://github.com/btcsuite/btcdb/pull/11.patch","issue_url":"https://api.github.com/repos/btcsuite/btcdb/issues/11","number":11,"state":"open","locked":false,"title":"Implement ldb database functionality for optional addr index. ","user":{"login":"Roasbeef","id":998190,"avatar_url":"https://avatars.githubusercontent.com/u/998190?v=3","gravatar_id":"","url":"https://api.github.com/users/Roasbeef","html_url":"https://github.com/Roasbeef","followers_url":"https://api.github.com/users/Roasbeef/followers","following_url":"https://api.github.com/users/Roasbeef/following{/other_user}","gists_url":"https://api.github.com/users/Roasbeef/gists{/gist_id}","starred_url":"https://api.github.com/users/Roasbeef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Roasbeef/subscriptions","organizations_url":"https://api.github.com/users/Roasbeef/orgs","repos_url":"https://api.github.com/users/Roasbeef/repos","events_url":"https://api.github.com/users/Roasbeef/events{/privacy}","received_events_url":"https://api.github.com/users/Roasbeef/received_events","type":"User","site_admin":false},"body":"This pull request alters the `btcdb.db` interface, adding new functions for accessing/updating/deleting the optional address index. For now, only the `ldb` driver implements the newly defined functions. `memdb` has also been altered, but only to supply skeleton functions in order for the package to conform to the new `btcdb` interface (won't compile otherwise). Additionally this PR makes progress towards completion of conformal/btcd#190. Subsequent PR's dependant upon this one will be opened across: `btcd` + `btcjson` + `btcrpcclient`, ultimately fully implementing `btcd`'s new optional `addrindex`. \r\n\r\nIn order to provide functionality for storage of a new address-based transaction index, the following functions have been added to the `btcdb`, `Db` interface:\r\n  ```\r\n  type Db interface {\r\n      ....\r\n      FetchAddrIndexTip() (sha *btcwire.ShaHash, height int64, err error)\r\n      UpdateAddrIndexForBlock(blkSha *btcwire.ShaHash, blkHeight int64, addrIndex *BlockAddrIndex) error\r\n      FetchTxsForAddr(addr *btcutil.Address, skip int, limit int) ([]*TxListReply, error)\r\n      DeleteAddrIndex() error\r\n  }\r\n  ```\r\n\r\nAlong with a helper type-def:\r\n  * ```type BlockAddrIndex map[[ripemd160.Size]byte][]*btcwire.TxLoc```\r\n\r\nA single entry in the new optional index takes up 38-bytes raw, and is layed out like the following:\r\n  ```\r\n       ----------------------------------------------------------------------\r\n       | Prefix  | Hash160  | BlkHeight | Tx Offset | Tx Size |\r\n       ----------------------------------------------------------------------\r\n       | 2 bytes | 20 bytes |  8 bytes  |  4 bytes  | 4 bytes |\r\n       ----------------------------------------------------------------------\r\n  ````\r\n\r\nEach index maps a `hash160` to a transaction locator object (offset and size within block). Indexes are stored purely in the key (leaving blank bytes for the value), to make it easy to seek and limit the number of transactions returned via iterators. An ability to `skip` and `limit` the number of returned transactions is also required to properly implement the `searchrawtransaction` RPC. ","created_at":"2014-12-25T00:08:00Z","updated_at":"2015-01-19T05:00:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4f1eb3f1544377ad589ed210d60b201e4808e50e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/btcsuite/btcdb/pulls/11/commits","review_comments_url":"https://api.github.com/repos/btcsuite/btcdb/pulls/11/comments","review_comment_url":"https://api.github.com/repos/btcsuite/btcdb/pulls/comments/{number}","comments_url":"https://api.github.com/repos/btcsuite/btcdb/issues/11/comments","statuses_url":"https://api.github.com/repos/btcsuite/btcdb/statuses/b89f62d4265a2b1e5a7e65ce8cba61e08f61674c","head":{"label":"Roasbeef:addrindex","ref":"addrindex","sha":"b89f62d4265a2b1e5a7e65ce8cba61e08f61674c","user":{"login":"Roasbeef","id":998190,"avatar_url":"https://avatars.githubusercontent.com/u/998190?v=3","gravatar_id":"","url":"https://api.github.com/users/Roasbeef","html_url":"https://github.com/Roasbeef","followers_url":"https://api.github.com/users/Roasbeef/followers","following_url":"https://api.github.com/users/Roasbeef/following{/other_user}","gists_url":"https://api.github.com/users/Roasbeef/gists{/gist_id}","starred_url":"https://api.github.com/users/Roasbeef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Roasbeef/subscriptions","organizations_url":"https://api.github.com/users/Roasbeef/orgs","repos_url":"https://api.github.com/users/Roasbeef/repos","events_url":"https://api.github.com/users/Roasbeef/events{/privacy}","received_events_url":"https://api.github.com/users/Roasbeef/received_events","type":"User","site_admin":false},"repo":{"id":25714163,"name":"btcdb","full_name":"Roasbeef/btcdb","owner":{"login":"Roasbeef","id":998190,"avatar_url":"https://avatars.githubusercontent.com/u/998190?v=3","gravatar_id":"","url":"https://api.github.com/users/Roasbeef","html_url":"https://github.com/Roasbeef","followers_url":"https://api.github.com/users/Roasbeef/followers","following_url":"https://api.github.com/users/Roasbeef/following{/other_user}","gists_url":"https://api.github.com/users/Roasbeef/gists{/gist_id}","starred_url":"https://api.github.com/users/Roasbeef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Roasbeef/subscriptions","organizations_url":"https://api.github.com/users/Roasbeef/orgs","repos_url":"https://api.github.com/users/Roasbeef/repos","events_url":"https://api.github.com/users/Roasbeef/events{/privacy}","received_events_url":"https://api.github.com/users/Roasbeef/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Roasbeef/btcdb","description":"Provides a database interface for the bitcoin block chain - a package from btcd","fork":true,"url":"https://api.github.com/repos/Roasbeef/btcdb","forks_url":"https://api.github.com/repos/Roasbeef/btcdb/forks","keys_url":"https://api.github.com/repos/Roasbeef/btcdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Roasbeef/btcdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Roasbeef/btcdb/teams","hooks_url":"https://api.github.com/repos/Roasbeef/btcdb/hooks","issue_events_url":"https://api.github.com/repos/Roasbeef/btcdb/issues/events{/number}","events_url":"https://api.github.com/repos/Roasbeef/btcdb/events","assignees_url":"https://api.github.com/repos/Roasbeef/btcdb/assignees{/user}","branches_url":"https://api.github.com/repos/Roasbeef/btcdb/branches{/branch}","tags_url":"https://api.github.com/repos/Roasbeef/btcdb/tags","blobs_url":"https://api.github.com/repos/Roasbeef/btcdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Roasbeef/btcdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Roasbeef/btcdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/Roasbeef/btcdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Roasbeef/btcdb/statuses/{sha}","languages_url":"https://api.github.com/repos/Roasbeef/btcdb/languages","stargazers_url":"https://api.github.com/repos/Roasbeef/btcdb/stargazers","contributors_url":"https://api.github.com/repos/Roasbeef/btcdb/contributors","subscribers_url":"https://api.github.com/repos/Roasbeef/btcdb/subscribers","subscription_url":"https://api.github.com/repos/Roasbeef/btcdb/subscription","commits_url":"https://api.github.com/repos/Roasbeef/btcdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/Roasbeef/btcdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/Roasbeef/btcdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/Roasbeef/btcdb/issues/comments/{number}","contents_url":"https://api.github.com/repos/Roasbeef/btcdb/contents/{+path}","compare_url":"https://api.github.com/repos/Roasbeef/btcdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Roasbeef/btcdb/merges","archive_url":"https://api.github.com/repos/Roasbeef/btcdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Roasbeef/btcdb/downloads","issues_url":"https://api.github.com/repos/Roasbeef/btcdb/issues{/number}","pulls_url":"https://api.github.com/repos/Roasbeef/btcdb/pulls{/number}","milestones_url":"https://api.github.com/repos/Roasbeef/btcdb/milestones{/number}","notifications_url":"https://api.github.com/repos/Roasbeef/btcdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Roasbeef/btcdb/labels{/name}","releases_url":"https://api.github.com/repos/Roasbeef/btcdb/releases{/id}","created_at":"2014-10-25T00:21:03Z","updated_at":"2014-09-29T09:47:26Z","pushed_at":"2015-01-06T20:05:06Z","git_url":"git://github.com/Roasbeef/btcdb.git","ssh_url":"git@github.com:Roasbeef/btcdb.git","clone_url":"https://github.com/Roasbeef/btcdb.git","svn_url":"https://github.com/Roasbeef/btcdb","homepage":null,"size":389,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"btcsuite:master","ref":"master","sha":"b2186ae5ec7910f29cbfd5ac14d27701aec26615","user":{"login":"btcsuite","id":10235229,"avatar_url":"https://avatars.githubusercontent.com/u/10235229?v=3","gravatar_id":"","url":"https://api.github.com/users/btcsuite","html_url":"https://github.com/btcsuite","followers_url":"https://api.github.com/users/btcsuite/followers","following_url":"https://api.github.com/users/btcsuite/following{/other_user}","gists_url":"https://api.github.com/users/btcsuite/gists{/gist_id}","starred_url":"https://api.github.com/users/btcsuite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btcsuite/subscriptions","organizations_url":"https://api.github.com/users/btcsuite/orgs","repos_url":"https://api.github.com/users/btcsuite/repos","events_url":"https://api.github.com/users/btcsuite/events{/privacy}","received_events_url":"https://api.github.com/users/btcsuite/received_events","type":"Organization","site_admin":false},"repo":{"id":10363013,"name":"btcdb","full_name":"btcsuite/btcdb","owner":{"login":"btcsuite","id":10235229,"avatar_url":"https://avatars.githubusercontent.com/u/10235229?v=3","gravatar_id":"","url":"https://api.github.com/users/btcsuite","html_url":"https://github.com/btcsuite","followers_url":"https://api.github.com/users/btcsuite/followers","following_url":"https://api.github.com/users/btcsuite/following{/other_user}","gists_url":"https://api.github.com/users/btcsuite/gists{/gist_id}","starred_url":"https://api.github.com/users/btcsuite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btcsuite/subscriptions","organizations_url":"https://api.github.com/users/btcsuite/orgs","repos_url":"https://api.github.com/users/btcsuite/repos","events_url":"https://api.github.com/users/btcsuite/events{/privacy}","received_events_url":"https://api.github.com/users/btcsuite/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/btcsuite/btcdb","description":"Provides a database interface for the bitcoin block chain - a package from btcd","fork":false,"url":"https://api.github.com/repos/btcsuite/btcdb","forks_url":"https://api.github.com/repos/btcsuite/btcdb/forks","keys_url":"https://api.github.com/repos/btcsuite/btcdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/btcsuite/btcdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/btcsuite/btcdb/teams","hooks_url":"https://api.github.com/repos/btcsuite/btcdb/hooks","issue_events_url":"https://api.github.com/repos/btcsuite/btcdb/issues/events{/number}","events_url":"https://api.github.com/repos/btcsuite/btcdb/events","assignees_url":"https://api.github.com/repos/btcsuite/btcdb/assignees{/user}","branches_url":"https://api.github.com/repos/btcsuite/btcdb/branches{/branch}","tags_url":"https://api.github.com/repos/btcsuite/btcdb/tags","blobs_url":"https://api.github.com/repos/btcsuite/btcdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/btcsuite/btcdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/btcsuite/btcdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/btcsuite/btcdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/btcsuite/btcdb/statuses/{sha}","languages_url":"https://api.github.com/repos/btcsuite/btcdb/languages","stargazers_url":"https://api.github.com/repos/btcsuite/btcdb/stargazers","contributors_url":"https://api.github.com/repos/btcsuite/btcdb/contributors","subscribers_url":"https://api.github.com/repos/btcsuite/btcdb/subscribers","subscription_url":"https://api.github.com/repos/btcsuite/btcdb/subscription","commits_url":"https://api.github.com/repos/btcsuite/btcdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/btcsuite/btcdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/btcsuite/btcdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/btcsuite/btcdb/issues/comments/{number}","contents_url":"https://api.github.com/repos/btcsuite/btcdb/contents/{+path}","compare_url":"https://api.github.com/repos/btcsuite/btcdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/btcsuite/btcdb/merges","archive_url":"https://api.github.com/repos/btcsuite/btcdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/btcsuite/btcdb/downloads","issues_url":"https://api.github.com/repos/btcsuite/btcdb/issues{/number}","pulls_url":"https://api.github.com/repos/btcsuite/btcdb/pulls{/number}","milestones_url":"https://api.github.com/repos/btcsuite/btcdb/milestones{/number}","notifications_url":"https://api.github.com/repos/btcsuite/btcdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/btcsuite/btcdb/labels{/name}","releases_url":"https://api.github.com/repos/btcsuite/btcdb/releases{/id}","created_at":"2013-05-29T15:36:06Z","updated_at":"2015-01-17T05:21:27Z","pushed_at":"2015-01-17T05:21:27Z","git_url":"git://github.com/btcsuite/btcdb.git","ssh_url":"git@github.com:btcsuite/btcdb.git","clone_url":"https://github.com/btcsuite/btcdb.git","svn_url":"https://github.com/btcsuite/btcdb","homepage":null,"size":1026,"stargazers_count":30,"watchers_count":30,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":5,"forks":15,"open_issues":5,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/11"},"html":{"href":"https://github.com/btcsuite/btcdb/pull/11"},"issue":{"href":"https://api.github.com/repos/btcsuite/btcdb/issues/11"},"comments":{"href":"https://api.github.com/repos/btcsuite/btcdb/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/btcsuite/btcdb/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/btcsuite/btcdb/statuses/b89f62d4265a2b1e5a7e65ce8cba61e08f61674c"}}}}