package console import ( "encoding/json" "fmt" "git.novox.be/novox/mesh-sdk/go/buscalls" "git.novox.be/novox/mesh-sdk/go/stateobjects" "github.com/novox/mesh-tools/node-tools/internal/bus" ) // resolveSent is the answer a person reads (ADR 0666 ยง16): an answer a module sent as a reference to an object of its // sent store is read from it when the bus grants this runner's account the read (the standing grant the manifests give // the callers of the verb), else shown as its reference with its size and why it was not read. func resolveSent(conn *bus.Conn, result json.RawMessage) (json.RawMessage, string) { ref, ok := stateobjects.ReadRef(result) if !ok { return result, "" } whole, err := stateobjects.Receive(result, func(r stateobjects.Ref) ([]byte, error) { got, err := conn.SentGet(buscalls.ObjectsSentGetRequest{Store: r.Store, Object: r.Object, Size: r.Size, Digest: r.Digest}) if err != nil { return nil, err } return got.Data, nil }) if err != nil { return result, fmt.Sprintf("the answer is %d bytes, held as the object %s of %s, and was not read: %v", ref.Size, ref.Object, ref.Store, err) } return whole, "" }