Skip to content

get_transactions() doesn't get segwit transactions #93

Closed

Description

@ChristianOConnor

I am trying to use get_transactions() to get segwit transactions. If I put "private_key.get_transactions()" it thinks I am looking for the transactions associated with the LEGACY address of that private key.

Is there a flag to give to "get_transactions()" to make it look for transactions associated with the segwit address of the private key? Like Ex... "private_key.get_transactions(segwit_address)"

Edit

I ran this through the debugger and walked through the get_transactions method in wallet.py step by step and I discovered that get_transactions is properly detecting that the transactions are through the private key's segwit address. The txids it fetches are wrong though. I'm not sure why.

Activity

  1. bjarnemagnussen commented on Jan 22, 2020

    @bjarnemagnussen
    Collaborator

    Hi and sorry for the delay.

    Can you post a Segwit address that when used with get_transactions returns wrong txids?

    Also just to be sure that this did not cause the mistake: With Segwit the txid != txhash.

  2. ChristianOConnor commented on Jan 27, 2020

    @ChristianOConnor
    ContributorAuthor

    @bjarnemagnussen I just reproduced the bug. When I run get_transactions() on the segwit (testnet) address '2MwxwQoEgQsdKFDFUr1xXKavY59rZLhxptT', where privKey == PrivateKeyfor('2MwxwQoEgQsdKFDFUr1xXKavY59rZLhxptT'), I do privKey.get_transactions(). and I get the following array ['65d89b1aee0818c082d5dba5020531b6c6ec61f7a4014df110b3fd645bd37d12', '0c5951a0cba0da6709e3d6caff52dc349102f48a85acb506d8690753d4deb187'].

    There is only 1 transaction for the private key of the address '2MwxwQoEgQsdKFDFUr1xXKavY59rZLhxptT' and it is 'f825688b407d6dd0433f91a3d9af490cfe57b9b8014b4a2ded68d50dfa8fb01e' NOT '65d89b1aee0818c082d5dba5020531b6c6ec61f7a4014df110b3fd645bd37d12' or '0c5951a0cba0da6709e3d6caff52dc349102f48a85acb506d8690753d4deb187'

    When I run get_transactions() on the non-segwit (testnet) address 'mquSX2dazgEdN1CEC1eB2aNQ4upB5B9uSG', where privKey == PrivateKeyfor('mquSX2dazgEdN1CEC1eB2aNQ4upB5B9uSG'), I do privKey.get_transactions(). and I get the following array ['c9ba98708ad79782ea4865a1dbb0850d25cddcfaeffb754bf3a286dc4deeea40', '9c1e7214e418905ef9e9799ad8076c1f8f0348ebabfd80643ac28ae30887fb79'].

    'c9ba98708ad79782ea4865a1dbb0850d25cddcfaeffb754bf3a286dc4deeea40' is the correct TXID for the address 'mquSX2dazgEdN1CEC1eB2aNQ4upB5B9uSG'.

    So it seems like get_transactions() only fetches the correct TXID for non-segwit transactions. Is there a way to fix this? Or maybe a work around it to get segwit TXIDs?

    P.S. these transactions that I'm fetching include an OP_RETURN value. Maybe that's what is throwing the ofek/bit off? Also, I am not sure what the second number is in the arrays. Maybe it has something to do with the OP_RETURN values?

  3. bjarnemagnussen commented on Jan 28, 2020

    @bjarnemagnussen
    Collaborator

    Thanks for the example which was very helpful.

    Currently we only use the APIs provided by Bitpay and Smartbit for the test network. But Bitpay is currently down and it therefore falls back to Smartbit only.

    I think I have identified a bug in Bit when it is polling the webAPI "Smartbit" for all transactions of an address. It returns the transaction hashes instead of ids:

    transactions.extend(t['hash'] for t in data['transactions'])

    This explains why polling the non-segwit address gave you a correct txid, as for non-segwit it is the same as the txhash (in most cases).

    Regarding the fact that you received two transactions when polling for the segwit address "2MwxwQoEgQsdKFDFUr1xXKavY59rZLhxptT": Are you sure that you did poll that address? Because the address has received funds from another segwit address "2MuWhT3LGwP49E2n2yH5UcZmz4G4yo38gnk" that contains exactly those two address hashes.

    Long story short: I will commit a fix to the polling of "Smartbit" ASAP and hopefully it will fix it. If not please re-open this issue!

  4. added a commit that references this issue on Jan 28, 2020
    225754d
  5. ofek commented on Jan 28, 2020

    @ofek
    Owner

    Nicely done 🙇‍♂️

  6. ChristianOConnor commented on Jan 29, 2020

    @ChristianOConnor
    ContributorAuthor

    Awesome thanks @bjarnemagnussen ! For everything! Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions