mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
invoice: Define specific error codes for duplicate label and preimage.
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
.\" Title: lightning-invoice
|
.\" Title: lightning-invoice
|
||||||
.\" Author: [see the "AUTHOR" section]
|
.\" Author: [see the "AUTHOR" section]
|
||||||
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
|
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
|
||||||
.\" Date: 04/23/2018
|
.\" Date: 04/26/2018
|
||||||
.\" Manual: \ \&
|
.\" Manual: \ \&
|
||||||
.\" Source: \ \&
|
.\" Source: \ \&
|
||||||
.\" Language: English
|
.\" Language: English
|
||||||
.\"
|
.\"
|
||||||
.TH "LIGHTNING\-INVOICE" "7" "04/23/2018" "\ \&" "\ \&"
|
.TH "LIGHTNING\-INVOICE" "7" "04/26/2018" "\ \&" "\ \&"
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
.\" * Define some portability stuff
|
.\" * Define some portability stuff
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
@@ -50,6 +50,45 @@ The \fIpreimage\fR is a 64\-digit hex string to be used as payment preimage for
|
|||||||
.SH "RETURN VALUE"
|
.SH "RETURN VALUE"
|
||||||
.sp
|
.sp
|
||||||
On success, a hash is returned as \fIpayment_hash\fR to be given to the payer, and the \fIexpiry_time\fR as a UNIX timestamp\&. It also returns a BOLT11 invoice as \fIbolt11\fR to be given to the payer\&. On failure, an error is returned and no invoice is created\&. If the lightning process fails before responding, the caller should use lightning\-listinvoice(7) to query whether this invoice was created or not\&.
|
On success, a hash is returned as \fIpayment_hash\fR to be given to the payer, and the \fIexpiry_time\fR as a UNIX timestamp\&. It also returns a BOLT11 invoice as \fIbolt11\fR to be given to the payer\&. On failure, an error is returned and no invoice is created\&. If the lightning process fails before responding, the caller should use lightning\-listinvoice(7) to query whether this invoice was created or not\&.
|
||||||
|
.sp
|
||||||
|
The following error codes may occur:
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
.sp -1
|
||||||
|
.IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
\-1\&. Catchall nonspecific error\&.
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
.sp -1
|
||||||
|
.IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
900\&. An invoice with the given
|
||||||
|
\fIlabel\fR
|
||||||
|
already exists\&.
|
||||||
|
.RE
|
||||||
|
.sp
|
||||||
|
.RS 4
|
||||||
|
.ie n \{\
|
||||||
|
\h'-04'\(bu\h'+03'\c
|
||||||
|
.\}
|
||||||
|
.el \{\
|
||||||
|
.sp -1
|
||||||
|
.IP \(bu 2.3
|
||||||
|
.\}
|
||||||
|
901\&. An invoice with the given
|
||||||
|
\fIpreimage\fR
|
||||||
|
already exists\&.
|
||||||
|
.RE
|
||||||
.SH "AUTHOR"
|
.SH "AUTHOR"
|
||||||
.sp
|
.sp
|
||||||
Rusty Russell <rusty@rustcorp\&.com\&.au> is mainly responsible\&.
|
Rusty Russell <rusty@rustcorp\&.com\&.au> is mainly responsible\&.
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ On failure, an error is returned and no invoice is created. If the
|
|||||||
lightning process fails before responding, the caller should use
|
lightning process fails before responding, the caller should use
|
||||||
lightning-listinvoice(7) to query whether this invoice was created or not.
|
lightning-listinvoice(7) to query whether this invoice was created or not.
|
||||||
|
|
||||||
//FIXME:Enumerate errors
|
The following error codes may occur:
|
||||||
|
|
||||||
|
* -1. Catchall nonspecific error.
|
||||||
|
* 900. An invoice with the given 'label' already exists.
|
||||||
|
* 901. An invoice with the given 'preimage' already exists.
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <hsmd/gen_hsm_client_wire.h>
|
#include <hsmd/gen_hsm_client_wire.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <lightningd/hsm_control.h>
|
#include <lightningd/hsm_control.h>
|
||||||
|
#include <lightningd/jsonrpc_errors.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
#include <lightningd/options.h>
|
#include <lightningd/options.h>
|
||||||
#include <sodium/randombytes.h>
|
#include <sodium/randombytes.h>
|
||||||
@@ -203,7 +204,9 @@ static void json_invoice(struct command *cmd,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (wallet_invoice_find_by_label(wallet, &invoice, label_val)) {
|
if (wallet_invoice_find_by_label(wallet, &invoice, label_val)) {
|
||||||
command_fail(cmd, "Duplicate label '%s'", label_val->s);
|
command_fail_detailed(cmd, INVOICE_LABEL_ALREADY_EXISTS,
|
||||||
|
NULL,
|
||||||
|
"Duplicate label '%s'", label_val->s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strlen(label_val->s) > INVOICE_MAX_LABEL_LEN) {
|
if (strlen(label_val->s) > INVOICE_MAX_LABEL_LEN) {
|
||||||
@@ -303,7 +306,8 @@ static void json_invoice(struct command *cmd,
|
|||||||
*/
|
*/
|
||||||
if (preimagetok &&
|
if (preimagetok &&
|
||||||
wallet_invoice_find_by_rhash(cmd->ld->wallet, &invoice, &rhash)) {
|
wallet_invoice_find_by_rhash(cmd->ld->wallet, &invoice, &rhash)) {
|
||||||
command_fail(cmd, "preimage already used");
|
command_fail_detailed(cmd, INVOICE_PREIMAGE_ALREADY_EXISTS,
|
||||||
|
NULL, "preimage already used");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,4 +23,8 @@
|
|||||||
#define PAY_UNSPECIFIED_ERROR 209
|
#define PAY_UNSPECIFIED_ERROR 209
|
||||||
#define PAY_STOPPED_RETRYING 210
|
#define PAY_STOPPED_RETRYING 210
|
||||||
|
|
||||||
|
/* Errors from `invoice` command */
|
||||||
|
#define INVOICE_LABEL_ALREADY_EXISTS 900
|
||||||
|
#define INVOICE_PREIMAGE_ALREADY_EXISTS 901
|
||||||
|
|
||||||
#endif /* LIGHTNING_LIGHTNINGD_JSONRPC_ERRORS_H */
|
#endif /* LIGHTNING_LIGHTNINGD_JSONRPC_ERRORS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user