| 133 | } |
| 134 | |
| 135 | static void paystatus_add_payment(struct json_stream *s, const struct payment *p) |
| 136 | { |
| 137 | char timestr[UTC_TIMELEN]; |
| 138 | |
| 139 | utc_timestring(&p->start_time, timestr); |
| 140 | |
| 141 | json_object_start(s, NULL); |
| 142 | if (p->why != NULL) |
| 143 | json_add_string(s, "strategy", p->why); |
| 144 | json_add_string(s, "start_time", timestr); |
| 145 | json_add_u64(s, "age_in_seconds", |
| 146 | time_to_sec(time_between(clock_time(), p->start_time))); |
| 147 | |
| 148 | /* Any final state will have an end time. */ |
| 149 | if (p->step >= PAYMENT_STEP_SPLIT) { |
| 150 | utc_timestring(&p->end_time, timestr); |
| 151 | json_add_string(s, "end_time", timestr); |
| 152 | } |
| 153 | |
| 154 | /* TODO Add routehint. */ |
| 155 | /* TODO Add route details */ |
| 156 | |
| 157 | if (p->step < PAYMENT_STEP_SPLIT) |
| 158 | json_add_string(s, "state", "pending"); |
| 159 | else |
| 160 | json_add_string(s, "state", "completed"); |
| 161 | |
| 162 | if (p->step == PAYMENT_STEP_SPLIT) { |
| 163 | /* Don't add anything, this is neither a success nor a failure. */ |
| 164 | } else if (p->result != NULL) { |
| 165 | if (p->step == PAYMENT_STEP_SUCCESS) |
| 166 | json_object_start(s, "success"); |
| 167 | else |
| 168 | json_object_start(s, "failure"); |
| 169 | json_add_sendpay_result(s, p->result); |
| 170 | json_object_end(s); |
| 171 | } else if (p->step >= PAYMENT_STEP_SPLIT) { |
| 172 | json_object_start(s, "failure"); |
| 173 | json_add_num(s, "code", PAY_ROUTE_NOT_FOUND); |
| 174 | json_add_string(s, "message", "Call to getroute: Could not find a route"); |
| 175 | json_object_end(s); |
| 176 | } |
| 177 | |
| 178 | json_object_end(s); |
| 179 | for (size_t i = 0; i < tal_count(p->children); i++) |
| 180 | paystatus_add_payment(s, p->children[i]); |
| 181 | } |
| 182 | |
| 183 | static struct command_result *json_paystatus(struct command *cmd, |
| 184 | const char *buf, |
no test coverage detected