mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
watchtower: Add a struct containing the penalty base information
Suggested-by: Rusty Russell <@rustyrussell>
This commit is contained in:
committed by
Rusty Russell
parent
3a881d9b41
commit
6e323ae0cd
@@ -47,6 +47,7 @@ COMMON_SRC_NOGEN := \
|
|||||||
common/onion.c \
|
common/onion.c \
|
||||||
common/onionreply.c \
|
common/onionreply.c \
|
||||||
common/param.c \
|
common/param.c \
|
||||||
|
common/penalty_base.c \
|
||||||
common/per_peer_state.c \
|
common/per_peer_state.c \
|
||||||
common/peer_billboard.c \
|
common/peer_billboard.c \
|
||||||
common/peer_failed.c \
|
common/peer_failed.c \
|
||||||
|
|||||||
37
common/penalty_base.c
Normal file
37
common/penalty_base.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <common/penalty_base.h>
|
||||||
|
#include <wire/wire.h>
|
||||||
|
|
||||||
|
/* txout must be within tx! */
|
||||||
|
struct penalty_base *penalty_base_new(const tal_t *ctx,
|
||||||
|
u64 commitment_num,
|
||||||
|
const struct bitcoin_tx *tx,
|
||||||
|
const struct wally_tx_output *txout)
|
||||||
|
{
|
||||||
|
struct penalty_base *pbase = tal(ctx, struct penalty_base);
|
||||||
|
|
||||||
|
pbase->commitment_num = commitment_num;
|
||||||
|
bitcoin_txid(tx, &pbase->txid);
|
||||||
|
pbase->outnum = txout - tx->wtx->outputs;
|
||||||
|
assert(pbase->outnum < tx->wtx->num_outputs);
|
||||||
|
pbase->amount.satoshis = txout->satoshi; /* Raw: from wally_tx_output */
|
||||||
|
|
||||||
|
return pbase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void towire_penalty_base(u8 **pptr, const struct penalty_base *pbase)
|
||||||
|
{
|
||||||
|
towire_u64(pptr, pbase->commitment_num);
|
||||||
|
towire_bitcoin_txid(pptr, &pbase->txid);
|
||||||
|
towire_u32(pptr, pbase->outnum);
|
||||||
|
towire_amount_sat(pptr, pbase->amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fromwire_penalty_base(const u8 **pptr, size_t *max,
|
||||||
|
struct penalty_base *pbase)
|
||||||
|
{
|
||||||
|
pbase->commitment_num = fromwire_u64(pptr, max);
|
||||||
|
fromwire_bitcoin_txid(pptr, max, &pbase->txid);
|
||||||
|
pbase->outnum = fromwire_u32(pptr, max);
|
||||||
|
pbase->amount = fromwire_amount_sat(pptr, max);
|
||||||
|
}
|
||||||
30
common/penalty_base.h
Normal file
30
common/penalty_base.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef LIGHTNING_COMMON_PENALTY_BASE_H
|
||||||
|
#define LIGHTNING_COMMON_PENALTY_BASE_H
|
||||||
|
#include "config.h"
|
||||||
|
#include <bitcoin/tx.h>
|
||||||
|
#include <ccan/short_types/short_types.h>
|
||||||
|
#include <common/amount.h>
|
||||||
|
|
||||||
|
/* To create a penalty, all we need are these. */
|
||||||
|
struct penalty_base {
|
||||||
|
/* The remote commitment index. */
|
||||||
|
u64 commitment_num;
|
||||||
|
/* The remote commitment txid. */
|
||||||
|
struct bitcoin_txid txid;
|
||||||
|
/* The remote commitment's "to-local" output. */
|
||||||
|
u32 outnum;
|
||||||
|
/* The amount of the remote commitment's "to-local" output. */
|
||||||
|
struct amount_sat amount;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* txout must be within tx! */
|
||||||
|
struct penalty_base *penalty_base_new(const tal_t *ctx,
|
||||||
|
u64 commitment_num,
|
||||||
|
const struct bitcoin_tx *tx,
|
||||||
|
const struct wally_tx_output *txout);
|
||||||
|
|
||||||
|
void towire_penalty_base(u8 **pptr, const struct penalty_base *pbase);
|
||||||
|
void fromwire_penalty_base(const u8 **ptr, size_t *max,
|
||||||
|
struct penalty_base *pbase);
|
||||||
|
|
||||||
|
#endif /* LIGHTNING_COMMON_PENALTY_BASE_H */
|
||||||
Reference in New Issue
Block a user