J7 (1): the assigner, the teller and the view read a kept ask through the operator-channel client
Their three copies of the id and option checks (askjson.go checkedAsk, the teller's routerAskOf, the view's routerAsk) are deleted; each calls occ.Carried with the id the key and the asking give. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -28,8 +28,8 @@ func AskOf(a delivery.AssignerAsk) (oc.Ask, error) {
|
||||
return ask, nil
|
||||
}
|
||||
|
||||
// EncodeAsk is delivery.EncodeAssignerAsk at key, after the checks mesh-sdk no longer makes, since it cannot name the
|
||||
// router's ask (ADR 0627 §4): the ask's id is delivery.AskingID(key, asking), and it offers at least one option.
|
||||
// EncodeAsk is delivery.EncodeAssignerAsk at key, after the checks every keeper of an ask owes (occ.Carried, ADR 0627 §4):
|
||||
// the ask's id is delivery.AskingID(key, asking), and it offers at least one option.
|
||||
func EncodeAsk(key string, a delivery.AssignerAsk) ([]byte, error) {
|
||||
if _, err := checkedAsk(key, a); err != nil {
|
||||
return nil, err
|
||||
@@ -38,15 +38,9 @@ func EncodeAsk(key string, a delivery.AssignerAsk) ([]byte, error) {
|
||||
}
|
||||
|
||||
func checkedAsk(key string, a delivery.AssignerAsk) (oc.Ask, error) {
|
||||
ask, err := AskOf(a)
|
||||
ask, err := occ.Carried(a.Ask, delivery.AskingID(key, a.Asking))
|
||||
if err != nil {
|
||||
return oc.Ask{}, err
|
||||
}
|
||||
if want := delivery.AskingID(key, a.Asking); ask.ID != want {
|
||||
return oc.Ask{}, fmt.Errorf("assign: the ask's id %q is not the asking's %q", ask.ID, want)
|
||||
}
|
||||
if len(ask.Options) == 0 {
|
||||
return oc.Ask{}, fmt.Errorf("assign: the ask %q offers no option", ask.ID)
|
||||
return oc.Ask{}, fmt.Errorf("assign: %w", err)
|
||||
}
|
||||
return ask, nil
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/go/seats/operatorchannel"
|
||||
"slices"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
@@ -115,13 +116,13 @@ type assignerAsked struct {
|
||||
}
|
||||
|
||||
// decodeAssignerAsk reads the assigner's ask at key as delivery.DecodeAssignerAsk did before the ask was JSON: it refuses an
|
||||
// id other than the one the key and the asking give, and an ask with no option (routerAskOf).
|
||||
// id other than the one the key and the asking give, and an ask with no option (occ.Carried).
|
||||
func decodeAssignerAsk(key string, data []byte) (assignerAsked, error) {
|
||||
a, err := delivery.DecodeAssignerAsk(key, data)
|
||||
if err != nil {
|
||||
return assignerAsked{}, err
|
||||
}
|
||||
ask, err := routerAskOf(a.Ask, key, a.Asking)
|
||||
ask, err := occ.Carried(a.Ask, delivery.AskingID(key, a.Asking))
|
||||
if err != nil {
|
||||
return assignerAsked{}, err
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
occ "git.novox.be/novox/mesh-contracts/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/go/seats/operatorchannel"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/go/seats/operatorchannel"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
)
|
||||
@@ -32,22 +33,6 @@ type gateAsked struct {
|
||||
Ask oc.Ask
|
||||
}
|
||||
|
||||
// routerAskOf decodes the router's ask a gate or assigner value carries and holds it to what mesh-sdk refused before it
|
||||
// named no seat's types: an id other than the one the key and the asking give, and an ask with no option.
|
||||
func routerAskOf(raw json.RawMessage, key string, asking int) (oc.Ask, error) {
|
||||
var a oc.Ask
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return oc.Ask{}, fmt.Errorf("the value carries no router's ask: %w", err)
|
||||
}
|
||||
if want := delivery.AskingID(key, asking); a.ID != want {
|
||||
return oc.Ask{}, fmt.Errorf("the ask's id %q is not %q, the id its key and asking %d give", a.ID, want, asking)
|
||||
}
|
||||
if len(a.Options) == 0 {
|
||||
return oc.Ask{}, fmt.Errorf("the ask has no option")
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// decodeGateAsk reads the gate's ask value and the router's ask in it, as delivery.DecodeAsk did before the ask was JSON.
|
||||
func decodeGateAsk(value []byte) (gateAsked, error) {
|
||||
ga, err := delivery.DecodeAsk(value)
|
||||
@@ -58,7 +43,7 @@ func decodeGateAsk(value []byte) (gateAsked, error) {
|
||||
if err != nil {
|
||||
return gateAsked{}, err
|
||||
}
|
||||
a, err := routerAskOf(ga.Ask, key, ga.Asking)
|
||||
a, err := occ.Carried(ga.Ask, delivery.AskingID(key, ga.Asking))
|
||||
if err != nil {
|
||||
return gateAsked{}, err
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ func (m *Model) apply(e Entry) {
|
||||
a, err := delivery.DecodeAsk(e.Value)
|
||||
var ask oc.Ask
|
||||
if err == nil {
|
||||
ask, err = routerAsk(e.Key, a.Asking, a.Ask)
|
||||
ask, err = occ.Carried(a.Ask, delivery.AskingID(e.Key, a.Asking))
|
||||
}
|
||||
m.asks[e.Key] = askRecord{value: a, ask: ask, err: errText(err)}
|
||||
case delivery.AssignerAsksBucket:
|
||||
@@ -958,23 +958,6 @@ func (m *Model) askRows() []AskRow {
|
||||
return out
|
||||
}
|
||||
|
||||
// routerAsk reads the router's ask a gate's or an assigner's value carries (operator-channel's ask as JSON). mesh-sdk keeps
|
||||
// no check of what the ask says (novox/hq ADR 0627 section 4): its id is the asking's (AskingID of key and asking) and it
|
||||
// offers an option, as the old decoding refused.
|
||||
func routerAsk(key string, asking int, raw json.RawMessage) (oc.Ask, error) {
|
||||
var a oc.Ask
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return oc.Ask{}, fmt.Errorf("the router's ask is not readable: %w", err)
|
||||
}
|
||||
if want := delivery.AskingID(key, asking); a.ID != want {
|
||||
return oc.Ask{}, fmt.Errorf("the ask's id %q is not its asking's %q", a.ID, want)
|
||||
}
|
||||
if len(a.Options) == 0 {
|
||||
return oc.Ask{}, fmt.Errorf("the ask offers no option")
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// expiry is when the ask lapses; zero when it says none or says it unreadably.
|
||||
func expiry(a oc.Ask) time.Time {
|
||||
t, err := occ.Time(a.Expires)
|
||||
@@ -985,13 +968,13 @@ func expiry(a oc.Ask) time.Time {
|
||||
}
|
||||
|
||||
// decodeAssignerAsk reads a key of the assigner's asks (mesh-sdk go/delivery DecodeAssignerAsk): the router's ask under its
|
||||
// asking's id, offering an option.
|
||||
// asking's id, offering an option (occ.Carried).
|
||||
func decodeAssignerAsk(key string, value []byte) (oc.Ask, error) {
|
||||
a, err := delivery.DecodeAssignerAsk(key, value)
|
||||
if err != nil {
|
||||
return oc.Ask{}, fmt.Errorf("the assigner's ask %s is not readable: %w", key, err)
|
||||
}
|
||||
ask, err := routerAsk(key, a.Asking, a.Ask)
|
||||
ask, err := occ.Carried(a.Ask, delivery.AskingID(key, a.Asking))
|
||||
if err != nil {
|
||||
return oc.Ask{}, fmt.Errorf("the assigner's ask %s is not readable: %w", key, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user