Example #1
0
func createGenesisSignature(master wallet.WalletEntry) coin.Sig {
	c := visor.NewVisorConfig()
	bc := coin.NewBlockchain()
	gb := bc.CreateGenesisBlock(master.Address, c.GenesisTimestamp,
		c.GenesisCoinVolume)
	return coin.SignHash(gb.HashHeader(), master.Secret)
}
// Loads a blockchain but subdues errors into the logger, or panics.
// If no blockchain is found, it creates a new empty one
func loadBlockchain(filename string, genAddr coin.Address) *coin.Blockchain {
	bc := &coin.Blockchain{}
	created := false
	if filename != "" {
		var err error
		bc, err = LoadBlockchain(filename)
		if err == nil {
			if len(bc.Blocks) == 0 {
				log.Panic("Loaded empty blockchain")
			}
			loadedGenAddr := bc.Blocks[0].Body.Transactions[0].Out[0].Address
			if loadedGenAddr != genAddr {
				log.Panic("Configured genesis address does not match the " +
					"address in the blockchain")
			}
			created = true
		} else {
			if os.IsNotExist(err) {
				logger.Info("No blockchain file, will create a new blockchain")
			} else {
				log.Panicf("Failed to load blockchain file \"%s\": %v",
					filename, err)
			}
		}
	}
	if !created {
		bc = coin.NewBlockchain()
	}
	return bc
}
Example #3
0
// Returns a Visor with minimum initialization necessary for empty blockchain
// access
func NewMinimalVisor(c VisorConfig) *Visor {
	return &Visor{
		Config:      c,
		Blockchain:  coin.NewBlockchain(),
		blockSigs:   NewBlockSigs(),
		Unconfirmed: NewUnconfirmedTxnPool(),
		//Wallets:     nil,
	}
}
Example #4
0
//Skycoin transactions are smaller than Bitcoin transactions so skycoin has
//a higher transactions per second for the same block size
func NewBlockchain() Blockchain {
	//set pubkey based upon testnet, mainnet and local
	bc := Blockchain{

		IsMaster:    false, //writes blocks
		TestNetwork: true,

		//BlockCreationInterval:    15,
		//UnconfirmedCheckInterval: time.Minute * 5,
		//UnconfirmedMaxAge:        time.Hour * 48, //drop transaction not executed in 48 hours
		//UnconfirmedRefreshRate:   time.Minute * 30,
		//TransactionsPerBlock:     150, //10 transactions/second, 1.5 KB/s

		//BlockchainFile:           "",
		//BlockSigsFile:            "",

		SecKey: coin.SecKey{},
	}
	bc.Blocks = make([]SignedBlock, 0) //save blocks to disc and only store head block
	bc.blockchain = coin.NewBlockchain()
	bc.Unconfirmed = NewUnconfirmedTxnPool()
	return bc
}