Skip to content

Commit 3293bef

Browse files
committed
Use i64 for LSPS error codes
LSPS doesn't specify what type error codes are, it just makes reference to JSON-RPC, which only specifies that they are "integers". In JSON this is also not defined, but probably means ~`i58`s which is the integer range in `f64`s. To ensure we don't spuriously fail to parse errors, best to just use `i64`s.
1 parent afb80e5 commit 3293bef

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

lightning-liquidity/src/lsps0/ser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ pub(crate) const JSONRPC_ID_FIELD_KEY: &str = "id";
5151
pub(crate) const JSONRPC_PARAMS_FIELD_KEY: &str = "params";
5252
pub(crate) const JSONRPC_RESULT_FIELD_KEY: &str = "result";
5353
pub(crate) const JSONRPC_ERROR_FIELD_KEY: &str = "error";
54-
pub(crate) const JSONRPC_INVALID_MESSAGE_ERROR_CODE: i32 = -32700;
54+
pub(crate) const JSONRPC_INVALID_MESSAGE_ERROR_CODE: i64 = -32700;
5555
pub(crate) const JSONRPC_INVALID_MESSAGE_ERROR_MESSAGE: &str = "parse error";
56-
pub(crate) const JSONRPC_INTERNAL_ERROR_ERROR_CODE: i32 = -32603;
56+
pub(crate) const JSONRPC_INTERNAL_ERROR_ERROR_CODE: i64 = -32603;
5757
pub(crate) const JSONRPC_INTERNAL_ERROR_ERROR_MESSAGE: &str = "Internal error";
5858

59-
pub(crate) const LSPS0_CLIENT_REJECTED_ERROR_CODE: i32 = 1;
59+
pub(crate) const LSPS0_CLIENT_REJECTED_ERROR_CODE: i64 = 1;
6060

