Exemple #1
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
}
Exemple #2
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
}
Exemple #3
0
func TransactionFromJSON(str string) (coin.Transaction, error) {

	var TxIn TransactionJSON
	err := json.Unmarshal([]byte(str), TxIn)

	if err != nil {
		errors.New("cannot deserialize")
	}

	var tx coin.Transaction

	tx.Sigs = make([]cipher.Sig, len(TxIn.Sigs))
	tx.In = make([]cipher.SHA256, len(TxIn.In))
	tx.Out = make([]coin.TransactionOutput, len(TxIn.Out))

	for i, _ := range tx.Sigs {
		sig2, err := cipher.SigFromHex(TxIn.Sigs[i])
		if err != nil {
			return coin.Transaction{}, errors.New("invalid signature")
		}
		tx.Sigs[i] = sig2
	}

	for i, _ := range tx.In {
		hash, err := cipher.SHA256FromHex(TxIn.In[i])
		if err != nil {
			return coin.Transaction{}, errors.New("invalid signature")
		}
		tx.In[i] = hash
	}

	for i, _ := range tx.Out {
		out, err := TransactionOutputFromJSON(TxIn.Out[i])
		if err != nil {
			return coin.Transaction{}, errors.New("invalid output")
		}
		tx.Out[i] = out
	}

	tx.Length = uint32(tx.Size())
	tx.Type = 0

	hash, err := cipher.SHA256FromHex(TxIn.Hash)
	if err != nil {
		return coin.Transaction{}, errors.New("invalid hash")
	}
	if hash != tx.Hash() {

	}

	InnerHash, err := cipher.SHA256FromHex(TxIn.Hash)

	if InnerHash != tx.InnerHash {
		return coin.Transaction{}, errors.New("inner hash")
	}

	err = tx.Verify()
	if err != nil {
		return coin.Transaction{}, errors.New("transaction failed verification")
	}

	return tx, nil
}