diff --git a/wallet/db.c b/wallet/db.c index 225089ada..e6fe5db4c 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1,6 +1,5 @@ #include "db.h" -#include #include #include #include @@ -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) { diff --git a/wallet/db.h b/wallet/db.h index 5641f25c5..9064bb21d 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -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 * diff --git a/wallet/wallet.c b/wallet/wallet.c index 4c790ccd4..a2637d7a7 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1,7 +1,6 @@ #include "wallet.h" #include -#include #include #include #include diff --git a/wallet/wallet_tests.c b/wallet/wallet_tests.c index 709a0d073..bba988e53 100644 --- a/wallet/wallet_tests.c +++ b/wallet/wallet_tests.c @@ -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;