6161
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6262
pub(crate) enum LSPSMethod {
@@ -306,7 +306,7 @@ impl Readable for LSPSDateTime {
306306
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
307307
pub struct LSPSResponseError {
308308
/// A number that indicates the error type that occurred.
309-
pub code: i32,
309+
pub code: i64,
310310
/// A string providing a short description of the error.
311311
pub message: String,
312312
/// A primitive or structured value that contains additional information about the error.

lightning-liquidity/src/lsps1/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub(crate) const LSPS1_GET_INFO_METHOD_NAME: &str = "lsps1.get_info";
2929
pub(crate) const LSPS1_CREATE_ORDER_METHOD_NAME: &str = "lsps1.create_order";
3030
pub(crate) const LSPS1_GET_ORDER_METHOD_NAME: &str = "lsps1.get_order";
3131

32-
pub(crate) const _LSPS1_CREATE_ORDER_REQUEST_INVALID_PARAMS_ERROR_CODE: i32 = -32602;
32+
pub(crate) const _LSPS1_CREATE_ORDER_REQUEST_INVALID_PARAMS_ERROR_CODE: i64 = -32602;
3333
#[cfg(lsps1_service)]
34-
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE: i32 = 100;
34+
pub(crate) const LSPS1_CREATE_ORDER_REQUEST_ORDER_MISMATCH_ERROR_CODE: i64 = 100;
3535

3636
/// The identifier of an order.
3737
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Hash)]

lightning-liquidity/src/lsps2/msgs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ use crate::utils;
3333
pub(crate) const LSPS2_GET_INFO_METHOD_NAME: &str = "lsps2.get_info";
3434
pub(crate) const LSPS2_BUY_METHOD_NAME: &str = "lsps2.buy";
3535

36-
pub(crate) const LSPS2_GET_INFO_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE: i32 = 200;
36+
pub(crate) const LSPS2_GET_INFO_REQUEST_UNRECOGNIZED_OR_STALE_TOKEN_ERROR_CODE: i64 = 200;
3737

38-
pub(crate) const LSPS2_BUY_REQUEST_INVALID_OPENING_FEE_PARAMS_ERROR_CODE: i32 = 201;
39-
pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_SMALL_ERROR_CODE: i32 = 202;
40-
pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_LARGE_ERROR_CODE: i32 = 203;
38+
pub(crate) const LSPS2_BUY_REQUEST_INVALID_OPENING_FEE_PARAMS_ERROR_CODE: i64 = 201;
39+
pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_SMALL_ERROR_CODE: i64 = 202;
40+
pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_LARGE_ERROR_CODE: i64 = 203;
4141

4242
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
4343
/// A request made to an LSP to learn their current channel fees and parameters.

lightning-liquidity/src/lsps5/msgs.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ pub const MAX_APP_NAME_LENGTH: usize = 64;
4141
pub const MAX_WEBHOOK_URL_LENGTH: usize = 1024;
4242

4343
/// Either the app name or the webhook URL is too long.
44-
pub const LSPS5_TOO_LONG_ERROR_CODE: i32 = 500;
44+
pub const LSPS5_TOO_LONG_ERROR_CODE: i64 = 500;
4545
/// The provided URL could not be parsed.
46-
pub const LSPS5_URL_PARSE_ERROR_CODE: i32 = 501;
46+
pub const LSPS5_URL_PARSE_ERROR_CODE: i64 = 501;
4747
/// The provided URL is not HTTPS.
48-
pub const LSPS5_UNSUPPORTED_PROTOCOL_ERROR_CODE: i32 = 502;
48+
pub const LSPS5_UNSUPPORTED_PROTOCOL_ERROR_CODE: i64 = 502;
4949
/// The client has too many webhooks registered.
50-
pub const LSPS5_TOO_MANY_WEBHOOKS_ERROR_CODE: i32 = 503;
50+
pub const LSPS5_TOO_MANY_WEBHOOKS_ERROR_CODE: i64 = 503;
5151
/// The app name was not found.
52-
pub const LSPS5_APP_NAME_NOT_FOUND_ERROR_CODE: i32 = 1010;
52+
pub const LSPS5_APP_NAME_NOT_FOUND_ERROR_CODE: i64 = 1010;
5353
/// An unknown error occurred.
54-
pub const LSPS5_UNKNOWN_ERROR_CODE: i32 = 1000;
54+
pub const LSPS5_UNKNOWN_ERROR_CODE: i64 = 1000;
5555
/// An error occurred during serialization of LSPS5 webhook notification.
56-
pub const LSPS5_SERIALIZATION_ERROR_CODE: i32 = 1001;
56+
pub const LSPS5_SERIALIZATION_ERROR_CODE: i64 = 1001;
5757
/// A notification was sent too frequently.
58-
pub const LSPS5_SLOW_DOWN_ERROR_CODE: i32 = 1002;
58+
pub const LSPS5_SLOW_DOWN_ERROR_CODE: i64 = 1002;
5959
/// A request was rejected because the client has no prior activity with the LSP (no open channel and no active LSPS1 or LSPS2 flow). The client should first open a channel
60-
pub const LSPS5_NO_PRIOR_ACTIVITY_ERROR_CODE: i32 = 1003;
60+
pub const LSPS5_NO_PRIOR_ACTIVITY_ERROR_CODE: i64 = 1003;
6161

6262
pub(crate) const LSPS5_SET_WEBHOOK_METHOD_NAME: &str = "lsps5.set_webhook";
6363
pub(crate) const LSPS5_LIST_WEBHOOKS_METHOD_NAME: &str = "lsps5.list_webhooks";
@@ -126,7 +126,7 @@ pub enum LSPS5ProtocolError {
126126

127127
impl LSPS5ProtocolError {
128128
/// The error code for the LSPS5 protocol error.
129-
pub fn code(&self) -> i32 {
129+
pub fn code(&self) -> i64 {
130130
match self {
131131
LSPS5ProtocolError::AppNameTooLong | LSPS5ProtocolError::WebhookUrlTooLong => {
132132
LSPS5_TOO_LONG_ERROR_CODE
@@ -197,9 +197,9 @@ pub enum LSPS5ClientError {
197197
}
198198

199199
impl LSPS5ClientError {
200-
const BASE: i32 = 100_000;
200+
const BASE: i64 = 100_000;
201201
/// The error code for the client error.
202-
pub fn code(&self) -> i32 {
202+
pub fn code(&self) -> i64 {
203203
use LSPS5ClientError::*;
204204
match self {
205205
InvalidSignature => Self::BASE + 1,

0 commit comments

Comments
 (0)