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

examples: Add salvage_webwallet.py. #194

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

Conversation

JoeGruffins
Copy link
Member

This might be a useful tool people trying to salvage funds from a "web wallet".

Comment on lines 118 to 124
try:
addr = addrlib.deriveChildAddress(key, idx, net)
except Exception:
# Very small chance of a bad address.
pass
try:
res = node.searchRawTransactions(addr, verbose=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a pattern where you check all the addresses at once using existsAddresses, and then only checking searchRawTransactions for those that pass existsAddresses. With existsAddresses, you can check all GAP_LIMIT addresses at once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't thought of that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to leave like it is for now, if that's ok.

decred/examples/drain_xpriv.py Outdated Show resolved Hide resolved
GAP_LIMIT = 20


def cfg(isTestnet):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function appears identical to this one, and about the same as this one. Maybe this function deserves a promotion to a common module like helpers or something. Not a perfect fit, but better than triplication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to fix in a future pr? I also need a check for txindex being enables for this...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just addrindex? not really sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking both, I'm sure there's a way to write it so that we can do everything with one method though.

return cfg


def decodeExtendedKey(netParams, key):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely encouraged to modify package code to help with examples. What's good is the code but if not to help with stuff like this? Consider https://github.com/JoeGruffins/tinydecred/compare/dumpxpriv...buck54321:jg?expand=1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I really wanted to make this script accessible with the release. I will change this in a later pr...

decred/examples/drain_xpriv.py Outdated Show resolved Hide resolved
Copy link
Member

@vctt94 vctt94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing on testnet I got the following result:

Is this mainnet or testnet?
testnet
Enter xpriv: tprvZbj7CwXadom3SKPoKo5hctmjqt2wn8uA4YKDwHnyoFEYwQBGD28VPidrSLZbik5zzkCucnZnWmrZNZB1xDcf4XTyvkPxEmDmJmDB9vueVkj
Found 1 outputs totalling 0.02858322 tdcr.

Input address to send funds: Tsa8ZBbLk2rRjrEQWoGaBXKBSztxdbs91WB
Got the raw hex: 0100000001c3581c5f38e852a05d705a5281d616454f0b43dfa2b03f8983e4a8b8abf37eff4300000000ffffffff0110992b000000000000001976a91463f040a8f1bd956ae62f1f4daeee6526b70090e988ac000000000000000001529d2b000000000000000000000000006b483045022100d0c927ebedb363eaa16956bcdf2220a1f942f78d96e2e4963818bd2ebf79263b02201719949b7a2436862f710d247a70ff7694f5bbadaa69c739abdc3bd6b148b7010121029f2b09b91e05ce793f782242f559b4b7317e05567ee3c2c35b83196678997cb5

txid: cb298ccd53c044e6a20dfcc6e50311a27379cd022b4b1cecbfbd8abe379e0e64
serType: 0
version: 1
txIn 0: 
    previousOutPoint: 
        txid: ff7ef3abb8a8e483893fb0a2df430b4f4516d681525a705da052e8385f1c58c3
        idx: 67
        tree: 0
    sequence: 4294967295
    valueIn: 2858322
    blockHeight: 0
    blockIndex: 0
    signatureScript: 483045022100d0c927ebedb363eaa16956bcdf2220a1f942f78d96e2e4963818bd2ebf79263b02201719949b7a2436862f710d247a70ff7694f5bbadaa69c739abdc3bd6b148b7010121029f2b09b91e05ce793f782242f559b4b7317e05567ee3c2c35b83196678997cb5
txOut 0: 
    value: 2857232
    version: 0
    pkScript: 76a91463f040a8f1bd956ae62f1f4daeee6526b70090e988ac
lockTime: 0
expiry: 0

Really send funds to Tsa8ZBbLk2rRjrEQWoGaBXKBSztxdbs91WB?
yes
Traceback (most recent call last):
  File "./drain_xpriv.py", line 255, in <module>
    main()
  File "./drain_xpriv.py", line 249, in main
    txid = node.sendRawTransaction(signedTx)
  File "/home/vctt/.local/lib/python3.7/site-packages/decred/dcr/rpc.py", line 1109, in sendRawTransaction
    txid = self.call("sendrawtransaction", msgTx.txHex(), allowHighFees)
  File "/home/vctt/.local/lib/python3.7/site-packages/decred/dcr/rpc.py", line 176, in call
    raise DecredError(f"{method} error: {resp.error}")
decred.DecredError: sendrawtransaction error: {'code': -1, 'message': 'rejected transaction cb298ccd53c044e6a20dfcc6e50311a27379cd022b4b1cecbfbd8abe379e0e64: transaction cb298ccd53c044e6a20dfcc6e50311a27379cd022b4b1cecbfbd8abe379e0e64 has insufficient priority (3.009644929411765e+07 <= 5.76e+07)'}

This script is meant to enable someone who has an xpriv from an old
copay wallet to move their funds to a new wallet.
@JoeGruffins JoeGruffins changed the title examples: Add drain_xpriv.py. examples: Add salvage_webwallet.py. Dec 8, 2020
@JoeGruffins
Copy link
Member Author

We have verification that this script was able to salvage someone's funds on mainnet: https://dcrdata.decred.org/tx/1fade79b970e330205f08703f13734b0fcb78ae21b8714e36df1ae1237d4e0e3

I am going to push back on any more optimization. This is working and doesn't need to be super optimal memory-wise. It's a one timer per person thing. Would like to make it more user friendly if possible. And of course if there are any bugs they should be fixed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants