From b45b731c556b2dbd9b97a839d670ebaff5e438c5 Mon Sep 17 00:00:00 2001
From: Rusty Russell <rusty@rustcorp.com.au>
Date: Fri, 1 Apr 2022 14:43:34 +1030
Subject: [PATCH] doc/schemas: fixes for request schemas.

Types are fixed, in particular:

* rename "OutputDesc" to more consistent "outputdesc".
* rename "utxo" to more consistent "outpoint".
* it's "boolean" not "bool".
* "number" means int or float, usually it should be u32.

Specific commands:

* close `id` can be by channel id, scid.
* close `feerange` is a feerate type.
* datastore/deldatastore/listdatastore `key` can be singleton.
* delexpiredinvoice: `maxexpirytime` is not required, is a u64.
* invoice/delinvoice/listinvoice `label` can be an integer
* fundpsbt: many fields are u32 not number (JSON for int or float).
* invoice: `msatoshi` can be "any".
* invoice: `expiry` has a type (now must be numeric).
* invoice: `exposeprivatechannels` can be bool or array of scids.
* invoice: `deschashonly` added
* keysend: there's no "float" type, use "number" or "u32" etc.
* keysend: `routehints` is a valid arg, as is `extratlvs` (EXPERIMENTAL_FEATURES)
* listdatastore: `key` is not required.
* newaddr: `addresstype` can be "all"
* pay: `exemptfee` is "msat", new fields `locaofferid` and `exclude`
* sendonion: was mis-formatted, missed `localofferid` and `groupid` fields.
* sendpay: add `localofferid` and `groupid` params.
* signpsbt: add `signonly` param.
* txprepare "outptus" typo.
* waitsendpay: add `groupid` and  fix `partid` type.
* withdraw: `destination` is a bitcoin address, not a pubkey.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 contrib/pyln-testing/pyln/testing/utils.py |  7 ++-
 doc/schemas/close.request.json             | 10 ++--
 doc/schemas/connect.request.json           |  2 +-
 doc/schemas/datastore.request.json         | 21 +++++++--
 doc/schemas/deldatastore.request.json      | 17 +++++--
 doc/schemas/delexpiredinvoice.request.json |  6 +--
 doc/schemas/delinvoice.request.json        | 15 +++++-
 doc/schemas/fundpsbt.request.json          | 10 ++--
 doc/schemas/invoice.request.json           | 37 ++++++++++++---
 doc/schemas/keysend.request.json           | 45 ++++++++++++++++--
 doc/schemas/listdatastore.request.json     | 22 +++++----
 doc/schemas/listinvoices.request.json      | 12 ++++-
 doc/schemas/newaddr.request.json           |  3 +-
 doc/schemas/pay.request.json               | 22 +++++++--
 doc/schemas/sendonion.request.json         | 54 ++++++++++++----------
 doc/schemas/sendpay.request.json           |  6 +++
 doc/schemas/sendpsbt.request.json          |  2 +-
 doc/schemas/signpsbt.request.json          |  6 +++
 doc/schemas/txprepare.request.json         |  6 +--
 doc/schemas/utxopsbt.request.json          | 12 ++---
 doc/schemas/waitanyinvoice.request.json    |  4 +-
 doc/schemas/waitsendpay.request.json       |  9 ++--
 doc/schemas/withdraw.request.json          |  6 +--
 23 files changed, 241 insertions(+), 93 deletions(-)

diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py
index fe0637a99..fdde6caa1 100644
--- a/contrib/pyln-testing/pyln/testing/utils.py
+++ b/contrib/pyln-testing/pyln/testing/utils.py
@@ -1159,7 +1159,12 @@ class LightningNode(object):
             "cltv": cltv,
             "dev-routes": dev_routes,
         }
-        return self.rpc.call("invoice", payload)
+        # FIXME? dev options are not in schema
+        old_check = self.rpc.check_request_schemas
+        self.rpc.check_request_schemas = False
+        ret = self.rpc.call("invoice", payload)
+        self.rpc.check_request_schemas = old_check
+        return ret
 
 
 @contextmanager
