Implement exporting a watching-only wallet.
This change allows for the use of watching-only wallets. Unlike normal, "hot" wallets, watching-only wallets do not contain any private keys, and can be used in situations where you want to keep one wallet online to create new receiving addresses and watch for received transactions, while keeping the hot wallet offline (possibly on an air-gapped computer). Two (websocket) extension RPC calls have been added: First, exportwatchingwallet, which will export the current hot wallet to a watching-only wallet, saving either to disk or returning the base64-encoded wallet files to the caller. Second, recoveraddresses, which is used to recover the next n addresses from the address chain. This is used to "sync" a watching wallet with the hot wallet, or vice versa.
This commit is contained in:
parent
8b65e651cd
commit
bd89f076cd
3 changed files with 234 additions and 0 deletions
49
disksync.go
49
disksync.go
|
@ -206,3 +206,52 @@ func (a *Account) writeDirtyToDisk() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteExport writes an account to a special export directory named
|
||||
// by dirName. Any previous files are overwritten.
|
||||
func (a *Account) WriteExport(dirName string) error {
|
||||
exportPath := filepath.Join(networkDir(cfg.Net()), dirName)
|
||||
if err := checkCreateDir(exportPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aname := a.Name()
|
||||
wfilepath := accountFilename("wallet.bin", aname, exportPath)
|
||||
txfilepath := accountFilename("tx.bin", aname, exportPath)
|
||||
utxofilepath := accountFilename("utxo.bin", aname, exportPath)
|
||||
|
||||
a.UtxoStore.RLock()
|
||||
defer a.UtxoStore.RUnlock()
|
||||
utxofile, err := os.Create(utxofilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer utxofile.Close()
|
||||
if _, err := a.UtxoStore.s.WriteTo(utxofile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.TxStore.RLock()
|
||||
defer a.TxStore.RUnlock()
|
||||
txfile, err := os.Create(txfilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer txfile.Close()
|
||||
if _, err := a.TxStore.s.WriteTo(txfile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.mtx.RLock()
|
||||
defer a.mtx.RUnlock()
|
||||
wfile, err := os.Create(wfilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wfile.Close()
|
||||
if _, err := a.Wallet.WriteTo(wfile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue