Skip to content

Commit

Permalink
Updated Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahanaFarooqui committed Dec 15, 2023
1 parent 1096e2e commit 27608da
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 83 deletions.
6 changes: 2 additions & 4 deletions doc/lightning-bkpr-listbalances.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ SYNOPSIS
DESCRIPTION
-----------

The **bkpr-listbalances** RPC command is a list of all current and historical account balances. An account is either the on-chain *wallet* or a channel balance.
Any funds sent to an *external* account will not be accounted for here.
The **bkpr-listbalances** RPC command is a list of all current and historical account balances. An account is either the on-chain *wallet* or a channel balance. Any funds sent to an *external* account will not be accounted for here.

Note that any channel that was recorded will be listed. Closed channel balances
will be 0msat.
Note that any channel that was recorded will be listed. Closed channel balances will be 0msat.

RETURN VALUE
------------
Expand Down
7 changes: 5 additions & 2 deletions doc/lightning-checkrune.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ On success, an object is returned, containing:

[comment]: # (GENERATE-FROM-SCHEMA-END)

ERRORS
------

The following error codes may occur:

- RUNE\_NOT\_AUTHORIZED (1501): rune is not for this node (or perhaps completely invalid)
Expand All @@ -34,8 +37,7 @@ The following error codes may occur:
AUTHOR
------

Shahana Farooqui <<[email protected]>> is mainly responsible
for consolidating logic from commando.
Shahana Farooqui <<[email protected]>> is mainly responsible for consolidating logic from commando.

SEE ALSO
--------
Expand All @@ -46,4 +48,5 @@ RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:977acf366f8fde1411f2c78d072b34b38b456e95381a6bce8fe6855a2d91434a)
3 changes: 3 additions & 0 deletions doc/lightning-commando.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ provided you with a *rune* which allows it.
RETURN VALUE
------------

