mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
paymod: Add attempts array to pay return value
This commit is contained in:
@@ -1054,6 +1054,42 @@ static void payment_child_finished(struct payment *p,
|
|||||||
payment_finished(p);
|
payment_finished(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void payment_add_attempt(struct json_stream *s, const char *fieldname, struct payment *p, bool recurse)
|
||||||
|
{
|
||||||
|
bool finished = p->step >= PAYMENT_STEP_RETRY,
|
||||||
|
success = p->step == PAYMENT_STEP_SUCCESS;
|
||||||
|
|
||||||
|
/* A fieldname is only reasonable if we're not recursing. Otherwise the
|
||||||
|
* fieldname would be reused for all attempts. */
|
||||||
|
assert(!recurse || fieldname == NULL);
|
||||||
|
|
||||||
|
json_object_start(s, fieldname);
|
||||||
|
|
||||||
|
if (!finished)
|
||||||
|
json_add_string(s, "status", "pending");
|
||||||
|
else if (success)
|
||||||
|
json_add_string(s, "status", "success");
|
||||||
|
else
|
||||||
|
json_add_string(s, "status", "failed");
|
||||||
|
|
||||||
|
if (p->failreason != NULL)
|
||||||
|
json_add_string(s, "failreason", p->failreason);
|
||||||
|
|
||||||
|
json_object_end(s);
|
||||||
|
for (size_t i=0; i<tal_count(p->children); i++) {
|
||||||
|
payment_add_attempt(s, fieldname, p->children[i], recurse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void payment_json_add_attempts(struct json_stream *s,
|
||||||
|
const char *fieldname, struct payment *p)
|
||||||
|
{
|
||||||
|
assert(p == payment_root(p));
|
||||||
|
json_array_start(s, fieldname);
|
||||||
|
payment_add_attempt(s, NULL, p, true);
|
||||||
|
json_array_end(s);
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is called whenever a payment ends up in a final state, or all
|
/* This function is called whenever a payment ends up in a final state, or all
|
||||||
* leafs in the subtree rooted in the payment are all in a final state. It is
|
* leafs in the subtree rooted in the payment are all in a final state. It is
|
||||||
* called only once, and it is guaranteed to be called in post-order
|
* called only once, and it is guaranteed to be called in post-order
|
||||||
@@ -1081,7 +1117,9 @@ static void payment_finished(struct payment *p)
|
|||||||
assert(result.preimage != NULL);
|
assert(result.preimage != NULL);
|
||||||
|
|
||||||
ret = jsonrpc_stream_success(p->cmd);
|
ret = jsonrpc_stream_success(p->cmd);
|
||||||
|
json_add_node_id(ret, "destination", p->destination);
|
||||||
json_add_sha256(ret, "payment_hash", p->payment_hash);
|
json_add_sha256(ret, "payment_hash", p->payment_hash);
|
||||||
|
json_add_timeabs(ret, "created_at", p->start_time);
|
||||||
json_add_num(ret, "parts", result.attempts);
|
json_add_num(ret, "parts", result.attempts);
|
||||||
|
|
||||||
json_add_amount_msat_compat(ret, p->amount, "msatoshi",
|
json_add_amount_msat_compat(ret, p->amount, "msatoshi",
|
||||||
@@ -1116,7 +1154,7 @@ static void payment_finished(struct payment *p)
|
|||||||
"%d attempt%s: see `paystatus`",
|
"%d attempt%s: see `paystatus`",
|
||||||
result.attempts,
|
result.attempts,
|
||||||
result.attempts == 1 ? "" : "s"));
|
result.attempts == 1 ? "" : "s"));
|
||||||
json_add_num(ret, "attempts", result.attempts);
|
payment_json_add_attempts(ret, "attempts", p);
|
||||||
if (command_finished(cmd, ret)) {/* Ignore result. */}
|
if (command_finished(cmd, ret)) {/* Ignore result. */}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user