carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package ledger
2
3import (
4 "context"
5 "errors"
6 "fmt"
7
8 "github.com/carlosframework/platform/internal/release"
9)
10
11func claimRawPutBlob(ctx context.Context, st release.Store, sqid, app, name string, body []byte) (string, error) {
12 if !ValidName(name) {
13 return "", fmt.Errorf("ledger: invalid ledger name %q", name)
14 }
15 if len(body) > MaxBlob {
16 return "", fmt.Errorf("ledger: blob %d bytes exceeds cap %d", len(body), MaxBlob)
17 }
18 sha := SHA256Hex(body)
19 if _, err := st.Put(ctx, BlobKey(sqid, app, name, sha), body, ""); err != nil {
20 // Content-addressed: an existing object with this key IS this
21 // content. A create-only conflict means it's already there.
22 if errors.Is(err, release.ErrCASConflict) {
23 return sha, nil
24 }
25 return "", err
26 }
27 return sha, nil
28}
29