mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
db: Cleanup all remaining traces of hex-encoded values
In addition we also set some of the test values to a pattern instead of just `memset`ting it to 0, which may hide some crossed lines. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
c1d364c5fb
commit
da183c22a0
4 changed files with 18 additions and 21 deletions
10
wallet/db.c
10
wallet/db.c
|
@ -1,6 +1,5 @@
|
|||
#include "db.h"
|
||||
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <inttypes.h>
|
||||
|
@ -411,15 +410,6 @@ bool db_set_intvar(struct db *db, char *varname, s64 val)
|
|||
varname, val);
|
||||
}
|
||||
|
||||
bool sqlite3_column_hexval(sqlite3_stmt *s, int col, void *dest, size_t destlen)
|
||||
{
|
||||
const char *source = sqlite3_column_blob(s, col);
|
||||
size_t sourcelen = sqlite3_column_bytes(s, col);
|
||||
if (sourcelen / 2 != destlen)
|
||||
return false;
|
||||
return hex_decode(source, sourcelen, dest, destlen);
|
||||
}
|
||||
|
||||
bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col,
|
||||
const struct short_channel_id *id)
|
||||
{
|
||||
|
|
|
@ -79,12 +79,6 @@ bool db_set_intvar(struct db *db, char *varname, s64 val);
|
|||
*/
|
||||
s64 db_get_intvar(struct db *db, char *varname, s64 defval);
|
||||
|
||||
/**
|
||||
* sqlite3_column_hexval - Helper to populate a binary field from a hex value
|
||||
*/
|
||||
bool sqlite3_column_hexval(sqlite3_stmt *s, int col, void *dest,
|
||||
size_t destlen);
|
||||
|
||||
/**
|
||||
* db_prepare -- Prepare a DB query/command
|
||||
*
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "wallet.h"
|
||||
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <inttypes.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
|
|
|
@ -11,6 +11,20 @@
|
|||
void invoice_add(struct invoices *invs,
|
||||
struct invoice *inv){}
|
||||
|
||||
/**
|
||||
* mempat -- Set the memory to a pattern
|
||||
*
|
||||
* Used mainly to check that we don't mix fields while
|
||||
* serializing/unserializing.
|
||||
*/
|
||||
static void mempat(void *dst, size_t len)
|
||||
{
|
||||
static int n = 0;
|
||||
u8 *p = (u8*)dst;
|
||||
for(int i=0 ; i < len; ++i)
|
||||
p[i] = n % 251; /* Prime */
|
||||
}
|
||||
|
||||
static struct wallet *create_test_wallet(const tal_t *ctx)
|
||||
{
|
||||
char filename[] = "/tmp/ldb-XXXXXX";
|
||||
|
@ -204,12 +218,12 @@ static bool test_channel_crud(const tal_t *ctx)
|
|||
memset(c2, 0, sizeof(*c2));
|
||||
memset(&p, 0, sizeof(p));
|
||||
memset(&ci, 3, sizeof(ci));
|
||||
memset(hash, 'B', sizeof(*hash));
|
||||
memset(sig, 0, sizeof(*sig));
|
||||
memset(&last_commit, 0, sizeof(last_commit));
|
||||
mempat(hash, sizeof(*hash));
|
||||
mempat(sig, sizeof(*sig));
|
||||
mempat(&last_commit, sizeof(last_commit));
|
||||
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
|
||||
ci.feerate_per_kw = 31337;
|
||||
memset(&p.id, 'A', sizeof(p.id));
|
||||
mempat(&p.id, sizeof(p.id));
|
||||
c1.peer = &p;
|
||||
p.id = pk;
|
||||
p.our_msatoshi = NULL;
|
||||
|
|
Loading…
Add table
Reference in a new issue