core-lightning/plugins/bkpr/channel_event.c

48 lines
1.3 KiB
C

#include "config.h"
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/tal/str/str.h>
#include <common/amount.h>
#include <common/json_stream.h>
#include <plugins/bkpr/channel_event.h>
struct channel_event *new_channel_event(const tal_t *ctx,
const char *tag,
struct amount_msat credit,
struct amount_msat debit,
struct amount_msat fees,
const char *currency,
struct sha256 *payment_id STEALS,
u32 part_id,
u64 timestamp)
{
struct channel_event *ev = tal(ctx, struct channel_event);
ev->tag = tal_strdup(ev, tag);
ev->credit = credit;
ev->debit = debit;
ev->fees = fees;
ev->currency = tal_strdup(ev, currency);
ev->payment_id = tal_steal(ev, payment_id);
ev->part_id = part_id;
ev->timestamp = timestamp;
return ev;
}
void json_add_channel_event(struct json_stream *out,
struct channel_event *ev)
{
json_object_start(out, NULL);
json_add_string(out, "account", ev->acct_name);
json_add_string(out, "type", "channel");
json_add_string(out, "tag", ev->tag);
json_add_amount_msat_only(out, "credit", ev->credit);
json_add_amount_msat_only(out, "debit", ev->debit);
json_add_string(out, "currency", ev->currency);
if (ev->payment_id)
json_add_sha256(out, "payment_id", ev->payment_id);
json_add_u64(out, "timestamp", ev->timestamp);
json_object_end(out);
}