{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "txs"
  ],
  "properties": {
    "txs": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "txid",
          "fees_paid_msat",
          "outputs"
        ],
        "properties": {
          "txid": {
            "type": "txid",
            "description": "transaction id"
          },
          "blockheight": {
            "type": "u32",
            "description": "Blockheight of transaction"
          },
          "fees_paid_msat": {
            "type": "msat",
            "description": "Amount paid in sats for this tx"
          },
          "outputs": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "account",
                "outnum",
                "output_value_msat",
                "currency"
              ],
              "additionalProperties": false,
              "properties": {
                "account": {
                  "type": "string",
                  "description": "Account this output affected"
                },
                "outnum": {
                  "type": "u32",
                  "description": "Index of output"
                },
                "output_value_msat": {
                  "type": "msat",
                  "description": "Value of the output"
                },
                "currency": {
                  "type": "string",
                  "description": "human-readable bech32 part for this coin type"
                },
                "credit_msat": {
                  "type": "msat",
                  "description": "Amount credited to account"
                },
                "debit_msat": {
                  "type": "msat",
                  "description": "Amount debited from account"
                },
                "originating_account": {
                  "type": "string",
                  "description": "Account this output originated from"
                },
                "output_tag": {
                  "type": "string",
                  "description": "Description of output creation event"
                },
                "spend_tag": {
                  "type": "string",
                  "description": "Description of output spend event"
                },
                "spending_txid": {
                  "type": "txid",
                  "description": "Transaction this output was spent in"
                },
                "payment_id": {
                  "type": "hex",
                  "description": "lightning payment identifier. For an htlc, this will be the preimage."
                }
              },
              "allOf": [
                {
                  "if": {
                    "required": [
                      "credit_msat"
                    ]
                  },
                  "then": {
                    "required": [
                      "output_tag"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "account": {},
                      "outnum": {},
                      "output_value_msat": {},
                      "currency": {},
                      "credit_msat": {},
                      "originating_account": {},
                      "debit_msat": {},
                      "output_tag": {},
                      "spend_tag": {},
                      "spending_txid": {},
                      "payment_id": {}
                    }
                  }
                },
                {
                  "if": {
                    "required": [
                      "spending_txid"
                    ]
                  },
                  "then": {
                    "required": [
                      "spend_tag",
                      "debit_msat"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "account": {},
                      "outnum": {},
                      "output_value_msat": {},
                      "currency": {},
                      "credit_msat": {},
                      "originating_account": {},
                      "debit_msat": {},
                      "output_tag": {},
                      "spend_tag": {},
                      "spending_txid": {},
                      "payment_id": {}
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
