@ -1328,31 +1328,33 @@ static struct command_result *json_sendpay(struct command *cmd,
route [ i ] . direction = direction ? * direction : 0 ;
route [ i ] . direction = direction ? * direction : 0 ;
}
}
/* The given msatoshi is the actual payment that the payee is
* requesting . The final hop amount is what we actually give , which can
* be from the msatoshi to twice msatoshi . */
if ( * partid & & ! msat )
if ( * partid & & ! msat )
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
" Must specify msatoshi with partid " ) ;
" Must specify msatoshi with partid " ) ;
/* finalhop.amount > 2 * msatoshi, fail. */
const struct amount_msat final_amount = route [ routetok - > size - 1 ] . amount ;
if ( msat ) {
struct amount_msat limit ;
if ( ! amount_msat_add ( & limit , * msat , * msat ) )
if ( msat & & ! * partid & & ! amount_msat_eq ( * msat , final_amount ) )
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
" Unbelievable msatoshi %s " ,
" Do not specify msatoshi (%s) without "
type_to_string ( tmpctx ,
" partid: if you do, it must be exactly "
struct amount_msat ,
" the final amount (%s) " ,
msat ) ) ;
type_to_string ( tmpctx , struct amount_msat ,
msat ) ,
type_to_string ( tmpctx , struct amount_msat ,
& final_amount ) ) ;
if ( amount_msat_greater ( route [ routetok - > size - 1 ] . amount , limit ) )
/* For MPP, the total we send must *exactly* equal the amount
* we promise to send ( msatoshi ) . So no single payment can be
* > than that . */
if ( * partid ) {
if ( amount_msat_greater ( final_amount , * msat ) )
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
return command_fail ( cmd , JSONRPC2_INVALID_PARAMS ,
" final %s more than twice msatoshi %s " ,
" Final amount %s is greater than "
" %s, despite MPP " ,
type_to_string ( tmpctx ,
type_to_string ( tmpctx ,
struct amount_msat ,
struct amount_msat ,
& route [ routetok - > size - 1 ] . amount ) ,
& final_ amount) ,
type_to_string ( tmpctx ,
type_to_string ( tmpctx ,
struct amount_msat ,
struct amount_msat ,
msat ) ) ;
msat ) ) ;
@ -1364,8 +1366,8 @@ static struct command_result *json_sendpay(struct command *cmd,
return send_payment ( cmd - > ld , cmd , rhash , * partid ,
return send_payment ( cmd - > ld , cmd , rhash , * partid ,
route ,
route ,
route [ routetok - > size - 1 ] . amount ,
final_ amount,
msat ? * msat : route [ routetok - > size - 1 ] . amount ,
msat ? * msat : final_ amount,
label , b11str , payment_secret ) ;
label , b11str , payment_secret ) ;
}
}