mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
pay: sendpay_result has payment on success or in-progress.
This commit is contained in:
parent
8f76581005
commit
fa281d32ea
2 changed files with 37 additions and 10 deletions
|
@ -93,21 +93,26 @@ static void waitsendpay_resolve(const tal_t *ctx,
|
||||||
|
|
||||||
static struct sendpay_result*
|
static struct sendpay_result*
|
||||||
sendpay_result_success(const tal_t *ctx,
|
sendpay_result_success(const tal_t *ctx,
|
||||||
const struct preimage *payment_preimage)
|
const struct preimage *payment_preimage,
|
||||||
|
const struct wallet_payment *payment)
|
||||||
{
|
{
|
||||||
struct sendpay_result *result = tal(ctx, struct sendpay_result);
|
struct sendpay_result *result = tal(ctx, struct sendpay_result);
|
||||||
result->succeeded = true;
|
result->succeeded = true;
|
||||||
result->preimage = *payment_preimage;
|
result->preimage = *payment_preimage;
|
||||||
|
result->payment = payment;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void payment_trigger_success(struct lightningd *ld,
|
static void payment_trigger_success(struct lightningd *ld,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash)
|
||||||
const struct preimage *payment_preimage)
|
|
||||||
{
|
{
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
|
struct wallet_payment *payment;
|
||||||
|
|
||||||
result = sendpay_result_success(tmpctx, payment_preimage);
|
payment = wallet_payment_by_hash(tmpctx, ld->wallet, payment_hash);
|
||||||
|
assert(payment);
|
||||||
|
|
||||||
|
result = sendpay_result_success(tmpctx, payment->payment_preimage, payment);
|
||||||
|
|
||||||
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
||||||
}
|
}
|
||||||
|
@ -161,12 +166,25 @@ sendpay_result_simple_fail(const tal_t *ctx,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sendpay_result *
|
||||||
|
sendpay_result_in_progress(const tal_t *ctx,
|
||||||
|
const struct wallet_payment* payment,
|
||||||
|
char const *details)
|
||||||
|
{
|
||||||
|
struct sendpay_result *result = tal(ctx, struct sendpay_result);
|
||||||
|
result->succeeded = false;
|
||||||
|
result->errorcode = PAY_IN_PROGRESS;
|
||||||
|
result->payment = payment;
|
||||||
|
result->details = details;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void payment_succeeded(struct lightningd *ld, struct htlc_out *hout,
|
void payment_succeeded(struct lightningd *ld, struct htlc_out *hout,
|
||||||
const struct preimage *rval)
|
const struct preimage *rval)
|
||||||
{
|
{
|
||||||
wallet_payment_set_status(ld->wallet, &hout->payment_hash,
|
wallet_payment_set_status(ld->wallet, &hout->payment_hash,
|
||||||
PAYMENT_COMPLETE, rval);
|
PAYMENT_COMPLETE, rval);
|
||||||
payment_trigger_success(ld, &hout->payment_hash, rval);
|
payment_trigger_success(ld, &hout->payment_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return NULL if the wrapped onion error message has no
|
/* Return NULL if the wrapped onion error message has no
|
||||||
|
@ -377,11 +395,14 @@ void payment_store(struct lightningd *ld,
|
||||||
struct sendpay_command *pc;
|
struct sendpay_command *pc;
|
||||||
struct sendpay_command *next;
|
struct sendpay_command *next;
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
|
const struct wallet_payment *payment;
|
||||||
|
|
||||||
wallet_payment_store(ld->wallet, payment_hash);
|
wallet_payment_store(ld->wallet, payment_hash);
|
||||||
|
payment = wallet_payment_by_hash(tmpctx, ld->wallet, payment_hash);
|
||||||
|
assert(payment);
|
||||||
|
|
||||||
/* Invent a sendpay result with PAY_IN_PROGRESS. */
|
/* Invent a sendpay result with PAY_IN_PROGRESS. */
|
||||||
result = sendpay_result_simple_fail(tmpctx, PAY_IN_PROGRESS,
|
result = sendpay_result_in_progress(tmpctx, payment,
|
||||||
"Payment is still in progress");
|
"Payment is still in progress");
|
||||||
|
|
||||||
/* Trigger any sendpay commands waiting for the store to occur. */
|
/* Trigger any sendpay commands waiting for the store to occur. */
|
||||||
|
@ -543,7 +564,8 @@ bool wait_payment(const tal_t *cxt,
|
||||||
|
|
||||||
case PAYMENT_COMPLETE:
|
case PAYMENT_COMPLETE:
|
||||||
result = sendpay_result_success(tmpctx,
|
result = sendpay_result_success(tmpctx,
|
||||||
payment->payment_preimage);
|
payment->payment_preimage,
|
||||||
|
payment);
|
||||||
cb(result, cbarg);
|
cb(result, cbarg);
|
||||||
cb_not_called = false;
|
cb_not_called = false;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -645,8 +667,8 @@ send_payment(const tal_t *ctx,
|
||||||
log_debug(ld->log, "send_payment: found previous");
|
log_debug(ld->log, "send_payment: found previous");
|
||||||
if (payment->status == PAYMENT_PENDING) {
|
if (payment->status == PAYMENT_PENDING) {
|
||||||
log_add(ld->log, "Payment is still in progress");
|
log_add(ld->log, "Payment is still in progress");
|
||||||
result = sendpay_result_simple_fail(tmpctx,
|
result = sendpay_result_in_progress(tmpctx,
|
||||||
PAY_IN_PROGRESS,
|
payment,
|
||||||
"Payment is still in progress");
|
"Payment is still in progress");
|
||||||
cb(result, cbarg);
|
cb(result, cbarg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -678,7 +700,8 @@ send_payment(const tal_t *ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
result = sendpay_result_success(tmpctx,
|
result = sendpay_result_success(tmpctx,
|
||||||
payment->payment_preimage);
|
payment->payment_preimage,
|
||||||
|
payment);
|
||||||
cb(result, cbarg);
|
cb(result, cbarg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ struct htlc_out;
|
||||||
struct lightningd;
|
struct lightningd;
|
||||||
struct route_hop;
|
struct route_hop;
|
||||||
struct sha256;
|
struct sha256;
|
||||||
|
struct wallet_payment;
|
||||||
|
|
||||||
/* Routing failure object */
|
/* Routing failure object */
|
||||||
struct routing_failure {
|
struct routing_failure {
|
||||||
|
@ -29,6 +30,9 @@ struct sendpay_result {
|
||||||
/* Error code, one of the PAY_* macro in jsonrpc_errors.h.
|
/* Error code, one of the PAY_* macro in jsonrpc_errors.h.
|
||||||
* Only loaded if payment failed. */
|
* Only loaded if payment failed. */
|
||||||
int errorcode;
|
int errorcode;
|
||||||
|
/* Pointer to the payment. Only loaded if payment
|
||||||
|
* succeeded or if error is PAY_IN_PROGRESS */
|
||||||
|
const struct wallet_payment *payment;
|
||||||
/* Unparseable onion reply. Only loaded if payment failed,
|
/* Unparseable onion reply. Only loaded if payment failed,
|
||||||
* and errorcode == PAY_UNPARSEABLE_ONION. */
|
* and errorcode == PAY_UNPARSEABLE_ONION. */
|
||||||
const u8* onionreply;
|
const u8* onionreply;
|
||||||
|
|
Loading…
Add table
Reference in a new issue