MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / getResponseHeader

Method getResponseHeader

sqlchain/observer/service.go:511–548  ·  view source on GitHub ↗
(dbID proto.DatabaseID, h *hash.Hash)

Source from the content-addressed store, hash-verified

509}
510
511func (s *Service) getResponseHeader(dbID proto.DatabaseID, h *hash.Hash) (response *types.SignedResponseHeader, err error) {
512 var (
513 blockHeight int32
514 dataOffset int32
515 )
516
517 err = s.db.Writer().QueryRow(getResponseByHashSQL, string(dbID), h.String()).Scan(&blockHeight, &dataOffset)
518 if err != nil {
519 if errors.Cause(err) == sql.ErrNoRows {
520 err = ErrNotFound
521 return
522 }
523
524 err = errors.Wrapf(err, "query response failed: %s, %s", dbID, h.String())
525 return
526 }
527
528 // get data from block
529 var b *types.Block
530 if _, b, err = s.getBlockByHeight(dbID, blockHeight); err != nil {
531 return
532 }
533
534 if dataOffset < 0 || int32(len(b.QueryTxs)) <= dataOffset {
535 err = ErrInconsistentData
536 return
537 }
538
539 response = b.QueryTxs[int(dataOffset)].Response
540
541 // verify hash
542 respHash := response.Hash()
543 if !respHash.IsEqual(h) {
544 err = ErrInconsistentData
545 }
546
547 return
548}
549
550func (s *Service) getHighestBlock(dbID proto.DatabaseID) (height int32, b *types.Block, err error) {
551 var (

Callers 1

GetResponseMethod · 0.80

Calls 7

getBlockByHeightMethod · 0.95
QueryRowMethod · 0.80
WriterMethod · 0.65
HashMethod · 0.65
ScanMethod · 0.45
StringMethod · 0.45
IsEqualMethod · 0.45

Tested by

no test coverage detected