Beispiel #1
0
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
}
Beispiel #2
0
func (self *Config) postProcess() {
	self.DataDirectory = util.InitDataDir(self.DataDirectory)
	if self.WebInterfaceCert == "" {
		self.WebInterfaceCert = filepath.Join(self.DataDirectory, "cert.pem")
	}
	if self.WebInterfaceKey == "" {
		self.WebInterfaceKey = filepath.Join(self.DataDirectory, "key.pem")
	}
	if self.MasterKeys == "" {
		self.MasterKeys = filepath.Join(self.DataDirectory, "master.keys")
	}
	if self.WalletFile == "" {
		self.WalletFile = filepath.Join(self.DataDirectory, "wallet.json")
	}
	if self.BlockchainFile == "" {
		self.BlockchainFile = filepath.Join(self.DataDirectory, "blockchain.bin")
	}
	if self.BlockSigsFile == "" {
		self.BlockSigsFile = filepath.Join(self.DataDirectory, "blockchain.sigs")
	}
	ll, err := logging.LogLevel(self.logLevel)
	if err != nil {
		log.Panic("Invalid -log-level %s: %v\n", self.logLevel, err)
	}
	self.LogLevel = ll
}
Beispiel #3
0
func (self *Config) postProcess() {

	//var GenesisSignatureStr string //only set if passed in command line arg
	//var GenesisAddressStr string   //only set if passed in command line arg
	//var BlockchainPubkeyStr string //only set if passed in command line arg
	//var BlockchainSeckeyStr string //only set if passed in command line arg

	var err error
	if GenesisSignatureStr != "" {
		self.GenesisSignature, err = cipher.SigFromHex(GenesisSignatureStr)
		if err != nil {
			log.Panic("Invalid Signature")
		}
	}
	if GenesisAddressStr != "" {
		self.GenesisAddress, err = cipher.DecodeBase58Address(GenesisAddressStr)
		if err != nil {
			log.Panic("Invalid Address")
		}
	}
	if BlockchainPubkeyStr != "" {
		self.BlockchainPubkey, err = cipher.PubKeyFromHex(BlockchainPubkeyStr)
		if err != nil {
			log.Panic("Invalid Pubkey")
		}
	}
	if BlockchainSeckeyStr != "" {
		self.BlockchainSeckey, err = cipher.SecKeyFromHex(BlockchainSeckeyStr)
		if err != nil {
			log.Panic("Invalid Seckey")
		}
		BlockchainSeckeyStr = ""
	}
	if BlockchainSeckeyStr != "" {
		self.BlockchainSeckey = cipher.SecKey{}
	}

	self.DataDirectory = util.InitDataDir(self.DataDirectory)
	if self.WebInterfaceCert == "" {
		self.WebInterfaceCert = filepath.Join(self.DataDirectory, "cert.pem")
	}
	if self.WebInterfaceKey == "" {
		self.WebInterfaceKey = filepath.Join(self.DataDirectory, "key.pem")
	}

	if self.BlockchainFile == "" {
		self.BlockchainFile = filepath.Join(self.DataDirectory, "blockchain.bin")
	}
	if self.BlockSigsFile == "" {
		self.BlockSigsFile = filepath.Join(self.DataDirectory, "blockchain.sigs")
	}
	if self.WalletDirectory == "" {
		self.WalletDirectory = filepath.Join(self.DataDirectory, "wallets/")
	}
	ll, err := logging.LogLevel(self.logLevel)
	if err != nil {
		log.Panic("Invalid -log-level %s: %v\n", self.logLevel, err)
	}
	self.LogLevel = ll
}
Beispiel #4
0
func (c *Config) postProcess() {
	var err error
	if GenesisSignatureStr != "" {
		c.GenesisSignature, err = cipher.SigFromHex(GenesisSignatureStr)
		panicIfError(err, "Invalid Signature")
	}
	if GenesisAddressStr != "" {
		c.GenesisAddress, err = cipher.DecodeBase58Address(GenesisAddressStr)
		panicIfError(err, "Invalid Address")
	}
	if BlockchainPubkeyStr != "" {
		c.BlockchainPubkey, err = cipher.PubKeyFromHex(BlockchainPubkeyStr)
		panicIfError(err, "Invalid Pubkey")
	}
	if BlockchainSeckeyStr != "" {
		c.BlockchainSeckey, err = cipher.SecKeyFromHex(BlockchainSeckeyStr)
		panicIfError(err, "Invalid Seckey")
		BlockchainSeckeyStr = ""
	}
	if BlockchainSeckeyStr != "" {
		c.BlockchainSeckey = cipher.SecKey{}
	}

	c.DataDirectory = util.InitDataDir(c.DataDirectory)
	if c.WebInterfaceCert == "" {
		c.WebInterfaceCert = filepath.Join(c.DataDirectory, "cert.pem")
	}
	if c.WebInterfaceKey == "" {
		c.WebInterfaceKey = filepath.Join(c.DataDirectory, "key.pem")
	}

	if c.BlockchainFile == "" {
		c.BlockchainFile = filepath.Join(c.DataDirectory, "blockchain.bin")
	}
	if c.BlockSigsFile == "" {
		c.BlockSigsFile = filepath.Join(c.DataDirectory, "blockchain.sigs")
	}
	if c.WalletDirectory == "" {
		c.WalletDirectory = filepath.Join(c.DataDirectory, "wallets/")
	}

	ll, err := logging.LogLevel(c.logLevel)
	panicIfError(err, "Invalid -log-level %s", c.logLevel)
	c.LogLevel = ll
}
Beispiel #5
0
func (c *Config) Parse() {
	// obtain values from flags
	c.fromFlags()
	// post process
	c.DataDirectory = util.InitDataDir(c.DataDirectory)
	// if HTTPS is turned off then cerk/key are never used
	if c.WebInterface.HTTPS == true {
		if c.WebInterface.Cert == "" {
			c.WebInterface.Cert = filepath.Join(c.DataDirectory, "cert.pem")
		}
		if c.WebInterface.Key == "" {
			c.WebInterface.Key = filepath.Join(c.DataDirectory, "key.pem")
		}
	}

	// initialize logger
	c.Log.InitLogger()
}