importx / importprivkey (rescan=last block) RPC command? #5899

issue jprichardson opened this issue on March 14, 2015
  1. jprichardson commented at 1:24 PM on March 14, 2015: none

    Thoughts on adding a new RPC command like importx that imports a known transaction ID directly into the wallet? Or, when calling importprivkey, add another parameter that tells the rescan to only go as far back as the block specified? e.g. (importprivkey <privkey> rescan=true xxxxxx) Maybe both?

    My use case:

    I've been experimenting with stealth addresses and as the receiver of a stealth payment, you don't know the private key in advance to redeem your funds. This is calculated using data from one of the null outputs (OP_RETURN). When you find a match and the associated private key, you need to import it into your wallet. Since the transaction ID is already known, this makes a rescan unnecessary and a waste of resources, unfortunately it must be done though if you want the balance and transaction to be added to the wallet.

  2. luke-jr commented at 2:25 PM on March 14, 2015: member

    A transaction id wouldn't necessarily help here if it's already spent (you do want to include past transactions, right?). Why not just add the stealth address support into Bitcoin Core directly?

  3. jprichardson commented at 6:51 PM on March 14, 2015: none

    @luke-jr There are no past transactions since it's a new address that's calculated at the time of the stealth payment. I'd think that Stealth support would be great, but that's like moving mountains compared to what I'm asking for.

    Either:

    1. Expose rescan to rpc and startup -rescan flag and a parameter to accept the start block. By default, it's the genesis block. In other words, just expose the method ScanForWalletTransactions as seen here https://github.com/bitcoin/bitcoin/blob/v0.10.0/src/wallet.cpp#L930 (Would probably want to modify importprivkey as well to have a parameter for starting block as well)
    2. Expose a method to add the transaction to the wallet i.e. AddToWalletIfInvolvingMe via RPC. Method found here: https://github.com/bitcoin/bitcoin/blob/v0.10.0/src/wallet.cpp#L684

    Even better, add both changes.

  4. sipa commented at 6:54 PM on March 14, 2015: member

    You can use importwallet, which can multiple keys at once, with birth time information, and will rescan whatever is necessary.

  5. jprichardson commented at 7:01 PM on March 14, 2015: none

    @sipa I don't see how importwallet would help solve this problem since (as far as I can tell) with the importwallet format I can only specify keys. A rescan would still be necessary. I'm trying to avoid doing the rescan as much as possible since I already know the transaction ID that I need to add to the wallet.

  6. jprichardson commented at 7:04 PM on March 14, 2015: none

    with birth time information

    Sorry, I just missed this important part. I assume this may solve the problem... hehehe

  7. jprichardson commented at 3:54 AM on March 15, 2015: none

    OK, after experimenting more with this, it looks like importwallet should be satisfactory for now. It'll be a minor inconvenience for the user if the birth time is really old, but it still won't be as bad as scanning the entire blockchain. I think the other requests are valid, but there are no doubt other higher priorities that you must take care of (and understandably so). Closing for now. Thanks for the suggestion and help.

  8. jprichardson closed this on Mar 15, 2015

  9. neocogent commented at 6:37 AM on July 19, 2015: none

    Having a rescan for starting at a specific block would also be very useful for joinmarket and similar uses. When first starting it adds a ton of new addresses to the wallet but since newly created we are sure they have no previous trxs. Currently it has to rescan from block 0, which takes for friggin ever.

  10. sipa commented at 12:27 PM on July 19, 2015: member

    Use dumpwallet/importwallet if you don't want to rescan everything. It is far more efficient, and supports timestamped keys. It will rescan multiple keys at once, and only the necessary part of the blockchain.

  11. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me