diff --git a/go/buscompose/names_test.go b/go/buscompose/names_test.go index da93c34..2f0b5cc 100644 --- a/go/buscompose/names_test.go +++ b/go/buscompose/names_test.go @@ -18,6 +18,12 @@ func TestTheBusNamesAgree(t *testing.T) { if LogStreamName("mesh-delivery-builder", "build-log") == "" || LogSubject("mesh-delivery-builder", "build-log") == "" { t.Fatal("a log has no stream or subject") } + // 1966/AC20: a ledger's history and snapshot subjects are one contract, which the grants part grants a ledger + // account its publish on. + if h, sn := LedgerHistorySubject("m", "records"), LedgerSnapshotSubject("m", "records"); h != "mesh.ledger.m.records.history" || + sn != "mesh.ledger.m.records.snapshot" { + t.Fatalf("a ledger's subjects are %q and %q", h, sn) + } // 1966/AC23: a wanted account of kind ledger for m on a names the user ledger.a.m and the own secret ledgers. ledger := WantedAccount{User: "ledger.a.m", Kind: KindLedger, Node: "a", Module: "m", URL: "nats://10.0.0.1:4222"} if got := (Principal{Kind: KindLedger, Node: "a", Module: "m"}).Username(); got != "ledger.a.m" { diff --git a/go/buscompose/nats.go b/go/buscompose/nats.go index c0f2618..f7f8ba8 100644 --- a/go/buscompose/nats.go +++ b/go/buscompose/nats.go @@ -50,6 +50,20 @@ const ( KindLedger Kind = "ledger" ) +// LedgerHistorySubject and LedgerSnapshotSubject are the subject prefixes of one ledger's history and of its instances' +// snapshots (novox/hq ADR 0597 §1, §8, §9): an instance's subject is the prefix, ".", and the instance's path with each +// "/" written "." (`decision/0290` is `….decision.0290`). One contract: the grants part grants a ledger account its +// publish on them, the tool runner appends and snapshots on them, and the bus module creates the history's stream over +// them. +func LedgerHistorySubject(module, local string) string { + return "mesh.ledger." + module + "." + local + ".history" +} + +// LedgerSnapshotSubject is the subject prefix of one ledger's instances' snapshots (LedgerHistorySubject). +func LedgerSnapshotSubject(module, local string) string { + return "mesh.ledger." + module + "." + local + ".snapshot" +} + // Seat is a role on the bus as a principal relates to it: the subjects it accepts, and those it // emits (novox/hq ADR 0118, design 29 §5). type Seat struct {