| 14 | static struct command_result *payment_finish(struct payment *p); |
| 15 | |
| 16 | struct payment *payment_new(const tal_t *ctx, const struct sha256 *payment_hash, |
| 17 | const char *invstr TAKES) |
| 18 | { |
| 19 | struct payment *p = tal(ctx, struct payment); |
| 20 | memset(p, 0, sizeof(struct payment)); |
| 21 | |
| 22 | struct payment_info *pinfo = &p->payment_info; |
| 23 | |
| 24 | assert(payment_hash); |
| 25 | pinfo->payment_hash = *payment_hash; |
| 26 | |
| 27 | assert(invstr); |
| 28 | pinfo->invstr = tal_strdup(p, invstr); |
| 29 | |
| 30 | p->status = PAYMENT_PENDING; |
| 31 | p->preimage = NULL; |
| 32 | p->error_code = LIGHTNINGD; |
| 33 | p->error_msg = NULL; |
| 34 | p->total_sent = AMOUNT_MSAT(0); |
| 35 | p->total_delivering = AMOUNT_MSAT(0); |
| 36 | p->paynotes = tal_arr(p, const char*, 0); |
| 37 | p->groupid = 1; |
| 38 | |
| 39 | p->exec_state = INVALID_STATE; |
| 40 | p->next_partid = 1; |
| 41 | p->cmd_array = tal_arr(p, struct command *, 0); |
| 42 | p->local_gossmods = NULL; |
| 43 | p->disabledmap = disabledmap_new(p); |
| 44 | p->have_results = false; |
| 45 | p->retry = false; |
| 46 | p->waitresult_timer = NULL; |
| 47 | p->routetracker = new_routetracker(p, p); |
| 48 | return p; |
| 49 | } |
| 50 | |
| 51 | /* A payment that finishes execution must clean its hidden state. */ |
| 52 | static void payment_cleanup(struct payment *p) |