| 42 | } |
| 43 | |
| 44 | struct payment *payment_new(tal_t *ctx, struct command *cmd, |
| 45 | struct payment *parent, |
| 46 | struct payment_modifier **mods) |
| 47 | { |
| 48 | struct payment *p = tal(ctx, struct payment); |
| 49 | |
| 50 | static u64 next_id = 0; |
| 51 | |
| 52 | p->children = tal_arr(p, struct payment *, 0); |
| 53 | p->parent = parent; |
| 54 | p->modifiers = mods; |
| 55 | p->cmd = cmd; |
| 56 | p->start_time = time_now(); |
| 57 | p->result = NULL; |
| 58 | p->why = NULL; |
| 59 | p->getroute = tal(p, struct getroute_request); |
| 60 | p->label = NULL; |
| 61 | p->failreason = NULL; |
| 62 | p->getroute->riskfactorppm = 10000000; |
| 63 | p->abort = false; |
| 64 | p->invstring_used = false; |
| 65 | p->route = NULL; |
| 66 | p->temp_exclusion = NULL; |
| 67 | p->failroute_retry = false; |
| 68 | p->routetxt = NULL; |
| 69 | p->max_htlcs = UINT32_MAX; |
| 70 | p->aborterror = NULL; |
| 71 | p->on_payment_success = NULL; |
| 72 | p->on_payment_failure = NULL; |
| 73 | |
| 74 | /* Copy over the relevant pieces of information. */ |
| 75 | if (parent != NULL) { |
| 76 | assert(cmd == NULL); |
| 77 | tal_arr_expand(&parent->children, p); |
| 78 | p->destination = parent->destination; |
| 79 | p->amount = parent->amount; |
| 80 | p->label = parent->label; |
| 81 | p->payment_hash = parent->payment_hash; |
| 82 | p->partid = payment_root(p->parent)->next_partid++; |
| 83 | p->plugin = parent->plugin; |
| 84 | |
| 85 | /* Re-establish the unmodified constraints for our sub-payment. */ |
| 86 | p->constraints = *parent->start_constraints; |
| 87 | p->deadline = parent->deadline; |
| 88 | |
| 89 | p->min_final_cltv_expiry = parent->min_final_cltv_expiry; |
| 90 | p->routes = parent->routes; |
| 91 | p->features = parent->features; |
| 92 | p->id = parent->id; |
| 93 | p->local_id = parent->local_id; |
| 94 | p->local_offer_id = parent->local_offer_id; |
| 95 | p->groupid = parent->groupid; |
| 96 | p->invstring = parent->invstring; |
| 97 | p->description = parent->description; |
| 98 | } else { |
| 99 | assert(cmd != NULL); |
| 100 | p->partid = 0; |
| 101 | p->next_partid = 1; |