mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
pay: Make wallet_payment->destination optional
If we use `sendonion` we don't actually know the destination, so we make the destination a pointer which is NULL if we don't know.
This commit is contained in:
parent
e13ee29544
commit
41221b6ecb
@ -80,7 +80,9 @@ void json_add_payment_fields(struct json_stream *response,
|
|||||||
{
|
{
|
||||||
json_add_u64(response, "id", t->id);
|
json_add_u64(response, "id", t->id);
|
||||||
json_add_sha256(response, "payment_hash", &t->payment_hash);
|
json_add_sha256(response, "payment_hash", &t->payment_hash);
|
||||||
json_add_node_id(response, "destination", &t->destination);
|
if (t->destination != NULL)
|
||||||
|
json_add_node_id(response, "destination", t->destination);
|
||||||
|
|
||||||
json_add_amount_msat_compat(response, t->msatoshi,
|
json_add_amount_msat_compat(response, t->msatoshi,
|
||||||
"msatoshi", "amount_msat");
|
"msatoshi", "amount_msat");
|
||||||
json_add_amount_msat_compat(response, t->msatoshi_sent,
|
json_add_amount_msat_compat(response, t->msatoshi_sent,
|
||||||
@ -738,12 +740,14 @@ send_payment(struct lightningd *ld,
|
|||||||
struct amount_msat,
|
struct amount_msat,
|
||||||
&payment->msatoshi));
|
&payment->msatoshi));
|
||||||
}
|
}
|
||||||
if (!node_id_eq(&payment->destination, &ids[n_hops-1])) {
|
if (payment->destination &&
|
||||||
|
!node_id_eq(payment->destination,
|
||||||
|
&ids[n_hops - 1])) {
|
||||||
return command_fail(cmd, PAY_RHASH_ALREADY_USED,
|
return command_fail(cmd, PAY_RHASH_ALREADY_USED,
|
||||||
"Already succeeded to %s",
|
"Already succeeded to %s",
|
||||||
type_to_string(tmpctx,
|
type_to_string(tmpctx,
|
||||||
struct node_id,
|
struct node_id,
|
||||||
&payment->destination));
|
payment->destination));
|
||||||
}
|
}
|
||||||
return sendpay_success(cmd, payment);
|
return sendpay_success(cmd, payment);
|
||||||
}
|
}
|
||||||
@ -800,7 +804,7 @@ send_payment(struct lightningd *ld,
|
|||||||
payment = tal(hout, struct wallet_payment);
|
payment = tal(hout, struct wallet_payment);
|
||||||
payment->id = 0;
|
payment->id = 0;
|
||||||
payment->payment_hash = *rhash;
|
payment->payment_hash = *rhash;
|
||||||
payment->destination = ids[n_hops - 1];
|
payment->destination = tal_dup(payment, struct node_id, &ids[n_hops - 1]);
|
||||||
payment->status = PAYMENT_PENDING;
|
payment->status = PAYMENT_PENDING;
|
||||||
payment->msatoshi = msat;
|
payment->msatoshi = msat;
|
||||||
payment->msatoshi_sent = route[0].amount;
|
payment->msatoshi_sent = route[0].amount;
|
||||||
|
@ -1248,7 +1248,8 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx);
|
||||||
|
|
||||||
mempat(t, sizeof(*t));
|
mempat(t, sizeof(*t));
|
||||||
memset(&t->destination, 2, sizeof(t->destination));
|
t->destination = tal(t, struct node_id);
|
||||||
|
memset(t->destination, 2, sizeof(struct node_id));
|
||||||
|
|
||||||
t->id = 0;
|
t->id = 0;
|
||||||
t->msatoshi = AMOUNT_MSAT(100);
|
t->msatoshi = AMOUNT_MSAT(100);
|
||||||
@ -1263,7 +1264,7 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
|
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
|
||||||
CHECK(t2 != NULL);
|
CHECK(t2 != NULL);
|
||||||
CHECK(t2->status == t->status);
|
CHECK(t2->status == t->status);
|
||||||
CHECK(node_id_cmp(&t2->destination, &t->destination) == 0);
|
CHECK(node_id_cmp(t2->destination, t->destination) == 0);
|
||||||
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
|
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
|
||||||
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
|
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
|
||||||
CHECK(!t2->payment_preimage);
|
CHECK(!t2->payment_preimage);
|
||||||
@ -1276,7 +1277,7 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
|
t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash);
|
||||||
CHECK(t2 != NULL);
|
CHECK(t2 != NULL);
|
||||||
CHECK(t2->status == t->status);
|
CHECK(t2->status == t->status);
|
||||||
CHECK(node_id_eq(&t2->destination, &t->destination));
|
CHECK(node_id_eq(t2->destination, t->destination));
|
||||||
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
|
CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi));
|
||||||
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
|
CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent));
|
||||||
CHECK(preimage_eq(t->payment_preimage, t2->payment_preimage));
|
CHECK(preimage_eq(t->payment_preimage, t2->payment_preimage));
|
||||||
|
@ -2129,7 +2129,12 @@ void wallet_payment_store(struct wallet *wallet,
|
|||||||
|
|
||||||
db_bind_int(stmt, 0, payment->status);
|
db_bind_int(stmt, 0, payment->status);
|
||||||
db_bind_sha256(stmt, 1, &payment->payment_hash);
|
db_bind_sha256(stmt, 1, &payment->payment_hash);
|
||||||
db_bind_node_id(stmt, 2, &payment->destination);
|
|
||||||
|
if (payment->destination != NULL)
|
||||||
|
db_bind_node_id(stmt, 2, payment->destination);
|
||||||
|
else
|
||||||
|
db_bind_null(stmt, 2);
|
||||||
|
|
||||||
db_bind_amount_msat(stmt, 3, &payment->msatoshi);
|
db_bind_amount_msat(stmt, 3, &payment->msatoshi);
|
||||||
db_bind_int(stmt, 4, payment->timestamp);
|
db_bind_int(stmt, 4, payment->timestamp);
|
||||||
|
|
||||||
@ -2189,7 +2194,13 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
|
|||||||
payment->id = db_column_u64(stmt, 0);
|
payment->id = db_column_u64(stmt, 0);
|
||||||
payment->status = db_column_int(stmt, 1);
|
payment->status = db_column_int(stmt, 1);
|
||||||
|
|
||||||
db_column_node_id(stmt, 2, &payment->destination);
|
if (!db_column_is_null(stmt, 2)) {
|
||||||
|
payment->destination = tal(payment, struct node_id);
|
||||||
|
db_column_node_id(stmt, 2, payment->destination);
|
||||||
|
} else {
|
||||||
|
payment->destination = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
db_column_amount_msat(stmt, 3, &payment->msatoshi);
|
db_column_amount_msat(stmt, 3, &payment->msatoshi);
|
||||||
db_column_sha256(stmt, 4, &payment->payment_hash);
|
db_column_sha256(stmt, 4, &payment->payment_hash);
|
||||||
|
|
||||||
|
@ -251,7 +251,9 @@ struct wallet_payment {
|
|||||||
u32 timestamp;
|
u32 timestamp;
|
||||||
struct sha256 payment_hash;
|
struct sha256 payment_hash;
|
||||||
enum wallet_payment_status status;
|
enum wallet_payment_status status;
|
||||||
struct node_id destination;
|
|
||||||
|
/* The destination may not be known if we used `sendonion` */
|
||||||
|
struct node_id *destination;
|
||||||
struct amount_msat msatoshi;
|
struct amount_msat msatoshi;
|
||||||
struct amount_msat msatoshi_sent;
|
struct amount_msat msatoshi_sent;
|
||||||
/* If and only if PAYMENT_COMPLETE */
|
/* If and only if PAYMENT_COMPLETE */
|
||||||
|
Loading…
Reference in New Issue
Block a user