forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common/channel_id: move channel_id into its own file.
The definition was in wire/wire.h, and helper functions in fromwire.c! Signed-off-by: Rusty Russell <[email protected]>
- Loading branch information
1 parent
f02c464
commit fda5f0b
Showing
42 changed files
with
211 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <bitcoin/tx.h> | ||
#include <common/channel_id.h> | ||
#include <common/type_to_string.h> | ||
#include <wire/wire.h> | ||
|
||
void derive_channel_id(struct channel_id *channel_id, | ||
const struct bitcoin_txid *txid, u16 txout) | ||
{ | ||
BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid)); | ||
memcpy(channel_id, txid, sizeof(*channel_id)); | ||
channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8; | ||
channel_id->id[sizeof(*channel_id)-1] ^= txout; | ||
} | ||
|
||
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id) | ||
{ | ||
towire(pptr, channel_id, sizeof(*channel_id)); | ||
} | ||
|
||
void fromwire_channel_id(const u8 **cursor, size_t *max, | ||
struct channel_id *channel_id) | ||
{ | ||
fromwire(cursor, max, channel_id, sizeof(*channel_id)); | ||
} | ||
|
||
REGISTER_TYPE_TO_HEXSTR(channel_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef LIGHTNING_COMMON_CHANNEL_ID_H | ||
#define LIGHTNING_COMMON_CHANNEL_ID_H | ||
#include "config.h" | ||
#include <ccan/short_types/short_types.h> | ||
#include <ccan/structeq/structeq.h> | ||
|
||
struct bitcoin_txid; | ||
|
||
/* BOLT #2: | ||
* | ||
* This message introduces the `channel_id` to identify the channel. It's | ||
* derived from the funding transaction by combining the `funding_txid` and | ||
* the `funding_output_index`, using big-endian exclusive-OR | ||
* (i.e. `funding_output_index` alters the last 2 bytes). | ||
*/ | ||
struct channel_id { | ||
u8 id[32]; | ||
}; | ||
/* Define channel_id_eq (no padding) */ | ||
STRUCTEQ_DEF(channel_id, 0, id); | ||
|
||
void derive_channel_id(struct channel_id *channel_id, | ||
const struct bitcoin_txid *txid, u16 txout); | ||
|
||
/* Marshalling/unmarshalling functions */ | ||
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); | ||
void fromwire_channel_id(const u8 **cursor, size_t *max, | ||
struct channel_id *channel_id); | ||
#endif /* LIGHTNING_COMMON_CHANNEL_ID_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.