@@ -1653,8 +1653,10 @@ struct pay_mpp {
1653
1653
1654
1654
/* This is the bolt11/bolt12 string */
1655
1655
const char * invstring ;
1656
- /* Status of combined payment */
1657
- const char * status ;
1656
+
1657
+ /* Accumulated states of all sendpay commands involved. */
1658
+ enum payment_result_state state ;
1659
+
1658
1660
/* Optional label (of first one!) */
1659
1661
const jsmntok_t * label ;
1660
1662
/* Optional preimage (iff status is successful) */
@@ -1763,7 +1765,14 @@ static void add_new_entry(struct json_stream *ret,
1763
1765
json_add_tok (ret , "destination" , pm -> destination , buf );
1764
1766
1765
1767
json_add_sha256 (ret , "payment_hash" , pm -> payment_hash );
1766
- json_add_string (ret , "status" , pm -> status );
1768
+
1769
+ if (pm -> state & PAYMENT_COMPLETE )
1770
+ json_add_string (ret , "status" , "complete" );
1771
+ else if (pm -> state & PAYMENT_PENDING || attempt_ongoing (pm -> payment_hash ))
1772
+ json_add_string (ret , "status" , "pending" );
1773
+ else
1774
+ json_add_string (ret , "status" , "failed" );
1775
+
1767
1776
json_add_u32 (ret , "created_at" , pm -> timestamp );
1768
1777
1769
1778
if (pm -> label )
@@ -1828,6 +1837,7 @@ static struct command_result *listsendpays_done(struct command *cmd,
1828
1837
pm = pay_map_get (& pay_map , & payment_hash );
1829
1838
if (!pm ) {
1830
1839
pm = tal (cmd , struct pay_mpp );
1840
+ pm -> state = 0 ;
1831
1841
pm -> payment_hash = tal_dup (pm , struct sha256 , & payment_hash );
1832
1842
pm -> invstring = tal_steal (pm , invstr );
1833
1843
pm -> destination = json_get_member (buf , t , "destination" );
@@ -1836,7 +1846,6 @@ static struct command_result *listsendpays_done(struct command *cmd,
1836
1846
pm -> amount_sent = AMOUNT_MSAT (0 );
1837
1847
pm -> amount = talz (pm , struct amount_msat );
1838
1848
pm -> num_nonfailed_parts = 0 ;
1839
- pm -> status = NULL ;
1840
1849
pm -> timestamp = created_at ;
1841
1850
pay_map_add (& pay_map , pm );
1842
1851
}
@@ -1845,24 +1854,15 @@ static struct command_result *listsendpays_done(struct command *cmd,
1845
1854
if (json_tok_streq (buf , status , "complete" )) {
1846
1855
add_amount_sent (cmd -> plugin , pm -> invstring , pm , buf , t );
1847
1856
pm -> num_nonfailed_parts ++ ;
1848
- pm -> status = "complete" ;
1849
1857
pm -> preimage
1850
1858
= json_get_member (buf , t , "payment_preimage" );
1859
+ pm -> state |= PAYMENT_COMPLETE ;
1851
1860
} else if (json_tok_streq (buf , status , "pending" )) {
1852
1861
add_amount_sent (cmd -> plugin , pm -> invstring , pm , buf , t );
1853
1862
pm -> num_nonfailed_parts ++ ;
1854
- /* Failed -> pending; don't downgrade success. */
1855
- if (!pm -> status || !streq (pm -> status , "complete" ))
1856
- pm -> status = "pending" ;
1863
+ pm -> state |= PAYMENT_PENDING ;
1857
1864
} else {
1858
- if (attempt_ongoing (pm -> payment_hash )) {
1859
- /* Failed -> pending; don't downgrade success. */
1860
- if (!pm -> status
1861
- || !streq (pm -> status , "complete" ))
1862
- pm -> status = "pending" ;
1863
- } else if (!pm -> status )
1864
- /* Only failed if they all failed */
1865
- pm -> status = "failed" ;
1865
+ pm -> state |= PAYMENT_FAILED ;
1866
1866
}
1867
1867
}
1868
1868
0 commit comments