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