mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-03 20:44:54 +01:00
55173a56b7
Before this patch we used `int` for error codes. The problem with `int` is that we try to pass it to/from wire and the size of `int` is not defined by the standard. So a sender with 4-byte `int` would write 4 bytes to the wire and a receiver with 2-byte `int` (for example) would read just 2 bytes from the wire. To resolve this: * Introduce an error code type with a known size: `typedef s32 errcode_t`. * Change all error code macros to constants of type `errcode_t`. Constants also play better with gdb - it would visualize the name of the constant instead of the numeric value. * Change all functions that take error codes to take the new type `errcode_t` instead of `int`. * Introduce towire / fromwire functions to send / receive the newly added type `errcode_t` and use it instead of `towire_int()`. In addition: * Remove the now unneeded `towire_int()`. * Replace a hardcoded error code `-2` with a new constant `INVOICE_EXPIRED_DURING_WAIT` (903). Changelog-Changed: The waitinvoice command would now return error code 903 to designate that the invoice expired during wait, instead of the previous -2
72 lines
2.4 KiB
C
72 lines
2.4 KiB
C
#ifndef LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
|
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
|
|
#include "config.h"
|
|
#include <bitcoin/short_channel_id.h>
|
|
#include <bitcoin/tx.h>
|
|
#include <ccan/autodata/autodata.h>
|
|
#include <ccan/json_escape/json_escape.h>
|
|
#include <ccan/time/time.h>
|
|
#include <common/amount.h>
|
|
#include <common/errcode.h>
|
|
#include <common/node_id.h>
|
|
#include <lightningd/htlc_end.h>
|
|
#include <lightningd/jsonrpc.h>
|
|
#include <lightningd/lightningd.h>
|
|
#include <lightningd/log.h>
|
|
#include <lightningd/pay.h>
|
|
#include <lightningd/plugin.h>
|
|
#include <wallet/wallet.h>
|
|
#include <wire/gen_onion_wire.h>
|
|
|
|
struct onionreply;
|
|
|
|
bool notifications_have_topic(const char *topic);
|
|
|
|
struct notification {
|
|
const char *topic;
|
|
/* the serialization interface */
|
|
void *serialize;
|
|
};
|
|
|
|
AUTODATA_TYPE(notifications, struct notification);
|
|
|
|
/* FIXME: Find a way to avoid back-to-back declaration and definition */
|
|
#define REGISTER_NOTIFICATION(topic, serialize) \
|
|
struct notification topic##_notification_gen = { \
|
|
stringify(topic), \
|
|
serialize, \
|
|
}; \
|
|
AUTODATA(notifications, &topic##_notification_gen);
|
|
|
|
void notify_connect(struct lightningd *ld, struct node_id *nodeid,
|
|
struct wireaddr_internal *addr);
|
|
void notify_disconnect(struct lightningd *ld, struct node_id *nodeid);
|
|
|
|
void notify_warning(struct lightningd *ld, struct log_entry *l);
|
|
|
|
void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount,
|
|
struct preimage preimage, const struct json_escape *label);
|
|
|
|
void notify_channel_opened(struct lightningd *ld, struct node_id *node_id,
|
|
struct amount_sat *funding_sat, struct bitcoin_txid *funding_txid,
|
|
bool *funding_locked);
|
|
|
|
void notify_forward_event(struct lightningd *ld,
|
|
const struct htlc_in *in,
|
|
const struct htlc_out *out,
|
|
enum forward_status state,
|
|
enum onion_type failcode,
|
|
struct timeabs *resolved_time);
|
|
|
|
void notify_sendpay_success(struct lightningd *ld,
|
|
const struct wallet_payment *payment);
|
|
|
|
void notify_sendpay_failure(struct lightningd *ld,
|
|
const struct wallet_payment *payment,
|
|
errcode_t pay_errcode,
|
|
const struct onionreply *onionreply,
|
|
const struct routing_failure *fail,
|
|
const char *errmsg);
|
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */
|