{"action":"created","issue":{"url":"https://api.github.com/repos/btcsuite/btcwallet/issues/217","labels_url":"https://api.github.com/repos/btcsuite/btcwallet/issues/217/labels{/name}","comments_url":"https://api.github.com/repos/btcsuite/btcwallet/issues/217/comments","events_url":"https://api.github.com/repos/btcsuite/btcwallet/issues/217/events","html_url":"https://github.com/btcsuite/btcwallet/pull/217","id":65338767,"number":217,"title":"Preview: add wtxmgr package","user":{"login":"jrick","id":1420313,"avatar_url":"https://avatars.githubusercontent.com/u/1420313?v=3","gravatar_id":"","url":"https://api.github.com/users/jrick","html_url":"https://github.com/jrick","followers_url":"https://api.github.com/users/jrick/followers","following_url":"https://api.github.com/users/jrick/following{/other_user}","gists_url":"https://api.github.com/users/jrick/gists{/gist_id}","starred_url":"https://api.github.com/users/jrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrick/subscriptions","organizations_url":"https://api.github.com/users/jrick/orgs","repos_url":"https://api.github.com/users/jrick/repos","events_url":"https://api.github.com/users/jrick/events{/privacy}","received_events_url":"https://api.github.com/users/jrick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-31T01:08:46Z","updated_at":"2015-04-01T13:37:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/btcsuite/btcwallet/pulls/217","html_url":"https://github.com/btcsuite/btcwallet/pull/217","diff_url":"https://github.com/btcsuite/btcwallet/pull/217.diff","patch_url":"https://github.com/btcsuite/btcwallet/pull/217.patch"},"body":"This is a **preview** of the new wallet transaction database and spend tracking implementation, based on `walletdb`.  It is not ready for merging, but is done enough to start receiving some feedback and suggestions.\r\n\r\nThis is not the final database change related to transactions.  In the future, wtxmgr will be an internal package used by waddrmgr to store transactions and manage output spend tracking per account.  However, in the interest of improving the current code on master in a timely manner, wtxmgr is currently being given its own namespace.  This matches with how the old transaction store was managed independent of addresses and accounts.\r\n\r\nKnown issues are marked with `TODO` comments.  Some of these are blockers (for example, `Store.ToJSON` is known broken when passed an unconfirmed transaction record) while others are performance issues (creating too many key byte slices may be hard on the collector, several places can be made faster by using a cursor for iteration, and there are some situations where too much data is read and parsed).  These performance issues are unfortunate, but can be improved at a later time.\r\n\r\nIntegration is currently happening here: https://github.com/jrick/btcwallet/tree/jrick_intwtxmgr.\r\n\r\nBefore integration can be completed, we need to settle on some APIs to query for transaction details.  Most of the needed functionality is done with the `Store.ToJSON` method, which returns `btcjson.ListTransactionResult` slices for the RPC server directly.  This matches how `txstore` worked.  Other RPC server code will need other details about transactions without using the listtransacction result structs, and there currently exists no API to query for arbitrary details for a transaction, or transactions within some block range.  Suggestions here are welcome."},"comment":{"url":"https://api.github.com/repos/btcsuite/btcwallet/issues/comments/88483393","html_url":"https://github.com/btcsuite/btcwallet/pull/217#issuecomment-88483393","issue_url":"https://api.github.com/repos/btcsuite/btcwallet/issues/217","id":88483393,"user":{"login":"jrick","id":1420313,"avatar_url":"https://avatars.githubusercontent.com/u/1420313?v=3","gravatar_id":"","url":"https://api.github.com/users/jrick","html_url":"https://github.com/jrick","followers_url":"https://api.github.com/users/jrick/followers","following_url":"https://api.github.com/users/jrick/following{/other_user}","gists_url":"https://api.github.com/users/jrick/gists{/gist_id}","starred_url":"https://api.github.com/users/jrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrick/subscriptions","organizations_url":"https://api.github.com/users/jrick/orgs","repos_url":"https://api.github.com/users/jrick/repos","events_url":"https://api.github.com/users/jrick/events{/privacy}","received_events_url":"https://api.github.com/users/jrick/received_events","type":"User","site_admin":false},"created_at":"2015-04-01T13:37:53Z","updated_at":"2015-04-01T13:37:53Z","body":"I'm currently adding APIs to query for all recorded details for a single transaction.  This is done under a single view.  At the moment the API looks like this:\r\n\r\n```Go\r\ntype TxDetails struct {\r\n        TxRecord\r\n        Block   BlockMeta\r\n        Credits []Credit\r\n        Debits  []Debit\r\n}\r\n\r\n// TxDetails returns all saved details regarding a transaction.  In case of a\r\n// hash collision, the most recent transaction with a matching hash is returned.\r\nfunc (s *Store) TxDetails(txHash *wire.ShaHash) (*TxDetails, error) {\r\n        var details *TxDetails\r\n        err := scopedUpdate(s.namespace, func(ns walletdb.Bucket) error {\r\n                var err error\r\n                details, err = s.txDetails(ns, txHash)\r\n                return err\r\n        })\r\n        return details, err\r\n}\r\n\r\nfunc (s *Store) txDetails(ns walletdb.Bucket, txHash *wire.ShaHash) (*TxDetails, error) {\r\n        // First, check whether there exists an unmined transaction with this\r\n        // hash.  Use it if found.\r\n        v := existsRawUnmined(ns, txHash[:])\r\n        if v != nil {\r\n                return s.unminedTxDetails(ns, txHash, v)\r\n        }\r\n\r\n        // Otherwise, if there exists a mined transaction with this matching\r\n        // hash, skip over to the newest and begin fetching all details.\r\n        k, v := latestTxRecord(txHash)\r\n        if v == nil {\r\n                // not found\r\n                return nil, nil\r\n        }\r\n\r\n        // Read k/v, lookup all matching credits, debits.\r\n\r\n        return nil, nil\r\n}\r\n\r\nfunc (s *Store) unminedTxDetails(ns walletdb.Bucket, txHash *wire.ShaHash, v []byte) (*TxDetails, error) {\r\n        // ...\r\n}\r\n```\r\n\r\nThis will only fetch details for one transaction at a time and is not suitable for fetching entire ranges of transactions, but perhaps some of this code can be reused for that."}}