[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, the return depends on the *method* invoked.

[comment]: # (GENERATE-FROM-SCHEMA-END)

ERRORS
------

Expand Down
7 changes: 3 additions & 4 deletions doc/lightning-decode.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,13 @@ SEE ALSO

lightning-pay(7), lightning-offer(7), lightning-fetchinvoice(7), lightning-sendinvoice(7), lightning-commando-rune(7)

RESOURCES
---------

[BOLT #11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)

[BOLT #12](https://github.com/rustyrussell/lightning-rfc/blob/guilt/offers/12-offer-encoding.md) (experimental, [bolt](https://github.com/lightning/bolts) #798)


RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:d62327dbe56d27e5e82d5ad2599d3d88495cc8360d84ff02fca59d08ab7fa14e)
5 changes: 2 additions & 3 deletions doc/lightning-decodepay.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ SEE ALSO

lightning-pay(7), lightning-getroute(7), lightning-sendpay(7).

[BOLT
\#11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md).

RESOURCES
---------

[BOLT #11](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md)

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:14c7dd565178078d7073e2837ad283a1e811affb5017e72c69e69d9f8c2baabd)
3 changes: 3 additions & 0 deletions doc/lightning-deldatastore.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ On success, an object is returned, containing:

[comment]: # (GENERATE-FROM-SCHEMA-END)

ERRORS
------

The following error codes may occur:

- 1200: the key does not exist
Expand Down
1 change: 1 addition & 0 deletions doc/lightning-delpay.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ EXAMPLE JSON REQUEST
}
```


RETURN VALUE
------------

Expand Down
15 changes: 5 additions & 10 deletions doc/lightning-emergencyrecover.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ SYNOPSIS
DESCRIPTION
-----------

The **emergencyrecover** RPC command fetches data from the emergency.recover
file and tries to reconnect to the peer and force him to close the channel.
The data in this file has enough information to reconnect and sweep the funds.
The **emergencyrecover** RPC command fetches data from the emergency.recover file and tries to reconnect to the peer and force him to close the channel. The data in this file has enough information to reconnect and sweep the funds.

This recovery method is not spontaneous and it depends on the peer, so it should
be used as a last resort to recover the funds stored in a channel in case of severe
data loss.
This recovery method is not spontaneous and it depends on the peer, so it should be used as a last resort to recover the funds stored in a channel in case of severe data loss.

RETURN VALUE
------------

On success, an object is returned, containing:

- **stubs** (array of hexs):
- Each item is the channel ID of the channel successfully inserted

- **stubs** (array of strings)
- Channel IDs of channels successfully inserted.

AUTHOR
------
Expand All @@ -41,4 +36,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:9cfaa9eb4609b36accc3e3b12a352c00ddd402307e4461f4df274146d12f6eb0)
[comment]: # ( SHA256STAMP:678c253c9bbd957d0d7f458d4697a66cad4cd7dc4c64b5f650e0e6a1c32d4c9f)
12 changes: 12 additions & 0 deletions doc/schemas/commando.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [],
"properties": {
"any": {
"type": "object",
"description": "the return depends on the *method* invoked"
}
}
}
2 changes: 1 addition & 1 deletion doc/schemas/delforward.request.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [],
"required": ["in_channel", "in_htlc_id", "status"],
"properties": {
"in_channel": {
"type": "short_channel_id"
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/emergencyrecover.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"stubs": {
"type": "array",
"items": {
"type": "string",
"type": "hex",
"description": "Channel IDs of channels successfully inserted."
}
}
Expand Down
79 changes: 39 additions & 40 deletions tools/fromschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,37 +288,6 @@ def output_params(schema):
output("\n")


def generate_from_request(schema):
props = schema["request"]["properties"]
toplevels = list(props.keys())
indent=""

output_title("SYNOPSIS")
output_params(schema)

if len(schema["request"]["properties"]) > 0:
output_title("METHOD PARAMETERS")
if toplevels == []:
sub = schema["request"]
elif len(toplevels) == 1 and "oneOf" in props[toplevels[0]] and isinstance(props[toplevels[0]]["oneOf"], list):
output("{}".format(fmt_propname(toplevels[0])))
output_type(props[toplevels[0]], False if toplevels[0] in schema["request"]["required"] else True)
output("\n")
indent = indent + " "
sub = props[toplevels[0]]
elif len(toplevels) == 1 and props[toplevels[0]]["type"] == "object":
output("{}\n".format(fmt_propname(toplevels[0])))
assert "description" not in toplevels[0]
sub = props[toplevels[0]]
elif len(toplevels) == 1 and props[toplevels[0]]["type"] == "array" and props[toplevels[0]]["items"]["type"] == "object":
output("{}\n".format(fmt_propname(toplevels[0])))
assert "description" not in toplevels[0]
sub = props[toplevels[0]]["items"]
else:
sub = schema["request"]
output_members(sub, indent)


def generate_from_response(schema):
"""This is not general, but works for us"""
output_title("RETURN VALUE")
Expand Down Expand Up @@ -374,46 +343,76 @@ def generate_from_response(schema):
outputs(["\n", "The following warnings may also be returned:\n\n"])
for w, desc in warnings:
output("- {}: {}".format(fmt_propname(w), desc))
output("\n")

if "post_return_value_notes" in response:
if warnings:
output("\n\n")
output("\n")
outputs(response["post_return_value_notes"], "\n")
output("\n")


def generate_header(schema):
output_title("".join(["lightning-", schema["rpc"], " -- ", schema["title"]]), "=", 0, 1)
output_title("SYNOPSIS")
output_params(schema)


def generate_request_details(schema):
def generate_from_request(schema):
request = schema["request"]
request_key_list = [key for key in list(request.keys()) if key not in ['required', 'properties']]
props = request["properties"]
toplevels = list(props.keys())
indent=""

for key in request_key_list:
output_title(key.replace("_", " ").upper())
if key == "description":
if "deprecated" in schema:
output("Command **deprecated, removal in {}**.\n\n".format(deprecated_to_deleted(schema["deprecated"])))
if "added" in schema:
output("Command *added* in {}.\n\n".format(schema["added"]))
outputs(request[key], "\n")
# Add single newline after the section
output("\n")
outputs(request[key], "\n")
if len(props) > 0:
output("\n\n")
if toplevels == []:
sub = schema["request"]
elif len(toplevels) == 1 and "oneOf" in props[toplevels[0]] and isinstance(props[toplevels[0]]["oneOf"], list):
output("{}".format(fmt_propname(toplevels[0])))
output_type(props[toplevels[0]], False if toplevels[0] in schema["request"]["required"] else True)
output("\n")
indent = indent + " "
sub = props[toplevels[0]]
elif len(toplevels) == 1 and props[toplevels[0]]["type"] == "object":
output("{}\n".format(fmt_propname(toplevels[0])))
assert "description" not in toplevels[0]
sub = props[toplevels[0]]
elif len(toplevels) == 1 and props[toplevels[0]]["type"] == "array" and props[toplevels[0]]["items"]["type"] == "object":
output("{}\n".format(fmt_propname(toplevels[0])))
assert "description" not in toplevels[0]
sub = props[toplevels[0]]["items"]
else:
sub = schema["request"]
output_members(sub, indent)
else:
output("\n")
else:
outputs(request[key], "\n")

def generate_footer(schema):
keys = list(schema.keys())
footer_key_list = [key for key in keys if key not in ['$schema', 'type', 'additionalProperties', 'rpc', 'title', 'request', 'response', 'added', 'deprecated']]
for key in footer_key_list:
output_title(key.replace("_", " ").upper(), "-", 2)
for i, key in enumerate(footer_key_list):
output_title(key.replace("_", " ").upper(), "-", 1 if i == 0 else 2)
outputs(schema[key], ", " if key in ['categories', 'see_also'] else "\n")
output("Main web site: <https://github.com/ElementsProject/lightning>\n\n")
output("\n\n")


def main(schemafile, markdownfile):
with open(schemafile, "r") as f:
schema = json.load(f)
generate_header(schema)
generate_from_request(schema)
generate_request_details(schema)
generate_from_response(schema)
generate_footer(schema)

Expand Down
Loading

0 comments on commit 27608da

Please sign in to comment.