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

Method getAck

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

Source from the content-addressed store, hash-verified

431}
432
433func (s *Service) getAck(dbID proto.DatabaseID, h *hash.Hash) (ack *types.SignedAckHeader, err error) {
434 var (
435 blockHeight int32
436 dataOffset int32
437 )
438
439 err = s.db.Writer().QueryRow(getAckByHashSQL, string(dbID), h.String()).Scan(&blockHeight, &dataOffset)
440 if err != nil {
441 if errors.Cause(err) == sql.ErrNoRows {
442 err = ErrNotFound
443 return
444 }
445
446 err = errors.Wrapf(err, "query ack failed: %s, %s", dbID, h.String())
447 return
448 }
449
450 // get data from block
451 var b *types.Block
452 if _, b, err = s.getBlockByHeight(dbID, blockHeight); err != nil {
453 return
454 }
455
456 if dataOffset < 0 || int32(len(b.Acks)) <= dataOffset {
457 err = ErrInconsistentData
458 return
459 }
460
461 ack = b.Acks[int(dataOffset)]
462
463 // verify hash
464 ackHash := ack.Hash()
465 if !ackHash.IsEqual(h) {
466 err = ErrInconsistentData
467 }
468
469 return
470}
471
472func (s *Service) getRequest(dbID proto.DatabaseID, h *hash.Hash) (request *types.Request, err error) {
473 var (

Callers 1

GetAckMethod · 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