Builds: design 47 G §15, §305 (a reader names a branch's source revision: SourceKey, the value SourceByBranchValue), §431 (the five verbs of release 6 leave the definition, so the list RemovedVerbs and its test go; the settle ask goes with the verb settle). Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
52 lines
2.1 KiB
Go
52 lines
2.1 KiB
Go
package meshdeliveryclient
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// A switched act is an act the gate owed before its switch to the delivery record (design 47 *The switch carries what is
|
|
// owed*): a key of the gate's state owed or merges that the old forge bridge had not performed. The gate says it as the
|
|
// event owed under an id made of the state, the key and its revision, so the new forge bridge counts it as performed when
|
|
// the old bridge's own bookkeeping names that key at that revision, and nothing is done twice. The form is
|
|
// `switched.<state>.<revision>.<key>`, the key last because it holds dots; it holds no `@`, which the gate's own ids hold,
|
|
// so the two never meet.
|
|
|
|
// The states a switched act comes from.
|
|
const (
|
|
SwitchedOwed = "owed"
|
|
SwitchedMerges = "merges"
|
|
)
|
|
|
|
const switchedPrefix = "switched."
|
|
|
|
// SwitchedActID is the id of the act the key of the state held at the revision.
|
|
func SwitchedActID(state, key string, revision uint64) (string, error) {
|
|
if state != SwitchedOwed && state != SwitchedMerges {
|
|
return "", fmt.Errorf("meshdeliveryclient: a switched act comes from the state owed or merges, not %q", state)
|
|
}
|
|
if key == "" || strings.Contains(key, "@") {
|
|
return "", fmt.Errorf("meshdeliveryclient: a switched act's key %q is empty or holds an @", key)
|
|
}
|
|
if revision == 0 {
|
|
return "", fmt.Errorf("meshdeliveryclient: a switched act's revision is 1 or more")
|
|
}
|
|
return switchedPrefix + state + "." + strconv.FormatUint(revision, 10) + "." + key, nil
|
|
}
|
|
|
|
// ParseSwitchedActID reads the state, the key and the revision out of a switched act's id; ok is false for any other id.
|
|
func ParseSwitchedActID(id string) (state, key string, revision uint64, ok bool) {
|
|
rest, found := strings.CutPrefix(id, switchedPrefix)
|
|
if !found || strings.Contains(id, "@") {
|
|
return "", "", 0, false
|
|
}
|
|
state, rest, _ = strings.Cut(rest, ".")
|
|
rev, key, _ := strings.Cut(rest, ".")
|
|
revision, err := strconv.ParseUint(rev, 10, 64)
|
|
if err != nil || revision == 0 || key == "" || (state != SwitchedOwed && state != SwitchedMerges) {
|
|
return "", "", 0, false
|
|
}
|
|
return state, key, revision, true
|
|
}
|