// 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 }
// 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 }
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 }
// 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 }