Exemple #1
0
// NewMinimalVisor returns a Visor with minimum initialization necessary for empty blockchain
// access
func NewMinimalVisor(c VisorConfig) *Visor {
	return &Visor{
		Config:      c,
		blockSigs:   blockdb.NewBlockSigs(),
		Unconfirmed: NewUnconfirmedTxnPool(),
		//Wallets:     nil,
	}
}
Exemple #2
0
// NewVisor 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.BlockchainPubkey != cipher.PubKeyFromSecKey(c.BlockchainSeckey) {
			log.Panicf("Cannot run in master: invalid seckey for pubkey")
		}
	}

	db, err := historydb.NewDB()
	if err != nil {
		log.Panic(err)
	}

	history, err := historydb.New(db)
	if err != nil {
		log.Panic(err)
	}

	tree := blockdb.NewBlockTree()
	bc := NewBlockchain(tree, walker)

	bp := NewBlockchainParser(history, bc)
	bp.Start()

	bc.BindListener(bp.BlockListener)

	v := &Visor{
		Config:      c,
		Blockchain:  bc,
		blockSigs:   blockdb.NewBlockSigs(),
		Unconfirmed: NewUnconfirmedTxnPool(),
		history:     history,
		bcParser:    bp,
	}
	gb := bc.GetGenesisBlock()
	if gb == nil {
		v.GenesisPreconditions()
		b := v.Blockchain.CreateGenesisBlock(c.GenesisAddress, c.GenesisCoinVolume, c.GenesisTimestamp)
		gb = &b
		logger.Debug("create genesis block")

		// record the signature of genesis block
		if c.IsMaster {
			sb := v.SignBlock(*gb)
			v.blockSigs.Add(&sb)
		} else {
			v.blockSigs.Add(&coin.SignedBlock{
				Block: *gb,
				Sig:   c.GenesisSignature,
			})
		}
	}

	if err := v.Blockchain.VerifySigs(c.BlockchainPubkey, v.blockSigs); err != nil {
		log.Panicf("Invalid block signatures: %v", err)
	}

	// db, err := historydb.NewDB()
	// if err != nil {
	// 	log.Panic(err)
	// }

	// v.history, err = historydb.New(db)
	// if err != nil {
	// 	log.Panic(err)
	// }

	// init the blockchain parser instance
	// v.bcParser = NewBlockchainParser(v.history, v.Blockchain)
	// v.StartParser()
	return v
}