Explorer

definy.get-event

description
The RPC GetEvent: the stored event with eventHash (spaces at both ends are ignored). invalid_argument without eventHash, not_found if it is not stored
type
Fn(request: @definy.json) -> @definy.service-io
expression
fn(request$0) =>
  let hash$1 = @definy.string-trim(
      value: match @definy.json-get-string(value: $0, key: "eventHash") {
        #some(text$2) =>
          $2,
        #none(_) =>
          ""
      }
    );
  match @core.equal(left: $1, right: "") {
    true =>
      @definy.rpc-error(code: "invalid_argument", message: "eventHash is required"),
    false =>
      @definy.store-read-events(
        event_hashes: [$1],
        then: fn(events$3) =>
          match @core.list-get(list: $3, index: 0) {
            #none(_) =>
              @definy.rpc-error(
                code: "not_found",
                message: @core.string-concat(left: @core.string-concat(left: "Event '", right: $1), right: "' not found")
              ),
            #some(element$2005) =>
              match $2005 {
                #none(_) =>
                  @definy.rpc-error(
                    code: "not_found",
                    message: @core.string-concat(left: @core.string-concat(left: "Event '", right: $1), right: "' not found")
                  ),
                #some(event$4) =>
                  @definy.json-response(
                    status: 200,
                    body: #object<@definy.json>([{key: "event", value: @definy.stored-event-json(event: $4)}])
                  )
              }
          }
      )
  }
visibility
public
definy.get-event (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: pBDffK0L15KBi-uxNjZ_5nT0yfD8yl5WJ7L16oDmmnM
content hash: 7FJlC2bnh9xhDfJ8XV688d-DVGSk6OxzxcOchhMYopo