mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
wire: add var_int parsing functions
so we can put and pull bitcoin 'var_int' length types from the wire. for more info on variable integers, see http://learnmeabitcoin.com/glossary/varint
This commit is contained in:
committed by
Rusty Russell
parent
1213f44071
commit
74ae9f09ac
@@ -54,6 +54,22 @@ void towire_bool(u8 **pptr, bool v)
|
||||
towire(pptr, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void towire_var_int(u8 **pptr, const u64 val)
|
||||
{
|
||||
if (val < 0xfd) {
|
||||
towire_u8(pptr, (u8)val);
|
||||
} else if (val <= 0xffff) {
|
||||
towire_u8(pptr, 0xfd);
|
||||
towire_u16(pptr, (u16)val);
|
||||
} else if (val <= 0xffffffff) {
|
||||
towire_u8(pptr, 0xfe);
|
||||
towire_u32(pptr, (u32)val);
|
||||
} else {
|
||||
towire_u8(pptr, 0xff);
|
||||
towire_u64(pptr, val);
|
||||
}
|
||||
}
|
||||
|
||||
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
|
||||
{
|
||||
u8 output[PUBKEY_DER_LEN];
|
||||
|
||||
Reference in New Issue
Block a user