Outputs fields, not a separate object*/
| 136 | |
| 137 | /* Outputs fields, not a separate object*/ |
| 138 | void json_add_payment_fields(struct json_stream *response, |
| 139 | const struct wallet_payment *t) |
| 140 | { |
| 141 | json_add_u64(response, "created_index", t->id); |
| 142 | json_add_u64(response, "id", t->id); |
| 143 | json_add_sha256(response, "payment_hash", &t->payment_hash); |
| 144 | json_add_u64(response, "groupid", t->groupid); |
| 145 | if (t->updated_index) |
| 146 | json_add_u64(response, "updated_index", t->updated_index); |
| 147 | if (t->partid) |
| 148 | json_add_u64(response, "partid", t->partid); |
| 149 | if (t->destination != NULL) |
| 150 | json_add_node_id(response, "destination", t->destination); |
| 151 | |
| 152 | /* If we have a 0 amount delivered at the remote end we simply don't |
| 153 | * know since the onion was generated externally. */ |
| 154 | if (amount_msat_greater(t->msatoshi, AMOUNT_MSAT(0))) |
| 155 | json_add_amount_msat(response, "amount_msat", t->msatoshi); |
| 156 | |
| 157 | json_add_amount_msat(response, "amount_sent_msat", t->msatoshi_sent); |
| 158 | json_add_u32(response, "created_at", t->timestamp); |
| 159 | if (t->completed_at) |
| 160 | json_add_u32(response, "completed_at", *t->completed_at); |
| 161 | |
| 162 | switch (t->status) { |
| 163 | case PAYMENT_PENDING: |
| 164 | json_add_string(response, "status", "pending"); |
| 165 | break; |
| 166 | case PAYMENT_COMPLETE: |
| 167 | json_add_string(response, "status", "complete"); |
| 168 | break; |
| 169 | case PAYMENT_FAILED: |
| 170 | json_add_string(response, "status", "failed"); |
| 171 | break; |
| 172 | } |
| 173 | if (t->payment_preimage) |
| 174 | json_add_preimage(response, "payment_preimage", |
| 175 | t->payment_preimage); |
| 176 | if (t->label) |
| 177 | json_add_string(response, "label", t->label); |
| 178 | if (t->invstring) { |
| 179 | if (strstarts(t->invstring, "lni")) |
| 180 | json_add_string(response, "bolt12", t->invstring); |
| 181 | else |
| 182 | json_add_string(response, "bolt11", t->invstring); |
| 183 | } |
| 184 | if (t->description) |
| 185 | json_add_string(response, "description", t->description); |
| 186 | |
| 187 | if (t->failonion) |
| 188 | json_add_hex(response, "erroronion", t->failonion, |
| 189 | tal_count(t->failonion)); |
| 190 | } |
| 191 | |
| 192 | static struct command_result *sendpay_success(struct command *cmd, |
| 193 | const struct wallet_payment *payment, |
no test coverage detected