Explorer

definy.submit-verified-event

description
The rest of SubmitEvent after verifying the signature: check the event with the rules (core.check-event) and the facts the server has, and if accepted, look for the contents missing from the CAS, check it with the type checker and store it. An accepted snapshot is also written to the snapshot cache (write_cached_commits) with the stored-snapshot decoded during the check and its light summary, so the next submit and the lists do not decode it again
type
Fn(signed_event_bytes: String, event: @definy.verified-event, facts: @core.event-check-facts) -> @definy.service-io
expression
fn(signed_event_bytes$0, event$1, facts$2) =>
  let rejections$3 = @core.check-event(content: $1.content, facts: $2);
  match @core.list-get(list: $3, index: 0) {
    #none(_) =>
      @definy.store-read-missing-content-hashes(
        content_hashes: $1.referenced_content_hashes,
        then: fn(missing$1024) =>
          match @core.list-get(list: $1024, index: 0) {
            #some(_) =>
              @definy.json-response(
                status: 200,
                body: #object<@definy.json>([
                  {key: "eventHash", value: #string<@definy.json>($1.event_hash)},
                  {key: "status", value: #string<@definy.json>("missing_content")},
                  {
                    key: "missingContentHashes",
                    value: #array<@definy.json>(@definy.json-string-array(items: $1024, index: 0))
                  }
                ])
              ),
            #none(_) =>
              @definy.check-snapshot(
                signed_event_bytes: $0,
                then: fn(errors$1025, commit$1027) =>
                  match @core.list-get(list: $1025, index: 0) {
                    #none(_) =>
                      @definy.store-write-event(
                        signed_event_bytes: $0,
                        event_hash: $1.event_hash,
                        account_id: $1.account_id,
                        event_type: @definy.event-type-name(content: $1.content),
                        time_ms: $1.time_ms,
                        then: fn(event_hash$1026) =>
                          match $1027 {
                            #none(_) =>
                              @definy.json-response(
                                status: 200,
                                body: #object<@definy.json>([
                                  {key: "eventHash", value: #string<@definy.json>($1026)},
                                  {key: "status", value: #string<@definy.json>("accepted")},
                                  {
                                    key: "missingContentHashes",
                                    value: #array<@definy.json>(@definy.json-string-array(items: [], index: 0))
                                  }
                                ])
                              ),
                            #some(_) =>
                              #write_cached_commits({
                                version: @definy.snapshot-cache-version,
                                entries: [
                                  {event_hash: $1.event_hash, commit: $1027},
                                  @definy.snapshot-cache-entry-summary(entry: {event_hash: $1.event_hash, commit: $1027})
                                ],
                                then: fn(written$1028) =>
                                  @definy.json-response(
                                    status: 200,
                                    body: #object<@definy.json>([
                                      {key: "eventHash", value: #string<@definy.json>($1026)},
                                      {key: "status", value: #string<@definy.json>("accepted")},
                                      {
                                        key: "missingContentHashes",
                                        value: #array<@definy.json>(@definy.json-string-array(items: [], index: 0))
                                      }
                                    ])
                                  )
                              })
                          }
                      ),
                    #some(_) =>
                      @definy.rpc-error(code: "invalid_argument", message: @definy.string-join-lines(items: $1025, index: 0, accum: ""))
                  }
              )
          }
      ),
    #some(_) =>
      @definy.rpc-error(code: "invalid_argument", message: @definy.event-rejection-lines(items: $3, index: 0, accum: ""))
  }
visibility
public
definy.submit-verified-event (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: QWK48BpgHekikbItyh6Kp6YoULrN8eVSREF66Bm9cG0
content hash: ktPlycyMi1z3vbickPgkEeUFGEqVftHXZ_VEgTTtmE4