Files
mtusi2026lab7/internal/attachment/lock.go
T
kudesn1k 8054913ef9
Application / e2e (pull_request) Blocked by required conditions
Application / unit (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Перенеси реализацию мессенджера из ЛР 6
Источник — проверенное рабочее дерево ЛР 6 поверх 18878d6, включая изменения после повторного ревью. SHA-256 списка исходных файлов: e45a3d85b41feff1da78dce3f20fd1f4af1c5ee629e6ed703218bc8e21ad58fe.
2026-11-30 10:54:41 +03:00

24 lines
655 B
Go

package attachment
import (
"context"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
"github.com/jackc/pgx/v5"
)
// LockHash serializes CAS publication and collection until the transaction ends.
// A collision in the signed first eight digest bytes only adds serialization.
func LockHash(ctx context.Context, tx pgx.Tx, hash []byte) error {
if len(hash) != sha256.Size {
return errors.New("attachment: lock requires a SHA256 hash")
}
_, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock($1)`, int64(binary.BigEndian.Uint64(hash[:8])))
return err
}
func BlobKey(hash []byte) string { return "blobs/" + hex.EncodeToString(hash) }