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)
})
)
}
}
)