diff --git a/doc/schemas/close.request.json b/doc/schemas/close.request.json
index 67480ff1e..1a6d8e0dc 100644
--- a/doc/schemas/close.request.json
+++ b/doc/schemas/close.request.json
@@ -7,8 +7,8 @@
   ],
   "properties": {
     "id": {
-      "type": "pubkey",
-      "description": ""
+      "type": "string",
+      "description": "peer id, channel id or short_channel_id"
     },
     "unilateraltimeout": {
       "type": "u32",
@@ -31,9 +31,9 @@
       "description": ""
     },
     "feerange": {
-      "type": {
-        "type": "array",
-        "items": "u32"
+      "type": "array",
+      "items": {
+        "type": "feerate"
       },
       "description": ""
     }
diff --git a/doc/schemas/connect.request.json b/doc/schemas/connect.request.json
index 72920c7ad..48303300b 100644
--- a/doc/schemas/connect.request.json
+++ b/doc/schemas/connect.request.json
@@ -7,7 +7,7 @@
   ],
   "properties": {
     "id": {
-      "type": "pubkey",
+      "type": "string",
       "description": ""
     },
     "host": {
diff --git a/doc/schemas/datastore.request.json b/doc/schemas/datastore.request.json
index f23105e39..d9c0a95e5 100644
--- a/doc/schemas/datastore.request.json
+++ b/doc/schemas/datastore.request.json
@@ -7,11 +7,22 @@
   ],
   "properties": {
     "key": {
-      "type": "array",
-      "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
-      "items": {
-        "type": "string"
-      }
+      "oneOf": [
+        {
+          "type": "array",
+          "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
+          "items": {
+            "type": "string"
+          }
+        },
+        {
+          "type": "string"
+        }
+      ]
+    },
+    "string": {
+      "type": "string",
+      "description": ""
     },
     "hex": {
       "type": "hex",
diff --git a/doc/schemas/deldatastore.request.json b/doc/schemas/deldatastore.request.json
index af73d1ac2..223674613 100644
--- a/doc/schemas/deldatastore.request.json
+++ b/doc/schemas/deldatastore.request.json
@@ -7,11 +7,18 @@
   ],
   "properties": {
     "key": {
-      "type": "array",
-      "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
-      "items": {
-        "type": "string"
-      }
+      "oneOf": [
+        {
+          "type": "array",
+          "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
+          "items": {
+            "type": "string"
+          }
+        },
+        {
+          "type": "string"
+        }
+      ]
     },
     "generation": {
       "type": "u64",
diff --git a/doc/schemas/delexpiredinvoice.request.json b/doc/schemas/delexpiredinvoice.request.json
index 7c86c8bc0..45ffc910e 100644
--- a/doc/schemas/delexpiredinvoice.request.json
+++ b/doc/schemas/delexpiredinvoice.request.json
@@ -2,12 +2,10 @@
   "$schema": "http://json-schema.org/draft-07/schema#",
   "type": "object",
   "additionalProperties": false,
-  "required": [
-    "maxexpirytime"
-  ],
+  "required": [],
   "properties": {
     "maxexpirytime": {
-      "type": "u32",
+      "type": "u64",
       "description": ""
     }
   }
diff --git a/doc/schemas/delinvoice.request.json b/doc/schemas/delinvoice.request.json
index f692129e0..1e2493839 100644
--- a/doc/schemas/delinvoice.request.json
+++ b/doc/schemas/delinvoice.request.json
@@ -8,8 +8,16 @@
   ],
   "properties": {
     "label": {
-      "type": "string",
-      "description": ""
+      "oneOf": [
+        {
+          "type": "string",
+          "description": ""
+        },
+        {
+          "type": "integer",
+          "description": ""
+        }
+      ]
     },
     "status": {
       "type": "string",
@@ -18,6 +26,9 @@
         "expired",
         "unpaid"
       ]
+    },
+    "desconly": {
+      "type": "boolean"
     }
   }
 }
diff --git a/doc/schemas/fundpsbt.request.json b/doc/schemas/fundpsbt.request.json
index 3bc156acf..f53d3f2d8 100644
--- a/doc/schemas/fundpsbt.request.json
+++ b/doc/schemas/fundpsbt.request.json
@@ -15,23 +15,23 @@
       "type": "feerate"
     },
     "startweight": {
-      "type": "number"
+      "type": "u32"
     },
     "minconf": {
-      "type": "number"
+      "type": "u32"
     },
     "reserve": {
-      "type": "number",
+      "type": "u32",
       "description": "reserve is a number: if non-zero number then reserveinputs is called (successfully, with exclusive true) on the returned PSBT for this number of blocks (default: 72)."
     },
     "locktime": {
-      "type": "number"
+      "type": "u32"
     },
     "min_witness_weight": {
       "type": "u32"
     },
     "excess_as_change": {
-      "type": "bool"
+      "type": "boolean"
     }
   }
 }
