コード例 #1
0
ファイル: util.go プロジェクト: 6londe/FactomCode
func exportECBlock(block *common.ECBlock) {
	if block == nil || procLog.Level() < factomlog.Info {
		return
	}

	data, err := block.MarshalBinary()
	if err != nil {
		panic(err)
	}

	strChainID := block.Header.ECChainID.String()
	if fileNotExists(dataStorePath + strChainID) {
		err := os.MkdirAll(dataStorePath+strChainID, 0777)
		if err == nil {
			procLog.Info("Created directory " + dataStorePath + strChainID)
		} else {
			procLog.Error(err)
		}
	}
	err = ioutil.WriteFile(fmt.Sprintf(dataStorePath+strChainID+"/store.%09d.block", block.Header.DBHeight), data, 0777)
	if err != nil {
		panic(err)
	}

}
コード例 #2
0
ファイル: ecblock.go プロジェクト: FactomProject/FactomCode
func (db *LevelDb) ProcessECBlockMultiBatch(block *common.ECBlock) error {
	if block == nil {
		return nil
	}

	if db.lbatch == nil {
		return fmt.Errorf("db.lbatch == nil")
	}

	binaryBlock, err := block.MarshalBinary()
	if err != nil {
		return err
	}

	// Insert the binary factom block
	var key = []byte{byte(TBL_CB)}
	hash, err := block.HeaderHash()
	if err != nil {
		return err
	}
	key = append(key, hash.Bytes()...)
	db.lbatch.Put(key, binaryBlock)

	// Insert block height cross reference
	var dbNumkey = []byte{byte(TBL_CB_NUM)}
	dbNumkey = append(dbNumkey, common.EC_CHAINID...)
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, block.Header.EBHeight)
	dbNumkey = append(dbNumkey, buf.Bytes()...)
	db.lbatch.Put(dbNumkey, hash.Bytes())
	//fmt.Println("ProcessECBlockBatch: key=", hex.EncodeToString(dbNumkey), ", hash=", hash)

	// Update the chain head reference
	key = []byte{byte(TBL_CHAIN_HEAD)}
	key = append(key, common.EC_CHAINID...)
	//hash, err = block.HeaderHash()
	//if err != nil {
	//return err
	//}
	db.lbatch.Put(key, hash.Bytes())

	return nil
}
コード例 #3
0
ファイル: ecblock.go プロジェクト: 6londe/FactomCode
// ProcessECBlockBatche inserts the ECBlock and update all it's cbentries in DB
func (db *LevelDb) ProcessECBlockBatch(block *common.ECBlock) error {

	if block != nil {
		if db.lbatch == nil {
			db.lbatch = new(leveldb.Batch)
		}

		defer db.lbatch.Reset()

		binaryBlock, err := block.MarshalBinary()
		if err != nil {
			return err
		}

		// Insert the binary factom block
		var key []byte = []byte{byte(TBL_CB)}
		hash, err := block.HeaderHash()
		if err != nil {
			return err
		}
		key = append(key, hash.Bytes()...)
		db.lbatch.Put(key, binaryBlock)

		// Update the chain head reference
		key = []byte{byte(TBL_CHAIN_HEAD)}
		key = append(key, common.EC_CHAINID...)
		hash, err = block.HeaderHash()
		if err != nil {
			return err
		}
		db.lbatch.Put(key, hash.Bytes())

		err = db.lDb.Write(db.lbatch, db.wo)
		if err != nil {
			log.Println("batch failed %v\n", err)
			return err
		}

	}
	return nil
}