コード例 #1
0
ファイル: wallet.go プロジェクト: keepwalking1234/skycoin
func NewWalletRPC() *WalletRPC {
	rpc := WalletRPC{}

	//wallet directory
	//cleanup, pass as parameter during init

	DataDirectory := util.InitDataDir("")
	rpc.WalletDirectory = filepath.Join(DataDirectory, "wallets/")
	logger.Debug("Wallet Directory= %v", rpc.WalletDirectory)
	util.InitDataDir(rpc.WalletDirectory)

	rpc.Wallets = wallet.Wallets{}

	//util.InitDataDir(".skycoin")
	//util.InitDataDir(".skycoin/wallets")

	//if rpc.WalletDirectory != "" {
	w, err := wallet.LoadWallets(rpc.WalletDirectory)
	if err != nil {
		log.Panicf("Failed to load all wallets: %v", err)
	}
	rpc.Wallets = w
	//}
	if len(rpc.Wallets) == 0 {
		rpc.Wallets.Add(wallet.NewWallet("")) //deterministic
		if rpc.WalletDirectory != "" {
			errs := rpc.Wallets.Save(rpc.WalletDirectory)
			if len(errs) != 0 {
				log.Panicf("Failed to save wallets: %v", errs)
			}
		}
	}

	return &rpc
}
コード例 #2
0
ファイル: wallet.go プロジェクト: Chao-Jia/skycoin
func NewWalletRPC(walletDir string) *WalletRPC {
	rpc := &WalletRPC{}

	if err := os.MkdirAll(walletDir, os.FileMode(0700)); err != nil {
		log.Panicf("Failed to create wallet directory %s: %v", walletDir, err)
	}

	rpc.WalletDirectory = walletDir

	w, err := wallet.LoadWallets(rpc.WalletDirectory)
	if err != nil {
		log.Panicf("Failed to load all wallets: %v", err)
	}
	rpc.Wallets = w

	if len(rpc.Wallets) == 0 {
		rpc.Wallets.Add(wallet.NewWallet("")) //deterministic
		errs := rpc.Wallets.Save(rpc.WalletDirectory)
		if len(errs) != 0 {
			log.Panicf("Failed to save wallets to %s: %v", rpc.WalletDirectory, errs)
		}
	}

	return rpc
}
コード例 #3
0
ファイル: visor.go プロジェクト: JmAbuDabi/skycoin
// Loads & unloads wallets based on WalletDirectory contents
func (self *Visor) ReloadWallets() error {
	wallets, err := wallet.LoadWallets(self.Config.WalletDirectory)
	if err != nil {
		return err
	}
	self.Wallets = wallets
	return nil
}
コード例 #4
0
ファイル: wallet.go プロジェクト: keepwalking1234/skycoin
func (self *WalletRPC) ReloadWallets() error {
	wallets, err := wallet.LoadWallets(self.WalletDirectory)
	if err != nil {
		return err
	}
	self.Wallets = wallets
	return nil
}
コード例 #5
0
ファイル: wallet.go プロジェクト: skycoin/skycoin
// NewWalletRPC new wallet rpc
func NewWalletRPC(walletDir string, options ...wallet.Option) *WalletRPC {
	rpc := &WalletRPC{}
	if err := os.MkdirAll(walletDir, os.FileMode(0700)); err != nil {
		log.Panicf("Failed to create wallet directory %s: %v", walletDir, err)
	}

	rpc.WalletDirectory = walletDir
	for i := range options {
		rpc.Options = append(rpc.Options, options[i])
	}

	w, err := wallet.LoadWallets(rpc.WalletDirectory)
	if err != nil {
		log.Panicf("Failed to load all wallets: %v", err)
	}
	rpc.Wallets = w

	if len(rpc.Wallets) == 0 {
		wltName := wallet.NewWalletFilename()
		rpc.CreateWallet(wltName)

		if err := rpc.SaveWallet(wltName); err != nil {
			log.Panicf("Failed to save wallets to %s: %v", rpc.WalletDirectory, err)
		}

		// newWlt := wallet.NewWallet("", wltName, wltName) //deterministic
		// newWlt.GenerateAddresses(1)
		// rpc.Wallets.Add(newWlt)
		// errs := rpc.Wallets.Save(rpc.WalletDirectory)
		// if len(errs) != 0 {
		// 	log.Panicf("Failed to save wallets to %s: %v", rpc.WalletDirectory, errs)
		// }
	}

	return rpc
}
コード例 #6
0
ファイル: visor.go プロジェクト: JmAbuDabi/skycoin
// Creates a normal Visor given a master's public key
func NewVisor(c VisorConfig) *Visor {
	logger.Debug("Creating new visor")
	// Make sure inputs are correct
	if c.IsMaster {
		logger.Debug("Visor is master")
	}
	if c.IsMaster {
		if err := c.MasterKeys.Verify(); err != nil {
			log.Panicf("Invalid master wallet entry: %v", err)
		}
	} else {
		if err := c.MasterKeys.VerifyPublic(); err != nil {
			log.Panicf("Invalid master address or pubkey: %v", err)
		}
	}

	// Load the wallets
	wallets := wallet.Wallets{}
	if c.IsMaster {
		wallets = wallet.Wallets{CreateMasterWallet(c.MasterKeys)}
	} else {
		if c.WalletDirectory != "" {
			w, err := wallet.LoadWallets(c.WalletDirectory)
			if err != nil {
				log.Panicf("Failed to load all wallets: %v", err)
			}
			wallets = w
		}
		if len(wallets) == 0 {
			wallets.Add(c.WalletConstructor())
			if c.WalletDirectory != "" {
				errs := wallets.Save(c.WalletDirectory)
				if len(errs) != 0 {
					log.Panicf("Failed to save wallets: %v", errs)
				}
			}
		}
	}

	// Load the blockchain the block signatures
	blockchain := loadBlockchain(c.BlockchainFile, c.MasterKeys.Address)
	blockSigs, err := LoadBlockSigs(c.BlockSigsFile)
	if err != nil {
		if os.IsNotExist(err) {
			logger.Info("BlockSigsFile \"%s\" not found", c.BlockSigsFile)
		} else {
			log.Panicf("Failed to load BlockSigsFile \"%s\"", c.BlockSigsFile)
		}
		blockSigs = NewBlockSigs()
	}

	v := &Visor{
		Config:      c,
		blockchain:  blockchain,
		blockSigs:   blockSigs,
		Unconfirmed: NewUnconfirmedTxnPool(),
		Wallets:     wallets,
	}
	// Load the genesis block and sign it, if we need one
	if len(blockchain.Blocks) == 0 {
		v.CreateGenesisBlock()
	}
	err = blockSigs.Verify(c.MasterKeys.Public, blockchain)
	if err != nil {
		log.Panicf("Invalid block signatures: %v", err)
	}

	return v
}