diff --git a/doc/schemas/invoice.request.json b/doc/schemas/invoice.request.json
index 34d40c267..a22cd12b0 100644
--- a/doc/schemas/invoice.request.json
+++ b/doc/schemas/invoice.request.json
@@ -9,7 +9,7 @@
   ],
   "properties": {
     "msatoshi": {
-      "type": "msat|any",
+      "type": "msat_or_any",
       "description": ""
     },
     "description": {
@@ -17,11 +17,19 @@
       "description": ""
     },
     "label": {
-      "type": "string",
-      "description": ""
+      "oneOf": [
+        {
+          "type": "string",
+          "description": ""
+        },
+        {
+          "type": "integer",
+          "description": ""
+        }
+      ]
     },
     "expiry": {
-      "type": "",
+      "type": "u64",
       "description": ""
     },
     "fallbacks": {
@@ -36,12 +44,29 @@
       "description": ""
     },
     "exposeprivatechannels": {
-      "type": "bool",
-      "description": ""
+      "oneOf": [
+        {
+          "type": "boolean",
+          "description": ""
+        },
+        {
+          "type": "array",
+          "items": {
+            "type": "short_channel_id"
+          }
+        },
+        {
+          "type": "short_channel_id"
+        }
+      ]
     },
     "cltv": {
       "type": "u32",
       "description": ""
+    },
+    "deschashonly": {
+      "type": "boolean",
+      "description": ""
     }
   }
 }
diff --git a/doc/schemas/keysend.request.json b/doc/schemas/keysend.request.json
index 022d18caa..fef9a5ab5 100644
--- a/doc/schemas/keysend.request.json
+++ b/doc/schemas/keysend.request.json
@@ -17,16 +17,55 @@
       "type": "string"
     },
     "maxfeepercent": {
-      "type": "float"
+      "type": "number"
     },
     "retry_for": {
-      "type": "number"
+      "type": "u32"
     },
     "maxdelay": {
-      "type": "number"
+      "type": "u32"
     },
     "exemptfee": {
       "type": "msat"
+    },
+    "routehints": {
+      "type": "array",
+      "items": {
+        "type": "array",
+        "items": {
+          "type": "object",
+          "additionalProperties": false,
+          "required": [
+            "id",
+            "scid",
+            "feebase",
+            "feeprop",
+            "expirydelta"
+          ],
+          "properties": {
+            "id": {
+              "type": "pubkey"
+            },
+            "scid": {
+              "type": "short_channel_id"
+            },
+            "feebase": {
+              "type": "msat"
+            },
+            "feeprop": {
+              "type": "u32"
+            },
+            "expirydelta": {
+              "type": "u16"
+            }
+          }
+        }
+      }
+    },
+    "extratlvs": {
+      "type": "object",
+      "additionalProperties": true,
+      "required": []
     }
   }
 }
diff --git a/doc/schemas/listdatastore.request.json b/doc/schemas/listdatastore.request.json
index a299a89d1..fc8175327 100644
--- a/doc/schemas/listdatastore.request.json
+++ b/doc/schemas/listdatastore.request.json
@@ -2,16 +2,22 @@
   "$schema": "http://json-schema.org/draft-07/schema#",
   "type": "object",
   "additionalProperties": false,
-  "required": [
-    "key"
-  ],
+  "required": [],
   "properties": {
     "key": {
-      "type": "array",
-      "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
-      "items": {
-        "type": "string"
-      }
+      "oneOf": [
+        {
+          "type": "array",
+          "description": "key is an array of values (though a single value is treated as a one-element array), to form a heirarchy. Using the first element of the key as the plugin name (e.g. [ 'summary' ]) is recommended. A key can either have children or a value, never both: parents are created and removed automatically.",
+          "items": {
+            "type": "string"
+          }
+        },
+        {
+          "type": "string",
+          "description": ""
+        }
+      ]
     }
   }
 }
