mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +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
@@ -101,6 +101,27 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
|
||||
return ret;
|
||||
}
|
||||
|
||||
u64 fromwire_var_int(const u8 **cursor, size_t *max)
|
||||
{
|
||||
if (*max < 1) {
|
||||
fromwire_fail(cursor, max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 flag = fromwire_u8(cursor, max);
|
||||
|
||||
switch(flag) {
|
||||
case 0xff:
|
||||
return fromwire_u64(cursor, max);
|
||||
case 0xfe:
|
||||
return (u64)fromwire_u32(cursor, max);
|
||||
case 0xfd:
|
||||
return (u64)fromwire_u16(cursor, max);
|
||||
default:
|
||||
return (u64)flag;
|
||||
}
|
||||
}
|
||||
|
||||
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
|
||||
{
|
||||
u8 der[PUBKEY_DER_LEN];
|
||||
|
||||
Reference in New Issue
Block a user