Ejemplo n.º 1
0
// FetchDirBlockInfoByKeyMR gets a dirblock info block by keyMR from the database.
func (db *Overlay) FetchDirBlockInfoByKeyMR(hash interfaces.IHash) (interfaces.IDirBlockInfo, error) {
	block, err := db.FetchBlock([]byte{byte(DIRBLOCKINFO_UNCONFIRMED)}, hash, dbInfo.NewDirBlockInfo())
	if err != nil {
		return nil, err
	}
	if block == nil {
		block, err = db.FetchBlock([]byte{byte(DIRBLOCKINFO)}, hash, dbInfo.NewDirBlockInfo())
		if err != nil {
			return nil, err
		}
		if block == nil {
			return nil, nil
		}
	}
	return block.(interfaces.IDirBlockInfo), nil
}
Ejemplo n.º 2
0
// FetchAllUnconfirmedDirBlockInfos gets all of the unconfirmed dirblock info blocks
func (db *Overlay) FetchAllUnconfirmedDirBlockInfos() ([]interfaces.IDirBlockInfo, error) {
	list, err := db.FetchAllBlocksFromBucket([]byte{byte(DIRBLOCKINFO_UNCONFIRMED)}, dbInfo.NewDirBlockInfo())
	if err != nil {
		return nil, err
	}
	return toDirBlockInfosList(list), nil
}
Ejemplo n.º 3
0
func CreateTestDirBlockInfo(prev *dbInfo.DirBlockInfo) *dbInfo.DirBlockInfo {
	dbi := dbInfo.NewDirBlockInfo()
	if prev == nil {
		dbi.DBHeight = 0
	} else {
		dbi.DBHeight = prev.DBHeight + 1
	}
	height := dbi.DBHeight

	dbi.DBHash.UnmarshalBinary(IntToByteSlice(int(height)))
	dbi.Timestamp = int64(height)
	dbi.BTCTxHash.UnmarshalBinary(IntToByteSlice(int(height)))
	dbi.BTCTxOffset = int32(int(height))
	dbi.BTCBlockHeight = int32(height)
	dbi.BTCBlockHash.UnmarshalBinary(IntToByteSlice(255 - int(height)))
	dbi.DBMerkleRoot.UnmarshalBinary(IntToByteSlice(255 - int(height)))
	dbi.BTCConfirmed = height%2 == 1

	return dbi
}
Ejemplo n.º 4
0
// FetchDirBlockInfoByHash gets a dirblock info block by hash from the database.
func (db *Overlay) FetchDirBlockInfoByHash(hash interfaces.IHash) (interfaces.IDirBlockInfo, error) {
	block, err := db.FetchBlockBySecondaryIndex(DIRBLOCKINFO_SECONDARYINDEX, DIRBLOCKINFO_UNCONFIRMED, hash, dbInfo.NewDirBlockInfo())
	if err != nil {
		return nil, err
	}
	if block == nil {
		block, err = db.FetchBlockBySecondaryIndex(DIRBLOCKINFO_SECONDARYINDEX, DIRBLOCKINFO, hash, dbInfo.NewDirBlockInfo())
		if err != nil {
			return nil, err
		}
		if block == nil {
			return nil, nil
		}
	}
	return block.(interfaces.IDirBlockInfo), nil
}