diff --git a/doc/schemas/listinvoices.request.json b/doc/schemas/listinvoices.request.json
index 6c4bb01f6..dc22b5b04 100644
--- a/doc/schemas/listinvoices.request.json
+++ b/doc/schemas/listinvoices.request.json
@@ -5,8 +5,16 @@
   "required": [],
   "properties": {
     "label": {
-      "type": "string",
-      "description": ""
+      "oneOf": [
+        {
+          "type": "string",
+          "description": ""
+        },
+        {
+          "type": "integer",
+          "description": ""
+        }
+      ]
     },
     "invstring": {
       "type": "string",
diff --git a/doc/schemas/newaddr.request.json b/doc/schemas/newaddr.request.json
index 90caa5b15..7140f97bf 100644
--- a/doc/schemas/newaddr.request.json
+++ b/doc/schemas/newaddr.request.json
@@ -8,7 +8,8 @@
       "type": "string",
       "enum": [
         "bech32",
-        "p2sh-segwit"
+        "p2sh-segwit",
+        "all"
       ]
     }
   }
diff --git a/doc/schemas/pay.request.json b/doc/schemas/pay.request.json
index 1bbd5c507..d7bcb5f85 100644
--- a/doc/schemas/pay.request.json
+++ b/doc/schemas/pay.request.json
@@ -16,10 +16,10 @@
       "type": "string"
     },
     "riskfactor": {
-      "type": "float"
+      "type": "number"
     },
     "maxfeepercent": {
-      "type": "f32"
+      "type": "number"
     },
     "retry_for": {
       "type": "u16"
@@ -28,7 +28,23 @@
       "type": "u16"
     },
     "exemptfee": {
-      "type": "f32"
+      "type": "msat"
+    },
+    "localofferid": {
+      "type": "hex"
+    },
+    "exclude": {
+      "type": "array",
+      "items": {
+        "oneOf": [
+          {
+            "type": "short_channel_id_dir"
+          },
+          {
+            "type": "pubkey"
+          }
+        ]
+      }
     }
   }
 }
diff --git a/doc/schemas/sendonion.request.json b/doc/schemas/sendonion.request.json
index 36ac75f9d..531f68093 100644
--- a/doc/schemas/sendonion.request.json
+++ b/doc/schemas/sendonion.request.json
@@ -28,31 +28,37 @@
         "delay": {
           "type": "u16"
         }
-      },
-      "payment_hash": {
-        "type": "hex"
-      },
-      "label": {
-        "type": "string"
-      },
-      "shared_secrets": {
-        "type": "array",
-        "itemtype": {
-          "type": "hex"
-        }
-      },
-      "partid": {
-        "type": "u16"
-      },
-      "bolt11": {
-        "type": "string"
-      },
-      "msatoshi": {
-        "type": "msat"
-      },
-      "destination": {
-        "type": "pubkey"
       }
+    },
+    "payment_hash": {
+      "type": "hex"
+    },
+    "label": {
+      "type": "string"
+    },
+    "shared_secrets": {
+      "type": "array",
+      "items": {
+        "type": "hex"
+      }
+    },
+    "partid": {
+      "type": "u16"
+    },
+    "bolt11": {
+      "type": "string"
+    },
+    "msatoshi": {
+      "type": "msat"
+    },
+    "destination": {
+      "type": "pubkey"
+    },
+    "localofferid": {
+      "type": "hash"
+    },
+    "groupid": {
+      "type": "u64"
     }
   }
 }
diff --git a/doc/schemas/sendpay.request.json b/doc/schemas/sendpay.request.json
index 889eb8c9e..c8b854a9e 100644
--- a/doc/schemas/sendpay.request.json
+++ b/doc/schemas/sendpay.request.json
@@ -50,6 +50,12 @@
     },
     "partid": {
       "type": "u16"
+    },
+    "localofferid": {
+      "type": "hex"
+    },
+    "groupid": {
+      "type": "u64"
     }
   }
 }
diff --git a/doc/schemas/sendpsbt.request.json b/doc/schemas/sendpsbt.request.json
index 6d2c6acee..bc55bb830 100644
--- a/doc/schemas/sendpsbt.request.json
+++ b/doc/schemas/sendpsbt.request.json
@@ -10,7 +10,7 @@
       "type": "string"
     },
     "reserve": {
-      "type": "bool"
+      "type": "boolean"
     }
   }
 }
