Skip to content

Commit

Permalink
rpc: improve error format
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jul 3, 2022
1 parent b548578 commit cf7617e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 67 deletions.
11 changes: 3 additions & 8 deletions doc/lightning-checkmessage.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ RETURN VALUE

[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object is returned, containing:
- **verified** (boolean): Whether the signature was valid

If **verified** is *true*:
- **pubkey** (pubkey): the *pubkey* parameter, or the pubkey found by looking for known nodes

If **verified** is *false*:
- **pubkey** (pubkey): the *pubkey* (if any) which could have signed this; this is usually not useful!
- **verified** (boolean): whether the signature was valid (always *true*)
- **pubkey** (pubkey): the *pubkey* parameter, or the pubkey found by looking for known nodes

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

Expand All @@ -54,4 +49,4 @@ RESOURCES

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

[comment]: # ( SHA256STAMP:6df0e61e28118786861aacc073e3289268fe1b00837c3fd02a537aa13e5acae5)
[comment]: # ( SHA256STAMP:af2feeb4eddafc509dff150ec4b11225618f1cbbea06ef81f6d97a1bece3e94c)
66 changes: 11 additions & 55 deletions doc/schemas/checkmessage.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,21 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"verified"
"verified",
"pubkey"
],
"additionalProperties": true,
"additionalProperties": false,
"properties": {
"verified": {
"type": "boolean",
"description": "Whether the signature was valid"
}
},
"allOf": [
{
"if": {
"properties": {
"verified": {
"type": "boolean",
"enum": [
true
]
}
}
},
"then": {
"additionalProperties": false,
"required": [
"pubkey"
],
"properties": {
"verified": {},
"pubkey": {
"type": "pubkey",
"description": "the *pubkey* parameter, or the pubkey found by looking for known nodes"
}
}
}
"enum": [
true
],
"description": "whether the signature was valid"
},
{
"if": {
"properties": {
"verified": {
"type": "boolean",
"enum": [
false
]
}
}
},
"then": {
"additionalProperties": false,
"required": [
"pubkey"
],
"properties": {
"verified": {},
"pubkey": {
"type": "pubkey",
"description": "the *pubkey* (if any) which could have signed this; this is usually not useful!"
}
}
}
"pubkey": {
"type": "pubkey",
"description": "the *pubkey* parameter, or the pubkey found by looking for known nodes"
}
]
}
}
9 changes: 6 additions & 3 deletions lightningd/signmessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ static void listnodes_done(const char *buffer,
t = json_get_member(buffer, t, "nodes");

if (!deprecated_apis && (!t || t->size == 0)) {
was_pending(command_fail(can->cmd, SIGNMESSAGE_PUBKEY_NOT_FOUND,
"pub key not found in the graph, expected pubkey is %s",
node_id_to_hexstr(tmpctx, &can->id)));
struct json_stream *response;
response = json_stream_fail(can->cmd, SIGNMESSAGE_PUBKEY_NOT_FOUND,
"pubkey not found in the graph");
json_add_node_id(response, "claimed_key", &can->id);
json_object_end(response);
was_pending(command_failed(can->cmd, response));
return;
}
response = json_stream_success(can->cmd);
Expand Down
5 changes: 4 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2661,8 +2661,11 @@ def test_checkmessage_pubkey_not_found(node_factory):
pubkey = "03be3b0e9992153b1d5a6e1623670b6c3663f72ce6cf2e0dd39c0a373a7de5a3b7"
zbase = "d66bqz3qsku5fxtqsi37j11pci47ydxa95iusphutggz9ezaxt56neh77kxe5hyr41kwgkncgiu94p9ecxiexgpgsz8daoq4tw8kj8yx"

with pytest.raises(RpcError, match="not found in the graph, expected pubkey is {}".format(pubkey)):
with pytest.raises(RpcError) as exception:
l1.rpc.checkmessage(msg, zbase)
err = exception.value
assert err.error['message'] == "pubkey not found in the graph"
assert err.error['data']['claimed_key'] == pubkey

check_result = l1.rpc.checkmessage(msg, zbase, pubkey=pubkey)
assert check_result["pubkey"] == pubkey
Expand Down

0 comments on commit cf7617e

Please sign in to comment.