Browse Source

db: route to extract an array of struct secret from a column.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
9b99b74c41
  1. 12
      wallet/db.c
  2. 3
      wallet/db.h

12
wallet/db.c

@ -525,6 +525,18 @@ bool sqlite3_column_sha256_double(sqlite3_stmt *stmt, int col, struct sha256_do
return memcpy(dest, sqlite3_column_blob(stmt, col), sizeof(struct sha256_double));
}
struct secret *sqlite3_column_secrets(const tal_t *ctx,
sqlite3_stmt *stmt, int col)
{
struct secret *secrets;
size_t n = sqlite3_column_bytes(stmt, col) / sizeof(*secrets);
/* Must fit exactly */
assert(n * sizeof(struct secret) == sqlite3_column_bytes(stmt, col));
secrets = tal_arr(ctx, struct secret, n);
return memcpy(secrets, sqlite3_column_blob(stmt, col), tal_len(secrets));
}
bool sqlite3_bind_sha256_double(sqlite3_stmt *stmt, int col, const struct sha256_double *p)
{
sqlite3_bind_blob(stmt, col, p, sizeof(struct sha256_double), SQLITE_TRANSIENT);

3
wallet/db.h

@ -134,5 +134,6 @@ bool sqlite3_bind_sha256(sqlite3_stmt *stmt, int col, const struct sha256 *p);
bool sqlite3_column_sha256_double(sqlite3_stmt *stmt, int col, struct sha256_double *dest);
bool sqlite3_bind_sha256_double(sqlite3_stmt *stmt, int col, const struct sha256_double *p);
struct secret *sqlite3_column_secrets(const tal_t *ctx,
sqlite3_stmt *stmt, int col);
#endif /* WALLET_DB_H */

Loading…
Cancel
Save