diff --git a/doc/schemas/signpsbt.request.json b/doc/schemas/signpsbt.request.json
index 1841440c9..c8a2bbf85 100644
--- a/doc/schemas/signpsbt.request.json
+++ b/doc/schemas/signpsbt.request.json
@@ -8,6 +8,12 @@
   "properties": {
     "psbt": {
       "type": "string"
+    },
+    "signonly": {
+      "type": "array",
+      "items": {
+        "type": "u32"
+      }
     }
   }
 }
diff --git a/doc/schemas/txprepare.request.json b/doc/schemas/txprepare.request.json
index b45075648..936c4d9e5 100644
--- a/doc/schemas/txprepare.request.json
+++ b/doc/schemas/txprepare.request.json
@@ -6,10 +6,10 @@
     "outputs"
   ],
   "properties": {
-    "outptus": {
+    "outputs": {
       "type": "array",
       "items": {
-        "type": "OutputDesc"
+        "type": "outputdesc"
       }
     },
     "feerate": {
@@ -21,7 +21,7 @@
     "utxos": {
       "type": "array",
       "items": {
-        "type": "utxo"
+        "type": "outpoint"
       }
     }
   }
diff --git a/doc/schemas/utxopsbt.request.json b/doc/schemas/utxopsbt.request.json
index 8fe22e6bf..1e1b07181 100644
--- a/doc/schemas/utxopsbt.request.json
+++ b/doc/schemas/utxopsbt.request.json
@@ -16,29 +16,29 @@
       "type": "feerate"
     },
     "startweight": {
-      "type": "number"
+      "type": "u32"
     },
     "utxos": {
       "type": "array",
       "items": {
-        "type": "utxo"
+        "type": "outpoint"
       }
     },
     "reserve": {
-      "type": "number",
+      "type": "u32",
       "description": "reserve is a number: if non-zero number then reserveinputs is called (successfully, with exclusive true) on the returned PSBT for this number of blocks (default: 72)."
     },
     "reservedok": {
-      "type": "bool"
+      "type": "boolean"
     },
     "locktime": {
-      "type": "number"
+      "type": "u32"
     },
     "min_witness_weight": {
       "type": "u32"
     },
     "excess_as_change": {
-      "type": "bool"
+      "type": "boolean"
     }
   }
 }
diff --git a/doc/schemas/waitanyinvoice.request.json b/doc/schemas/waitanyinvoice.request.json
index 826302319..5c9ce9867 100644
--- a/doc/schemas/waitanyinvoice.request.json
+++ b/doc/schemas/waitanyinvoice.request.json
@@ -5,10 +5,10 @@
   "required": [],
   "properties": {
     "lastpay_index": {
-      "type": "number"
+      "type": "u64"
     },
     "timeout": {
-      "type": "number"
+      "type": "u64"
     }
   }
 }
diff --git a/doc/schemas/waitsendpay.request.json b/doc/schemas/waitsendpay.request.json
index af3d9d2b4..e47340252 100644
--- a/doc/schemas/waitsendpay.request.json
+++ b/doc/schemas/waitsendpay.request.json
@@ -9,11 +9,14 @@
     "payment_hash": {
       "type": "hex"
     },
-    "partid": {
-      "type": "u16"
-    },
     "timeout": {
       "type": "u32"
+    },
+    "partid": {
+      "type": "u64"
+    },
+    "groupid": {
+      "type": "u64"
     }
   }
 }
diff --git a/doc/schemas/withdraw.request.json b/doc/schemas/withdraw.request.json
index 55ec64462..8a43b988f 100644
--- a/doc/schemas/withdraw.request.json
+++ b/doc/schemas/withdraw.request.json
@@ -7,10 +7,10 @@
   ],
   "properties": {
     "destination": {
-      "type": "pubkey"
+      "type": "string"
     },
     "satoshi": {
-      "type": "msat|all"
+      "type": "msat_or_all"
     },
     "feerate": {
       "type": "feerate"
@@ -21,7 +21,7 @@
     "utxos": {
       "type": "array",
       "items": {
-        "type": "utxo"
+        "type": "outpoint"
       }
     }
   }