{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "events"
  ],
  "properties": {
    "events": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "account",
          "type",
          "tag",
          "credit_msat",
          "debit_msat",
          "currency",
          "timestamp"
        ],
        "properties": {
          "account": {
            "type": "string",
            "description": "The account name. If the account is a channel, the channel_id"
          },
          "type": {
            "type": "string",
            "enum": [
              "onchain_fee",
              "chain",
              "channel"
            ],
            "description": "Coin movement type"
          },
          "tag": {
            "type": "string",
            "description": "Description of movement"
          },
          "credit_msat": {
            "type": "msat",
            "description": "Amount credited"
          },
          "debit_msat": {
            "type": "msat",
            "description": "Amount debited"
          },
          "currency": {
            "type": "string",
            "description": "human-readable bech32 part for this coin type"
          },
          "timestamp": {
            "type": "u32",
            "description": "Timestamp this event was recorded by the node. For consolidated events such as onchain_fees, the most recent timestamp"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "chain"
                  ]
                }
              }
            },
            "then": {
              "properties": {
                "account": {},
                "type": {},
                "tag": {},
                "credit_msat": {},
                "debit_msat": {},
                "currency": {},
                "timestamp": {},
                "outpoint": {
                  "type": "string",
                  "description": "The txid:outnum for this event"
                },
                "blockheight": {
                  "type": "u32",
                  "description": "For chain events, blockheight this occured at"
                },
                "origin": {
                  "type": "string",
                  "description": "The account this movement originated from"
                },
                "payment_id": {
                  "type": "hex",
                  "description": "lightning payment identifier. For an htlc, this will be the preimage."
                },
                "txid": {
                  "type": "txid",
                  "description": "The txid of the transaction that created this event"
                },
                "description": {
                  "type": "string",
                  "description": "The description of this event"
                }
              },
              "required": [
                "outpoint",
                "blockheight"
              ],
              "additionalProperties": false
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "onchain_fee"
                  ]
                }
              }
            },
            "then": {
              "properties": {
                "account": {},
                "type": {},
                "tag": {},
                "credit_msat": {},
                "debit_msat": {},
                "currency": {},
                "timestamp": {},
                "description": {},
                "txid": {
                  "type": "txid",
                  "description": "The txid of the transaction that created this event"
                }
              },
              "required": [
                "txid"
              ],
              "additionalProperties": false
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "channel"
                  ]
                }
              }
            },
            "then": {
              "properties": {
                "account": {},
                "type": {},
                "tag": {},
                "credit_msat": {},
                "debit_msat": {},
                "currency": {},
                "timestamp": {},
                "description": {},
                "fees_msat": {
                  "type": "msat",
                  "description": "Amount paid in fees"
                },
                "is_rebalance": {
                  "type": "boolean",
                  "description": "Is this payment part of a rebalance"
                },
                "payment_id": {
                  "type": "hex",
                  "description": "lightning payment identifier. For an htlc, this will be the preimage."
                },
                "part_id": {
                  "type": "u32",
                  "description": "Counter for multi-part payments"
                }
              },
              "additionalProperties": false
            }
          }
        ]
      }
    }
  }
}
