func (w *Wallet) Load033xWallet(masterKey crypto.TwofishKey, filepath033x string) error {
	if err := w.tg.Add(); err != nil {
		return err
	}
	defer w.tg.Done()
	err := func() error {
		w.mu.Lock()
		defer w.mu.Unlock()
		var savedKeys []savedKey033x
		err := encoding.ReadFile(filepath033x, &savedKeys)
		if err != nil {
			return err
		}
		var seedsLoaded int
		for _, savedKey := range savedKeys {
			spendKey := spendableKey{
				UnlockConditions: savedKey.UnlockConditions,
				SecretKeys:       []crypto.SecretKey{savedKey.SecretKey},
			}
			err = w.loadSpendableKey(masterKey, spendKey)
			if err != nil && err != errDuplicateSpendableKey {
				return err
			}
			if err == nil {
				seedsLoaded++
			}
			w.integrateSpendableKey(masterKey, spendKey)
		}
		if seedsLoaded == 0 {
			return errAllDuplicates
		}
		if err = w.dbTx.DeleteBucket(bucketProcessedTransactions); err != nil {
			return err
		}
		if _, err = w.dbTx.CreateBucket(bucketProcessedTransactions); err != nil {
			return err
		}
		w.unconfirmedProcessedTransactions = nil
		err = dbPutConsensusChangeID(w.dbTx, modules.ConsensusChangeBeginning)
		if err != nil {
			return err
		}
		return dbPutConsensusHeight(w.dbTx, 0)
	}()
	if err != nil {
		return err
	}
	w.cs.Unsubscribe(w)
	w.tpool.Unsubscribe(w)
	done := make(chan struct{})
	go w.rescanMessage(done)
	defer close(done)
	err = w.cs.ConsensusSetSubscribe(w, modules.ConsensusChangeBeginning, w.tg.StopChan())
	if err != nil {
		return err
	}
	w.tpool.TransactionPoolSubscribe(w)
	return nil
}
Load033xWallet loads a v0.3.3.x wallet as an unseeded key, such that the
funds become spendable to the current wallet.
package wallet
import (
	"errors"
	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/encoding"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"
	"github.com/NebulousLabs/fastrand"
)
const (
	SiagFileExtension = ".siakey"
	SiagFileHeader = "siag"
	SiagFileVersion = "1.0"
)
var (
	errAllDuplicates         = errors.New("old wallet has no new seeds")
	errDuplicateSpendableKey = errors.New("key has already been loaded into the wallet")
	ErrInconsistentKeys = errors.New("keyfiles provided that are for different addresses")
	ErrInsufficientKeys = errors.New("not enough keys provided to spend the siafunds")
	ErrNoKeyfile = errors.New("no keyfile has been presented")
	ErrUnknownHeader = errors.New("file contains the wrong header")
	ErrUnknownVersion = errors.New("file has an unknown version number")
)
type siagKeyPair struct {
	Header           string
	Version          string
	Index            int  
	SecretKey        crypto.SecretKey
	UnlockConditions types.UnlockConditions
}
type savedKey033x struct {
	SecretKey        crypto.SecretKey
	UnlockConditions types.UnlockConditions
	Visible          bool
}
func decryptSpendableKeyFile(masterKey crypto.TwofishKey, uk spendableKeyFile) (sk spendableKey, err error) {
	decryptionKey := uidEncryptionKey(masterKey, uk.UID)
	err = verifyEncryption(decryptionKey, uk.EncryptionVerification)
	if err != nil {
		return
	}
	encodedKey, err := decryptionKey.DecryptBytes(uk.SpendableKey)
	if err != nil {
		return
	}
	err = encoding.Unmarshal(encodedKey, &sk)
	return
}
func (w *Wallet) integrateSpendableKey(masterKey crypto.TwofishKey, sk spendableKey) {
	w.keys[sk.UnlockConditions.UnlockHash()] = sk
}
func (w *Wallet) loadSpendableKey(masterKey crypto.TwofishKey, sk spendableKey) error {
	if !w.unlocked {
		return modules.ErrLockedWallet
	}
	_, exists := w.keys[sk.UnlockConditions.UnlockHash()]
	if exists {
		return errDuplicateSpendableKey
	}
	var skf spendableKeyFile
	fastrand.Read(skf.UID[:])
	encryptionKey := uidEncryptionKey(masterKey, skf.UID)
	skf.EncryptionVerification = encryptionKey.EncryptBytes(verificationPlaintext)
	skf.SpendableKey = encryptionKey.EncryptBytes(encoding.Marshal(sk))
	err := checkMasterKey(w.dbTx, masterKey)
	if err != nil {
		return err
	}
	var current []spendableKeyFile
	err = encoding.Unmarshal(w.dbTx.Bucket(bucketWallet).Get(keySpendableKeyFiles), &current)
	if err != nil {
		return err
	}
	return w.dbTx.Bucket(bucketWallet).Put(keySpendableKeyFiles, encoding.Marshal(append(current, skf)))
}
func (w *Wallet) loadSiagKeys(masterKey crypto.TwofishKey, keyfiles []string) error {
	if len(keyfiles) < 1 {
		return ErrNoKeyfile
	}
	skps := make([]siagKeyPair, len(keyfiles))
	for i, keyfile := range keyfiles {
		err := encoding.ReadFile(keyfile, &skps[i])
		if err != nil {
			return err
		}
		if skps[i].Header != SiagFileHeader {
			return ErrUnknownHeader
		}
		if skps[i].Version != SiagFileVersion {
			return ErrUnknownVersion
		}
	}
	baseUnlockHash := skps[0].UnlockConditions.UnlockHash()
	for _, skp := range skps {
		if skp.UnlockConditions.UnlockHash() != baseUnlockHash {
			return ErrInconsistentKeys
		}
	}
	if uint64(len(skps)) < skps[0].UnlockConditions.SignaturesRequired {
		return ErrInsufficientKeys
	}
	skps = skps[0:skps[0].UnlockConditions.SignaturesRequired]
	var sk spendableKey
	sk.UnlockConditions = skps[0].UnlockConditions
	for _, skp := range skps {
		sk.SecretKeys = append(sk.SecretKeys, skp.SecretKey)
	}
	err := w.loadSpendableKey(masterKey, sk)
	if err != nil {
		return err
	}
	w.integrateSpendableKey(masterKey, sk)
	return nil
}
func (w *Wallet) LoadSiagKeys(masterKey crypto.TwofishKey, keyfiles []string) error {
	if err := w.tg.Add(); err != nil {
		return err
	}
	defer w.tg.Done()
	err := func() error {
		w.mu.Lock()
		defer w.mu.Unlock()
		err := w.loadSiagKeys(masterKey, keyfiles)
		if err != nil {
			return err
		}
		if err = w.dbTx.DeleteBucket(bucketProcessedTransactions); err != nil {
			return err
		}
		if _, err = w.dbTx.CreateBucket(bucketProcessedTransactions); err != nil {
			return err
		}
		w.unconfirmedProcessedTransactions = nil
		err = dbPutConsensusChangeID(w.dbTx, modules.ConsensusChangeBeginning)
		if err != nil {
			return err
		}
		return dbPutConsensusHeight(w.dbTx, 0)
	}()
	if err != nil {
		return err
	}
	w.cs.Unsubscribe(w)
	w.tpool.Unsubscribe(w)
	done := make(chan struct{})
	go w.rescanMessage(done)
	defer close(done)
	err = w.cs.ConsensusSetSubscribe(w, modules.ConsensusChangeBeginning, w.tg.StopChan())
	if err != nil {
		return err
	}
	w.tpool.TransactionPoolSubscribe(w)
	return nil
}