Explorer

definy.submit-event

description
The RPC SubmitEvent: verify the signature of signedEventBytes, read the facts the rules use (whether the account was created, the accepted project snapshots) and continue with definy.submit-verified-event
type
Fn(request: @definy.json) -> @definy.service-io
expression
fn(request$1017) =>
  let signed_event_bytes$1019 = @definy.string-trim(
      value: match @definy.json-get-string(value: $1017, key: "signedEventBytes") {
        #some(text$1018) =>
          $1018,
        #none(_) =>
          ""
      }
    );
  match @core.equal(left: $1019, right: "") {
    true =>
      @definy.rpc-error(code: "invalid_argument", message: "signedEventBytes is required"),
    false =>
      @definy.verify-signed-event(
        signed_event_bytes: $1019,
        then: fn(result$1020) =>
          match $1020 {
            #invalid(message$1021) =>
              @definy.rpc-error(code: "invalid_argument", message: $1021),
            #valid(meta$1022) =>
              @definy.read-account-created(
                account_id: $1022.account_id,
                offset: 0,
                then: fn(created$1023) =>
                  match $1022.content {
                    #create_account(_) =>
                      @definy.submit-verified-event(
                        signed_event_bytes: $1019,
                        event: $1022,
                        facts: {account_id: $1022.account_id, account_created: $1023, commits: []}
                      ),
                    _ =>
                      @definy.read-snapshot-summaries(
                        then: fn(commits$1024) =>
                          @definy.submit-verified-event(
                            signed_event_bytes: $1019,
                            event: $1022,
                            facts: {account_id: $1022.account_id, account_created: $1023, commits: $1024}
                          )
                      )
                  }
              )
          }
      )
  }
visibility
public
definy.submit-event (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: nNPKDjsmk_PFkIUUSTZccTyLcgcVXaBuwX_tIs5MayA
content hash: G8KxgPdq8b-BCCwHp5stMrinvaMfoJ-wmDuk9Pak4Sw