Exemplo n.º 1
0
// FetchAllABlocks gets all of the admin blocks
func (db *LevelDb) FetchAllABlocks() (aBlocks []common.AdminBlock, err error) {
	db.dbLock.RLock()
	defer db.dbLock.RUnlock()
	var fromkey = []byte{byte(TBL_AB)}   // Table Name (1 bytes)						// Timestamp  (8 bytes)
	var tokey = []byte{byte(TBL_AB + 1)} // Table Name (1 bytes)
	var iter iterator.Iterator
	aBlockSlice := make([]common.AdminBlock, 0, 10)
	iter = db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		var aBlock common.AdminBlock
		_, err := aBlock.UnmarshalBinaryData(iter.Value())
		if err != nil {
			return nil, err
		}
		//TODO: to be optimized??
		_, err = aBlock.PartialHash()
		if err != nil {
			return nil, err
		}

		aBlockSlice = append(aBlockSlice, aBlock)

	}
	iter.Release()
	err = iter.Error()

	return aBlockSlice, nil
}
Exemplo n.º 2
0
// FetchAllFBlocks gets all of the factoid blocks
func (db *LevelDb) FetchAllFBlocks() (FBlocks []block.IFBlock, err error) {
	db.dbLock.RLock()
	defer db.dbLock.RUnlock()

	var fromkey = []byte{byte(TBL_SC)}   // Table Name (1 bytes)						// Timestamp  (8 bytes)
	var tokey = []byte{byte(TBL_SC + 1)} // Table Name (1 bytes)
	var iter iterator.Iterator
	FBlockSlice := make([]block.IFBlock, 0, 10)
	iter = db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		FBlock := new(block.FBlock)
		_, err := FBlock.UnmarshalBinaryData(iter.Value())
		if err != nil {
			return nil, err
		}

		FBlockSlice = append(FBlockSlice, FBlock)

	}
	iter.Release()
	err = iter.Error()

	return FBlockSlice, nil
}
Exemplo n.º 3
0
// FetchAllECBlocks gets all of the entry credit blocks
func (db *LevelDb) FetchAllECBlocks() (ecBlocks []common.ECBlock, err error) {
	db.dbLock.RLock()
	defer db.dbLock.RUnlock()

	var fromkey = []byte{byte(TBL_CB)}   // Table Name (1 bytes)						// Timestamp  (8 bytes)
	var tokey = []byte{byte(TBL_CB + 1)} // Table Name (1 bytes)
	ecBlockSlice := make([]common.ECBlock, 0, 10)
	var iter iterator.Iterator
	iter = db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)

	for iter.Next() {
		ecBlock := common.NewECBlock()
		_, err := ecBlock.UnmarshalBinaryData(iter.Value())
		if err != nil {
			return nil, err
		}
		ecBlockSlice = append(ecBlockSlice, *ecBlock)
	}
	iter.Release()
	err = iter.Error()

	return ecBlockSlice, nil
}