Explorer

definy.accept-submit-event

description
SubmitEvent of definy.handle-event-service: after verifying the signature, rejects (permission_denied) an event whose account is not in accept_accounts, unless accept_any_account is true (the public server accepts every account: accounts made in the browser of html-ui, and their snapshots). Then it allows the upload of the contents of the event that the store does not have yet (the table upload_allowances, which definy.accept-upload-content reads) and continues with definy.submit-event (the same check as the public server: signature, rules, types)
type
Fn(request: @definy.json, accept_accounts: List<String>, accept_any_account: Boolean) -> @definy.service-io
expression
fn(request$0, accept_accounts$1, accept_any_account$8) =>
  @definy.verify-signed-event(
    signed_event_bytes: @definy.string-trim(
      value: match @definy.json-get-string(value: $0, key: "signedEventBytes") {
        #some(text$2) =>
          $2,
        #none(_) =>
          ""
      }
    ),
    then: fn(result$3) =>
      match $3 {
        #invalid(message$4) =>
          @definy.rpc-error(code: "invalid_argument", message: $4),
        #valid(event$5) =>
          match @core.or(left: $8, right: @definy.strings-contain(items: $1, value: $5.account_id, index: 0)) {
            false =>
              @definy.rpc-error(
                code: "permission_denied",
                message: @core.string-concat(left: "This server accepts only the events of its own accounts, not of ", right: $5.account_id)
              ),
            true =>
              @definy.store-read-missing-content-hashes(
                content_hashes: $5.referenced_content_hashes,
                then: fn(missing$6) =>
                  #sql<@definy.service-io>({
                    statements: [
                      {sql: "CREATE TABLE IF NOT EXISTS upload_allowances (content_hash TEXT PRIMARY KEY)", params: []},
                      {
                        sql: "INSERT OR IGNORE INTO upload_allowances (content_hash) SELECT value FROM json_each(?)",
                        params: [
                          #text<@definy.sql-value>(@definy.json-to-string(value: #array<@definy.json>(@definy.json-string-array(items: $6, index: 0))))
                        ]
                      }
                    ],
                    then: fn(results$7) =>
                      @definy.submit-event(request: $0)
                  })
              )
          }
      }
  )
visibility
public
definy.accept-submit-event (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: 7OJl7wiTRJeex98GHG-T5qhhVNvdigRGyKdfqRoH7q4
content hash: 6D77tknJhpnLLREyYI_-5zofEFPtk2DK_Z_FXWPpJIY