rm pullpush: cleans up unused methods for push/pull

most likely unused since the switch to libwally for internal blockchain
things.

these method names were clashing with ones that are to be introduced
with some libwally cleanups, so getting rid of them pre-emptively keeps
us libwally compatible
This commit is contained in:
niftynei
2020-06-22 22:07:55 -05:00
committed by neil saitug
parent 8185474bfb
commit 2ab41af8e2
8 changed files with 48 additions and 137 deletions

View File

@@ -9,7 +9,6 @@ BITCOIN_SRC := \
bitcoin/privkey.c \
bitcoin/psbt.c \
bitcoin/pubkey.c \
bitcoin/pullpush.c \
bitcoin/script.c \
bitcoin/shadouble.c \
bitcoin/short_channel_id.c \
@@ -30,7 +29,6 @@ BITCOIN_HEADERS := bitcoin/address.h \
bitcoin/privkey.h \
bitcoin/psbt.h \
bitcoin/pubkey.h \
bitcoin/pullpush.h \
bitcoin/script.h \
bitcoin/shadouble.h \
bitcoin/short_channel_id.h \

View File

@@ -1,11 +1,58 @@
#include <assert.h>
#include <bitcoin/block.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/pullpush.h>
#include <bitcoin/tx.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
/* Sets *cursor to NULL and returns NULL when a pull fails. */
static const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n)
{
const u8 *p = *cursor;
if (*max < n) {
*cursor = NULL;
*max = 0;
/* Just make sure we don't leak uninitialized mem! */
if (copy)
memset(copy, 0, n);
return NULL;
}
*cursor += n;
*max -= n;
assert(p);
if (copy)
memcpy(copy, p, n);
return memcheck(p, n);
}
static u32 pull_le32(const u8 **cursor, size_t *max)
{
le32 ret;
if (!pull(cursor, max, &ret, sizeof(ret)))
return 0;
return le32_to_cpu(ret);
}
static u64 pull_varint(const u8 **cursor, size_t *max)
{
u64 ret;
size_t len;
len = varint_get(*cursor, *max, &ret);
if (len == 0) {
*cursor = NULL;
*max = 0;
return 0;
}
pull(cursor, max, NULL, len);
return ret;
}
static void sha256_varint(struct sha256_ctx *ctx, u64 val)
{
u8 vt[VARINT_MAX_LEN];

View File

@@ -1,104 +0,0 @@
#include "pullpush.h"
#include "varint.h"
#include <assert.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
void push_varint(varint_t v,
void (*push)(const void *, size_t, void *), void *pushp)
{
u8 buf[VARINT_MAX_LEN];
push(buf, varint_put(buf, v), pushp);
}
void push_le32(u32 v,
void (*push)(const void *, size_t, void *), void *pushp)
{
le32 l = cpu_to_le32(v);
push(&l, sizeof(l), pushp);
}
void push_le64(u64 v,
void (*push)(const void *, size_t, void *), void *pushp)
{
le64 l = cpu_to_le64(v);
push(&l, sizeof(l), pushp);
}
void push_amount_sat(struct amount_sat v,
void (*push)(const void *, size_t, void *), void *pushp)
{
push_le64(v.satoshis, push, pushp); /* Raw: low-level helper */
}
void push_varint_blob(const tal_t *blob,
void (*push)(const void *, size_t, void *),
void *pushp)
{
push_varint(tal_bytelen(blob), push, pushp);
push(blob, tal_bytelen(blob), pushp);
}
void push(const void *data, size_t len, void *pptr_)
{
u8 **pptr = pptr_;
size_t oldsize = tal_count(*pptr);
tal_resize(pptr, oldsize + len);
memcpy(*pptr + oldsize, memcheck(data, len), len);
}
/* Sets *cursor to NULL and returns NULL when a pull fails. */
const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n)
{
const u8 *p = *cursor;
if (*max < n) {
*cursor = NULL;
*max = 0;
/* Just make sure we don't leak uninitialized mem! */
if (copy)
memset(copy, 0, n);
return NULL;
}
*cursor += n;
*max -= n;
assert(p);
if (copy)
memcpy(copy, p, n);
return memcheck(p, n);
}
u64 pull_varint(const u8 **cursor, size_t *max)
{
u64 ret;
size_t len;
len = varint_get(*cursor, *max, &ret);
if (len == 0) {
*cursor = NULL;
*max = 0;
return 0;
}
pull(cursor, max, NULL, len);
return ret;
}
u32 pull_le32(const u8 **cursor, size_t *max)
{
le32 ret;
if (!pull(cursor, max, &ret, sizeof(ret)))
return 0;
return le32_to_cpu(ret);
}
u64 pull_le64(const u8 **cursor, size_t *max)
{
le64 ret;
if (!pull(cursor, max, &ret, sizeof(ret)))
return 0;
return le64_to_cpu(ret);
}

View File

@@ -1,26 +0,0 @@
#ifndef LIGHTNING_BITCOIN_PULLPUSH_H
#define LIGHTNING_BITCOIN_PULLPUSH_H
#include "config.h"
#include "bitcoin/varint.h"
#include <ccan/tal/tal.h>
#include <common/amount.h>
void push_varint(varint_t v,
void (*push)(const void *, size_t, void *), void *pushp);
void push_le32(u32 v, void (*push)(const void *, size_t, void *), void *pushp);
void push_le64(u64 v, void (*push)(const void *, size_t, void *), void *pushp);
void push_amount_sat(struct amount_sat v,
void (*push)(const void *, size_t, void *), void *pushp);
void push_varint_blob(const tal_t *blob,
void (*push)(const void *, size_t, void *),
void *pushp);
u64 pull_varint(const u8 **cursor, size_t *max);
u32 pull_le32(const u8 **cursor, size_t *max);
u64 pull_le64(const u8 **cursor, size_t *max);
/* This extends **pptr by tal_resize */
void push(const void *data, size_t len, void *pptr_);
const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n);
#endif /* LIGHTNING_BITCOIN_PULLPUSH_H */

View File

@@ -1,6 +1,5 @@
#include "../block.c"
#include "../psbt.c"
#include "../pullpush.c"
#include "../shadouble.c"
#include "../tx.c"
#include "../varint.c"

View File

@@ -1,6 +1,5 @@
#include <assert.h>
#include <bitcoin/psbt.c>
#include <bitcoin/pullpush.c>
#include <bitcoin/shadouble.c>
#include <bitcoin/tx.c>
#include <bitcoin/varint.c>

View File

@@ -2,7 +2,6 @@
#include <bitcoin/block.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/psbt.h>
#include <bitcoin/pullpush.h>
#include <bitcoin/script.h>
#include <bitcoin/tx.h>
#include <ccan/cast/cast.h>

View File

@@ -22,7 +22,6 @@ PLUGIN_COMMON_OBJS := \
bitcoin/privkey.o \
bitcoin/psbt.o \
bitcoin/pubkey.o \
bitcoin/pullpush.o \
bitcoin/script.o \
bitcoin/shadouble.o \
bitcoin/short_channel_id.o \