Skip to content

Seed initialization and sweeping

Luke Champine requested to merge wallet-seeds into wallet

This PR adds seed initialization (creating a new wallet from an existing seed) and seed sweeping (scanning the blockchain for outputs generated by a seed, and transferring them to the wallet).

InitFromSeed works by scanning the blockchain for uses of the seed. It records the highest seedIndex seen, and sets the wallet's PrimarySeedProgress to that value (plus a 10% fudge factor). Note that this means the blockchain must be fully synced before calling InitFromSeed. When the wallet is unlocked for the first time, another full rescan will be triggered so that the wallet can record all its outputs, processed txns, etc. (Obviously there is room for an optimization here; we should only need to scan the blockchain once.) Scanning the blockchain takes a while, and there is currently no visual indication that InitFromSeed is making progress. We should at least add terminal output similar to the unlock output. InitFromSeed also needs a test (whoops).

SweepSeed similarly scans the blockchain for uses of the seed. It then creates a new transaction, containing inputs for each seen output, and an output belonging to the wallet. Outputs less than the "dustThreshold" are discarded. Currently, siacoin outputs and miner payouts are supported, but not siafunds. (I didn't trust myself to get the code right with those.) As with InitFromSeed, the blockchain must be fully synced and the process can take a while.

Merge request reports