| 1 | package ledger |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/release" |
| 9 | ) |
| 10 | |
| 11 | // Each ledger writer runs as one app mutation of sqid/app: the HEAD read, the |
| 12 | // chained entry and the HEAD CAS (or the blob, or the manifest swap) share one |
| 13 | // admitted operation on an enabled console store. Ordinary stores do not |
| 14 | // implement release.AppMutationRunner, so on boxes and with host claims off |
| 15 | // each writer runs its original body unchanged. |
| 16 | |
| 17 | // Append is claimRawAppend under the app mutation of sqid/app. |
| 18 | func Append(ctx context.Context, st release.Store, sqid, app, name, writer string, |
| 19 | payload json.RawMessage, now func() time.Time) (Appended, error) { |
| 20 | var a Appended |
| 21 | err := release.WithAppMutation(ctx, st, sqid, app, "ledger.Append", func(ctx context.Context) error { |
| 22 | var err error |
| 23 | a, err = claimRawAppend(ctx, st, sqid, app, name, writer, payload, now) |
| 24 | return err |
| 25 | }) |
| 26 | return a, err |
| 27 | } |
| 28 | |
| 29 | // PutBlob is claimRawPutBlob under the app mutation of sqid/app. |
| 30 | func PutBlob(ctx context.Context, st release.Store, sqid, app, name string, body []byte) (string, error) { |
| 31 | var sha string |
| 32 | err := release.WithAppMutation(ctx, st, sqid, app, "ledger.PutBlob", func(ctx context.Context) error { |
| 33 | var err error |
| 34 | sha, err = claimRawPutBlob(ctx, st, sqid, app, name, body) |
| 35 | return err |
| 36 | }) |
| 37 | return sha, err |
| 38 | } |
| 39 | |
| 40 | // UpdateManifest is claimRawUpdateManifest under the app mutation of sqid/app. |
| 41 | func UpdateManifest(ctx context.Context, st release.Store, sqid, app string, |
| 42 | apply func(*Manifest) error) (Manifest, error) { |
| 43 | var m Manifest |
| 44 | err := release.WithAppMutation(ctx, st, sqid, app, "ledger.UpdateManifest", func(ctx context.Context) error { |
| 45 | var err error |
| 46 | m, err = claimRawUpdateManifest(ctx, st, sqid, app, apply) |
| 47 | return err |
| 48 | }) |
| 49 | return m, err |
| 50 | } |
| 51 | |