{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://multi-network-ws-api-specs.docs.alchemy.com/stellar-websocket/messages.schema.json",
  "title": "Stellar WebSocket requests and notifications",
  "description": "Public wire shapes. StrKey checksums and decoded XDR validity must also be checked. Unknown response fields are allowed.",
  "$defs": {
    "EmptyFilter": {
      "type": "object",
      "properties": {},
      "required": [],
      "additionalProperties": false
    },
    "EventFilter": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "contract",
            "system"
          ]
        },
        "contractIds": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^C[A-Z2-7]{55}$",
            "description": "Valid contract StrKey, including checksum."
          },
          "minItems": 1,
          "maxItems": 100
        },
        "topics": {
          "type": "array",
          "minItems": 1,
          "maxItems": 5,
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 4,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096,
              "description": "A base64 XDR segment or *. Encoded bytes must have a positive length divisible by four."
            }
          }
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "TransactionFilter": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "SUCCESS",
            "FAILED"
          ]
        },
        "accounts": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
            "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
          },
          "minItems": 1,
          "maxItems": 100
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "PaymentFilter": {
      "type": "object",
      "properties": {
        "accounts": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
            "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
          },
          "minItems": 1,
          "maxItems": 100
        },
        "from": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
            "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
          },
          "minItems": 1,
          "maxItems": 100
        },
        "to": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
            "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
          },
          "minItems": 1,
          "maxItems": 100
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "SubscribeParams": {
      "oneOf": [
        {
          "type": "array",
          "items": [
            {
              "const": "newLedgers"
            },
            {
              "$ref": "#/$defs/EmptyFilter"
            }
          ],
          "minItems": 1,
          "maxItems": 2,
          "additionalItems": false
        },
        {
          "type": "array",
          "items": [
            {
              "const": "events"
            },
            {
              "$ref": "#/$defs/EventFilter"
            }
          ],
          "minItems": 1,
          "maxItems": 2,
          "additionalItems": false
        },
        {
          "type": "array",
          "items": [
            {
              "const": "transactions"
            },
            {
              "$ref": "#/$defs/TransactionFilter"
            }
          ],
          "minItems": 1,
          "maxItems": 2,
          "additionalItems": false
        },
        {
          "type": "array",
          "items": [
            {
              "const": "payments"
            },
            {
              "$ref": "#/$defs/PaymentFilter"
            }
          ],
          "minItems": 1,
          "maxItems": 2,
          "additionalItems": false
        }
      ]
    },
    "UnsubscribeParams": {
      "type": "array",
      "items": [
        {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        }
      ],
      "minItems": 1,
      "maxItems": 1,
      "additionalItems": false
    },
    "Ledger": {
      "type": "object",
      "properties": {
        "sequence": {
          "type": "integer",
          "minimum": 0
        },
        "hash": {
          "type": "string"
        },
        "ledgerCloseTime": {
          "type": "string",
          "pattern": "^[0-9]+$",
          "description": "Unix seconds as a decimal string."
        },
        "headerXdr": {
          "type": "string",
          "description": "Base64 ledger header XDR."
        },
        "metadataXdr": {
          "type": "string",
          "description": "Base64 ledger metadata XDR."
        }
      },
      "required": [
        "sequence",
        "hash",
        "ledgerCloseTime",
        "headerXdr",
        "metadataXdr"
      ],
      "additionalProperties": true
    },
    "Event": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "description": "Event type; may include values beyond the contract/system filter choices."
        },
        "ledger": {
          "type": "integer",
          "minimum": 0
        },
        "ledgerClosedAt": {
          "type": "string",
          "description": "ISO-8601 ledger close timestamp."
        },
        "contractId": {
          "type": "string",
          "description": "Contract StrKey; can be empty or absent when there is no associated contract."
        },
        "id": {
          "type": "string"
        },
        "operationIndex": {
          "type": "integer",
          "minimum": 0
        },
        "transactionIndex": {
          "type": "integer",
          "minimum": 0
        },
        "txHash": {
          "type": "string"
        },
        "inSuccessfulContractCall": {
          "type": "boolean"
        },
        "topic": {
          "type": "array",
          "items": {
            "type": "string",
            "description": "Base64 XDR topic value."
          }
        },
        "value": {
          "type": "string",
          "description": "Base64 XDR event value."
        }
      },
      "required": [
        "type",
        "ledger",
        "id",
        "topic",
        "value"
      ],
      "additionalProperties": true
    },
    "Transaction": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "SUCCESS",
            "FAILED"
          ]
        },
        "txHash": {
          "type": "string"
        },
        "applicationOrder": {
          "type": "integer",
          "minimum": 0
        },
        "feeBump": {
          "type": "boolean"
        },
        "envelopeJson": {
          "type": "object",
          "description": "Stellar SEP-0051 transaction envelope union: tx, tx_v0, or tx_fee_bump."
        },
        "resultJson": {
          "type": "object"
        },
        "resultMetaJson": {
          "type": "object"
        },
        "events": {
          "type": "object"
        },
        "ledger": {
          "type": "integer",
          "minimum": 0
        },
        "createdAt": {
          "type": "integer",
          "description": "Unix seconds."
        }
      },
      "required": [
        "status",
        "txHash",
        "envelopeJson",
        "ledger",
        "createdAt"
      ],
      "additionalProperties": true
    },
    "Asset": {
      "oneOf": [
        {
          "const": "native"
        },
        {
          "type": "object",
          "properties": {
            "credit_alphanum4": {
              "type": "object",
              "properties": {
                "asset_code": {
                  "type": "string"
                },
                "issuer": {
                  "type": "string",
                  "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
                  "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
                }
              },
              "required": [
                "asset_code",
                "issuer"
              ],
              "additionalProperties": true
            }
          },
          "required": [
            "credit_alphanum4"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "credit_alphanum12": {
              "type": "object",
              "properties": {
                "asset_code": {
                  "type": "string"
                },
                "issuer": {
                  "type": "string",
                  "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
                  "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
                }
              },
              "required": [
                "asset_code",
                "issuer"
              ],
              "additionalProperties": true
            }
          },
          "required": [
            "credit_alphanum12"
          ],
          "additionalProperties": false
        }
      ]
    },
    "PaymentOperation": {
      "type": "object",
      "properties": {
        "destination": {
          "type": "string",
          "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
          "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
        },
        "asset": {
          "$ref": "#/$defs/Asset"
        },
        "amount": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Stellar integer units as a decimal string; classic assets use 7 decimal places."
        }
      },
      "required": [
        "destination",
        "asset",
        "amount"
      ],
      "additionalProperties": true
    },
    "StrictReceiveOperation": {
      "type": "object",
      "properties": {
        "send_asset": {
          "$ref": "#/$defs/Asset"
        },
        "send_max": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Stellar integer units as a decimal string; classic assets use 7 decimal places."
        },
        "destination": {
          "type": "string",
          "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
          "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
        },
        "dest_asset": {
          "$ref": "#/$defs/Asset"
        },
        "dest_amount": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Stellar integer units as a decimal string; classic assets use 7 decimal places."
        },
        "path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Asset"
          }
        }
      },
      "required": [
        "send_asset",
        "send_max",
        "destination",
        "dest_asset",
        "dest_amount",
        "path"
      ],
      "additionalProperties": true
    },
    "StrictSendOperation": {
      "type": "object",
      "properties": {
        "send_asset": {
          "$ref": "#/$defs/Asset"
        },
        "send_amount": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Stellar integer units as a decimal string; classic assets use 7 decimal places."
        },
        "destination": {
          "type": "string",
          "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
          "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
        },
        "dest_asset": {
          "$ref": "#/$defs/Asset"
        },
        "dest_min": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Stellar integer units as a decimal string; classic assets use 7 decimal places."
        },
        "path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Asset"
          }
        }
      },
      "required": [
        "send_asset",
        "send_amount",
        "destination",
        "dest_asset",
        "dest_min",
        "path"
      ],
      "additionalProperties": true
    },
    "Payment": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "ledger": {
              "type": "integer",
              "minimum": 0
            },
            "txHash": {
              "type": "string"
            },
            "createdAt": {
              "type": "integer",
              "description": "Unix seconds."
            },
            "operationIndex": {
              "type": "integer",
              "minimum": 0
            },
            "from": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "to": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "type": {
              "const": "payment"
            },
            "operation": {
              "$ref": "#/$defs/PaymentOperation"
            }
          },
          "required": [
            "ledger",
            "txHash",
            "createdAt",
            "operationIndex",
            "from",
            "to",
            "type",
            "operation"
          ],
          "additionalProperties": true
        },
        {
          "type": "object",
          "properties": {
            "ledger": {
              "type": "integer",
              "minimum": 0
            },
            "txHash": {
              "type": "string"
            },
            "createdAt": {
              "type": "integer",
              "description": "Unix seconds."
            },
            "operationIndex": {
              "type": "integer",
              "minimum": 0
            },
            "from": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "to": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "type": {
              "const": "path_payment_strict_receive"
            },
            "operation": {
              "$ref": "#/$defs/StrictReceiveOperation"
            }
          },
          "required": [
            "ledger",
            "txHash",
            "createdAt",
            "operationIndex",
            "from",
            "to",
            "type",
            "operation"
          ],
          "additionalProperties": true
        },
        {
          "type": "object",
          "properties": {
            "ledger": {
              "type": "integer",
              "minimum": 0
            },
            "txHash": {
              "type": "string"
            },
            "createdAt": {
              "type": "integer",
              "description": "Unix seconds."
            },
            "operationIndex": {
              "type": "integer",
              "minimum": 0
            },
            "from": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "to": {
              "type": "string",
              "pattern": "^(G[A-Z2-7]{55}|M[A-Z2-7]{68})$",
              "description": "Valid case-sensitive account StrKey, including checksum. M and G addresses match exactly."
            },
            "type": {
              "const": "path_payment_strict_send"
            },
            "operation": {
              "$ref": "#/$defs/StrictSendOperation"
            }
          },
          "required": [
            "ledger",
            "txHash",
            "createdAt",
            "operationIndex",
            "from",
            "to",
            "type",
            "operation"
          ],
          "additionalProperties": true
        }
      ]
    },
    "Notification": {
      "type": "object",
      "properties": {
        "jsonrpc": {
          "const": "2.0"
        },
        "method": {
          "const": "stellar_subscription"
        },
        "params": {
          "type": "object",
          "properties": {
            "subscription": {
              "type": "string"
            },
            "result": {
              "oneOf": [
                {
                  "$ref": "#/$defs/Ledger"
                },
                {
                  "$ref": "#/$defs/Event"
                },
                {
                  "$ref": "#/$defs/Transaction"
                },
                {
                  "$ref": "#/$defs/Payment"
                }
              ]
            }
          },
          "required": [
            "subscription",
            "result"
          ],
          "additionalProperties": true
        }
      },
      "required": [
        "jsonrpc",
        "method",
        "params"
      ],
      "additionalProperties": true
    },
    "SubscribeRequest": {
      "type": "object",
      "properties": {
        "jsonrpc": {
          "const": "2.0"
        },
        "id": {
          "type": [
            "integer",
            "string"
          ]
        },
        "method": {
          "const": "stellar_subscribe"
        },
        "params": {
          "$ref": "#/$defs/SubscribeParams"
        }
      },
      "required": [
        "jsonrpc",
        "id",
        "method",
        "params"
      ],
      "additionalProperties": true
    },
    "UnsubscribeRequest": {
      "type": "object",
      "properties": {
        "jsonrpc": {
          "const": "2.0"
        },
        "id": {
          "type": [
            "integer",
            "string"
          ]
        },
        "method": {
          "const": "stellar_unsubscribe"
        },
        "params": {
          "$ref": "#/$defs/UnsubscribeParams"
        }
      },
      "required": [
        "jsonrpc",
        "id",
        "method",
        "params"
      ],
      "additionalProperties": true
    }
  },
  "oneOf": [
    {
      "$ref": "#/$defs/SubscribeRequest"
    },
    {
      "$ref": "#/$defs/UnsubscribeRequest"
    },
    {
      "$ref": "#/$defs/Notification"
    }
  ]
}
