mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
rpc: improve error format
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
1d671a2380
commit
7ae616ef60
@ -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)
|
||||
|
||||
@ -54,4 +49,4 @@ RESOURCES
|
||||
|
||||
Main web site: <https://github.com/ElementsProject/lightning>
|
||||
|
||||
[comment]: # ( SHA256STAMP:7dcca1fd1708d93b4a0c9b83955630fc4f551c4ffd452fb866c624c72aeaa44d)
|
||||
[comment]: # ( SHA256STAMP:af2feeb4eddafc509dff150ec4b11225618f1cbbea06ef81f6d97a1bece3e94c)
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -135,9 +135,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);
|
||||
|
@ -2722,9 +2722,12 @@ 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
|
||||
assert check_result["verified"] is True
|
||||
assert check_result["verified"] is True
|
||||
|
Loading…
Reference in New Issue
Block a user