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.
Move short_channel_id primitive into bitcoin
Not really a bitcoin primitive but the place where we keep all the small stuff currently.
- Loading branch information
1 parent
5912c68
commit fa6e53b
Showing
7 changed files
with
65 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <bitcoin/short_channel_id.h> | ||
#include <ccan/tal/str/str.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
bool short_channel_id_from_str(const char *str, size_t strlen, | ||
struct short_channel_id *dst) | ||
{ | ||
u32 blocknum, txnum; | ||
u16 outnum; | ||
int matches; | ||
|
||
char buf[strlen + 1]; | ||
memcpy(buf, str, strlen); | ||
buf[strlen] = 0; | ||
|
||
matches = sscanf(buf, "%u:%u:%hu", &blocknum, &txnum, &outnum); | ||
dst->blocknum = blocknum; | ||
dst->txnum = txnum; | ||
dst->outnum = outnum; | ||
return matches == 3; | ||
} | ||
|
||
char *short_channel_id_to_str(tal_t *ctx, const struct short_channel_id *scid) | ||
{ | ||
return tal_fmt(ctx, "%d:%d:%d", scid->blocknum, scid->txnum, scid->outnum); | ||
} | ||
|
||
bool short_channel_id_eq(const struct short_channel_id *a, | ||
const struct short_channel_id *b) | ||
{ | ||
return a->blocknum == b->blocknum && a->txnum == b->txnum && | ||
a->outnum == b->outnum; | ||
} |
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,28 @@ | ||
#ifndef LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H | ||
#define LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H | ||
#include "config.h" | ||
#include <ccan/short_types/short_types.h> | ||
#include <ccan/tal/tal.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
|
||
/* Short Channel ID is composed of 3 bytes for the block height, 3 | ||
* bytes of tx index in block and 2 bytes of output index. The | ||
* bitfield is mainly for unit tests where it is nice to be able to | ||
* just memset them and not have to take care about the extra byte for | ||
* u32 */ | ||
struct short_channel_id { | ||
u32 blocknum : 24; | ||
u32 txnum : 24; | ||
u16 outnum; | ||
}; | ||
|
||
bool short_channel_id_from_str(const char *str, size_t strlen, | ||
struct short_channel_id *dst); | ||
|
||
bool short_channel_id_eq(const struct short_channel_id *a, | ||
const struct short_channel_id *b); | ||
|
||
char *short_channel_id_to_str(tal_t *ctx, const struct short_channel_id *scid); | ||
|
||
#endif /* LIGHTNING_BITCOIN_SHORT_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