diff --git a/modules/mesh-delivery-assigner/internal/assign/asks_test.go b/modules/mesh-delivery-assigner/internal/assign/asks_test.go index d550f1fa..5264609f 100644 --- a/modules/mesh-delivery-assigner/internal/assign/asks_test.go +++ b/modules/mesh-delivery-assigner/internal/assign/asks_test.go @@ -147,7 +147,7 @@ func anAskEndedAtTheChannelIsReadAtBind(t *testing.T) { t.Error("with no ask held the channel is asked") } q, ok := ChannelAsksQuery(held) - if since, _ := q["since"].(string); !ok || q["state"] != "ended" || since != asked.Add(-time.Hour-time.Minute).Format(time.RFC3339) { + if !ok || q.State != "ended" || q.Bound != ChannelAsksBound || q.Since != asked.Add(-time.Hour-time.Minute).Format(time.RFC3339) { t.Errorf("the query is %v, want the ended asks since %s", q, asked.Add(-time.Hour-time.Minute).Format(time.RFC3339)) } at := func(key string, a asks.Ask, state string) string { diff --git a/modules/mesh-delivery-assigner/internal/assign/ended.go b/modules/mesh-delivery-assigner/internal/assign/ended.go index 8b5e4e7f..a59e1bbf 100644 --- a/modules/mesh-delivery-assigner/internal/assign/ended.go +++ b/modules/mesh-delivery-assigner/internal/assign/ended.go @@ -84,7 +84,7 @@ const ChannelAsksBound = 1 << 20 // every asking of its held asks (key to value, as the asks state holds them) that ended at the channel: the ended asks // opened since the earliest of them could have been opened, less a minute (issue 1966 note 155, ADR 0668 §4). ok is false // when no held ask reads, and then nothing is asked. -func ChannelAsksQuery(held map[string][]byte) (query map[string]any, ok bool) { +func ChannelAsksQuery(held map[string][]byte) (query oc.AsksInput, ok bool) { var since time.Time for key, value := range held { a, ask, err := DecodeAsk(key, value) @@ -102,19 +102,9 @@ func ChannelAsksQuery(held map[string][]byte) (query map[string]any, ok bool) { } } if !ok { - return nil, false + return oc.AsksInput{}, false } - return map[string]any{"state": "ended", "since": since.Add(-time.Minute).UTC().Format(time.RFC3339), "bound": ChannelAsksBound}, true -} - -// channelAsks is what the assigner reads of the verb asks' answer: each ask's key (".", the seat's state asks) -// and the state it ended with. -type channelAsks struct { - Asks []struct { - Key string `json:"key"` - State string `json:"state"` - } `json:"asks"` - Cut string `json:"cut"` + return oc.AsksInput{State: "ended", Since: since.Add(-time.Minute).UTC().Format(time.RFC3339), Bound: ChannelAsksBound}, true } // EndedAtChannel is, of the operator-channel seat's answer of its verb asks, each held ask whose asking ended there @@ -123,7 +113,7 @@ type channelAsks struct { // to it (issue 1966 note 155, ADR 0668 §4). cut is the answer's own cut, said by the caller; an answer that does not read // is the error. func EndedAtChannel(held map[string][]byte, answer []byte) (ended []tellerevents.Ended, cut string, err error) { - var got channelAsks + var got oc.AsksAnswer // the seat's declared answer: each ask's key and its state, and the cut if err := json.Unmarshal(answer, &got); err != nil { return nil, "", fmt.Errorf("assign: the operator channel's asks do not read: %w", err) }