Skip to content

Report PaymentStatus using the variant name, not the i32 discriminant of the variant #120

@tankyleo

Description

@tankyleo

Probably part of #14

PaymentStatus is defined in ldk-server-protos/src/types.rs:

/// Represents the current status of a payment.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum PaymentStatus {
        /// The payment is still pending.
        Pending = 0,
        /// The payment succeeded.
        Succeeded = 1,
        /// The payment failed.
        Failed = 2,
}

and we print this struct serialized with serde_json::to_string_pretty in ldk-server-cli/src/main.rs

fn handle_response_result<Rs, Js>(response: Result<Rs, LdkServerError>)
where
        Rs: Into<Js>,
        Js: Serialize + std::fmt::Debug,
{
        match response {
                Ok(response) => {
                        let json_response: Js = response.into();
                        match serde_json::to_string_pretty(&json_response) {
                                Ok(json) => println!("{json}"),
                                Err(e) => {
                                        eprintln!("Error serializing response ({json_response:?}) to JSON: {e}");
                                        std::process::exit(1);
                                },
                        }
                },
                Err(e) => {
                        handle_error(e);
                },
        }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions