core-lightning/funding.h
Rusty Russell 3260fb2ed1 protocol: add commitment fee logic.
Both sides elect a commitment fee, and the lowest is chosen.  That means
you can't game the other side (but if you offer too low, then can error
out of course).

Fees are split 50-50 if possible: originally the whole fee has to be
paid by the (single) funder.  Neither side can withdraw funds which
would make them unable to pay fees.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-07-29 16:16:24 +09:30

50 lines
1.4 KiB
C

#ifndef LIGHTNING_FUNDING_H
#define LIGHTNING_FUNDING_H
#include <stdbool.h>
#include "lightning.pb-c.h"
/**
* initial_funding: Given A, B, and anchor, what is initial state?
* @a: A's openchannel offer
* @b: B's openchannel offer
* @anchor: The anchor offer (A or B)
* @fee: amount to pay in fees.
* @a_amount: amount commit tx will output to A.
* @b_amount: amount commit tx will output to B.
*/
bool initial_funding(const OpenChannel *a,
const OpenChannel *b,
const OpenAnchor *anchor,
uint64_t fee,
uint64_t *a_amount,
uint64_t *b_amount);
/**
* funding_delta: With this change, what's the new state?
* @a: A's openchannel offer
* @b: B's openchannel offer
* @anchor: The anchor offer (A or B)
* @fee: amount to pay in fees.
* @channel_delta: In/out amount funder pays to non-funder (channel state)
* @delta_a_to_b: How much A pays to B (satoshi).
* @a_amount: amount commit tx will output to A.
* @b_amount: amount commit tx will output to B.
*/
bool funding_delta(const OpenChannel *a,
const OpenChannel *b,
const OpenAnchor *anchor,
uint64_t fee,
uint64_t *channel_delta,
int64_t delta_a_to_b,
uint64_t *a_amount,
uint64_t *b_amount);
/**
* commit_fee: Fee amount for commit tx.
* @a: A's openchannel offer
* @b: B's openchannel offer
*/
uint64_t commit_fee(const OpenChannel *a, const OpenChannel *b);
#endif /* LIGHTNING_FUNDING_H */