Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txdb: Include in TXDetails value of individual transaction from viewpoint of accounts and overall wallet #687

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pinheadmz
Copy link
Member

This PR adds two new functions and their return values to the Details object defined in txdb.js and returned by wallet.getHistory() API calls, as well as by wallet events confirmed, unconfirmed, tx, and conflict.

The new values are walletValue which returns the total change to total wallet balance affected by this transaction, and accountValues which is an object whose keys are account IDs and values are the total balance affected to which accounts by this transaction.

The effect is that tx events and history queries can now inform the user exactly "what happened" in a transaction.

Example output is below. Notice this is a transaction that sent Bitcoin from account 0 to account 1 (as well as a few other outputs, it was randomly generated)

  {
    "hash": "c03ba942470dc0ee91ec53d2d6af9b7b67355fa8afb4f9d91ec337c71f8d6341",
    "height": 436,
    "block": "10cb8cc432c821f0b29c1431a3bb7f877dbfa6e258c614b77b86ab9b582bf787",
    "time": 1549134071,
    "mtime": 1549134002,
    "date": "2019-02-02T19:01:11Z",
    "mdate": "2019-02-02T19:00:02Z",
    "size": 324,
    "virtualSize": 324,
    "fee": 3260,
    "rate": 10061,
    "walletValue": -94054,
    "accountValues": {
      "0": -126079,
      "1": 32025
    },
    "confirmations": 8,
    "inputs": [
      {
        "value": 12458239242,
        "address": "RP9XvkG6aGrRNZVojGv8QW51RQ5uN3yUxm",
        "path": {
          "name": "default",
          "account": 0,
          "change": true,
          "derivation": "m/0'/1/0"
        }
      }
    ],
    "outputs": [
      {
        "value": 31657,
        "address": "RMUuKM8eP4xy4XqfrL8WQPqrDbhxjkqyfB",
        "path": null
      },
      {
        "value": 32025,
        "address": "rb1qydqrkmj02stgeg57kkh4hjwegmja3h38uls2se",
        "path": {
          "name": "hot",
          "account": 1,
          "change": false,
          "derivation": "m/1'/0/5"
        }
      },
      {
        "value": 54978,
        "address": "RUnrdH8PLFCT23z8ukUHdmoR1sqTbrK8Kg",
        "path": {
          "name": "default",
          "account": 0,
          "change": false,
          "derivation": "m/0'/0/5"
        }
      },
      {
        "value": 59137,
        "address": "RUg1P6822SshctwCBhtiENnov7frvGeuMK",
        "path": null
      },
      {
        "value": 12458058185,
        "address": "R9xUg3LgPHuy4f8ex4t613LzqMUP7Lp1HN",
        "path": {
          "name": "default",
          "account": 0,
          "change": true,
          "derivation": "m/0'/1/4"
        }
      }
    ],
    "tx": "0100000001c3e7cf424527740b2e74d120b2968ba7399e749c5d1f8ea93bc926b90e68a9f9020000006a47304402200097c6b8c182ca0c961969a3e711a8e5948e7c32c5e5c3f199575a6757a34b16022047797f4d031fd3dda61913b7b691edb5121bae1e9839b2866ed652dbfa57c766012103e65d40b501b36741d841cfaa5c7ce9f9eff8e523afebf0528fab2f7e708caa45ffffffff05a97b0000000000001976a91485d88256a7747a9c1f099c315a4ed3b77764a94888ac197d00000000000016001423403b6e4f54168ca29eb5af5bc9d946e5d8de27c2d60000000000001976a914d606a1776e73aad0c4a8f79ea82eda9b63b1364588ac01e70000000000001976a914d4bb07105abf02d54467f386ab2bb17582284e5388acc9e18ee6020000001976a914076e13564800491744daba48dff4ade034ee2c7f88ac00000000"
  }

TODO:

  • Write tests

@pinheadmz pinheadmz added enhancement Improving a current feature wallet Wallet related labels Feb 2, 2019
@codecov-io
Copy link

codecov-io commented Feb 2, 2019

Codecov Report

Merging #687 into master will increase coverage by 0.04%.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
+ Coverage   53.38%   53.42%   +0.04%     
==========================================
  Files         104      104              
  Lines       27716    27743      +27     
  Branches     4748     4754       +6     
==========================================
+ Hits        14796    14822      +26     
- Misses      12920    12921       +1
Impacted Files Coverage Δ
lib/wallet/txdb.js 80.3% <96.29%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2e176d...ade1f01. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving a current feature wallet Wallet related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants