|
@ -113,14 +113,13 @@ static void json_pay_failure(struct command *cmd, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Start a payment attempt. */ |
|
|
/* Start a payment attempt. */ |
|
|
static void json_pay_try(struct pay *pay); |
|
|
static bool json_pay_try(struct pay *pay); |
|
|
|
|
|
|
|
|
/* Call when sendpay returns to us. */ |
|
|
/* Call when sendpay returns to us. */ |
|
|
static void json_pay_sendpay_resolve(const struct sendpay_result *r, |
|
|
static void json_pay_sendpay_resolve(const struct sendpay_result *r, |
|
|
void *vpay) |
|
|
void *vpay) |
|
|
{ |
|
|
{ |
|
|
struct pay *pay = (struct pay *) vpay; |
|
|
struct pay *pay = (struct pay *) vpay; |
|
|
struct timeabs now = time_now(); |
|
|
|
|
|
|
|
|
|
|
|
/* If we succeed, hurray */ |
|
|
/* If we succeed, hurray */ |
|
|
if (r->succeeded) { |
|
|
if (r->succeeded) { |
|
@ -136,13 +135,6 @@ static void json_pay_sendpay_resolve(const struct sendpay_result *r, |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* If too late anyway, fail now. */ |
|
|
|
|
|
if (time_after(now, pay->expiry)) { |
|
|
|
|
|
/* FIXME: maybe another error kind? */ |
|
|
|
|
|
json_pay_failure(pay->cmd, r); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
json_pay_try(pay); |
|
|
json_pay_try(pay); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -199,11 +191,26 @@ static void json_pay_getroute_reply(struct subd *gossip, |
|
|
&json_pay_sendpay_resolve, pay); |
|
|
&json_pay_sendpay_resolve, pay); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Start a payment attempt */ |
|
|
/* Start a payment attempt. Return true if deferred,
|
|
|
static void json_pay_try(struct pay *pay) |
|
|
* false if resolved now. */ |
|
|
|
|
|
static bool json_pay_try(struct pay *pay) |
|
|
{ |
|
|
{ |
|
|
u8 *req; |
|
|
u8 *req; |
|
|
struct command *cmd = pay->cmd; |
|
|
struct command *cmd = pay->cmd; |
|
|
|
|
|
struct timeabs now = time_now(); |
|
|
|
|
|
struct json_result *data; |
|
|
|
|
|
|
|
|
|
|
|
/* If too late anyway, fail now. */ |
|
|
|
|
|
if (time_after(now, pay->expiry)) { |
|
|
|
|
|
data = new_json_result(cmd); |
|
|
|
|
|
json_object_start(data, NULL); |
|
|
|
|
|
json_add_num(data, "now", now.ts.tv_sec); |
|
|
|
|
|
json_add_num(data, "expiry", pay->expiry.ts.tv_sec); |
|
|
|
|
|
json_object_end(data); |
|
|
|
|
|
command_fail_detailed(cmd, PAY_INVOICE_EXPIRED, data, |
|
|
|
|
|
"Invoice expired"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* Clear previous sendpay. */ |
|
|
/* Clear previous sendpay. */ |
|
|
pay->sendpay_parent = tal_free(pay->sendpay_parent); |
|
|
pay->sendpay_parent = tal_free(pay->sendpay_parent); |
|
@ -218,6 +225,8 @@ static void json_pay_try(struct pay *pay) |
|
|
pay->riskfactor, |
|
|
pay->riskfactor, |
|
|
pay->min_final_cltv_expiry); |
|
|
pay->min_final_cltv_expiry); |
|
|
subd_req(pay, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay); |
|
|
subd_req(pay, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void json_pay(struct command *cmd, |
|
|
static void json_pay(struct command *cmd, |
|
@ -316,7 +325,7 @@ static void json_pay(struct command *cmd, |
|
|
pay->sendpay_parent = NULL; |
|
|
pay->sendpay_parent = NULL; |
|
|
|
|
|
|
|
|
/* Initiate payment */ |
|
|
/* Initiate payment */ |
|
|
json_pay_try(pay); |
|
|
if (json_pay_try(pay)) |
|
|
command_still_pending(cmd); |
|
|
command_still_pending(cmd); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|