Explorer

definy.mirror-submit

description
Stores a signed event that another server already accepted, checking only the signature and the contents (not the event rules or the types). A mirror (docs/html-ui.md) uses it instead of definy.submit-event. The response is the same JSON as SubmitEvent
type
Fn(request: @definy.json) -> @definy.service-io
expression
fn(request$0) =>
  let signed_event_bytes$1 = @definy.string-trim(
      value: match @definy.json-get-string(value: $0, key: "signedEventBytes") {
        #some(text$2) =>
          $2,
        #none(_) =>
          ""
      }
    );
  @definy.verify-signed-event(
    signed_event_bytes: $1,
    then: fn(result$3) =>
      match $3 {
        #invalid(message$4) =>
          @definy.rpc-error(code: "invalid_argument", message: $4),
        #valid(event$5) =>
          @definy.store-read-missing-content-hashes(
            content_hashes: $5.referenced_content_hashes,
            then: fn(missing$6) =>
              match @core.list-get(list: $6, index: 0) {
                #some(_) =>
                  @definy.json-response(
                    status: 200,
                    body: #object<@definy.json>([
                      {key: "eventHash", value: #string<@definy.json>($5.event_hash)},
                      {key: "status", value: #string<@definy.json>("missing_content")},
                      {
                        key: "missingContentHashes",
                        value: #array<@definy.json>(@definy.json-string-array(items: $6, index: 0))
                      }
                    ])
                  ),
                #none(_) =>
                  @definy.store-write-event(
                    signed_event_bytes: $1,
                    event_hash: $5.event_hash,
                    account_id: $5.account_id,
                    event_type: @definy.event-type-name(content: $5.content),
                    time_ms: $5.time_ms,
                    then: fn(event_hash$7) =>
                      @definy.json-response(
                        status: 200,
                        body: #object<@definy.json>([
                          {key: "eventHash", value: #string<@definy.json>($7)},
                          {key: "status", value: #string<@definy.json>("accepted")},
                          {
                            key: "missingContentHashes",
                            value: #array<@definy.json>(@definy.json-string-array(items: [], index: 0))
                          }
                        ])
                      )
                  )
              }
          )
      }
  )
visibility
public
definy.mirror-submit (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: TKWTl9YL9x94jJTKEk-1oyRrzOI3wa8NEb1epkjAEn8
content hash: ULjFHtmOMXC1Yf6royVfnopwIFyHL2eXIGCCW2G1i2s